/* =========================================================
   Petty Cash Manager – iOS-inspired design system
   ========================================================= */

/* ── Design tokens ─────────────────────────────────────── */
:root {
  /* Colours */
  --blue:       #007AFF;
  --blue-light: rgba(0,122,255,.10);
  --green:      #34C759;
  --red:        #FF3B30;
  --orange:     #FF9500;
  --yellow:     #FFCC00;
  --indigo:     #5856D6;

  /* Surfaces */
  --bg:         #F2F2F7;
  --card:       #FFFFFF;
  --card-2:     rgba(118,118,128,.12);
  --fill:       rgba(120,120,128,.20);
  --fill-2:     rgba(120,120,128,.16);
  --fill-3:     rgba(120,120,128,.12);

  /* Text */
  --text:       #000000;
  --text-2:     rgba(60,60,67,.85);
  --text-muted: rgba(60,60,67,.55);
  --sep:        rgba(60,60,67,.18);
  --sep-opaque: #C6C6C8;

  /* Brand */
  --brand:      var(--blue);
  --brand-light:var(--blue-light);

  /* Spacing & shape */
  --radius-sm:  8px;
  --radius:     12px;
  --radius-lg:  16px;
  --radius-xl:  20px;
  --shadow-sm:  0 1px 3px rgba(0,0,0,.06),0 1px 2px rgba(0,0,0,.04);
  --shadow:     0 2px 10px rgba(0,0,0,.08),0 1px 3px rgba(0,0,0,.05);
  --shadow-lg:  0 8px 30px rgba(0,0,0,.10),0 2px 8px rgba(0,0,0,.06);

  /* Layout */
  --sidebar-w:  240px;
  --topbar-h:   56px;
  --tab-bar-h:  56px;
  --card-pad:   20px;

  /* Typography */
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue',
          system-ui, Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, 'SF Pro Display',
                  'Helvetica Neue', system-ui, Arial, sans-serif;
  --font-mono: 'SF Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Transitions */
  --t: 220ms cubic-bezier(.4,0,.2,1);
  --t-fast: 140ms cubic-bezier(.4,0,.2,1);
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:         #000000;
    --card:       #1C1C1E;
    --card-2:     rgba(118,118,128,.24);
    --fill:       rgba(118,118,128,.36);
    --fill-2:     rgba(118,118,128,.32);
    --fill-3:     rgba(118,118,128,.24);
    --text:       #FFFFFF;
    --text-2:     rgba(235,235,245,.90);
    --text-muted: rgba(235,235,245,.50);
    --sep:        rgba(84,84,88,.65);
    --sep-opaque: #38383A;
    --blue:       #0A84FF;
    --green:      #30D158;
    --red:        #FF453A;
    --orange:     #FF9F0A;
    --shadow-sm:  0 1px 3px rgba(0,0,0,.30),0 1px 2px rgba(0,0,0,.20);
    --shadow:     0 2px 10px rgba(0,0,0,.40),0 1px 3px rgba(0,0,0,.25);
    --shadow-lg:  0 8px 30px rgba(0,0,0,.50),0 2px 8px rgba(0,0,0,.30);
  }
}
:root[data-theme="dark"] {
  --bg:#000000;--card:#1C1C1E;--card-2:rgba(118,118,128,.24);
  --fill:rgba(118,118,128,.36);--fill-2:rgba(118,118,128,.32);
  --fill-3:rgba(118,118,128,.24);--text:#FFFFFF;
  --text-2:rgba(235,235,245,.90);--text-muted:rgba(235,235,245,.50);
  --sep:rgba(84,84,88,.65);--sep-opaque:#38383A;
  --blue:#0A84FF;--green:#30D158;--red:#FF453A;--orange:#FF9F0A;
  --shadow-sm:0 1px 3px rgba(0,0,0,.30),0 1px 2px rgba(0,0,0,.20);
  --shadow:0 2px 10px rgba(0,0,0,.40),0 1px 3px rgba(0,0,0,.25);
  --shadow-lg:0 8px 30px rgba(0,0,0,.50),0 2px 8px rgba(0,0,0,.30);
}
:root[data-theme="light"] {
  --bg:#F2F2F7;--card:#FFFFFF;--card-2:rgba(118,118,128,.12);
  --fill:rgba(120,120,128,.20);--fill-2:rgba(120,120,128,.16);
  --fill-3:rgba(120,120,128,.12);--text:#000000;
  --text-2:rgba(60,60,67,.85);--text-muted:rgba(60,60,67,.55);
  --sep:rgba(60,60,67,.18);--sep-opaque:#C6C6C8;
  --blue:#007AFF;--green:#34C759;--red:#FF3B30;--orange:#FF9500;
  --shadow-sm:0 1px 3px rgba(0,0,0,.06),0 1px 2px rgba(0,0,0,.04);
  --shadow:0 2px 10px rgba(0,0,0,.08),0 1px 3px rgba(0,0,0,.05);
  --shadow-lg:0 8px 30px rgba(0,0,0,.10),0 2px 8px rgba(0,0,0,.06);
}

