@font-face {
  font-family: "Geist";
  src: url("/fonts/Geist-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --fichte: #2c4a3d;
  --fichte-deep: #223a30;
  --paper: #f4f0e6;
  --paper-soft: #ece6d8;
  --ink: #1b1a17;
  --ink-soft: #5f5c55;
  --line: rgba(27, 26, 23, 0.12);
  --danger: #a3372f;
  --radius: 8px;
  --shadow: 0 2px 10px rgba(27, 26, 23, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Geist", "Helvetica Neue", Arial, sans-serif;
  background: var(--paper-soft);
  color: var(--ink);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.logo { display: inline-flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; }
.logo svg { width: 16px; height: 19px; flex-shrink: 0; }
.logo-word { letter-spacing: 0.22em; text-transform: uppercase; font-size: 14px; font-weight: 400; }
a { color: var(--fichte); }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 40px 36px; width: 100%; max-width: 360px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px;
}
.login-brand { display: flex; justify-content: center; margin-bottom: 4px; }
.login-brand .logo svg { width: 22px; height: 26px; }
.login-brand .logo-word { font-size: 20px; }
.login-sub { text-align: center; color: var(--ink-soft); font-size: 12px; letter-spacing: 1px; text-transform: uppercase; margin-top: -8px; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  background: var(--paper); color: var(--ink); border-bottom: 1px solid var(--line);
  padding: 0 20px; height: 58px; position: sticky; top: 0; z-index: 10;
}
.topbar-brand .tag { font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-soft); padding-left: 10px; border-left: 1px solid var(--line); }
.topbar-nav { display: flex; gap: 2px; margin-left: 16px; flex: 1; }
.nav-btn {
  background: transparent; border: none; color: var(--ink-soft);
  padding: 8px 12px; border-radius: 6px; cursor: pointer; font-size: 14px;
  text-decoration: none; white-space: nowrap;
}
.nav-btn:hover { background: rgba(27, 26, 23, 0.05); color: var(--ink); }
.nav-btn.active { background: rgba(27, 26, 23, 0.07); color: var(--ink); font-weight: 500; }
.topbar .btn-ghost { border-color: var(--line); color: var(--ink-soft); }
.topbar .btn-ghost:hover { color: var(--ink); border-color: var(--ink-soft); }

/* ---------- Layout ---------- */
#main { max-width: 1200px; margin: 0 auto; padding: 28px 20px 80px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-head h1 { font-weight: 500; font-size: 24px; letter-spacing: -0.01em; margin: 0; }
.page-sub { color: var(--ink-soft); font-size: 13.5px; margin-top: 2px; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid transparent; border-radius: 6px; padding: 9px 16px; font-size: 14px;
  cursor: pointer; font-family: inherit; line-height: 1;
}
a.btn { text-decoration: none; display: inline-block; }
.btn-primary { background: var(--fichte); color: var(--paper); }
.btn-primary:hover { background: var(--fichte-deep); }
.btn-ghost { background: transparent; border-color: currentColor; color: inherit; }
.btn-outline { background: var(--paper); border-color: var(--line); color: var(--ink); }
.btn-outline:hover { border-color: var(--fichte); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn[disabled] { opacity: 0.5; cursor: default; }

/* ---------- Cards / tables ---------- */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table.list { width: 100%; border-collapse: collapse; background: var(--paper); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table.list th { text-align: left; font-size: 11px; letter-spacing: 1px; text-transform: uppercase; color: var(--ink-soft); padding: 12px 14px; border-bottom: 1px solid var(--line); }
table.list td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr:last-child td { border-bottom: none; }
table.list tr:hover td { background: var(--paper-soft); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.right { text-align: right; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.empty { text-align: center; color: var(--ink-soft); padding: 48px; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge.draft { background: #e4e0d4; color: #6b6657; }
.badge.sent { background: #dbe6ef; color: #2f5676; }
.badge.accepted { background: #d8e8dd; color: #2c4a3d; }
.badge.paid { background: #cfe8d2; color: #1f6b35; }
.badge.cancelled { background: #efd9d6; color: #a3372f; }
.badge.open { background: #dbe6ef; color: #2f5676; }
.badge.partial { background: #f3e6c4; color: #7a5a12; }
.badge.overdue { background: #a3372f; color: #fff; }
.badge.rejected { background: #efd9d6; color: #a3372f; }
.badge.expired { background: #e4e0d4; color: #8a5a2b; }
.badge.level { background: transparent; border: 1px solid #a3372f; color: #a3372f; margin-left: 4px; }

/* ---------- Forms ---------- */
label { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 4px; }
input, textarea, select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 6px;
  background: #fff; font-family: inherit; font-size: 14px; color: var(--ink);
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--fichte); }
textarea { resize: vertical; min-height: 60px; }
.field { margin-bottom: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.form-error { color: var(--danger); font-size: 13px; min-height: 18px; }
.section-title { font-size: 12px; letter-spacing: 1px; text-transform: uppercase; color: var(--fichte); margin: 24px 0 10px; font-weight: 700; }

/* ---------- Editor items ---------- */
table.items-edit { width: 100%; border-collapse: collapse; }
table.items-edit th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--ink-soft); text-align: left; padding: 6px 6px; }
table.items-edit td { padding: 4px 6px; vertical-align: top; }
table.items-edit input, table.items-edit textarea { padding: 7px 8px; }
.col-qty-e, .col-unit-e, .col-price-e { width: 110px; }
.line-total { padding-top: 9px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.totals-preview { margin-top: 16px; margin-left: auto; width: 300px; }
.totals-preview .tp-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); }
.totals-preview .tp-row.grand { border-bottom: none; border-top: 2px solid var(--fichte); font-weight: 700; color: var(--fichte); font-size: 18px; padding-top: 10px; }

.editor-actions { display: flex; gap: 10px; margin-top: 24px; justify-content: flex-end; flex-wrap: wrap; }
.toolbar { display: flex; gap: 8px; align-items: center; }

/* ---------- Helpers ---------- */
.muted { color: var(--ink-soft); }
.small { font-size: 13px; }
.danger-text { color: var(--danger); }
.ok-text { color: #1f6b35; }
.clickable tbody tr { cursor: pointer; }
table.list tfoot td { font-weight: 700; border-top: 2px solid var(--line); background: var(--paper-soft); }
.page-head .head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.page-head h1 .badge { vertical-align: middle; margin-left: 10px; }
.warn-text { color: #8a6212; }

/* ---------- Filter bar ---------- */
.filterbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  background: transparent; border: 1px solid transparent; border-radius: 20px; padding: 6px 12px;
  font-size: 13px; cursor: pointer; color: var(--ink-soft); font-family: inherit;
}
.tab:hover { border-color: var(--line); }
.tab.active { background: var(--fichte); color: var(--paper); }
.tab .count { opacity: 0.7; margin-left: 4px; font-variant-numeric: tabular-nums; }
.search { max-width: 260px; }

/* ---------- Dashboard ---------- */
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.card-head h2 { font-size: 15px; margin: 0; font-weight: 600; }
.card-body { padding: 14px 20px; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.kpi { padding: 16px 18px 14px; text-decoration: none; color: inherit; display: flex; flex-direction: column; min-height: 148px; }
a.kpi { transition: border-color 0.15s, transform 0.15s; }
a.kpi:hover { border-color: var(--ink-soft); }
.kpi-label { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); font-weight: 500; }
.kpi-value { font-size: 25px; font-weight: 500; letter-spacing: -0.01em; margin-top: 8px; line-height: 1.15; }
.kpi-value .cur { font-size: 13px; font-weight: 400; color: var(--ink-soft); margin-right: 6px; letter-spacing: 0; }
.kpi-sub { font-size: 13px; color: var(--ink-soft); margin-top: 4px; }
.kpi-foot { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--line); font-size: 13px; color: var(--ink-soft); }
.kpi-foot::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 7px; vertical-align: 1px; background: currentColor; opacity: 0.9; }
.kpi-foot.danger { color: var(--danger); font-weight: 500; }
.kpi-foot.warn { color: #8a6212; }
.kpi-foot.ok { color: #2e6b45; }
.cash { margin-top: 8px; font-size: 13.5px; }
.cash-row { display: flex; justify-content: space-between; padding: 3px 0; }
.cash-row span:first-child { color: var(--ink-soft); }
.cash-row.total { margin-top: 6px; padding-top: 8px; border-top: 1px solid var(--line); font-weight: 600; font-size: 15px; }
.cash-row.total span:first-child { color: var(--ink); }

.dash-main { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 16px; align-items: start; }
.dash-side { display: flex; flex-direction: column; gap: 16px; }

.task-group + .task-group { border-top: 1px solid var(--line); }
.task-group-head { display: flex; align-items: center; gap: 9px; padding: 14px 20px 4px; }
.task-group-head h3 { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 600; color: var(--ink-soft); margin: 0; }
.task-group-sum { margin-left: auto; font-size: 13px; color: var(--ink-soft); }
.count-pill { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 10px; background: rgba(27, 26, 23, 0.07); color: var(--ink); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--ink-soft); }
.dot.danger { background: var(--danger); }
.dot.warn { background: #c48a1c; }
.dot.info { background: #8c877c; }
.task-list { list-style: none; margin: 0; padding: 0 0 8px; }
.task { display: grid; grid-template-columns: minmax(0, 1fr) 120px 232px; align-items: center; gap: 16px; padding: 10px 20px; cursor: pointer; }
.task:hover { background: rgba(27, 26, 23, 0.035); }
.task-main { min-width: 0; }
.task-title { font-weight: 600; color: var(--ink); text-decoration: none; }
.task-title:hover { text-decoration: underline; }
.task-meta { font-size: 13px; color: var(--ink-soft); margin-top: 1px; }
.task-amount { font-weight: 500; text-align: right; }
.task-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.task-actions .btn { white-space: nowrap; }
.task.is-waiting .task-title, .task.is-waiting .task-amount { color: var(--ink-soft); }
.task-more { display: block; padding: 0 20px 14px 37px; font-size: 13px; color: var(--ink-soft); }
.task-more:hover { color: var(--ink); }
.all-done { text-align: center; padding: 44px 20px 48px; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.all-done-mark { width: 40px; height: 40px; border-radius: 50%; border: 1.5px solid #2e6b45; color: #2e6b45; display: grid; place-items: center; font-size: 18px; margin-bottom: 6px; }

.pay-list { list-style: none; margin: 0; padding: 4px 0; }
.pay-list a { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 8px 20px; color: inherit; text-decoration: none; }
.pay-list a:hover { background: rgba(27, 26, 23, 0.035); }
.pay-who { min-width: 0; display: flex; flex-direction: column; }
.pay-who strong, .pay-who .small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pay-who strong { font-weight: 500; }
.pay-amt { font-weight: 500; white-space: nowrap; }
.pay-amt.in { color: #2e6b45; }
.export label { margin-bottom: 4px; }
.export select { margin-bottom: 10px; }
.export-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.export .hint { margin: 10px 0 0; }

/* ---------- Detail ---------- */
.detail-grid { display: grid; grid-template-columns: 3fr 2fr; gap: 14px; margin-bottom: 14px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; font-size: 14px; }
.facts dt { color: var(--ink-soft); }
.facts dd { margin: 0; }
.amounts .row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.amounts .row.big { border-bottom: none; font-size: 22px; font-weight: 500; padding-top: 12px; }
.progress { height: 8px; border-radius: 4px; background: var(--paper-soft); overflow: hidden; margin-top: 10px; }
.progress > div { height: 100%; background: #1f6b35; }
.section-card { margin-bottom: 14px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 14px; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.timeline li:last-child { border-bottom: none; }
.timeline .when { color: var(--ink-soft); min-width: 86px; font-variant-numeric: tabular-nums; }
.notice { padding: 10px 14px; border-radius: 6px; background: #f3e6c4; color: #6b4f10; font-size: 14px; margin-bottom: 14px; }
.notice.danger { background: #efd9d6; color: var(--danger); }
.copy { cursor: pointer; border-bottom: 1px dotted var(--ink-soft); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(27, 26, 23, 0.45); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px 16px; overflow-y: auto;
}
.modal { background: var(--paper); border-radius: 10px; width: 100%; max-width: 480px; box-shadow: 0 20px 50px rgba(0,0,0,0.25); }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); font-size: 17px; font-weight: 500; }
.modal-body { padding: 18px 20px 4px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; }
.hint { font-size: 13px; color: var(--ink-soft); margin: -6px 0 12px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 12px 20px; border-radius: 8px;
  box-shadow: var(--shadow); z-index: 100; font-size: 14px;
}
.toast.error { background: var(--danger); }

@media (max-width: 1060px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; }
  .topbar-nav { order: 3; flex: 1 1 100%; margin-left: 0; overflow-x: auto; }
  #logout { margin-left: auto; }
}

@media (max-width: 1240px) {
  .dash-main { grid-template-columns: 1fr; }
  .dash-side { display: grid; grid-template-columns: 1fr 1fr; align-items: start; }
}

@media (max-width: 900px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .task { grid-template-columns: minmax(0, 1fr) auto; row-gap: 8px; }
  .task-actions { grid-column: 1 / -1; justify-content: flex-start; }
}

@media (max-width: 720px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr; }
  .kpi { min-height: 0; }
  .dash-side { grid-template-columns: 1fr; }
  .page-head { flex-wrap: wrap; gap: 10px; }
  table.list, table.items-edit { display: block; overflow-x: auto; white-space: nowrap; }
  table.items-edit textarea, table.items-edit input { min-width: 90px; }
  table.items-edit textarea { min-width: 220px; white-space: normal; }
}
