/* ── Design Tokens ─────────────────────────────────────────── */
:root {
  /* Brand — Reimbursements green */
  --navy:       #064e3b;
  --navy-dark:  #053b2d;
  --primary:    #059669;
  --primary-dk: #047857;
  --success:    #059669;
  --success-bg: #ecfdf5;
  --warn:       #d97706;
  --warn-bg:    #fffbeb;
  --danger:     #dc2626;
  --danger-dk:  #b91c1c;
  --danger-bg:  #fef2f2;

  /* Neutrals */
  --gray-50:  #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-900: #111827;
  --border:   #e5e7eb;

  /* Surfaces */
  --bg:         #f0f1f3;
  --surface:    #ffffff;
  --surface-alt: #f9fafb;
  --surface-hover: #e8ecf1;
  --overlay-bg: rgba(17,24,39,.35);
  --text:       #111827;
  --text-muted: #6b7280;
  --radius:     8px;
  --radius-sm:  5px;
  --radius-lg:  10px;
  --shadow:     0 1px 2px rgba(0,0,0,.05);
  --shadow-md:  0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.04);
  --shadow-lg:  0 4px 16px rgba(0,0,0,.10), 0 12px 40px rgba(0,0,0,.06);

  /* Typography */
  --font:       'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:  'JetBrains Mono', 'SF Mono', Consolas, monospace;

  --ease: cubic-bezier(.4, 0, .2, 1);
}

/* ── Dark mode ────────────────────────────────────────────── */
.dark {
  --bg: #111827;
  --surface: #1f2937;
  --surface-alt: #1a2332;
  --surface-hover: #2a3544;
  --text: #f3f4f6;
  --text-muted: #9ca3af;
  --border: #374151;
  --gray-100: #1f2937;
  --gray-200: #374151;
  --gray-300: #4b5563;
  --gray-50: #1a2332;
  --overlay-bg: rgba(0,0,0,.55);
  --shadow: 0 1px 2px rgba(0,0,0,.2);
  --shadow-md: 0 1px 3px rgba(0,0,0,.3), 0 4px 12px rgba(0,0,0,.15);
  --shadow-lg: 0 4px 16px rgba(0,0,0,.3), 0 12px 40px rgba(0,0,0,.2);
}

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

body {
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
}

/* ── Header ────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  padding: 0 16px;
  height: 48px;
  background: var(--navy);
  color: #fff;
  flex-shrink: 0;
  gap: 12px;
  z-index: 20;
}
.header-left  { display: flex; align-items: center; gap: 10px; }
.header-right { display: flex; align-items: center; gap: 6px; margin-left: auto; }

/* Auth chip */
.auth-wrap { position: relative; }
.auth-chip {
  display: inline-flex; align-items: center; padding: 4px 10px;
  border: 1px solid rgba(255,255,255,.18); border-radius: var(--radius-sm);
  background: rgba(255,255,255,.07); color: #fff; cursor: pointer;
  font: inherit; font-size: 12px; font-weight: 500;
  transition: background .12s;
}
.auth-chip:hover { background: rgba(255,255,255,.14); }
.auth-user-name { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.auth-popover {
  display: none; position: absolute; top: calc(100% + 4px); right: 0;
  min-width: 200px; background: var(--surface); color: var(--gray-900);
  border-radius: var(--radius); border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-lg); padding: 10px 12px; z-index: 100;
}
.auth-popover.open { display: block; }
.auth-popover-name { font-size: 13px; font-weight: 600; }
.auth-popover-email { font-size: 11px; color: var(--gray-500); word-break: break-all; }
.auth-popover-action {
  display: block; width: 100%; text-align: left; background: none; border: none;
  padding: 5px 4px; font-size: 12px; color: var(--gray-700); cursor: pointer;
  border-radius: 4px; text-decoration: none; transition: background .1s;
}
.auth-popover-action:hover { background: var(--gray-100); color: var(--danger); }
.app-logo  { height: 38px; width: auto; display: block; }
.app-title { font-size: 13px; font-weight: 600; color: rgba(255,255,255,.7); letter-spacing: .04em; text-transform: uppercase; }

