:root {
  --bg: #f4f1ec;
  --fg: #1c1917;
  --muted: #57534e;
  --faint: #78716c;
  --card: #fffcf8;
  --border: #e4ddd4;
  --line: #ece6de;
  --accent: #b4232c;
  --accent-ink: #8e1522;
  --accent-soft: #f8e8e6;
  --ok: #166534;
  --ok-soft: #e8f3ec;
  --warn: #92400e;
  --warn-soft: #f8efd8;
  --danger: #9f1239;
  --danger-soft: #fde8ee;
  --sidebar: #161311;
  --sidebar-ink: #f5f0ea;
  --shadow: 0 1px 0 rgba(28, 25, 23, 0.04), 0 16px 40px rgba(28, 25, 23, 0.05);
  --radius: 16px;
  --font: "Montserrat", "Segoe UI", sans-serif;
  --display: "Cormorant", Georgia, serif;
  --sidebar-w: 272px;
  color-scheme: light;
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
}

button, input, select, textarea { font: inherit; color: inherit; }

button { cursor: pointer; }

img { max-width: 100%; display: block; }

h1, h2, h3, p { margin: 0; }

a { color: var(--accent-ink); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* Boot */
#boot {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: #120f0d;
  color: #f7f2eb;
  overflow: hidden;
}

#boot.is-leaving {
  animation: boot-out 0.7s cubic-bezier(0.7, 0, 0.2, 1) forwards;
}

.boot-glow {
  position: absolute;
  width: 520px;
  height: 520px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(180, 35, 44, 0.45), transparent 68%);
  filter: blur(8px);
  animation: glow-in 1.4s ease both;
}

.boot-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px;
  width: min(440px, 92vw);
}

.boot-logo {
  position: relative;
  width: 168px;
  height: 168px;
  animation: logo-in 0.9s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.boot-logo img {
  width: 168px;
  height: 168px;
  border-radius: 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

.boot-ring {
  position: absolute;
  inset: -16px;
  border: 1px solid rgba(244, 196, 196, 0.7);
  border-radius: 40px;
  animation: ring-out 1.6s ease-out 0.2s both;
}

.boot-kicker {
  margin-top: 28px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 600;
  color: #e7b4b4;
  animation: rise 0.7s ease 0.35s both;
}

#boot-title {
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(48px, 8vw, 72px);
  line-height: 0.9;
  font-style: italic;
  animation: rise 0.8s ease 0.48s both;
}

.boot-address {
  margin-top: 10px;
  color: #d6cdc3;
  font-size: 14px;
  animation: rise 0.8s ease 0.6s both;
}

.boot-progress {
  width: 100%;
  margin-top: 36px;
  animation: rise 0.8s ease 0.72s both;
}

.boot-track {
  height: 2px;
  background: rgba(255, 255, 255, 0.16);
  border-radius: 99px;
  overflow: hidden;
}

#boot-bar {
  display: block;
  height: 100%;
  width: 0;
  background: #e8c6c4;
}

#boot-status {
  margin-top: 12px;
  min-height: 1.5em;
  font-size: 13px;
  color: #cfc4b8;
}

.boot-skip {
  margin-top: 22px;
  background: transparent;
  color: #f3ebe3;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  min-height: 44px;
  padding: 0 18px;
  animation: rise 0.8s ease 0.85s both;
}

.boot-skip:hover { background: rgba(255, 255, 255, 0.06); }

@keyframes logo-in {
  from { opacity: 0; transform: scale(0.92) translateY(8px); }
  to { opacity: 1; transform: none; }
}

