:root {
  --bg: #0d1117;
  --bg-elev: #161b22;
  --bg-elev-2: #1c2129;
  --border: #2a2f37;
  --text: #e6edf3;
  --text-dim: #9aa4b2;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, 0.15);
  --danger: #f85149;
  --success: #3fb950;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 1.4rem; margin: 0 0 4px; }
.login-card p { color: var(--text-dim); margin: 0 0 24px; font-size: 0.9rem; }
.login-error { color: var(--danger); font-size: 0.85rem; min-height: 1.1em; margin-top: 10px; }
#gbtn { display: flex; justify-content: center; margin-top: 8px; }

/* ---------- Forms ---------- */
input, select {
  width: 100%;
  padding: 11px 13px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label { display: block; font-size: 0.8rem; color: var(--text-dim); margin: 14px 0 6px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 16px;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  border-radius: 8px;
  font-size: 0.9rem;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: #232a33; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; width: 100%; }
.btn-primary:hover { background: #3d7bff; }
.btn-danger { color: var(--danger); border-color: rgba(248,81,73,0.4); }
.btn-danger:hover { background: rgba(248,81,73,0.12); }
.btn-sm { padding: 6px 10px; font-size: 0.8rem; }

/* ---------- Layout ---------- */
.container { max-width: 1100px; margin: 0 auto; padding: 24px; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.topbar h1 { font-size: 1.3rem; margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.topbar-actions input[type="month"] { width: auto; }

/* ---------- Cards ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.card .label { color: var(--text-dim); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
.card .value { font-size: 1.55rem; font-weight: 600; margin-top: 8px; }
.card .sub { color: var(--text-dim); font-size: 0.78rem; margin-top: 4px; }

/* ---------- Charts ---------- */
.charts {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 14px;
  margin-bottom: 22px;
}
.panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.panel h2 { font-size: 0.95rem; margin: 0 0 14px; color: var(--text-dim); font-weight: 600; }
.chart-box { position: relative; height: 280px; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-dim); font-weight: 600; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.04em; }
td.amount, th.amount { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--bg-elev-2); }
.item-cell { white-space: normal; max-width: 280px; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
}
.row-actions { display: flex; gap: 6px; }

.empty { text-align: center; color: var(--text-dim); padding: 40px; }
.loading { text-align: center; color: var(--text-dim); padding: 60px; }

/* ---------- Controls / pager ---------- */
.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 20px;
}
.controls .ctrl { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 0.8rem; color: var(--text-dim); }
.controls input[type="month"], .controls input[type="date"] { width: auto; }
.ctrl-or, .ctrl-arrow { color: var(--text-dim); font-size: 0.8rem; }

.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.panel-head h2 { margin: 0; }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 14px; }
.pager-info { color: var(--text-dim); font-size: 0.82rem; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 50;
}
.modal {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%; max-width: 420px;
  box-shadow: var(--shadow);
}
.modal h2 { margin: 0 0 16px; font-size: 1.1rem; }
.modal-actions { display: flex; gap: 10px; margin-top: 22px; }
.modal-actions .btn { flex: 1; }

/* ---------- Report page ---------- */
.report { max-width: 980px; margin: 0 auto; padding: 32px; }
.report-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 28px; }
.report-header h1 { margin: 0; font-size: 1.7rem; }
.report-header .gen { color: var(--text-dim); font-size: 0.85rem; margin-top: 6px; }
.report-section { margin-bottom: 32px; }
.report-section h2 { font-size: 1rem; color: var(--text-dim); border-bottom: 1px solid var(--border); padding-bottom: 8px; margin-bottom: 16px; }
.exec-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .charts { grid-template-columns: 1fr; }
  .exec-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .cards { grid-template-columns: 1fr; }
  .container, .report { padding: 16px; }
}

/* ---------- Voice FAB + toast (PWA) ---------- */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 1.5rem;
  box-shadow: var(--shadow);
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
}
.fab:hover { background: #3d7bff; }
.fab:active { transform: scale(0.94); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%) translateY(16px);
  max-width: 88%;
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 12px 18px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Print (report PDF) ---------- */
@media print {
  :root {
    --bg: #ffffff; --bg-elev: #ffffff; --bg-elev-2: #f5f5f5;
    --border: #d0d7de; --text: #1c2128; --text-dim: #57606a;
  }
  body { background: #fff; }
  .no-print, .fab, .toast { display: none !important; }
  .report { padding: 0; max-width: 100%; }
  .panel, .card { break-inside: avoid; }
}
