/* ── Fonts ─────────────────────────────────────────────────────────────── */
/* Galvji is a macOS system font — no @font-face needed on macOS */

/* ── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand-black:  #1a1a1a;
  --brand-accent: #c4922a;
  --brand-accent-light: #f9f0e0;
  --bg:           #f5f4f0;
  --card-bg:      #ffffff;
  --border:       #e0ddd8;
  --text:         #1a1a1a;
  --text-muted:   #888880;
  --font: 'Galvji', 'Georgia', -apple-system, BlinkMacSystemFont, serif;
}

html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
/* Sticky rather than a viewport-locked flex shell — the page scrolls
   normally (friendlier to mobile browsers, whose address bar resizing and
   on-screen keyboard both fight a 100vh + overflow:hidden shell), while the
   header still stays put as you scroll. */
.app-header {
  background: var(--brand-black);
  color: white;
  padding: 0 16px 0 24px;
  display: flex;
  align-items: center;
  height: 54px;
  flex-shrink: 0;
  gap: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  position: sticky;
  top: 0;
  z-index: 50;
}
.app-brand {
  display: flex;
  align-items: center;
  text-decoration: none;
  margin-right: 24px;
}
.header-logo {
  height: 36px;
  width: auto;
  filter: invert(1);
  opacity: 0.9;
}
.app-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
}
.nav-link {
  padding: 6px 14px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-decoration: none;
  color: rgba(255,255,255,0.6);
  transition: color 0.15s, background 0.15s;
}
.nav-link:hover  { color: white; background: rgba(255,255,255,0.08); }
.nav-link.active { color: white; background: rgba(255,255,255,0.12); }
.header-actions { display: flex; gap: 8px; align-items: center; }
.nav-toggle {
  display: none;
  background: none;
  border: none;
  color: white;
  font-size: 20px;
  line-height: 1;
  padding: 4px 6px;
  cursor: pointer;
}
.nav-scrim { display: none; }

/* ── Main content ─────────────────────────────────────────────────────────── */
.main-content {
  padding: 32px 0 48px;
}
.page-wrap {
  max-width: 1360px;
  margin: 0 auto;
  padding: 0 24px;
  width: 100%;
}

/* ── Responsive: header/nav collapse, tighter spacing ───────────────────────
   One breakpoint (780px) covers phones and small tablets in portrait; above
   it the layout is unchanged from the original fixed design. */
@media (max-width: 780px) {
  .app-header { padding: 0 12px 0 16px; }
  .header-logo { height: 30px; }
  .nav-toggle { display: block; }
  .app-nav {
    display: none;
    position: fixed;
    top: 54px;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    background: var(--brand-black);
    box-shadow: 0 8px 20px rgba(0,0,0,0.3);
    max-height: calc(100vh - 54px);
    overflow-y: auto;
    z-index: 50;
  }
  .app-nav.open { display: flex; }
  .nav-link {
    padding: 14px 20px;
    border-radius: 0;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    font-size: 13px;
  }
  .nav-scrim.visible {
    display: block;
    position: fixed;
    inset: 54px 0 0 0;
    background: rgba(0,0,0,0.35);
    z-index: 40;
  }
  .main-content { padding: 20px 0 40px; }
  .page-wrap { padding: 0 14px; }
  /* Header only has room for one quick-action button at this width —
     +New Invoice stays (matches the original design), +New Receipt is
     still one tap away via the Receipts page itself. */
  .header-action-secondary { display: none; }
}

/* ── Page header ─────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-bottom: 24px;
}
.page-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.header-right {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
}
.back-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
}
.back-link:hover { color: var(--text); }

/* ── Hero (home) ─────────────────────────────────────────────────────────── */
.page-hero {
  text-align: center;
  padding: 40px 0 36px;
}
.hero-name {
  font-size: 42px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brand-black);
  line-height: 1;
}
.hero-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

/* ── Dashboard ───────────────────────────────────────────────────────────── */
.dashboard-section { margin-bottom: 36px; }
.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.section-label-row {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
}
.section-link {
  margin-left: auto;
  font-size: 12px;
  color: var(--brand-accent);
  text-decoration: none;
  font-weight: 600;
}
.section-link:hover { text-decoration: underline; }