@keyframes ring-out {
  from { opacity: 0; transform: scale(0.86); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes glow-in {
  from { opacity: 0; transform: scale(0.7); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

@keyframes boot-out {
  to { opacity: 0; visibility: hidden; transform: scale(1.03); }
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 35;
  display: grid;
  place-items: center;
  padding: 24px;
  color: #f7f2eb;
  background: radial-gradient(circle at 50% 42%, rgba(180, 35, 44, 0.2), transparent 38%), #120f0d;
}

.login-screen[hidden] { display: none; }

.login-card {
  width: min(400px, 100%);
  text-align: center;
  padding: 34px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.035);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
}

.login-card > img {
  width: 72px;
  height: 72px;
  margin: 0 auto 18px;
  border-radius: 14px;
}

.login-kicker {
  color: #e7b4b4;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.login-card h1 {
  margin-top: 8px;
  font-family: var(--display);
  font-size: 42px;
  font-weight: 500;
}

.login-copy { margin-top: 6px; color: #cfc4b8; font-size: 13px; }

.login-form { display: grid; gap: 9px; margin-top: 24px; text-align: left; }
.login-form label { font-size: 13px; font-weight: 600; }
.login-form input {
  min-height: 46px;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  color: #fff;
  background: rgba(0, 0, 0, 0.25);
}
.login-form button {
  min-height: 46px;
  margin-top: 6px;
  border: 0;
  border-radius: 10px;
  color: #fff;
  background: var(--accent);
  font-weight: 600;
}
.login-form button:hover { background: var(--accent-ink); }
.login-error { color: #ffb8c5; font-size: 12px; }
.login-error[hidden] { display: none; }

/* Shell */
#app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
}

#app.is-in .workspace { animation: rise 0.45s ease both; }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  color: var(--sidebar-ink);
  padding: 22px 16px 18px;
  overflow: auto;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  text-decoration: none;
  color: inherit;
  padding: 4px 8px 18px;
}

.brand img {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  background: #fff;
}

.brand strong {
  display: block;
  font-size: 13px;
  letter-spacing: 0.16em;
  font-weight: 700;
}

.brand em {
  display: block;
  margin-top: 2px;
  font-family: var(--display);
  font-style: italic;
  font-size: 22px;
  font-weight: 500;
  line-height: 1;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  text-align: left;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #e7e0d8;
  padding: 8px 10px;
  transition: background 0.18s ease, color 0.18s ease;
}

.nav button svg { width: 18px; height: 18px; flex: 0 0 auto; }

.nav button:hover { background: rgba(255, 255, 255, 0.06); }

.nav button[aria-current="page"] {
  background: rgba(180, 35, 44, 0.22);
  color: #fff;
  box-shadow: inset 2px 0 0 var(--accent);
}

.sidebar-foot {
  margin-top: auto;
  padding: 16px 10px 4px;
  color: #b7aea4;
  font-size: 12px;
  line-height: 1.6;
}

.workspace { min-width: 0; }

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: flex-end;
  gap: 20px;
  padding: 22px 32px 16px;
  background: rgba(244, 241, 236, 0.88);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid transparent;
}

.top-title { min-width: 0; }

.eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent-ink);
}

#view-title {
  font-family: var(--display);
  font-size: clamp(36px, 4vw, 52px);
  font-weight: 500;
  line-height: 0.95;
  letter-spacing: -0.02em;
}

.top-tools {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  width: min(320px, 42vw);
  padding: 0 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.search svg { width: 16px; height: 16px; color: var(--faint); }

.search input {
  width: 100%;
  border: 0;
  background: transparent;
  min-height: 40px;
  outline: none;
}

.search:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

.top-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.status-open {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--ok-soft);
  color: var(--ok);
  font-weight: 600;
}

.status-open::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
}

.menu-btn { display: none; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: inherit;
}

.icon-btn svg { width: 20px; height: 20px; }

main {
  padding: 8px 32px 48px;
}

.lead {
  max-width: 68ch;
  color: var(--muted);
  margin: 4px 0 22px;
}

.grid {
  display: grid;
  gap: 16px;
}

.kpis { grid-template-columns: repeat(4, 1fr); }

.split { grid-template-columns: 1.4fr 0.8fr; margin-top: 16px; }

main > .split:first-child { margin-top: 0; }

.thirds { grid-template-columns: 1.1fr 0.9fr; margin-top: 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 18px 16px;
}

