:root {
  /* Classic Gold */
  --accent: #C9A84C;
  --accent-light: #E8D5A3;
  --accent-dark: #9A7A2E;
  --accent-rgb: 201, 168, 76;

  --bg-primary: #FFFFFF;
  --bg-secondary: #FAFAF8;
  --bg-tertiary: #F5F2EC;
  --bg-sidebar: #1C1C1E;

  --text-primary: #1A1A1A;
  --text-secondary: #5A5A5A;
  --text-muted: #9A9A9A;
  --text-inverse: #FFFFFF;

  --border: #E8E4DC;
  --border-accent: rgba(201, 168, 76, 0.3);
  --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
  --shadow-accent: 0 4px 20px rgba(201, 168, 76, 0.2);

  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;

  --font-display: 'Playfair Display', serif;
  --font-body: 'Jost', sans-serif;

  --sidebar-width: 260px;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);

  --ok: #2E7D5B;
  --ok-bg: #E6F3EC;
  --over: #A8741A;
  --over-bg: #FBF1DC;
  --short: #B3261E;
  --short-bg: #FBE7E5;
  --idle: #8A8A8A;
  --idle-bg: #F0EEE9;
}

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

html, body { min-height: 100%; }
body {
  font-family: var(--font-body);
  font-weight: 400;
  font-size: 15px;
  color: var(--text-primary);
  background: var(--bg-secondary);
  -webkit-font-smoothing: antialiased;
  scrollbar-width: thin;
  scrollbar-color: var(--accent-light) transparent;
}
* { scrollbar-width: thin; scrollbar-color: var(--accent-light) transparent; }

button { font-family: inherit; cursor: pointer; }
h1, h2, h3 { font-family: var(--font-display); letter-spacing: 0.04em; font-weight: 600; }

/* ---------- Layout ---------- */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  color: var(--text-inverse);
  position: fixed;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  z-index: 60;
  transition: var(--transition);
}
.sidebar-header {
  display: flex; align-items: center; gap: 14px;
  padding: 28px 24px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.logo-mark {
  width: 42px; height: 42px; border-radius: 50%;
  border: 2px solid var(--accent-light);
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; font-size: 15px;
  color: var(--accent-light); letter-spacing: 0.04em;
}
.brand-title { font-family: var(--font-display); font-size: 17px; letter-spacing: 0.04em; line-height: 1.2; }
.brand-sub { font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--accent-light); opacity: 0.75; margin-top: 3px; }

.sidebar-nav { padding: 20px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  background: transparent; border: 0;
  border-left: 3px solid transparent;
  color: rgba(255, 255, 255, 0.66);
  padding: 13px 16px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 400; letter-spacing: 0.04em; text-align: left;
  transition: var(--transition);
}
.nav-item svg { width: 18px; height: 18px; flex: none; }
.nav-item:hover { color: #fff; background: rgba(255, 255, 255, 0.05); }
.nav-item.active {
  color: var(--accent-light);
  background: rgba(var(--accent-rgb), 0.12);
  border-left-color: var(--accent);
}
.sidebar-footer { padding: 20px 24px 26px; border-top: 1px solid rgba(255, 255, 255, 0.08); }
.sf-label { font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: rgba(255, 255, 255, 0.45); }
.sf-value { margin-top: 6px; font-family: var(--font-display); font-size: 18px; color: var(--accent-light); letter-spacing: 0.04em; }

.sidebar-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45);
  z-index: 55; opacity: 0; pointer-events: none; transition: var(--transition);
}
.sidebar-overlay.show { opacity: 1; pointer-events: auto; }

.main { margin-left: var(--sidebar-width); flex: 1; min-width: 0; }
.topbar { display: none; }
.page { padding: 32px 36px 60px; max-width: 1320px; margin: 0 auto; }

.page-head { margin-bottom: 24px; }
.page-head h1 { font-size: 30px; }
.page-head p { color: var(--text-secondary); margin-top: 6px; font-weight: 300; }

