@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  --bg: #EEF0F3;
  --surface: #FFFFFF;
  --surface2: #F5F6F8;
  --border: #DDE1E6;
  --text: #1B1F27;
  --muted: #6B7280;
  --accent: #F97316;
  --accent-soft: #FFF1E7;
  --green: #16A34A;
  --green-soft: #E9F8EF;
  --red: #DC2626;
  --red-soft: #FDECEC;
  --amber: #D97706;
  --amber-soft: #FEF3E1;
  --blue: #0EA5E9;
  --blue-soft: #E8F7FD;
  --sidebar-w: 240px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
}

.num {
  font-family: 'IBM Plex Mono', monospace;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

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

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: margin-left 0.2s ease;
  z-index: 30;
}
.sidebar.collapsed { margin-left: calc(-1 * var(--sidebar-w)); }

.sidebar-header {
  padding: 20px 16px;
  font-weight: 800;
  font-size: 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-section {
  padding: 12px 16px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
}

.sidebar-link {
  display: block;
  padding: 10px 16px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  border-left: 3px solid transparent;
  cursor: pointer;
}
.sidebar-link:hover { background: var(--surface2); }
.sidebar-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-soft);
}

.reopen-tab {
  position: fixed;
  left: 0;
  top: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 8px 8px 0;
  padding: 8px 6px;
  cursor: pointer;
  z-index: 20;
  display: none;
}
.reopen-tab.visible { display: block; }

.collapse-btn {
  margin: 8px 16px;
  padding: 6px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  background: var(--surface2);
  border-radius: 8px;
  cursor: pointer;
  align-self: flex-start;
}

.topbar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 15;
}
.hamburger {
  font-size: 20px;
  background: none;
  border: none;
  cursor: pointer;
}

.drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 25;
}
.drawer-backdrop.visible { display: block; }

.content { flex: 1; padding: 24px; max-width: 1200px; margin: 0 auto; width: 100%; }

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .collapse-btn { display: none; }
  .topbar { display: flex; }
  .reopen-tab { display: none !important; }
  .content { padding: 16px; }
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}

.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.kpi-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.kpi-value { font-family: 'IBM Plex Mono', monospace; font-size: 24px; font-weight: 600; }

/* Tables */
table.ledger { width: 100%; border-collapse: collapse; }
table.ledger th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
table.ledger th.num, table.ledger td.num { text-align: right; }
table.ledger td {
  padding: 10px;
  border-bottom: 1px solid var(--surface2);
  font-size: 14px;
}
table.ledger tbody tr:hover { background: var(--surface2); cursor: pointer; }

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }
.badge-muted { background: var(--surface2); color: var(--muted); }

/* Buttons */
.btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}
.btn:hover { background: var(--surface2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn-primary:hover { background: #ea6a0e; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-danger { color: var(--red); }

/* Forms */
label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 4px; color: var(--muted); }
input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
}
.field { margin-bottom: 14px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }

/* Pill toggle */
.pill-toggle { display: inline-flex; background: var(--surface2); border-radius: 20px; padding: 3px; gap: 2px; }
.pill-toggle button {
  border: none;
  background: transparent;
  padding: 6px 14px;
  border-radius: 18px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--muted);
}
.pill-toggle button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,0.08); }

/* Modal bottom-sheet */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 50;
}
.modal-sheet {
  background: var(--surface);
  width: 100%; max-width: 640px;
  border-radius: 16px 16px 0 0;
  padding: 20px;
  max-height: 88vh;
  overflow-y: auto;
  animation: slideUp 0.2s ease;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Switch */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--border); border-radius: 22px; transition: 0.2s;
}
.switch-slider:before {
  content: ""; position: absolute; height: 16px; width: 16px; left: 3px; bottom: 3px;
  background: white; border-radius: 50%; transition: 0.2s;
}
.switch input:checked + .switch-slider { background: var(--accent); }
.switch input:checked + .switch-slider:before { transform: translateX(18px); }

/* Autocomplete */
.autocomplete { position: relative; }
.autocomplete-list {
  position: absolute; top: 100%; left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  margin-top: 4px; max-height: 220px; overflow-y: auto; z-index: 10;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.autocomplete-item { padding: 8px 12px; cursor: pointer; font-size: 14px; }
.autocomplete-item:hover { background: var(--surface2); }
.autocomplete-item.new { color: var(--accent); font-weight: 500; }

h1 { font-size: 22px; font-weight: 700; margin: 0 0 4px; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 12px; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 10px; }
.muted { color: var(--muted); font-size: 13px; }
.text-right { text-align: right; }
.collapsible-toggle { cursor: pointer; color: var(--accent); font-size: 13px; font-weight: 500; }
.hidden { display: none !important; }
.bar-track { background: var(--surface2); border-radius: 6px; height: 8px; overflow: hidden; }
.bar-fill { background: var(--accent); height: 100%; }
