:root {
  --bg: #f2f4f1;
  --surface: #ffffff;
  --surface-soft: #f7f8f6;
  --ink: #16251f;
  --muted: #65736d;
  --line: #dde3df;
  --line-strong: #cbd4ce;
  --green: #173f36;
  --green-2: #235b4d;
  --mint: #c9f3da;
  --mint-ink: #18513f;
  --blue: #dcecf8;
  --blue-ink: #275b78;
  --amber: #fae9c8;
  --amber-ink: #8a5b12;
  --red: #f8ded9;
  --red-ink: #9a3c2e;
  --shadow: 0 12px 30px rgba(31, 54, 45, .07);
  --radius: 16px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(rgba(242, 244, 241, .78), rgba(242, 244, 241, .88)),
    url("atyrau-background.png") center bottom / cover fixed no-repeat;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button { color: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid rgba(203, 212, 206, .75);
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(18px);
}

.topbar__inner {
  width: min(1420px, calc(100% - 48px));
  height: 72px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
}

.brand__mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  color: #fff;
  background: var(--green);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -.03em;
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 14px; letter-spacing: -.01em; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 12px; }

.topbar__actions { display: flex; align-items: center; gap: 14px; }

.storage-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.storage-state__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #42b982;
  box-shadow: 0 0 0 4px rgba(66, 185, 130, .12);
}

.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  list-style: none;
  transition: border-color .18s ease, background .18s ease, transform .18s ease;
}

.icon-button:hover { border-color: var(--line-strong); background: var(--surface-soft); }
.icon-button:active { transform: translateY(1px); }
.icon-button svg { width: 19px; height: 19px; fill: currentColor; stroke: none; }
.icon-button--light { color: var(--muted); }
.icon-button--light svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

.more-menu { position: relative; }
.more-menu summary::-webkit-details-marker { display: none; }
.more-menu__panel {
  position: absolute;
  right: 0;
  top: calc(100% + 9px);
  width: 245px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
  box-shadow: 0 18px 40px rgba(22, 37, 31, .14);
}

.more-menu__panel button {
  width: 100%;
  padding: 10px 11px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
}

.more-menu__panel button:hover { background: var(--surface-soft); }
.more-menu__panel svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.more-menu__divider { height: 1px; margin: 6px 4px; background: var(--line); }
.danger-text { color: var(--red-ink) !important; }

.page-shell {
  width: min(1420px, calc(100% - 48px));
  margin: 0 auto;
  padding: 42px 0 72px;
}

.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--green-2);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .11em;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 7px; font-size: clamp(30px, 3.6vw, 48px); line-height: 1.03; letter-spacing: -.045em; }
.page-heading__subtitle { margin-bottom: 0; color: var(--muted); font-size: 15px; }

.primary-button, .secondary-button, .ghost-button, .delete-button {
  min-height: 42px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border-radius: 11px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 750;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease, border-color .16s ease;
}