/* ---------- Card ---------- */
.card {
  background: linear-gradient(135deg, var(--bg-primary), var(--bg-tertiary));
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.card.active { border-color: var(--border-accent); box-shadow: var(--shadow-md); }
.card-pad { padding: 22px 24px; }
.card-title { font-size: 17px; margin-bottom: 14px; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 22px; padding: 18px 24px; margin-bottom: 18px; }
.date-nav { display: flex; align-items: center; gap: 8px; }
.date-nav input[type=date] {
  font-family: var(--font-body); font-size: 15px; color: var(--text-primary);
  border: 0; border-bottom: 1px solid var(--border); background: transparent;
  padding: 8px 4px; transition: var(--transition);
}
.date-nav input[type=date]:focus { outline: none; border-bottom-color: var(--accent); }
.date-label { font-family: var(--font-display); font-size: 17px; letter-spacing: 0.04em; min-width: 190px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); background: var(--bg-primary); color: var(--text-primary);
  padding: 10px 18px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500; letter-spacing: 0.04em;
  transition: var(--transition);
}
.btn:hover { border-color: var(--accent); color: var(--accent-dark); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: var(--shadow-accent); }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }
.btn-danger { color: var(--short); border-color: rgba(179, 38, 30, 0.35); }
.btn-danger:hover { background: var(--short-bg); border-color: var(--short); color: var(--short); }
.btn-danger-solid { background: var(--short); border-color: var(--short); color: #fff; }
.btn-danger-solid:hover { background: #8E1D17; border-color: #8E1D17; color: #fff; }
.btn-sq { width: 38px; height: 38px; padding: 0; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--bg-primary); }
.seg-btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: 0; border-right: 1px solid var(--border); background: transparent;
  padding: 10px 22px; font-size: 14px; font-weight: 500; letter-spacing: 0.06em; color: var(--text-secondary);
  transition: var(--transition);
}
.seg-btn:last-child { border-right: 0; }
.seg-btn:hover { background: var(--bg-tertiary); }
.seg-btn.active { background: var(--accent); color: #fff; }
.dot { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--text-muted); }
.dot.filled { background: var(--ok); border-color: var(--ok); }
.seg-btn.active .dot { border-color: rgba(255, 255, 255, 0.8); }
.seg-btn.active .dot.filled { background: #fff; border-color: #fff; }

/* ---------- Mode banner ---------- */
.mode {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 18px; margin-bottom: 18px;
  border-radius: var(--radius-sm); font-size: 14px; letter-spacing: 0.02em;
  border: 1px solid var(--border);
  background: var(--bg-primary); color: var(--text-secondary);
}
.mode::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.mode.new::before { background: var(--ok); }
.mode.edit { border-color: var(--border-accent); background: rgba(var(--accent-rgb), 0.1); color: var(--accent-dark); }
.mode.edit::before { background: var(--accent); }

/* ---------- Calc grid ---------- */
.calc-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(330px, 1fr); gap: 24px; align-items: start; }
.summary { position: sticky; top: 24px; }

table.denom { width: 100%; border-collapse: collapse; }
table.denom th {
  font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--text-muted); font-weight: 500; text-align: center;
  padding: 14px 14px; border-bottom: 1px solid var(--border);
}
table.denom tbody tr:nth-child(even) { background: var(--bg-secondary); }
table.denom td { padding: 7px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.denom td.ctr { text-align: center; }
table.denom td.cnum { font-weight: 500; font-variant-numeric: tabular-nums; color: var(--accent-dark); }
table.denom tfoot td {
  padding: 14px; font-weight: 500; font-size: 13px; background: rgba(var(--accent-rgb), 0.1);
  border-bottom: 0; font-variant-numeric: tabular-nums;
}
table.denom tfoot td.lbl { letter-spacing: 0.14em; text-transform: uppercase; font-size: 12px; }
.money { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; }
.cur { color: var(--text-muted); font-size: 12px; letter-spacing: 0.08em; }

input.cnt {
  width: 100%; max-width: 92px; text-align: center;
  font-family: var(--font-body); font-size: 15px; color: var(--text-primary);
  border: 0; border-bottom: 1px solid var(--border); background: transparent;
  padding: 7px 4px; transition: var(--transition);
}
input.cnt:focus { outline: none; border-bottom-color: var(--accent); box-shadow: 0 1px 0 var(--accent); background: rgba(var(--accent-rgb), 0.06); }
input.cnt::placeholder { color: #CFCAC0; }

/* ---------- Summary ---------- */
.srow { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 13px 0; border-bottom: 1px solid var(--border); }
.srow .k { font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-secondary); }
.srow .v { font-variant-numeric: tabular-nums; font-size: 17px; font-weight: 500; }
.srow.big .v { font-family: var(--font-display); font-size: 24px; letter-spacing: 0.02em; }
.srow.total .v { color: var(--accent-dark); }
.srow.var { border-bottom: 0; }
.field { padding: 14px 0 4px; }
.field label { display: block; font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-secondary); margin-bottom: 4px; }
.field input, .field textarea {
  width: 100%; font-family: var(--font-body); font-size: 15px; color: var(--text-primary);
  border: 0; border-bottom: 1px solid var(--border); background: transparent;
  padding: 9px 2px; transition: var(--transition); resize: none;
}
.field input:focus, .field textarea:focus { outline: none; border-bottom-color: var(--accent); box-shadow: 0 1px 0 var(--accent); }
.field input.due { font-size: 20px; font-variant-numeric: tabular-nums; }
.hint { min-height: 18px; margin-top: 4px; font-size: 12px; color: var(--accent-dark); font-variant-numeric: tabular-nums; }

