:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #667085;
  --line: #d8e0e7;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --income: #157347;
  --expense: #b42318;
  --warning: #b7791f;
  --ink: #0f172a;
  --soft: #eef6f4;
  --shadow: 0 10px 26px rgba(15, 23, 42, .07);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #102a2e;
}

.auth-card {
  width: min(460px, 100%);
  background: var(--panel);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.brand-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
  min-width: 0;
}

.brand-mark {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, #2dd4bf, #f59e0b);
  color: #082f2d;
  font-weight: 800;
}

.brand-row h1 { margin: 0; font-size: 20px; color: var(--ink); overflow-wrap: anywhere; }
.brand-row p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  background: #102a2e;
  color: #f8fafc;
  padding: 20px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sidebar .brand-row { margin-bottom: 4px; }
.sidebar .brand-row h1 { color: #fff; font-size: 17px; }
.sidebar .brand-row p { color: #b9c8c9; }

.nav { display: grid; gap: 6px; }
.nav a {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  padding: 9px 11px;
  border-radius: 8px;
  color: #d7e6e4;
  white-space: nowrap;
}
.nav a:hover, .nav a.active { background: rgba(255,255,255,.11); color: #fff; }

.sidebar-foot {
  margin-top: auto;
  padding: 12px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px;
  color: #d7e6e4;
  font-size: 13px;
}

.main { min-width: 0; padding: 24px; }

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.topbar h2 { margin: 0; color: var(--ink); font-size: 26px; letter-spacing: 0; }
.topbar p { margin: 4px 0 0; color: var(--muted); }

.panel, .metric, .auth-card {
  border: 1px solid var(--line);
}

.panel {
  background: var(--panel);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.panel-header {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.panel-header h3 { margin: 0; font-size: 16px; color: var(--ink); }
.panel-header p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.panel-body { padding: 16px; }

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, .55fr);
  gap: 14px;
  align-items: start;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric {
  background: var(--panel);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
  min-height: 112px;
}

.metric span { color: var(--muted); font-size: 13px; }
.metric strong { display: block; margin-top: 8px; font-size: 24px; color: var(--ink); word-break: break-word; }
.metric small { display: block; margin-top: 8px; color: var(--muted); }

.panel-body .metrics .metric {
  box-shadow: none;
  background: #fbfdfd;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field { display: grid; gap: 6px; }
.field.full { grid-column: 1 / -1; }
label { font-size: 12px; color: #475569; font-weight: 700; }

input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}
textarea { min-height: 82px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 3px solid rgba(37, 99, 235, .18);
  border-color: #2563eb;
}

.btn {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 700;
  cursor: pointer;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.danger { color: var(--expense); border-color: #efb3ac; }
.btn.wide { width: 100%; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.table-wrap {
  overflow-x: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
}
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 11px 10px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; vertical-align: top; }
th { background: #f8fafc; color: #475569; font-size: 12px; text-transform: uppercase; letter-spacing: 0; }
.num { text-align: right; white-space: nowrap; }

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 800;
  background: #eef2f7;
  color: #475569;
}
.badge.income, .badge.approved { background: #e8f6ee; color: var(--income); }
.badge.expense, .badge.draft { background: #fff0ed; color: var(--expense); }
.badge.warn { background: #fff8e6; color: var(--warning); }

.alert {
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  background: #f8fafc;
}
.alert.success { border-color: #b7e1c7; background: #e8f6ee; color: #166534; }
.alert.danger { border-color: #f3b5ad; background: #fff0ed; color: #991b1b; }
.muted { color: var(--muted); }
.demo-box { background: var(--soft); padding: 12px; border-radius: 8px; margin: 12px 0; }

.quick-list { display: grid; gap: 8px; }
.quick-list a { padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.quick-list a:hover { border-color: var(--primary); background: var(--soft); }

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
    gap: 12px;
  }
  .sidebar .brand-row {
    margin-bottom: 0;
  }
  .nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 2px 0 6px;
    margin: 0 -2px;
    -webkit-overflow-scrolling: touch;
  }
  .nav a {
    flex: 0 0 auto;
    background: rgba(255,255,255,.06);
    border: 1px solid rgba(255,255,255,.08);
  }
  .sidebar-foot {
    margin-top: 0;
    display: flex;
    align-items: center;
    gap: 8px 12px;
    flex-wrap: wrap;
    padding: 10px;
  }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .auth-page {
    align-items: start;
    padding: 14px;
  }
  .auth-card {
    padding: 18px;
  }
  .main {
    padding: 14px;
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
  }
  .topbar {
    flex-direction: column;
    gap: 10px;
    margin-bottom: 14px;
  }
  .topbar h2 {
    font-size: 22px;
    line-height: 1.2;
  }
  .topbar p {
    font-size: 13px;
  }
  .panel-header {
    flex-direction: column;
    padding: 14px;
  }
  .panel-body {
    padding: 14px;
  }
  .metrics, .form-grid { grid-template-columns: 1fr; }
  .panel-body .metrics {
    grid-template-columns: 1fr !important;
  }
  .metric {
    min-height: auto;
    padding: 14px;
  }
  .metric strong {
    font-size: 21px;
  }
  .actions {
    justify-content: flex-start;
    width: 100%;
  }
  .actions .btn,
  .actions .badge {
    flex: 1 1 auto;
  }
  .btn {
    width: 100%;
  }
  input, select, textarea {
    font-size: 16px;
  }
  table {
    min-width: 680px;
  }
  th, td {
    padding: 10px 9px;
    font-size: 13px;
  }
  .sidebar {
    padding: 12px 12px 10px;
  }
  .sidebar .brand-row h1 {
    font-size: 16px;
  }
  .sidebar-foot {
    font-size: 12px;
  }
}

@media (max-width: 420px) {
  .brand-mark {
    width: 38px;
    height: 38px;
  }
  .nav a {
    min-height: 42px;
    padding: 8px 10px;
    font-size: 13px;
  }
  .metric span,
  label,
  .panel-header p {
    font-size: 12px;
  }
  .panel-header h3 {
    font-size: 15px;
  }
}