.primary-button {
  border: 1px solid var(--green);
  color: #fff;
  background: var(--green);
  box-shadow: 0 8px 18px rgba(23, 63, 54, .16);
}
.primary-button:hover { background: #0f342c; box-shadow: 0 10px 22px rgba(23, 63, 54, .22); }
.primary-button:active, .secondary-button:active, .ghost-button:active { transform: translateY(1px); }
.primary-button svg, .delete-button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.secondary-button { border: 1px solid var(--line-strong); background: #fff; }
.secondary-button:hover { background: var(--surface-soft); }
.ghost-button { min-height: 38px; padding-inline: 13px; border: 1px solid var(--line); background: transparent; color: var(--muted); }
.ghost-button:hover { border-color: var(--line-strong); color: var(--ink); background: #fff; }

.kpi-grid {
  margin-top: 30px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.kpi-card {
  min-height: 138px;
  padding: 22px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .92);
  box-shadow: var(--shadow);
}

.kpi-card--dark { color: #fff; border-color: var(--green); background: var(--green); }
.kpi-card__icon { flex: 0 0 39px; width: 39px; height: 39px; display: grid; place-items: center; border-radius: 11px; color: #fff; background: rgba(255,255,255,.13); }
.kpi-card__icon--mint { color: var(--mint-ink); background: var(--mint); }
.kpi-card__icon--blue { color: var(--blue-ink); background: var(--blue); }
.kpi-card__icon--amber { color: var(--amber-ink); background: var(--amber); }
.kpi-card__icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.kpi-card span { display: block; margin: 1px 0 6px; color: var(--muted); font-size: 12px; font-weight: 650; }
.kpi-card--dark span, .kpi-card--dark small { color: rgba(255,255,255,.66); }
.kpi-card strong { display: block; font-size: clamp(24px, 2.2vw, 32px); line-height: 1; letter-spacing: -.035em; }
.kpi-card small { display: block; margin-top: 8px; color: var(--muted); font-size: 11px; }

.registry-card {
  margin-top: 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.registry-card__header { padding: 24px 25px 18px; display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.registry-card__header h2 { margin-bottom: 4px; font-size: 19px; letter-spacing: -.02em; }
.registry-card__header p, .last-updated { margin-bottom: 0; color: var(--muted); font-size: 12px; }
.last-updated { padding-top: 4px; }

.filters { padding: 0 25px 18px; display: flex; align-items: flex-end; gap: 10px; }
.search-field { position: relative; flex: 1 1 440px; min-width: 240px; }
.search-field svg { position: absolute; left: 13px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); fill: none; stroke: #89958f; stroke-width: 1.8; stroke-linecap: round; }
.search-field input { width: 100%; height: 42px; padding: 0 14px 0 41px; border: 1px solid var(--line); border-radius: 10px; outline: 0; background: var(--surface-soft); color: var(--ink); }
.search-field input:focus { border-color: #75a898; background: #fff; box-shadow: 0 0 0 3px rgba(117, 168, 152, .12); }

.select-field { min-width: 170px; }
.select-field > span { display: block; margin: 0 0 5px 2px; color: var(--muted); font-size: 10px; font-weight: 750; text-transform: uppercase; letter-spacing: .06em; }
.select-field select { width: 100%; height: 42px; padding: 0 35px 0 12px; border: 1px solid var(--line); border-radius: 10px; outline: 0; background: var(--surface-soft); color: var(--ink); font-size: 13px; }
.select-field select:focus { border-color: #75a898; box-shadow: 0 0 0 3px rgba(117, 168, 152, .12); }

.table-wrap { overflow-x: auto; border-top: 1px solid var(--line); }
table { width: 100%; min-width: 1020px; border-collapse: collapse; }
th { height: 42px; padding: 0 16px; color: #748078; background: #f7f8f6; text-align: left; font-size: 10px; font-weight: 800; letter-spacing: .065em; text-transform: uppercase; }
th:first-child, td:first-child { padding-left: 25px; }
th:last-child, td:last-child { width: 58px; padding-right: 18px; }
td { padding: 15px 16px; border-top: 1px solid #edf0ee; vertical-align: middle; font-size: 13px; }
tbody tr { transition: background .14s ease; }
tbody tr:hover { background: #fbfcfb; }

.client-cell { min-width: 240px; }
.client-cell strong { display: block; max-width: 360px; color: var(--ink); font-size: 13px; line-height: 1.35; }
.client-cell span { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.money-cell { white-space: nowrap; font-weight: 750; font-variant-numeric: tabular-nums; }
.condition-cell strong, .delay-cell strong { display: block; font-size: 13px; }
.condition-cell span, .delay-cell span, .end-cell span { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.end-cell { text-transform: capitalize; }

.status-badge {
  width: max-content;
  max-width: 170px;
  padding: 5px 9px;
  border-radius: 999px;
  color: #54615b;
  background: #e9eeeb;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .015em;
  white-space: nowrap;
}
.status-badge--approved { color: var(--mint-ink); background: var(--mint); }
.status-badge--pending { color: var(--amber-ink); background: var(--amber); }
.status-badge--rejected { color: var(--red-ink); background: var(--red); }
.status-badge--review { color: var(--blue-ink); background: var(--blue); }

.row-action { width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid transparent; border-radius: 9px; background: transparent; color: #75827b; cursor: pointer; }
.row-action:hover { border-color: var(--line); background: #fff; color: var(--ink); }
.row-action svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.empty-state { padding: 68px 24px 74px; text-align: center; }
.empty-state__icon { width: 48px; height: 48px; margin: 0 auto 15px; display: grid; place-items: center; border-radius: 14px; color: var(--green-2); background: var(--mint); }
.empty-state__icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.empty-state h3 { margin-bottom: 6px; font-size: 16px; }
.empty-state p { margin-bottom: 16px; color: var(--muted); font-size: 13px; }

.record-dialog {
  width: min(910px, calc(100% - 32px));
  max-height: min(880px, calc(100vh - 32px));
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 30px 90px rgba(15, 35, 28, .28);
}
.record-dialog::backdrop { background: rgba(13, 30, 25, .48); backdrop-filter: blur(4px); }
.record-dialog form { max-height: inherit; display: flex; flex-direction: column; }
.dialog-head { flex: 0 0 auto; padding: 22px 24px 18px; display: flex; align-items: flex-start; justify-content: space-between; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin-bottom: 0; font-size: 23px; letter-spacing: -.025em; }
.dialog-body { overflow-y: auto; padding: 4px 24px 8px; }
.form-section { padding: 24px 0 26px; border-bottom: 1px solid var(--line); }
.form-section:last-child { border-bottom: 0; }
.form-section__heading { margin-bottom: 18px; display: flex; align-items: flex-start; gap: 12px; }
.form-section__heading > span { width: 29px; height: 29px; flex: 0 0 29px; display: grid; place-items: center; border-radius: 9px; color: var(--mint-ink); background: var(--mint); font-size: 10px; font-weight: 850; }
.form-section__heading h3 { margin-bottom: 3px; font-size: 15px; }
.form-section__heading p { margin-bottom: 0; color: var(--muted); font-size: 11px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.field { display: block; }
.field--wide { grid-column: 1 / -1; }
.field > span { display: block; margin: 0 0 6px 2px; color: #4f5d56; font-size: 11px; font-weight: 750; }
.field b { color: var(--red-ink); }
.field input, .field select, .field textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; outline: 0; background: var(--surface-soft); color: var(--ink); font-size: 13px; transition: border-color .15s ease, background .15s ease, box-shadow .15s ease; }
.field input, .field select { height: 41px; padding: 0 12px; }
.field textarea { min-height: 80px; padding: 11px 12px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: #75a898; background: #fff; box-shadow: 0 0 0 3px rgba(117, 168, 152, .12); }
.field input:invalid:not(:placeholder-shown) { border-color: #d78374; }

.history-fill {
  margin-top: -3px;
  padding: 11px 13px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid #b9dfcc;
  border-radius: 10px;
  color: var(--mint-ink);
  background: #eefaf3;
}
.history-fill svg { width: 19px; height: 19px; flex: 0 0 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.history-fill strong, .history-fill span { display: block; }
.history-fill strong { margin-bottom: 2px; font-size: 11px; }
.history-fill span { color: #4f7465; font-size: 10px; line-height: 1.35; }

.dialog-foot { flex: 0 0 auto; min-height: 72px; padding: 14px 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-top: 1px solid var(--line); background: #fbfcfb; }
.dialog-foot__right { margin-left: auto; display: flex; align-items: center; gap: 9px; }
.delete-button { padding: 0; border: 0; background: transparent; color: var(--red-ink); }
.delete-button:hover { text-decoration: underline; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 80;
  min-width: 220px;
  max-width: calc(100% - 32px);
  padding: 12px 16px;
  border-radius: 11px;
  color: #fff;
  background: #173f36;
  box-shadow: 0 14px 35px rgba(16, 43, 35, .24);
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 14px);
  transition: opacity .2s ease, transform .2s ease;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1080px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters { flex-wrap: wrap; }
  .search-field { flex-basis: 100%; }
  .select-field { flex: 1 1 180px; }
}

@media (max-width: 680px) {
  .topbar__inner, .page-shell { width: min(100% - 28px, 1420px); }
  .topbar__inner { height: 64px; }
  .storage-state { display: none; }
  .page-shell { padding-top: 28px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .page-heading .primary-button { width: 100%; }
  .kpi-grid { grid-template-columns: 1fr; gap: 10px; }
  .kpi-card { min-height: 112px; padding: 18px; }
  .registry-card__header { padding: 20px 18px 15px; }
  .last-updated { display: none; }
  .filters { padding: 0 18px 16px; }
  .select-field { min-width: 0; flex-basis: calc(50% - 5px); }
  .filters > .ghost-button { width: 100%; }
  th:first-child, td:first-child { padding-left: 18px; }
  .record-dialog { width: 100%; max-width: none; max-height: 95vh; margin: auto 0 0; border-radius: 18px 18px 0 0; }
  .dialog-head, .dialog-body, .dialog-foot { padding-left: 18px; padding-right: 18px; }
  .form-grid { grid-template-columns: 1fr; }
  .field--wide { grid-column: auto; }
  .dialog-foot { align-items: stretch; flex-direction: column-reverse; }
  .dialog-foot__right { width: 100%; margin: 0; }
  .dialog-foot__right > * { flex: 1; }
  .delete-button { align-self: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