/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.47;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; }
ul, ol { list-style: none; }

/* ── App shell ──────────────────────────────────────────── */
.app-shell {
  display: flex;
  min-height: 100dvh;
}
.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.content {
  flex: 1;
  padding: 24px 20px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}

/* Bottom tabs: hidden on desktop, shown on mobile via media query */
.bottom-tabs { display: none; }

/* ── Sidebar ────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100dvh;
  background: var(--card);
  border-right: 1px solid var(--sep);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100dvh;
  overflow-y: auto;
  z-index: 100;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--sep);
}
.brand-mark {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--blue);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  letter-spacing: .5px;
}
.brand-text strong { display: block; font-size: 14px; font-weight: 600; line-height: 1.2; }
.brand-text small { font-size: 11px; color: var(--text-muted); letter-spacing: .1px; }
.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-link {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14.5px;
  font-weight: 500;
  transition: background var(--t-fast), color var(--t-fast);
  text-decoration: none;
}
.nav-link:hover { background: var(--fill-3); text-decoration: none; }
.nav-link.active {
  background: var(--blue-light);
  color: var(--blue);
  font-weight: 600;
}
.sidebar-footer {
  padding: 12px 16px;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--sep);
}

/* ── Topbar ─────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: var(--card);
  border-bottom: 1px solid var(--sep);
  position: sticky;
  top: 0;
  z-index: 90;
}
.page-title {
  flex: 1;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.topbar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: background var(--t-fast);
}
.topbar-user:hover { background: var(--fill-3); }
.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.topbar-user-text { display: none; }
.topbar-user-text strong { display: block; font-size: 13px; font-weight: 600; color: var(--text); }
.topbar-user-text small { font-size: 11px; color: var(--text-muted); }
.icon-btn {
  width: 34px; height: 34px;
  display: none;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--fill-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 18px;
  color: var(--text);
  transition: background var(--t-fast);
}
.icon-btn:hover { background: var(--fill); }

/* ── Theme toggle button ────────────────────────────────── */
.theme-btn {
  display: flex !important;
  font-size: 16px;
  width: 32px; height: 32px;
  background: var(--fill-3);
  border-radius: var(--radius-sm);
}
.theme-btn:hover { background: var(--fill); }

/* ── Page head ──────────────────────────────────────────── */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.page-head .page-actions { display: flex; gap: 8px; flex-wrap: wrap; flex-shrink: 0; }
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.breadcrumb a { color: var(--blue); }
.breadcrumb span { color: var(--sep-opaque); }
.section-title {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -.4px;
  color: var(--text);
  line-height: 1.2;
}

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--sep);
  box-shadow: var(--shadow-sm);
  padding: var(--card-pad);
  margin-bottom: 16px;
}
.card h2, .card h3 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
}
.card h3 { font-size: 15px; color: var(--text); }
.card-footer-actions { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--sep); }

/* ── Two-column grid (profile, etc.) ────────────────────── */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