.var-box { margin-top: 6px; padding: 16px 18px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--idle-bg); transition: var(--transition); }
.var-box .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.var-box .num { font-family: var(--font-display); font-size: 26px; font-variant-numeric: tabular-nums; }
.var-box .note { margin-top: 8px; font-size: 11.5px; color: var(--text-muted); line-height: 1.5; }
.var-box.ok { background: var(--ok-bg); border-color: rgba(46, 125, 91, 0.3); }
.var-box.ok .num { color: var(--ok); }
.var-box.over { background: var(--over-bg); border-color: rgba(168, 116, 26, 0.35); }
.var-box.over .num { color: var(--over); }
.var-box.short { background: var(--short-bg); border-color: rgba(179, 38, 30, 0.3); }
.var-box.short .num { color: var(--short); }

.badge {
  display: inline-block; padding: 4px 11px; border-radius: 999px;
  font-size: 11.5px; font-weight: 500; letter-spacing: 0.08em; white-space: nowrap;
  background: var(--idle-bg); color: var(--idle);
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.over { background: var(--over-bg); color: var(--over); }
.badge.short { background: var(--short-bg); color: var(--short); }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.actions .btn-primary { flex: 1 1 100%; padding: 13px 18px; font-size: 15px; }
.actions .btn { flex: 1 1 auto; }

/* ---------- Data tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; min-width: 760px; }
table.data th {
  font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-muted);
  font-weight: 500; text-align: left; padding: 13px 14px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 14px; white-space: nowrap; }
table.data tbody tr:nth-child(even) { background: var(--bg-secondary); }
table.data tbody tr:hover { background: rgba(var(--accent-rgb), 0.07); }
table.data .r { text-align: right; font-variant-numeric: tabular-nums; }
table.data .shift { font-weight: 500; letter-spacing: 0.06em; }
table.data .muted { color: var(--text-muted); }
.v-ok { color: var(--ok); } .v-over { color: var(--over); } .v-short { color: var(--short); }

.icon-btn {
  border: 1px solid var(--border); background: var(--bg-primary); color: var(--text-secondary);
  padding: 5px 12px; border-radius: var(--radius-sm); font-size: 12.5px; margin-left: 6px; transition: var(--transition);
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent-dark); }
.icon-btn.danger:hover { border-color: var(--short); color: var(--short); background: var(--short-bg); }

.section-gap { margin-top: 24px; }
.empty { padding: 34px 20px; text-align: center; color: var(--text-muted); font-weight: 300; }

.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 20px; padding: 18px 24px; margin-bottom: 18px; }
.filters .field { padding: 0; min-width: 150px; }
.filters .field.grow { flex: 1 1 220px; }
.filters select {
  width: 100%; font-family: var(--font-body); font-size: 15px; color: var(--text-primary);
  border: 0; border-bottom: 1px solid var(--border); background: transparent; padding: 9px 2px;
}
.filters select:focus, .filters input:focus { outline: none; border-bottom-color: var(--accent); }
.hist-summary { display: flex; flex-wrap: wrap; gap: 28px; padding: 16px 24px; border-top: 1px solid var(--border); background: rgba(var(--accent-rgb), 0.07); font-size: 13.5px; color: var(--text-secondary); }
.hist-summary b { color: var(--text-primary); font-weight: 500; font-variant-numeric: tabular-nums; }

/* ---------- Due Back ---------- */
.nav-badge {
  margin-left: auto; min-width: 22px; padding: 2px 8px; border-radius: 999px;
  background: var(--accent); color: #fff; font-size: 11.5px; font-weight: 500; text-align: center;
}
.stat-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-bottom: 18px; }
.stat { padding: 20px 24px; }
.stat-k { font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-secondary); }
.stat-v { margin-top: 8px; font-family: var(--font-display); font-size: 28px; letter-spacing: 0.02em; font-variant-numeric: tabular-nums; }
.stat.active .stat-v { color: var(--accent-dark); }
.stat-s { margin-top: 4px; font-size: 13px; color: var(--text-muted); }
.due-form { display: grid; grid-template-columns: 170px minmax(220px, 1fr) 200px 200px; gap: 22px; align-items: start; }
.due-form .field { padding: 10px 0 0; }
.due-hint { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.due-hint .icon-btn { margin-left: 0; }
input#dueBack[readonly] { cursor: default; color: var(--accent-dark); }
table.data tr.is-done td { color: var(--text-muted); }
table.data tr.is-done td.r { text-decoration: line-through; }
.icon-btn.ok:hover { border-color: var(--ok); color: var(--ok); background: var(--ok-bg); }

/* ---------- Skeleton ---------- */
.sk {
  height: 14px; border-radius: 6px;
  background: linear-gradient(90deg, #F0ECE3 25%, #F8F5EE 50%, #F0ECE3 75%);
  background-size: 200% 100%; animation: shimmer 1.2s infinite;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.sk-block { padding: 18px 24px; display: grid; gap: 14px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal {
  width: 100%; max-width: 420px; padding: 28px; background: var(--bg-primary);
  border: 1px solid var(--border-accent); border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
}
.modal h3 { font-size: 20px; margin-bottom: 10px; }
.modal p { color: var(--text-secondary); line-height: 1.55; font-weight: 300; }
.modal .m-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

/* ---------- Toast ---------- */
#toasts { position: fixed; right: 22px; bottom: 22px; display: grid; gap: 10px; z-index: 120; }
.toast {
  min-width: 240px; max-width: 360px; padding: 13px 18px; border-radius: var(--radius-sm);
  background: var(--bg-sidebar); color: #fff; font-size: 14px; line-height: 1.4;
  border-left: 4px solid var(--accent); box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s ease;
}
.toast.success { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--short); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .calc-grid { grid-template-columns: 1fr; }
  .summary { position: static; }
  .due-form { grid-template-columns: 1fr 1fr; }
  .due-form { grid-auto-flow: dense; }
  .due-form .field.grow { grid-column: 1 / -1; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .main { margin-left: 0; }
  .topbar {
    display: flex; align-items: center; gap: 14px; position: sticky; top: 0; z-index: 40;
    padding: 12px 16px; background: var(--bg-sidebar); color: #fff;
  }
  .topbar .ttl { font-family: var(--font-display); letter-spacing: 0.04em; }
  .hamburger { background: transparent; border: 0; color: var(--accent-light); width: 36px; height: 36px; }
  .hamburger svg { width: 24px; height: 24px; }
  .page { padding: 20px 16px 50px; }
  .page-head h1 { font-size: 24px; }
  .toolbar { padding: 16px; gap: 14px; }
  .date-label { min-width: 0; flex: 1 1 100%; order: 3; }
  .seg { width: 100%; }
  .seg-btn { flex: 1; justify-content: center; padding: 11px 8px; }
  table.denom td, table.denom th { padding-left: 8px; padding-right: 8px; }
  input.cnt { max-width: 64px; }
  .filters { padding: 16px; }
  .stat-row { grid-template-columns: 1fr; gap: 12px; }
  .stat-v { font-size: 24px; }
  .due-form { grid-template-columns: 1fr; gap: 6px; }
  #toasts { left: 16px; right: 16px; bottom: 16px; }
  .toast { max-width: none; }
}

.sf-logout { display: inline-block; margin-top: 14px; font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: rgba(255,255,255,0.55); text-decoration: none; transition: var(--transition); }
.sf-logout:hover { color: var(--accent-light); }
