:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #fbfcfb;
  --text: #1a1f1b;
  --muted: #6f7c73;
  --line: #e7ece8;
  --line-soft: #eff2ef;
  --accent: #1f6a45;
  --accent-soft: #edf5f0;
  --gold: #e9b949;
  --gold-soft: #fff8e6;
  --danger: #c94b4b;
  --danger-soft: #fff1f1;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(16,24,20,.04), 0 8px 24px rgba(16,24,20,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Manrope', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
.app { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }

/* Sidebar */
.sidebar {
  background: #fff;
  border-right: 1px solid var(--line);
  padding: 28px 16px;
  display: flex; flex-direction: column; gap: 32px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 0 8px; }
.logo { width: 42px; height: 42px; flex: 0 0 42px; }
.brand-name { font-weight: 800; font-size: 1rem; letter-spacing: -0.02em; line-height: 1.2; }
.brand-tag { font-size: 0.72rem; color: var(--muted); margin-top: 2px; line-height: 1.3; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  width: 100%; text-align: left; padding: 11px 12px; border: 0; border-radius: 12px;
  background: transparent; color: #4b5a50; cursor: pointer; font-weight: 600; font-size: 0.92rem;
  display: flex; gap: 10px; align-items: center; transition: .15s;
}
.nav-item:hover { background: #f4f7f5; color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-icon { width: 20px; text-align: center; font-size: 0.95rem; opacity: .9; }
.sidebar-foot { margin-top: auto; padding: 0 8px; }
.storage-note { font-size: 0.74rem; color: var(--muted); line-height: 1.5; padding: 12px 0; border-top: 1px solid var(--line); }
.storage-note.cloud-ok { color: var(--accent); }
.storage-note.cloud-off { color: #b07a12; }

/* Main */
.main { padding: 36px 40px; min-width: 0; max-width: 1400px; }
.topbar { display: flex; justify-content: space-between; gap: 20px; align-items: flex-end; margin-bottom: 32px; }
.topbar h1 { margin: 0; font-size: 1.9rem; font-weight: 800; letter-spacing: -0.035em; }
.subtitle { margin: 6px 0 0; color: var(--muted); font-size: 0.95rem; }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.date-pill { padding: 9px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; font-size: 0.82rem; color: var(--muted); font-weight: 600; }

/* Buttons */
.btn {
  border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 650; font-size: 0.88rem; cursor: pointer;
  background: var(--accent); color: #fff; display: inline-flex; align-items: center; gap: 8px; transition: .15s;
}
.btn:hover { filter: brightness(0.95); }
.btn-ghost { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.btn-ghost:hover { background: #f7f9f7; filter: none; }
.btn-sm { padding: 7px 12px; font-size: 0.8rem; border-radius: 8px; }
.btn-danger { background: var(--surface); color: var(--danger); border: 1px solid #f0d4d4; }
.btn-danger:hover { background: var(--danger-soft); filter: none; }
.file-label { position: relative; overflow: hidden; }

/* Views & cards */
.view { display: none; }
.view.active { display: block; animation: fade .15s ease; }
@keyframes fade { from { opacity: .6; transform: translateY(2px); } to { opacity: 1; transform: none; } }
.grid { display: grid; gap: 16px; }
.stats { grid-template-columns: repeat(4, minmax(0,1fr)); margin-bottom: 16px; }
.two-col { grid-template-columns: 1.4fr 1fr; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; min-width: 0;
}
.card h3 { margin: 0 0 18px; font-size: 0.95rem; font-weight: 700; letter-spacing: -0.01em; }
.stat-label { color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.stat-value { font-size: 1.75rem; font-weight: 800; margin-top: 10px; letter-spacing: -0.03em; line-height: 1; }
.stat-meta { margin-top: 8px; font-size: 0.78rem; color: var(--muted); }
.stat-value.good { color: var(--accent); }
.stat-value.warn { color: #b07a12; }

/* Toolbar */
.toolbar { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 20px; flex-wrap: wrap; }
.toolbar h3 { margin: 0; font-size: 1rem; }
.search {
  padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; min-width: 240px;
  background: #fff; outline: none; font-size: 0.9rem;
}
.search:focus { border-color: #c9d8ce; box-shadow: 0 0 0 3px rgba(31,106,69,.06); }

/* List rows (app-like cards, not spreadsheet) */
.table-wrap { overflow: visible; }
table { width: 100%; border-collapse: separate; border-spacing: 0 10px; font-size: 0.9rem; }
thead { display: none; }
tbody tr {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px 18px;
  padding: 18px; background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: 14px; align-items: center;
}
td { padding: 0; border: 0; min-width: 0; }
td::before {
  content: attr(data-label);
  display: block; font-size: 0.69rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--muted); margin-bottom: 4px;
}
td.row-actions::before { display: none; }
td.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; align-self: center; }
.empty { padding: 40px 10px; text-align: center; color: var(--muted); font-size: 0.9rem; grid-column: 1 / -1; background: transparent; border: 0; }
td.empty::before { display: none !important; }

/* Badges */
.badge { display: inline-flex; padding: 5px 10px; border-radius: 999px; font-size: 0.72rem; font-weight: 700; background: #f0f4f1; color: #506358; white-space: nowrap; }
.badge.pending { background: var(--gold-soft); color: #8a6500; }
.badge.paid, .badge.received { background: var(--accent-soft); color: var(--accent); }
.badge.overdue, .badge.spent { background: var(--danger-soft); color: var(--danger); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(26,31,27,0.28); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; backdrop-filter: blur(4px); }
.modal.hidden { display: none; }
.modal-card { background: #fff; width: min(680px, 100%); max-height: calc(100vh - 40px); overflow: auto; border-radius: 20px; box-shadow: 0 20px 60px rgba(0,0,0,0.12); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 22px 24px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 1.15rem; letter-spacing: -0.02em; }
.icon-btn { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 1rem; color: var(--muted); }
.icon-btn:hover { background: #f7f9f7; color: var(--text); }
#modalBody { padding: 24px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 0.8rem; font-weight: 650; color: #45544b; }
.field input, .field select, .field textarea {
  padding: 11px 13px; border-radius: 10px; border: 1px solid #dce4de; background: #fff; width: 100%; font-size: 0.92rem;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: #b9ccb9; box-shadow: 0 0 0 3px rgba(31,106,69,.06); }
.field textarea { min-height: 84px; resize: vertical; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; right: 24px; background: #1f2922; color: #fff; padding: 12px 16px;
  border-radius: 10px; font-size: 0.88rem; font-weight: 600; opacity: 0; transform: translateY(8px); transition: .2s; z-index: 60;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* Dashboard lists */
.list { display: flex; flex-direction: column; }
.list-row { display: flex; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--line-soft); align-items: center; }
.list-row:last-child { border-bottom: 0; padding-bottom: 0; }
.list-title { font-weight: 650; font-size: 0.9rem; }
.list-meta { color: var(--muted); font-size: 0.79rem; margin-top: 3px; }
.list-val { font-weight: 750; white-space: nowrap; font-size: 0.92rem; }
.muted { color: var(--muted); font-size: 0.85rem; }

@media (max-width: 1100px) { .stats { grid-template-columns: repeat(2, minmax(0,1fr)); } .two-col { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 20px; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 4px; }
  .main { padding: 24px 20px; }
  .topbar { flex-direction: column; align-items: stretch; }
}
@media (max-width: 560px) {
  .nav { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr; }
  .search { min-width: 0; width: 100%; }
  tbody tr { grid-template-columns: 1fr 1fr; }
}