/* ── Stat cards (dashboard + project) ──────────────────── */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--sep);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat-label { font-size: 12px; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.stat-value {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.3px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.stat-value.dr      { color: var(--blue); }
.stat-value.cr      { color: var(--red); }
.stat-value.balance { color: var(--green); }
.stat-value.negative{ color: var(--red); }
.stat-value.small-value { font-size: 14px; font-weight: 500; }

/* ── Project list (dashboard) ───────────────────────────── */
.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.project-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform var(--t-fast), box-shadow var(--t-fast);
  cursor: pointer;
  border: 1px solid transparent;
}
.project-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  text-decoration: none;
  border-color: var(--sep);
}
.project-card:active { transform: translateY(0); }
.project-card-name { font-size: 15px; font-weight: 600; }
.project-card-meta { font-size: 12px; color: var(--text-muted); }
.project-card-balance {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -.4px;
  font-variant-numeric: tabular-nums;
}
.project-card-balance.positive { color: var(--green); }
.project-card-balance.negative { color: var(--red); }
.project-card-balance.zero     { color: var(--text-muted); }
.project-card-stats { display: flex; gap: 16px; }
.project-card-stat { font-size: 12px; color: var(--text-muted); }
.project-card-stat strong { display: block; font-size: 13px; color: var(--text-2); font-weight: 600; }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: opacity var(--t-fast), transform var(--t-fast), background var(--t-fast);
  white-space: nowrap;
  -webkit-user-select: none;
  user-select: none;
}
.btn:hover { text-decoration: none; opacity: .88; }
.btn:active { transform: scale(.97); }
.btn-primary    { background: var(--blue); color: #fff; }
.btn-primary:hover { opacity: 1; background: #0071EB; }
.btn-ghost      { background: var(--fill-2); color: var(--text); }
.btn-ghost:hover{ background: var(--fill); opacity: 1; }
.btn-danger     { background: var(--red); color: #fff; }
.btn-danger:hover { opacity: 1; background: #E0332A; }
.btn-danger-ghost { background: rgba(255,59,48,.12); color: var(--red); }
.btn-danger-ghost:hover { background: rgba(255,59,48,.20); opacity: 1; }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-xs { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-block { width: 100%; }

/* ── Forms ──────────────────────────────────────────────── */
.stack { display: flex; flex-direction: column; gap: 16px; }
label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  letter-spacing: .1px;
}
label small { font-size: 12px; font-weight: 400; color: var(--text-muted); line-height: 1.4; }
input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="search"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--sep-opaque);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  font-size: 15px;
  font-family: var(--font);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-light);
}
input::placeholder, textarea::placeholder { color: var(--text-muted); font-weight: 400; }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23888' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px; }
textarea { resize: vertical; min-height: 80px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .span-2 { grid-column: span 2; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 4px; }
.inline-form { display: inline; }
.filter-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; padding-top: 16px; }
.filter-grid .span-2 { grid-column: span 2; }
.filter-actions { display: flex; gap: 8px; align-items: flex-end; }

/* ── Currency input ─────────────────────────────────────── */
.currency-input {
  display: flex;
  align-items: stretch;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1.5px solid var(--sep-opaque);
  background: var(--card);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.currency-input:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-light);
}
.currency-input span {
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: var(--fill-3);
  border-right: 1.5px solid var(--sep-opaque);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
  flex-shrink: 0;
}
.currency-input input {
  flex: 1;
  border: none !important;
  box-shadow: none !important;
  border-radius: 0 !important;
  background: transparent;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* ── Transaction type toggle ────────────────────────────── */
.fieldset {
  border: 1.5px solid var(--sep-opaque);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.fieldset legend {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  padding: 0 4px;
}
.type-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.type-option {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--sep-opaque);
  cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast);
  align-items: flex-start;
}
.type-option input { width: auto; margin-top: 2px; flex-shrink: 0; accent-color: var(--blue); }
.type-option span { display: flex; flex-direction: column; }
.type-option strong { font-size: 14px; }
.type-option small { color: var(--text-muted); font-size: 12px; }
.type-option.selected { border-color: var(--blue); background: var(--blue-light); }
.amount-fields { display: grid; gap: 12px; }