.tool-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.tool-card {
  background: var(--card-bg);
  border-radius: 10px;
  padding: 24px 20px;
  box-shadow: 0 1px 6px rgba(0,0,0,0.07);
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 1.5px solid transparent;
  transition: box-shadow 0.15s, transform 0.15s, border-color 0.15s;
}
.tool-card:hover {
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  transform: translateY(-2px);
  border-color: var(--brand-accent);
}
.tool-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
}
.tool-icon--fee     { background: #e8f5e9; color: #2e7d32; }
.tool-icon--perdiem { background: #e3f2fd; color: #1565c0; }
.tool-icon--expense { background: #fff8e1; }
.tool-card-name {
  font-size: 15px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.2px;
  color: var(--brand-black);
}
.tool-card-desc { font-size: 12.5px; color: var(--text-muted); line-height: 1.5; }

/* Recent invoices list */
.recent-list { display: flex; flex-direction: column; gap: 2px; }
.recent-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--card-bg);
  border-radius: 7px;
  text-decoration: none;
  color: inherit;
  font-size: 13px;
  border: 1px solid transparent;
  transition: border-color 0.12s, background 0.12s;
}
.recent-row:hover { background: #f0ede6; border-color: var(--border); }
.recent-num   { font-weight: 700; min-width: 120px; color: var(--brand-black); font-size: 13px; }
/* min-width:0 matters here beyond the mobile fix below: a flex item's
   default min-width is auto (its content's natural size), so despite the
   ellipsis styling this would refuse to shrink past a long client name and
   force the whole row — and with it the whole page — wider than the
   viewport even on desktop with a long enough name. */
.recent-client { flex: 1; min-width: 0; color: #555; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-type  { flex-shrink: 0; }
.recent-date  { color: var(--text-muted); font-size: 12px; min-width: 90px; text-align: right; }
.recent-amount { font-weight: 700; min-width: 80px; text-align: right; }

@media (max-width: 600px) {
  /* The five fixed-width pieces (number, type badge, date, amount) add up
     to more than a phone screen can hold on one line regardless of how far
     the client name shrinks — reflow into two lines instead of relying on
     flex-shrink alone. The type badge is dropped at this width rather than
     wrapped onto a third line; it's redundant with the invoice list itself
     one tap away. */
  .recent-row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    row-gap: 2px;
    column-gap: 8px;
  }
  .recent-num { min-width: 0; grid-column: 1; grid-row: 1; }
  .recent-amount { min-width: 0; grid-column: 2; grid-row: 1; }
  .recent-client { grid-column: 1; grid-row: 2; }
  .recent-date { min-width: 0; grid-column: 2; grid-row: 2; }
  .recent-type { display: none; }
}
.amount--due   { color: var(--brand-accent); }

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border-radius: 10px;
  padding: 20px 24px;
  margin-bottom: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  border: 1px solid var(--border);
}
.card-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.currency-badge {
  background: var(--brand-accent-light);
  color: var(--brand-accent);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

/* ── Forms ──────────────────────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 20px;
}
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.form-group input,
.form-group textarea,
.form-group select {
  border: 1.5px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13.5px;
  font-family: var(--font);
  color: var(--text);
  background: white;
  transition: border-color 0.15s;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--brand-accent);
}
.form-group textarea { resize: vertical; min-height: 72px; }
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
  padding-bottom: 24px;
}

/* ── Buttons ──────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 6px;
  border: none;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary   { background: var(--brand-black); color: white; }
.btn-primary:hover { opacity: 0.82; }
.btn-secondary { background: #e8e6e0; color: var(--brand-black); }
.btn-danger    { background: #c0392b; color: white; }
.btn-outline   { background: white; color: var(--brand-black); border: 1.5px solid var(--border); }
.btn-outline:hover { border-color: #aaa; }
.btn-sm  { padding: 5px 12px; font-size: 12px; }
.btn-lg  { padding: 11px 24px; font-size: 14px; }

/* ── Data table ──────────────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 10px 16px;
  border-bottom: 1.5px solid var(--border);
  background: #faf9f6;
}
.data-table td { padding: 10px 16px; border-bottom: 1px solid #f0ede8; }
.data-row { cursor: pointer; transition: background 0.1s; }
.data-row:hover { background: #faf9f6; }
.inv-num { font-weight: 700; font-size: 12.5px; }

/* ── Type badges ─────────────────────────────────────────────────────────── */
.type-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.type-fee     { background: #e8f5e9; color: #2e7d32; }
.type-perdiem { background: #e3f2fd; color: #1565c0; }
.type-expense { background: #fff8e1; color: #6d4c00; }

/* ── Invoice preview ─────────────────────────────────────────────────────── */
/* The preview is styled to look like a printed document with fixed
   proportions — rather than reflow it into a single mobile column (which
   would stop looking like the invoice it represents), it keeps its
   designed width and scrolls horizontally on narrow screens. */
.invoice-preview { font-family: var(--font); overflow-x: auto; -webkit-overflow-scrolling: touch; }
.inv-preview-inner { min-width: 640px; }
.inv-header {
  display: flex;
  align-items: center;
  margin-bottom: 16px;
}
.inv-name-block { flex: 1; }
.inv-logo { width: 180px; max-width: 100%; height: auto; display: block; }
.inv-title {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 0.05em;
  flex: 1;
  text-align: center;
}
.inv-addr-block {
  flex: 1;
  text-align: right;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.7;
}
.inv-rule { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.inv-meta {
  display: flex;
  gap: 24px;
  margin-bottom: 24px;
}
.inv-bill-to { flex: 1; font-size: 13px; line-height: 1.7; }
.inv-meta-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); margin-bottom: 4px; }
.inv-client-name { font-weight: 700; font-size: 13.5px; }
.inv-details { min-width: 260px; }
.inv-detail-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: 13px;
  padding: 3px 0;
}
.inv-detail-label { color: var(--text-muted); font-size: 12px; }

.inv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-bottom: 16px;
}
.inv-table thead tr { background: var(--brand-black); color: white; }
.inv-table th {
  padding: 9px 12px;
  text-align: left;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.inv-table td { padding: 8px 12px; border-bottom: 1px solid #f0ede8; }
.inv-table tbody tr:nth-child(even) { background: #faf9f6; }
.col-wide { width: 48%; }
.col-num  { text-align: right; width: 13%; }
.col-per  { width: 13%; }
.num-cell { text-align: right; }

.inv-totals { display: flex; justify-content: flex-end; margin-bottom: 16px; }
.totals-inner { width: 280px; }
.totals-line {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 13px;
  border-bottom: 1px solid #f0ede8;
}
.totals-due {
  font-size: 14px;
  font-weight: 700;
  border-top: 2px solid var(--brand-black);
  border-bottom: none;
  padding-top: 8px;
  margin-top: 4px;
  background: var(--brand-black);
  color: white;
  padding: 8px 10px;
  border-radius: 5px;
}

.inv-footer {
  display: flex;
  gap: 32px;
  font-size: 12.5px;
}
.inv-footer-col { flex: 1; }
.inv-footer-heading { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 6px; }
.inv-footer-row { margin-bottom: 3px; }
.inv-footer-row span { font-weight: 700; color: var(--text-muted); font-size: 11px; }
.inv-notes { margin-top: 12px; font-size: 12px; color: var(--text-muted); }
.inv-notes-label { font-weight: 700; }

/* ── Accounting ──────────────────────────────────────────────────────────── */
.accounting-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}
.stat-card { text-align: center; padding: 24px 20px; }
.stat-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); margin-bottom: 8px; }
.stat-value { font-size: 32px; font-weight: 700; color: var(--brand-black); margin-bottom: 6px; }
.stat-sub   { font-size: 12px; color: var(--text-muted); }

.year-select {
  padding: 6px 10px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: var(--font);
  background: white;
}
.year-select:focus { outline: none; border-color: var(--brand-accent); }

.sa-grid { display: flex; flex-direction: column; gap: 0; }
.sa-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #f0ede8;
  font-size: 13px;
}
.sa-label { color: var(--text-muted); }
.sa-value { font-weight: 700; }
.sa-note {
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--brand-accent-light);
  border-left: 3px solid var(--brand-accent);
  padding: 8px 12px;
  border-radius: 0 5px 5px 0;
  line-height: 1.5;
}

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 10px 16px; border-radius: 7px; font-size: 13px; font-weight: 500; min-width: 240px; box-shadow: 0 2px 10px rgba(0,0,0,0.15); animation: slide-in 0.2s ease; }
@keyframes slide-in { from { transform: translateX(30px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.toast.success { background: #d4edda; color: #155724; }
.toast.error   { background: #f8d7da; color: #721c24; }
.toast.info    { background: #d1ecf1; color: #0c5460; }

/* ── Wide-table scrolling ────────────────────────────────────────────────────
   Wrap a <table> in <div class="table-scroll"> wherever it has enough
   columns to overflow a phone width — scrolls horizontally within its own
   card rather than the table silently clipping or forcing the whole page
   to scroll sideways. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ── Responsive: grids, touch targets ────────────────────────────────────── */
@media (max-width: 780px) {
  .tool-grid { grid-template-columns: repeat(2, 1fr); }
  .accounting-grid { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .btn { padding: 10px 18px; }
  .btn-sm { padding: 7px 14px; }
}
@media (max-width: 480px) {
  .tool-grid { grid-template-columns: 1fr; }
  .accounting-grid { grid-template-columns: 1fr; }
  .hero-name { font-size: 30px; }
}

/* ── Misc ────────────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); font-size: 14px; }