.card h2 {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.kpi strong {
  display: block;
  margin-top: 10px;
  font-size: 28px;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.finance-load {
  min-height: 320px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 16px;
  color: var(--muted);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.nav .load-btn {
  color: #fff;
}

.nav .load-btn.is-loading svg { animation: spin 0.7s linear infinite; }

.nav .memory-note {
  margin: 2px 0 0;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(159, 18, 57, 0.45);
  color: #ffe4ea;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.45;
}

.kpi span, .delta {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.delta.up { color: var(--ok); }
.delta.down { color: var(--accent-ink); }

.people {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.person {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 12px;
  align-items: center;
}

.avatar {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 13px;
}

.person b { display: block; font-weight: 600; }
.person span { color: var(--muted); font-size: 13px; }

.bars { display: grid; gap: 10px; margin-top: 16px; }

.bar-row { display: grid; grid-template-columns: 160px 1fr auto; gap: 10px; align-items: center; font-size: 13px; }

.bar-track {
  height: 8px;
  background: #efeae3;
  border-radius: 99px;
  overflow: hidden;
}

.bar-track span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
}

.bar-row em { font-style: normal; font-variant-numeric: tabular-nums; color: var(--muted); }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  font-weight: 600;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.btn:hover { background: #fff; border-color: #d9d0c6; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn.primary:hover { background: var(--accent-ink); }

.btn.ghost { background: transparent; }

.btn.danger {
  background: var(--danger-soft);
  border-color: transparent;
  color: var(--danger);
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
}

.chip[aria-pressed="true"] {
  background: var(--fg);
  border-color: var(--fg);
  color: #fff;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}

table { width: 100%; border-collapse: collapse; min-width: 720px; }

caption { text-align: left; padding: 14px 16px 0; font-weight: 600; }

th, td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  background: #faf7f3;
  position: sticky;
  top: 0;
}

th button {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: inherit;
  font-weight: 600;
  min-height: 32px;
}

tbody tr:hover { background: #fbf8f4; }

td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #f3eee8;
  color: var(--fg);
}

.badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 2px;
  background: currentColor;
}

.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.quiet { background: #f3eee8; color: var(--muted); }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.row-actions button {
  min-height: 36px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
}

.chart {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 10px;
  align-items: end;
  height: 220px;
  margin-top: 18px;
}

.col { display: flex; flex-direction: column; justify-content: flex-end; height: 100%; gap: 6px; }

.col .stack {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
  height: 180px;
}

.col .omzet, .col .winst {
  width: 42%;
  border-radius: 6px 6px 2px 2px;
  min-height: 2px;
}

.col .omzet { background: var(--accent); }
.col .winst { background: #1c1917; }

.col small {
  text-align: center;
  color: var(--muted);
  font-size: 11px;
}

.legend {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 6px;
  vertical-align: -1px;
}

.swatch.a { background: var(--accent); }
.swatch.b { background: #1c1917; }

.note {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.facts { display: grid; gap: 10px; margin-top: 14px; }

.fact {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}

.fact span { color: var(--muted); }

.kassa-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.kassa {
  padding: 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--card);
  box-shadow: var(--shadow);
}

.kassa header { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }

.kassa h3 { font-size: 18px; letter-spacing: -0.02em; }

.kassa p { margin-top: 8px; color: var(--muted); font-size: 13px; }

.kassa strong {
  display: block;
  margin-top: 12px;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.doc-list, .contact-list, .bank-list { display: grid; gap: 10px; }

.doc, .contact, .bank {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
}

.doc h3, .contact h3, .bank h3 { font-size: 16px; }

.bank strong {
  display: block;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.doc p, .contact p, .bank p { color: var(--muted); font-size: 13px; margin-top: 4px; }

.iban {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.empty {
  padding: 36px 16px;
  text-align: center;
  color: var(--muted);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(22, 19, 17, 0.46);
}

.modal[hidden], #app[hidden], .backdrop[hidden] { display: none; }

.modal-card {
  width: min(560px, 100%);
  max-height: min(86vh, 760px);
  overflow: auto;
  background: #fffdfb;
  border-radius: 18px;
  box-shadow: 0 24px 80px rgba(22, 19, 17, 0.28);
  padding: 8px 8px 18px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 8px 0 14px;
}

.modal-head h2 {
  font-family: var(--display);
  font-size: 34px;
  font-weight: 500;
}

.form { display: grid; gap: 12px; padding: 8px 14px 0; }

.field { display: grid; gap: 6px; }

.field span { font-size: 13px; font-weight: 600; }

.field input, .field select, .field textarea {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
}

.field textarea { min-height: 88px; resize: vertical; }

.field .error { color: var(--danger); font-size: 13px; font-weight: 500; }

.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%) translateY(12px);
  background: var(--fg);
  color: #fff;
  border-radius: 999px;
  padding: 12px 16px;
  min-height: 44px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(22, 19, 17, 0.45);
  z-index: 6;
}

@media (max-width: 1100px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .split, .thirds { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 120px 1fr auto; }
}

@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    z-index: 8;
    width: min(84vw, 320px);
    transform: translateX(-105%);
    transition: transform 0.25s ease;
  }
  .sidebar.is-open { transform: none; }
  .menu-btn { display: inline-grid; color: var(--fg); }
  .top { padding: 16px; align-items: center; }
  main { padding: 8px 16px 40px; }
  .top-tools { width: 100%; align-items: stretch; }
  .search { width: 100%; }
  .top-meta { justify-content: space-between; }
  #view-title { font-size: 36px; }
  .doc, .contact, .bank { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