/* ── Alerts / Flash ─────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 12px;
  border: 1.5px solid transparent;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.alert p { margin-top: 4px; font-size: 13px; }
.alert strong { font-weight: 600; }
.alert-success { background: rgba(52,199,89,.12); border-color: rgba(52,199,89,.30); color: #1a7a2e; }
.alert-error   { background: rgba(255,59,48,.10); border-color: rgba(255,59,48,.30); color: #b91c1c; }
.alert-warning { background: rgba(255,149,0,.10); border-color: rgba(255,149,0,.30); color: #92400e; }
.alert-info    { background: var(--blue-light); border-color: rgba(0,122,255,.25); color: #1d4ed8; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    .alert-success { color: #34C759; }
    .alert-error   { color: #FF453A; }
    .alert-warning { color: #FF9F0A; }
    .alert-info    { color: #0A84FF; }
  }
}
:root[data-theme="dark"] {
  .alert-success { color: #34C759; }
  .alert-error   { color: #FF453A; }
  .alert-warning { color: #FF9F0A; }
  .alert-info    { color: #0A84FF; }
}
:root[data-theme="dark"] .bottom-tabs { background: rgba(18,18,18,.90); }

/* ── Toast notifications ────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: calc(var(--tab-bar-h) + 12px);
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: rgba(29,29,31,.90);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: #fff;
  padding: 12px 18px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 500;
  max-width: 320px;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toast-in 300ms var(--t) both;
}
.toast.toast-out { animation: toast-out 280ms var(--t) both; }
@keyframes toast-in  { from { opacity:0; transform:translateY(12px) scale(.95); } to { opacity:1; transform:none; } }
@keyframes toast-out { from { opacity:1; transform:none; } to { opacity:0; transform:translateY(8px) scale(.95); } }
@media (min-width: 769px) {
  .toast-container { bottom: 20px; }
}

/* ── Tables ─────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 calc(-1 * var(--card-pad)); }
.table-scroll .table { margin: 0; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.table thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1.5px solid var(--sep);
  white-space: nowrap;
  background: var(--card);
}
.table tbody tr {
  border-bottom: 1px solid var(--sep);
  transition: background var(--t-fast);
}
.table tbody tr:last-child { border-bottom: none; }
.table tbody tr:hover { background: var(--fill-3); }
.table tbody td { padding: 11px 14px; vertical-align: middle; }
.table tfoot th { padding: 10px 14px; border-top: 1.5px solid var(--sep); font-size: 13px; font-weight: 600; }
.table tfoot { background: var(--fill-3); }
.table-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0 0;
  gap: 12px;
  flex-wrap: wrap;
}
.empty-cell { text-align: center; color: var(--text-muted); padding: 32px 14px !important; font-size: 14px; }
.ledger-table .row-receipt td:nth-child(5) { font-weight: 600; }
.row-opening { background: var(--fill-3); font-style: italic; }
.row-opening td { color: var(--text-muted); font-size: 13px; }
.nowrap { white-space: nowrap; }
.sortable { color: var(--text); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; white-space: nowrap; text-decoration: none; }
.sortable:hover { color: var(--blue); text-decoration: none; }

/* ── Pagination ─────────────────────────────────────────── */
.pagination { display: flex; gap: 4px; align-items: center; }
.pagination a, .pagination span {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; text-decoration: none; color: var(--text-2);
  transition: background var(--t-fast);
}
.pagination a:hover { background: var(--fill-2); }
.pagination .current { background: var(--blue); color: #fff; font-weight: 600; }
.pagination .ellipsis { background: none; color: var(--text-muted); }

/* ── Pills / badges ─────────────────────────────────────── */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.6;
  letter-spacing: .2px;
  white-space: nowrap;
}
.pill-success { background: rgba(52,199,89,.14); color: var(--green); }
.pill-danger  { background: rgba(255,59,48,.12); color: var(--red); }
.pill-warning { background: rgba(255,149,0,.14); color: var(--orange); }
.pill-info    { background: var(--blue-light); color: var(--blue); }
.pill-muted   { background: var(--fill-2); color: var(--text-muted); }

