/* ============================================================
   Couture Digital Design System — Expenses App
   Palette extracted from couturedigital.com:
   Colors  : #052E25 (header/footer deep green), #B29A61 (gold accent),
             #D5CDBF (taupe), #F7F7F7 (bg), white cards, #161615 text
   Font    : Raleway (Google Fonts)

   NOTE: these are the fallback defaults. The live values are injected from
   config.yaml `brand:` in base.html/login.html, so re-skinning only requires
   editing the brand block (and static/brand/ assets).
   ============================================================ */

:root {
  --brand-navy: #052E25;          /* primary dark — header/footer */
  --brand-navy-soft: #0A4033;
  --accent: #B29A61;              /* champagne gold — links/actions */
  --accent-dark: #A58D54;
  --secondary: #D5CDBF;           /* taupe */
  --bg: #F7F7F7;                 /* page background */
  --card-bg: #ffffff;
  --text: #161615;
  --muted: #7A7D82;
  --border: #E8E6E1;
  --table-hover: rgba(5,46,37,0.02);
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --success: #10B981;
  --success-bg: #d1fae5;
  --warning: #F59E0B;
  --warning-bg: #fef3c7;
  --shadow: 0 12px 30px rgba(15,23,42,0.06);
  --shadow-sm: 0 4px 20px rgba(5,46,37,0.08);
  --radius: 16px;
  --radius-sm: 12px;
  --radius-pill: 999px;
  --font: 'Raleway', system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* Dark mode overrides — very dark green (not the legacy navy/blue-grey) */
[data-theme="dark"] {
  --brand-navy: #04140F;
  --brand-navy-soft: #052E25;
  --bg: #08120E;
  --card-bg: #0F1D17;
  --text: #E9E6DE;
  --muted: #8DA095;
  --border: #1E3229;
  --table-hover: rgba(178,154,97,0.05);
  --shadow: 0 12px 30px rgba(0,0,0,0.45);
  --shadow-sm: 0 4px 20px rgba(0,0,0,0.45);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background 0.2s ease, color 0.2s ease;
}

/* ---- Header Bar (mirrors invoices/reports/guides) ---- */
.topbar {
  background: var(--brand-navy);
  color: #fff;
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar .logo { height: 38px; width: auto; display: block; }
.topbar .title-block { display: flex; flex-direction: column; margin-right: auto; }
.topbar .title-block .eyebrow {
  font-size: 0.7rem; letter-spacing: 0.18em; text-transform: uppercase;
  color: rgba(255,255,255,0.6); font-weight: 500;
}
.topbar .title-block .title { font-size: 1.25rem; font-weight: 600; letter-spacing: 0.01em; }
.topbar .nav { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; justify-content: flex-end; }
.topbar .nav a {
  color: rgba(255,255,255,0.9); text-decoration: none;
  font-size: 0.85rem; font-weight: 500; padding: 0.4rem 0.8rem;
  border-radius: var(--radius-pill); transition: background 0.15s;
}
.topbar .nav a:hover, .topbar .nav a.active { background: rgba(255,255,255,0.12); }

.user-chip {
  display: flex; align-items: center; gap: 0.5rem;
  color: #fff; font-size: 0.85rem; font-weight: 500;
}
.user-chip a { color: #fff; text-decoration: none; }

/* ---- Layout ---- */
.wrapper { max-width: 1200px; margin: 0 auto; padding: 2rem 1.5rem 4rem; width: 100%; flex: 1; }
.wrapper.narrow { max-width: 560px; }
.wrapper.fluid { max-width: none; padding: 1.5rem 1.25rem 4rem; }
.card {
  background: var(--card-bg); border-radius: var(--radius); padding: 2rem 2.25rem;
  box-shadow: var(--shadow);
}
h1 { color: var(--brand-navy); font-weight: 600; font-size: 1.5rem; margin: 0 0 0.4rem; }
[data-theme="dark"] h1 { color: var(--text); }
.subtitle { color: var(--muted); margin: 0 0 1.5rem; font-size: 0.95rem; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.45rem 1.1rem; border-radius: var(--radius-pill);
  background: var(--accent); color: #fff; text-decoration: none;
  font-family: var(--font); font-size: 0.84rem; font-weight: 500;
  border: none; cursor: pointer; transition: background 0.15s, transform 0.05s;
  line-height: 1.4; white-space: nowrap;
}
.btn:hover { background: var(--accent-dark); transform: translateY(-1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn.navy { background: var(--brand-navy); }
.btn.navy:hover { background: var(--brand-navy-soft); }
.btn.ghost {
  background: transparent; color: var(--accent); border: 1px solid var(--accent);
}
.btn.ghost:hover { background: var(--accent); color: #fff; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #b91c1c; }
.btn.sm { padding: 0.28rem 0.8rem; font-size: 0.78rem; }

/* ---- Icons (flat line SVGs, inherit currentColor) ---- */
.icon { display: inline-block; vertical-align: middle; flex-shrink: 0; }
.btn .icon { margin-right: 0.15rem; }
.btn.sm .icon { width: 14px; height: 14px; }
.tabbar a .tab-ico { display: inline-flex; align-items: center; justify-content: center; height: 22px; }
.fab .icon { width: 26px; height: 26px; }
.modal-close .icon { width: 18px; height: 18px; }

/* ---- Forms ---- */
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: 0.8rem; font-weight: 500; color: var(--muted); margin-bottom: 0.3rem; }
.input, .textarea, select.input {
  width: 100%; padding: 0.55rem 0.85rem; border: 1px solid var(--border);
  border-radius: 10px; font-family: var(--font); font-size: 0.9rem;
  background: var(--card-bg); color: var(--text); transition: border 0.15s, box-shadow 0.15s;
}
.input:focus, .textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(178,154,97,0.22);
}
.textarea { min-height: 90px; resize: vertical; }
.form-row { display: flex; gap: 1rem; }
.form-row .field { flex: 1; }

/* ---- Badges / pills ---- */
.pill {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font-size: 0.72rem; font-weight: 600; padding: 0.15rem 0.6rem;
  border-radius: var(--radius-pill); letter-spacing: 0.02em;
}
.pill-count {
  font-size: 0.72rem; font-weight: 600; padding: 0.15rem 0.6rem;
  border-radius: var(--radius-pill); background: rgba(178,154,97,0.14);
  color: var(--accent-dark);
}
.pill-warn { background: var(--warning-bg); color: #92400e; }
.pill-danger { background: var(--danger-bg); color: #991b1b; }
.pill-success { background: var(--success-bg); color: #065f46; }

/* ---- Tables ---- */
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { padding: 0.7rem 0.6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-weight: 500; color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--table-hover); }
td.num, th.num { text-align: right; }

/* ---- Toast notifications ---- */
.toast-container { position: fixed; top: 70px; right: 20px; z-index: 1000; display: flex; flex-direction: column; gap: 0.6rem; }
.toast {
  background: var(--card-bg); color: var(--text); border-left: 4px solid var(--accent);
  padding: 0.8rem 1.1rem; border-radius: 10px; box-shadow: var(--shadow);
  font-size: 0.85rem; max-width: 320px; animation: slideIn 0.25s ease;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(13,18,32,0.5); backdrop-filter: blur(2px);
  display: none; align-items: center; justify-content: center; z-index: 200; padding: 1.5rem;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--card-bg); border-radius: var(--radius); width: 100%; max-width: 640px;
  max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow);
  animation: modalIn 0.2s ease;
}
@keyframes modalIn { from { transform: translateY(10px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-header { padding: 1.25rem 1.5rem 0.75rem; display: flex; align-items: flex-start; gap: 1rem; border-bottom: 1px solid var(--border); }
.modal-header h3 { margin: 0; font-size: 1.15rem; font-weight: 600; flex: 1; color: var(--text); }
.modal-body { padding: 1.25rem 1.5rem 1.5rem; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--muted); line-height: 1; padding: 0.2rem; display: inline-flex; align-items: center; }

/* ---- Footer ---- */
.footer {
  background: var(--brand-navy); color: rgba(255,255,255,0.85);
  text-align: center; padding: 1.1rem 1.5rem; font-size: 0.82rem; line-height: 1.6;
}
.footer .company { font-weight: 600; color: #fff; }
.footer a { color: rgba(255,255,255,0.85); text-decoration: none; }
.footer .tagline { font-size: 0.72rem; opacity: 0.6; margin-top: 3px; }

/* ---- Empty state ---- */
.empty { color: var(--muted); font-style: italic; font-size: 0.95rem; padding: 2rem 0; text-align: center; }

/* ---- Misc utility ---- */
.flex { display: flex; align-items: center; gap: 0.75rem; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.grid { display: grid; gap: 1.25rem; }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.mt-1 { margin-top: 0.5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; } .mb-2 { margin-bottom: 1rem; } .mb-3 { margin-bottom: 1.75rem; }
.text-muted { color: var(--muted); }
.text-right { text-align: right; }
a.link { color: var(--accent); text-decoration: none; }
a.link:hover { text-decoration: underline; }

/* ---- Stat / summary cards ---- */
.stat-card {
  background: var(--card-bg); border-radius: var(--radius); padding: 1.4rem 1.5rem;
  box-shadow: var(--shadow-sm); border: 1px solid var(--border);
}
.stat-card .stat-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 0.3rem; }
.stat-card .stat-value { font-size: 1.5rem; font-weight: 600; color: var(--brand-navy); }
[data-theme="dark"] .stat-card .stat-value { color: var(--text); }
.stat-card .stat-sub { font-size: 0.78rem; color: var(--muted); margin-top: 0.2rem; }

/* ---- Trip / item cards ---- */
.item-card {
  background: var(--card-bg); border-radius: var(--radius-sm); padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow-sm); text-decoration: none; color: var(--text);
  display: block; transition: transform 0.12s, box-shadow 0.12s; cursor: pointer;
  border: 1px solid var(--border);
}
.item-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--accent); }
.item-card h3 { margin: 0 0 0.25rem; font-size: 1rem; font-weight: 600; color: var(--text); }
.item-card p { margin: 0; color: var(--muted); font-size: 0.82rem; }
.item-card .meta { margin-top: 0.75rem; display: flex; align-items: center; gap: 0.5rem; font-size: 0.75rem; color: var(--muted); flex-wrap: wrap; }

/* Category color dot */
.cat-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }

/* Page header: title + actions */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.page-actions { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.page-head h1 { margin: 0; }

/* Month navigation (Everyday view) */
.month-nav {
  display: flex; align-items: center; gap: 0.5rem; margin-bottom: 1rem;
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius-pill); padding: 0.3rem 0.5rem;
  box-shadow: var(--shadow-sm); width: fit-content;
}
.month-nav .month-label {
  font-weight: 600; font-size: 0.9rem; color: var(--text);
  min-width: 140px; text-align: center;
}
.month-nav .btn { padding: 0.25rem 0.7rem; }
.month-nav #toggle-all { margin-left: auto; }

/* ---- Report builder ---- */
.report-filters { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.report-filters .input { flex: 1 1 160px; min-width: 130px; }
.report-filters .chk {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-size: 0.82rem; color: var(--muted); white-space: nowrap; cursor: pointer;
}
.report-filters .chk input { accent-color: var(--accent); width: 16px; height: 16px; }

.report-row {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.65rem 0.35rem; border-bottom: 1px solid var(--border); cursor: pointer;
}
.report-row:last-child { border-bottom: none; }
.report-row:hover { background: var(--table-hover); }
.report-row input[type=checkbox] { accent-color: var(--accent); width: 18px; height: 18px; flex-shrink: 0; }
.report-row .rr-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.report-row .rr-merchant { font-weight: 500; font-size: 0.9rem; color: var(--text); }
.report-row .rr-meta { font-size: 0.74rem; color: var(--muted); }
.report-row .rr-missing { color: var(--danger); font-weight: 600; }
.report-row .rr-amount { font-weight: 600; font-size: 0.9rem; white-space: nowrap; }

/* Sticky action bar for the report builder */
.report-bar {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--card-bg); border-top: 1px solid var(--border);
  padding: 0.6rem 1rem; display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; z-index: 130; box-shadow: 0 -4px 16px rgba(5,46,37,0.08);
}
.report-bar .rb-info { font-size: 0.85rem; color: var(--muted); }
.report-bar .rb-info strong { color: var(--text); }
.report-spacer { height: 5rem; }
.report-result { border: 1px solid var(--accent); }

@media (max-width: 768px) {
  .report-bar { bottom: calc(3.5rem + env(safe-area-inset-bottom, 0px)); padding: 0.55rem 0.9rem; }
}

/* Row actions (receipt view / edit / delete) */
.row-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }

/* Receipt chips in the expense modal */
.receipt-chip {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  padding: 0.5rem 0.6rem; border: 1px solid var(--border);
  border-radius: 10px; margin-bottom: 0.5rem; background: var(--bg);
}
.receipt-chip .rc-name {
  flex: 1 1 auto; min-width: 120px; font-size: 0.8rem; color: var(--muted);
  word-break: break-all;
}

/* ============================================================
   Mobile / PWA
   ============================================================ */

/* Elements that only appear on small screens */
.tabbar, .fab, .avatar-link { display: none; }

.avatar-link {
  width: 36px; height: 36px; border-radius: 50%;
  align-items: center; justify-content: center;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 0.9rem;
  text-decoration: none; flex-shrink: 0;
}

/* Floating capture button */
.fab {
  position: fixed;
  right: 1.1rem;
  bottom: calc(4.6rem + env(safe-area-inset-bottom, 0px));
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--accent); color: #fff; border: none; cursor: pointer;
  font-size: 1.5rem; line-height: 1;
  box-shadow: 0 8px 24px rgba(178,154,97,0.45);
  align-items: center; justify-content: center;
  z-index: 150;
  transition: transform 0.12s, background 0.15s;
}
.fab:active { transform: scale(0.94); }
.fab:hover { background: var(--accent-dark); }

/* Bottom tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  padding: 0.35rem 0.25rem calc(0.35rem + env(safe-area-inset-bottom, 0px));
  z-index: 140;
  box-shadow: 0 -4px 20px rgba(5,46,37,0.06);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 0.15rem;
  text-decoration: none; color: var(--muted);
  font-size: 0.66rem; font-weight: 500; padding: 0.3rem 0;
  border-radius: 10px;
}
.tabbar a .tab-ico { font-size: 1.25rem; line-height: 1; }
.tabbar a.active { color: var(--accent); }

/* Responsive data tables -> cards on small screens */
@media (max-width: 768px) {
  .nav-desktop { display: none !important; }
  .avatar-link { display: inline-flex; }
  .tabbar { display: flex; }
  .fab { display: flex; }

  /* Room for the fixed tab bar + FAB */
  .wrapper { padding: 1.25rem 0.9rem calc(7rem + env(safe-area-inset-bottom, 0px)); }
  .card { padding: 1.15rem 1rem; border-radius: 14px; }
  .topbar { padding: calc(0.7rem + env(safe-area-inset-top, 0px)) 1rem 0.7rem; }
  .topbar .logo { height: 30px; }
  .topbar .title-block .title { font-size: 1.05rem; }
  .topbar .title-block .eyebrow { font-size: 0.62rem; }
  .form-row { flex-direction: column; gap: 0; }
  h1 { font-size: 1.3rem; }

  /* Header stacks: title on top, actions below and full-width */
  .page-head { flex-direction: column; align-items: stretch; gap: 0.6rem; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1 1 auto; }
  .hide-mobile { display: none !important; }

  /* Other title/action rows wrap instead of overflowing */
  .flex-between { flex-wrap: wrap; }
  .flex-between > .flex { flex-wrap: wrap; }

  /* Bigger touch targets */
  .btn { padding: 0.6rem 1.1rem; font-size: 0.9rem; }
  .btn.sm { padding: 0.42rem 0.9rem; font-size: 0.82rem; }
  .input, .textarea, select.input { padding: 0.7rem 0.9rem; font-size: 1rem; }

  /* Tables become stacked cards */
  table.responsive { font-size: 0.9rem; }
  table.responsive thead { display: none; }
  table.responsive tr {
    display: block; background: var(--card-bg);
    border: 1px solid var(--border); border-radius: 12px;
    padding: 0.6rem 0.75rem; margin-bottom: 0.7rem;
    box-shadow: 0 1px 2px rgba(15,23,42,0.04);
  }
  table.responsive tr:hover td { background: transparent; }
  table.responsive td {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    border: none; padding: 0.28rem 0; text-align: right;
  }
  table.responsive td::before {
    content: attr(data-label);
    font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--muted); font-weight: 600; text-align: left; flex-shrink: 0;
  }
  table.responsive td[data-label=""]::before { content: none; }
  table.responsive td.num { text-align: right; }
  /* Empty cells hidden on mobile */
  table.responsive td.is-empty { display: none; }

  .footer { padding-bottom: calc(1.1rem + 3.5rem + env(safe-area-inset-bottom, 0px)); }
  .toast-container { top: auto; bottom: calc(5rem + env(safe-area-inset-bottom, 0px)); right: 12px; left: 12px; }
  .toast { max-width: none; }
}

@media (max-width: 640px) {
  .wrapper { padding: 1.25rem 0.9rem calc(7rem + env(safe-area-inset-bottom, 0px)); }
  .card { padding: 1.15rem 1rem; }
  .topbar { flex-wrap: nowrap; padding: calc(0.7rem + env(safe-area-inset-top, 0px)) 1rem 0.7rem; }
  .topbar .title-block .title { font-size: 1.05rem; }
  .form-row { flex-direction: column; gap: 0; }
}