/* ── Button System ──────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  height: 32px; padding: 0 14px;
  border: 1px solid transparent; border-radius: var(--radius);
  font-family: var(--font); font-size: 12px; font-weight: 600;
  cursor: pointer; white-space: nowrap; text-decoration: none;
  text-transform: capitalize;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
  transition: all .15s var(--ease);
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dk); }
.btn-outline { background: var(--surface); color: var(--text); border-color: var(--gray-300); }
.btn-outline:hover { background: var(--gray-100); border-color: var(--gray-400); }
.btn-ghost { background: transparent; color: var(--text-muted); border: none; box-shadow: none; }
.btn-ghost:hover { background: var(--gray-100); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-dk); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: var(--primary-dk); }
.btn-sm { height: 26px; padding: 0 10px; font-size: 11px; }
.btn-icon {
  width: 32px; height: 32px; padding: 0;
  background: rgba(255,255,255,.07); color: #fff;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: var(--radius-sm); font-size: 15px;
}
.btn-icon:hover { background: rgba(255,255,255,.14); }

/* ── Nav Bar ──────────────────────────────────────────────── */
.nav-bar {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 12px;
  height: 38px;
  background: var(--navy-dark);
  flex-shrink: 0;
  overflow-x: auto;
  z-index: 15;
}
.nav-section {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 8px;
  border-right: 1px solid rgba(255,255,255,.08);
  height: 100%;
}
.nav-section:last-child { border-right: none; }
.nav-section-label {
  font-size: 9px; font-weight: 700; color: rgba(255,255,255,.3);
  text-transform: uppercase; letter-spacing: .08em;
  margin-right: 6px; white-space: nowrap;
}
.nav-segment { display: flex; gap: 1px; }
.nav-btn {
  background: transparent; border: none; color: rgba(255,255,255,.55);
  font: inherit; font-size: 12px; font-weight: 500;
  padding: 6px 10px; border-radius: var(--radius-sm);
  cursor: pointer; white-space: nowrap;
  transition: all .12s var(--ease);
}
.nav-btn:hover { background: rgba(255,255,255,.08); color: rgba(255,255,255,.85); }
.nav-btn.active { background: rgba(255,255,255,.12); color: #fff; font-weight: 600; }

/* ── Filter Bar ──────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.search-wrap {
  position: relative;
  flex: 1;
  max-width: 320px;
}
.search-icon {
  position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; color: var(--gray-400); pointer-events: none;
}
.search-input {
  width: 100%; height: 30px; padding: 0 28px 0 30px;
  border: 1px solid var(--gray-200); border-radius: var(--radius-sm);
  font: inherit; font-size: 12px; background: var(--bg); color: var(--text);
  transition: border-color .15s;
}
.search-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(5,150,105,.15); }
.search-clear {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 20px; height: 20px; background: none; border: none;
  color: var(--gray-400); font-size: 14px; cursor: pointer;
  display: none;
}
.search-input:not(:placeholder-shown) + .search-clear + .search-clear,
.search-wrap:focus-within .search-clear { display: block; }
.filter-select {
  height: 30px; padding: 0 28px 0 8px;
  border: 1px solid var(--gray-200); border-radius: var(--radius-sm);
  font: inherit; font-size: 12px; background: var(--surface); color: var(--text);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%239ca3af'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  cursor: pointer;
}
.filter-select:focus { outline: none; border-color: var(--primary); }
.filter-summary { font-size: 11px; color: var(--text-muted); white-space: nowrap; margin-left: auto; }

/* ── Main Content ─────────────────────────────────────────── */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
.view { display: none; }
.view.active { display: block; }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  overflow: hidden;
}
.card-header {
  padding: 10px 16px;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-body { padding: 16px; }

/* ── Stat Tiles ────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  position: relative;
  overflow: hidden;
}
.stat-tile::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
}
.stat-tile.green::before { background: var(--success); }
.stat-tile.amber::before { background: var(--warn); }
.stat-tile.red::before   { background: var(--danger); }
.stat-tile.blue::before  { background: #3b82f6; }
.stat-label { font-size: 10px; font-weight: 600; text-transform: uppercase; color: var(--text-muted); letter-spacing: .04em; }
.stat-value { font-size: 26px; font-weight: 700; color: var(--text); margin-top: 4px; font-family: var(--font-mono); }

/* ── Tables ────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.data-table th {
  padding: 8px 12px;
  text-align: left;
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted);
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 2;
}
.data-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
.data-table tr:hover td { background: var(--surface-hover); }
.data-table tr { cursor: pointer; transition: background .1s; }
.data-table td.mono { font-family: var(--font-mono); font-size: 11px; }
.data-table td.right { text-align: right; }

/* ── Status Badges ────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .03em;
  white-space: nowrap;
}
.badge-draft       { background: var(--gray-200); color: var(--gray-700); }
.badge-submitted,
.badge-pending_approval { background: #dbeafe; color: #1e40af; }
.badge-approved     { background: #d1fae5; color: #065f46; }
.badge-rejected     { background: #fecaca; color: #991b1b; }
.badge-sent_to_payroll { background: #e0e7ff; color: #3730a3; }
.badge-paid         { background: #d1fae5; color: #065f46; }
.badge-finance_review { background: #fef3c7; color: #92400e; }
.badge-ready_to_post { background: #cffafe; color: #155e75; }
.badge-posted_to_xero { background: #d1fae5; color: #065f46; }
.badge-exception    { background: #fecaca; color: #991b1b; }
.badge-closed       { background: var(--gray-200); color: var(--gray-600); }

.dark .badge-submitted,
.dark .badge-pending_approval { background: #1e3a5f; color: #93c5fd; }
.dark .badge-approved { background: #064e3b; color: #6ee7b7; }
.dark .badge-rejected { background: #7f1d1d; color: #fca5a5; }
.dark .badge-sent_to_payroll { background: #312e81; color: #a5b4fc; }
.dark .badge-paid { background: #064e3b; color: #6ee7b7; }
.dark .badge-finance_review { background: #78350f; color: #fcd34d; }
.dark .badge-ready_to_post { background: #164e63; color: #67e8f9; }
.dark .badge-posted_to_xero { background: #064e3b; color: #6ee7b7; }
.dark .badge-exception { background: #7f1d1d; color: #fca5a5; }

/* ── Forms ─────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 12px;
}
.form-label {
  display: block;
  font-size: 11px; font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .03em;
  margin-bottom: 4px;
}
.form-control {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font: inherit; font-size: 13px;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(5,150,105,.15); }
textarea.form-control { height: auto; padding: 8px 10px; resize: vertical; min-height: 60px; }
select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%239ca3af'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.form-help { font-size: 11px; color: var(--gray-400); margin-top: 2px; }

/* ── Dialog ────────────────────────────────────────────────── */
.dialog-overlay {
  display: none; position: fixed; inset: 0; z-index: 1000;
  background: var(--overlay-bg);
  align-items: center; justify-content: center;
}
.dialog-overlay.open { display: flex; }
.dialog-box {
  background: var(--surface); border-radius: var(--radius-lg);
  padding: 24px; width: min(420px, 90vw);
  box-shadow: var(--shadow-lg);
}
.dialog-title { font-size: 15px; font-weight: 700; margin-bottom: 8px; }
.dialog-message { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; }
.dialog-input, .dialog-textarea {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--gray-200); border-radius: var(--radius-sm);
  font: inherit; font-size: 13px; margin-bottom: 12px;
  background: var(--surface); color: var(--text);
}
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ── Detail Panel ─────────────────────────────────────────── */
.detail-overlay {
  display: none; position: fixed; inset: 0; z-index: 500;
  background: var(--overlay-bg);
}
.detail-overlay.open { display: flex; justify-content: flex-end; }
.detail-panel {
  width: min(600px, 90vw); height: 100%;
  background: var(--surface); display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: slide-in .2s var(--ease);
}
@keyframes slide-in { from { transform: translateX(100%); } to { transform: translateX(0); } }
.detail-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.detail-panel-header h3 { font-size: 15px; font-weight: 700; }
.detail-close {
  width: 28px; height: 28px; border: none; background: transparent;
  color: var(--gray-500); font-size: 16px; cursor: pointer;
  border-radius: var(--radius-sm);
}
.detail-close:hover { background: var(--gray-100); color: var(--danger); }
.detail-panel-body { flex: 1; overflow-y: auto; padding: 16px 20px; }

/* ── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 600;
  background: var(--overlay-bg);
  align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  max-height: 90vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 15px; font-weight: 700; }
.modal-close {
  width: 28px; height: 28px; border: none; background: transparent;
  color: var(--gray-500); font-size: 16px; cursor: pointer;
  border-radius: var(--radius-sm);
}
.modal-close:hover { background: var(--gray-100); color: var(--danger); }
.modal-body { flex: 1; overflow-y: auto; padding: 16px 20px; }

/* Settings tabs */
.settings-tab-bar { display: flex; gap: 2px; margin-bottom: 16px; }
.settings-tab-btn {
  background: transparent; border: none; padding: 6px 14px;
  font: inherit; font-size: 12px; font-weight: 500; color: var(--text-muted);
  border-radius: var(--radius-sm); cursor: pointer;
}
.settings-tab-btn:hover { background: var(--gray-100); }
.settings-tab-btn.active { background: var(--primary); color: #fff; font-weight: 600; }

/* ── Toast ─────────────────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 20px; right: 20px; z-index: 2000;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 12px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toast-in .25s var(--ease);
  max-width: 360px;
}
.toast-success { background: #059669; color: #fff; }
.toast-error   { background: #dc2626; color: #fff; }
.toast-info    { background: #3b82f6; color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* ── Timeline ──────────────────────────────────────────────── */
.timeline { padding: 0; list-style: none; }
.timeline-item {
  position: relative;
  padding: 0 0 16px 24px;
}
.timeline-item::before {
  content: '';
  position: absolute; left: 7px; top: 6px; bottom: 0;
  width: 2px; background: var(--gray-200);
}
.timeline-item:last-child::before { display: none; }
.timeline-item::after {
  content: '';
  position: absolute; left: 2px; top: 4px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--surface);
}
.timeline-item .timeline-date { font-size: 10px; color: var(--text-muted); }
.timeline-item .timeline-text { font-size: 12px; color: var(--text); margin-top: 2px; }

/* ── Claim Form ────────────────────────────────────────────── */
.line-item-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
}
.line-item-card .line-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.line-item-card .line-number {
  font-size: 11px; font-weight: 700; color: var(--primary);
}
.attachment-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; background: var(--gray-100); border-radius: var(--radius-sm);
  font-size: 11px; color: var(--text-muted); margin: 2px;
}
.attachment-chip .remove-att {
  cursor: pointer; color: var(--danger); font-weight: 700; margin-left: 2px;
}
.drop-zone {
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius);
  padding: 20px; text-align: center;
  color: var(--gray-400); font-size: 12px;
  transition: border-color .15s, background .15s;
  cursor: pointer;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--primary);
  background: rgba(5,150,105,.04);
}

/* ── Empty state ───────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state h3 { font-size: 16px; color: var(--text); margin-bottom: 8px; }
.empty-state p { font-size: 13px; max-width: 400px; margin: 0 auto; }

/* ── Misc ──────────────────────────────────────────────────── */
.amount { font-family: var(--font-mono); font-weight: 500; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 11px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 768px) {
  .nav-bar { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
  .filter-bar { flex-wrap: wrap; }
  .detail-panel { width: 100vw; }
}