/* ── Detail list ────────────────────────────────────────── */
.detail-list { display: flex; flex-direction: column; gap: 0; }
.detail-list > div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--sep);
  font-size: 14px;
}
.detail-list > div:last-child { border-bottom: none; }
.detail-list dt { color: var(--text-muted); font-size: 13px; flex-shrink: 0; }
.detail-list dd { font-weight: 500; text-align: right; }

/* ── Grid form (side panel layout) ─────────────────────── */
.grid-form { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.grid-form > *, .grid-2 > * { min-width: 0; }
.side-card h3 { margin-bottom: 12px; }
.formula {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--fill-3);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  margin: 8px 0;
}

/* ── Colours for amounts ────────────────────────────────── */
.dr { color: var(--blue); }
.cr { color: var(--red); }
.negative { color: var(--red) !important; }
.strong { font-weight: 600; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.text-right { text-align: right !important; }

/* ── Filter panel ───────────────────────────────────────── */
.filter-panel { margin-bottom: 12px; }
.filter-panel > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  list-style: none;
  padding: 4px 0 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
  border-bottom: 1px solid var(--sep);
}
.filter-panel > summary::-webkit-details-marker { display: none; }
.filter-panel > summary::before {
  content: '›';
  display: inline-block;
  transition: transform var(--t-fast);
  font-size: 18px;
  line-height: 1;
  color: var(--text-muted);
}
.filter-panel[open] > summary::before { transform: rotate(90deg); }
.filter-summary {
  font-size: 13px;
  color: var(--text-muted);
  padding: 8px 0 12px;
  border-bottom: 1px solid var(--sep);
  margin-bottom: 4px;
}

/* ── Recalc form ────────────────────────────────────────── */
.recalc-form {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--sep);
  margin-top: 4px;
}

/* ── Confirm page ───────────────────────────────────────── */
.confirm-card { max-width: 560px; }
.confirm-message {
  font-size: 14px;
  color: var(--text-2);
  background: var(--fill-3);
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  margin: 16px 0;
  line-height: 1.6;
}
.confirm-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.tone-warning .confirm-message { background: rgba(255,149,0,.10); border-left: 3px solid var(--orange); }
.tone-danger  .confirm-message { background: rgba(255,59,48,.08); border-left: 3px solid var(--red); }

/* ── Install wizard ─────────────────────────────────────── */
.install-body { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.install-shell { width: 100%; max-width: 560px; }
.install-header { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.install-header h1 { font-size: 22px; font-weight: 700; }
.install-header p { font-size: 13px; color: var(--text-muted); }
.install-steps {
  display: flex;
  list-style: none;
  gap: 0;
  margin-bottom: 24px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--sep);
}
.install-steps li {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 2px;
  padding: 10px 4px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--card);
  border-right: 1px solid var(--sep);
  text-align: center;
}
.install-steps li:last-child { border-right: none; }
.install-steps li span { width: 22px; height: 22px; border-radius: 50%; background: var(--fill-2); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; margin-bottom: 2px; }
.install-steps li.current { color: var(--blue); background: var(--blue-light); }
.install-steps li.current span { background: var(--blue); color: #fff; }
.install-steps li.done span { background: var(--green); color: #fff; }
.install-footer { text-align: center; padding: 16px; font-size: 12px; color: var(--text-muted); }

/* ── Login / guest pages ────────────────────────────────── */
.login-body, .guest-body {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: var(--bg);
}
.login-shell, .guest-shell { width: 100%; max-width: 420px; }
.login-brand, .guest-brand {
  text-align: center;
  margin-bottom: 32px;
}
.login-brand .brand-mark,
.guest-brand .brand-mark {
  width: 56px; height: 56px; border-radius: 16px; font-size: 20px;
  margin: 0 auto 14px;
}
.login-brand h1, .guest-brand h1 {
  font-family: var(--font-display);
  font-size: 26px; font-weight: 700; margin-bottom: 4px;
}
.login-brand p, .guest-brand p { font-size: 14px; color: var(--text-muted); }
.login-card, .auth-card { padding: 28px; }
.guest-footer { text-align: center; padding: 16px; font-size: 12px; color: var(--text-muted); }

/* ── Import screens ─────────────────────────────────────── */
.import-option-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 8px; }
.import-option {
  border: 1.5px solid var(--sep-opaque);
  border-radius: var(--radius-sm);
  padding: 14px;
  cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast);
  display: flex; gap: 10px; align-items: flex-start;
}
.import-option input { accent-color: var(--blue); flex-shrink: 0; margin-top: 3px; }
.import-option:has(input:checked) { border-color: var(--blue); background: var(--blue-light); }
.import-option strong { display: block; font-size: 14px; }
.import-option small { font-size: 12px; color: var(--text-muted); }
[data-mode-panel][hidden] { display: none; }

/* ── Upload area ────────────────────────────────────────── */
.upload-area {
  border: 2px dashed var(--sep-opaque);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.upload-area:hover { border-color: var(--blue); background: var(--blue-light); }
.upload-area input[type="file"] { margin-top: 12px; }
.upload-icon { font-size: 36px; color: var(--text-muted); margin-bottom: 8px; }
.upload-area p { font-size: 14px; color: var(--text-muted); }

/* ── Import preview status colours ─────────────────────── */
.row-ok       { background: rgba(52,199,89,.04); }
.row-duplicate{ background: rgba(255,149,0,.06); }
.row-error    { background: rgba(255,59,48,.06); }
.row-skipped  { opacity: .55; }
.row-imported { background: rgba(52,199,89,.06); }

/* ── Import summary bar ─────────────────────────────────── */
.import-summary {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 0;
  border-bottom: 1px solid var(--sep);
  margin-bottom: 12px;
  font-size: 13px;
}
.import-summary-item { display: flex; align-items: center; gap: 6px; color: var(--text-2); }

/* ── Print styles ───────────────────────────────────────── */
@media print {
  .sidebar,.topbar,.page-actions,.btn,.filter-panel,.table-footer,
  .recalc-form,.alert,.toast-container { display: none !important; }
  .app-main { margin: 0; }
  .content { padding: 0; }
  .card { box-shadow: none; border: 1px solid #ddd; page-break-inside: avoid; }
  body { background: #fff; }
}

/* ── Mobile responsive ──────────────────────────────────── */
@media (max-width: 768px) {
  /* Hide desktop sidebar */
  .sidebar {
    position: fixed;
    left: -280px;
    width: 280px;
    top: 0;
    height: 100dvh;
    z-index: 200;
    transition: left var(--t), box-shadow var(--t);
    box-shadow: none;
  }
  .sidebar.open {
    left: 0;
    box-shadow: var(--shadow-lg);
  }
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 190;
  }
  .sidebar.open ~ .sidebar-overlay { display: block; }

  /* Show hamburger */
  .icon-btn { display: flex; }

  /* Bottom tab bar */
  .bottom-tabs {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: var(--tab-bar-h);
    background: rgba(249,249,249,.88);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--sep);
    display: flex;
    z-index: 150;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .tab-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 500;
    transition: color var(--t-fast);
    padding: 8px 4px;
  }
  .tab-item.active { color: var(--blue); }
  .tab-icon { font-size: 20px; line-height: 1; }

  /* Content padding for bottom tabs */
  .content { padding-bottom: calc(var(--tab-bar-h) + 20px + env(safe-area-inset-bottom, 0px)); }
  .app-main { padding-bottom: 0; }

  /* Topbar shrink */
  .topbar { padding: 0 12px; }
  .topbar-user-text { display: none; }
  .page-title { font-size: 16px; }

  /* Content */
  .content { padding: 16px 12px; }
  .section-title { font-size: 24px; }
  .grid-2 { grid-template-columns: 1fr; }

  /* Stat grid */
  .stat-row { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-value { font-size: 18px; }

  /* Project grid */
  .project-grid { grid-template-columns: 1fr; }

  /* Table: scroll */
  :root { --card-pad: 16px; }
  .card { padding: var(--card-pad); }
  input[type="text"], input[type="email"], input[type="password"], input[type="date"],
  input[type="search"], input[type="number"], select, textarea { font-size: 16px; }
  .grid-form, .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .table { font-size: 13px; }
  .page-head .page-actions { width: 100%; }
  .page-head .page-actions .btn { flex: 1 1 auto; }
  .form-actions .btn { flex: 1 1 auto; }

  /* Stacked rows: each table row becomes a labelled card */
  .table-stack { display: block; }
  .table-stack thead { display: none; }
  .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tbody tr { padding: 12px var(--card-pad); border-bottom: 1px solid var(--sep); }
  .table-stack tbody tr:hover { background: transparent; }
  .table-stack tbody td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 4px 0; text-align: right; white-space: normal;
  }
  .table-stack tbody td::before {
    content: attr(data-label); flex-shrink: 0; text-align: left;
    font-size: 11px; font-weight: 600; letter-spacing: .5px; text-transform: uppercase; color: var(--text-muted);
  }
  .table-stack tbody td.empty-cell { display: block; text-align: center; }
  .table-stack tbody td.empty-cell::before { content: none; }
  .table-stack tbody td.row-actions { justify-content: flex-end; padding-top: 8px; }
  .table-stack tbody td.row-actions::before { content: none; }
  .table-stack .table-scroll { margin: 0; }

  /* Form */
  .field-row, .form-grid, .filter-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
  .grid-form { grid-template-columns: 1fr; }
  .import-option-grid { grid-template-columns: 1fr; }

  /* Page head */
  .page-head { flex-direction: column; }

  /* Toast */
  .toast-container { left: 12px; right: 12px; bottom: calc(var(--tab-bar-h) + env(safe-area-inset-bottom, 0px) + 12px); }
  .toast { max-width: 100%; }
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .bottom-tabs {
    background: rgba(18,18,18,.90);
  }
}

/* ── Dashboard filter bar ───────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--sep);
  margin-bottom: 12px;
}
.filter-bar label { flex: 1 1 180px; }
.filter-bar label.grow { flex: 2 1 240px; }
.filter-bar .filter-actions { flex-shrink: 0; display: flex; gap: 8px; align-items: flex-end; padding-bottom: 2px; }

/* ── View toggle (table/cards) ──────────────────────────── */
.view-toggle { display: flex; gap: 4px; padding: 8px 0 12px; }
.chip {
  display: inline-flex; align-items: center; padding: 5px 14px;
  border-radius: 20px; font-size: 13px; font-weight: 500;
  background: var(--fill-2); color: var(--text-2);
  text-decoration: none; transition: background var(--t-fast), color var(--t-fast);
}
.chip:hover { background: var(--fill); text-decoration: none; }
.chip-active { background: var(--blue); color: #fff; }
.chip-active:hover { background: var(--blue); }

/* ── Project card figures (cards view) ──────────────────── */
.project-card header { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.project-card h3 { font-size: 15px; font-weight: 600; }
.project-card-figures { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.project-card-figures > div { display: flex; flex-direction: column; gap: 3px; }
.project-card-figures .stat-label { font-size: 11px; }
.project-card-figures span:last-child { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.project-card-figures .dr  { color: var(--blue); }
.project-card-figures .cr  { color: var(--red); }
.project-card-figures .balance  { color: var(--green); }
.project-card-figures .negative { color: var(--red); }
.project-card footer { font-size: 12px; color: var(--text-muted); }

/* ── Link strong ────────────────────────────────────────── */
.link-strong { color: var(--text); font-weight: 600; text-decoration: none; }
.link-strong:hover { color: var(--blue); text-decoration: none; }

/* ── Empty state ────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state h3 { font-size: 18px; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.empty-state p { font-size: 14px; margin-bottom: 16px; }

/* ── Flash stack ────────────────────────────────────────── */
.flash-stack { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }

/* ── Confirm card tones ──────────────────────────────────── */
.confirm-warning .confirm-message { background: rgba(255,149,0,.10); border-left: 3px solid var(--orange); }
.confirm-danger  .confirm-message { background: rgba(255,59,48,.08); border-left: 3px solid var(--red); }

/* ── Confirm form actions ────────────────────────────────── */
.confirm-card form.inline-form { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

/* ── Utility classes ────────────────────────────────────── */
.hidden, [hidden] { display: none !important; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }
.mb-3 { margin-bottom: 16px; }
