@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;600;700;900&display=swap');

/* Dark theme site-wide (TAB M Solutions brand red on a dark charcoal
   surface) — header is darkest, page background sits above that, cards sit
   above the page, hover states are brightest. Everything below reads off
   these variables rather than hardcoding light-mode colors, so there's one
   place to retune the palette. */
:root {
  --brand: #cc3627;
  --brand-dark: #a82c1f;
  --brand-light: #f9dedb;
  --accent-blue: #2563a8;
  --accent-blue-light: #e3edf7;
  --ink: #e5e7eb;
  --muted: #9aa3af;
  --bg: #12151c;
  --card: #1b1f29;
  --card-raised: #242a36;
  --input-bg: #10131a;
  --border: #2b3140;
  --link: #ff9086;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.25);
  --shadow-hover: 0 6px 16px rgba(0, 0, 0, 0.4), 0 2px 6px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

body {
  font-family: 'Roboto', -apple-system, Segoe UI, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  margin: 0;
}

/* .topbar/.brand/.brand-mark/.brand-name are owned by tabm-brand.css
   (linked before this file in every view's <head>) -- see that file for
   the header bar, logo, and brand text. Only the parts specific to this
   app's own nav (the links themselves) live here. */
.topnav { display: flex; gap: 18px; align-items: center; }
.topnav a { color: #fff; font-weight: 500; opacity: 0.8; font-size: 14px; position: relative; padding: 4px 0; text-decoration: none; }
.topnav a:hover { opacity: 1; }
.topnav a::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -2px; height: 2px;
  background: var(--brand); transform: scaleX(0); transition: transform 0.15s ease;
}
.topnav a:hover::after { transform: scaleX(1); }
.topnav form { margin: 0; }

main { max-width: 1100px; margin: 24px auto; padding: 0 16px; }
h1, h2 { font-weight: 600; color: var(--ink); }
h1 { font-size: 22px; }
h2 { font-size: 16px; margin-top: 32px; }

/* Section headers used to visually group a page into named zones
   (Purchasing / Invoices / etc.) instead of one undifferentiated grid. */
.section-title {
  display: flex; align-items: center; gap: 10px; margin: 32px 0 14px;
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
}
.section-title:first-child { margin-top: 0; }
.section-title::after { content: ''; flex: 1; height: 1px; background: rgba(255, 255, 255, 0.12); }
.section-title .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dot-color, var(--brand)); flex-shrink: 0; }

.stat-row { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 28px; }
a.stat-tile, .stat-tile {
  background: var(--card); border-radius: 8px; padding: 16px 20px 16px 18px; flex: 1 1 150px; min-width: 150px;
  box-shadow: var(--shadow); text-decoration: none; color: inherit; display: block;
  border: 1px solid var(--border); border-left: 3px solid var(--tile-accent, var(--border));
  transition: box-shadow 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}
a.stat-tile { cursor: pointer; }
a.stat-tile:hover { box-shadow: var(--shadow-hover); border-color: var(--brand); border-left-color: var(--brand); transform: translateY(-1px); }
.stat-tile .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-tile .value { font-size: 24px; font-weight: 700; margin-top: 4px; color: var(--ink); }
.stat-tile.warn { --tile-accent: #d97706; }
.stat-tile.warn .value { color: #f5a623; }
.stat-tile.danger { --tile-accent: #dc2626; }
.stat-tile.danger .value { color: #ff6b6b; }

/* "Needs your attention" hero on the dashboard — a calm card when nothing's
   urgent, a brand-red-tinted one the moment something is, so the home
   screen visually escalates instead of treating every state the same. */
.hero-attention {
  border-radius: 10px; padding: 18px 22px; margin-bottom: 28px; box-shadow: var(--shadow);
  background: var(--card); border: 1px solid var(--border);
}
.hero-attention.is-urgent {
  background: linear-gradient(135deg, #241a19 0%, #2e1815 130%);
  border: 1px solid #5a2b26;
}
.hero-attention h2 { margin: 0 0 4px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.hero-attention .hero-sub { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.hero-attention.is-urgent .hero-sub { color: #e0a89f; }
.hero-chips { display: flex; flex-wrap: wrap; gap: 10px; }
.hero-chip {
  display: flex; align-items: baseline; gap: 6px; background: var(--card-raised); border-radius: 20px;
  padding: 6px 14px 6px 12px; font-size: 13px; font-weight: 600; text-decoration: none; color: var(--ink);
  border: 1px solid var(--border); box-shadow: var(--shadow); transition: transform 0.15s ease, border-color 0.15s ease;
}
.hero-chip:hover { transform: translateY(-1px); border-color: var(--brand); }
.hero-chip .n { font-size: 15px; font-weight: 700; }
.hero-chip.chip-danger { border-color: #6b322c; }
.hero-chip.chip-danger .n { color: #ff8a80; }
.hero-chip.chip-warn { border-color: #6b5323; }
.hero-chip.chip-warn .n { color: #f5b544; }
.hero-chip.chip-ok .n { color: #4ade80; }

.badge-overdue { background: #4a1f1f; color: #ff8a80; }
.badge-due-soon { background: #4a3a12; color: #fbbf24; }

.quick-links { display: flex; gap: 12px; margin-bottom: 28px; }
.quick-links a {
  background: var(--card); border-radius: 8px; padding: 14px 20px; flex: 1; text-align: center;
  font-weight: 600; text-decoration: none; color: var(--ink); box-shadow: var(--shadow);
  border: 1px solid var(--border); transition: box-shadow 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}
.quick-links a:hover { box-shadow: var(--shadow-hover); border-color: var(--brand); transform: translateY(-1px); }

.tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs a {
  padding: 6px 14px; border-radius: 16px; background: var(--card); text-decoration: none;
  color: var(--ink); font-size: 13px; font-weight: 600; box-shadow: var(--shadow); border: 1px solid var(--border);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.tabs a:hover { background: #3a2321; border-color: #6b322c; color: #ff9086; }
.tabs a.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.tabs a.active:hover { background: var(--brand-dark); }

table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 8px; overflow: hidden; margin-bottom: 32px; box-shadow: var(--shadow); border: 1px solid var(--border); }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 14px; overflow-wrap: break-word; }
th { background: var(--card-raised); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
th[data-sort] { cursor: pointer; user-select: none; position: relative; padding-right: 20px; }
th[data-sort]:hover { color: var(--ink); }
th[data-sort]::after { content: '⇅'; position: absolute; right: 6px; opacity: 0.35; font-size: 11px; }
th[data-sort][data-sort-dir="asc"]::after { content: '↑'; opacity: 1; color: var(--brand); }
th[data-sort][data-sort-dir="desc"]::after { content: '↓'; opacity: 1; color: var(--brand); }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--card-raised); }
td a, table a { color: var(--ink); text-decoration: none; font-weight: 600; }
td a:hover, table a:hover { text-decoration: underline; }

/* Tables scroll horizontally inside their own box on narrow viewports
   rather than squeezing every column or overflowing the page. */
.table-wrap { width: 100%; overflow-x: auto; margin-bottom: 32px; }
.table-wrap table { margin-bottom: 0; }

.badge { padding: 2px 8px; border-radius: 12px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-pending { background: #4a3a12; color: #fbbf24; }
.badge-approved { background: #12362a; color: #4ade80; }
.badge-rejected { background: #4a1f1f; color: #ff8a80; }
.badge-paid { background: #241f47; color: #a5b4fc; }

form.card, .card { background: var(--card); padding: 20px; border-radius: 8px; margin-bottom: 24px; max-width: 480px; box-shadow: var(--shadow); border: 1px solid var(--border); }
label { display: block; margin-top: 12px; font-size: 13px; font-weight: 600; color: var(--ink); }
input, select, textarea {
  width: 100%; padding: 8px 10px; margin-top: 4px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 14px; font-family: inherit; background: var(--input-bg); color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input::placeholder, textarea::placeholder { color: #6b7280; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(204, 54, 39, 0.2);
}

button {
  margin-top: 16px; background: var(--brand); color: #fff; border: none; padding: 10px 16px;
  border-radius: 6px; font-weight: 600; cursor: pointer; transition: background 0.15s ease;
}
button:hover { background: var(--brand-dark); }
button.secondary { background: #4b5563; }
button.secondary:hover { background: #3a4150; }
button.danger { background: #dc2626; }
button.danger:hover { background: #b91c1c; }

/* flex + gap instead of inline+margin: rows can carry 3-5 action buttons
   (complete/approve/reject/mark-paid/demote/delete) and plain inline
   margins left them crowded edge-to-edge; this also lets them wrap cleanly
   on a narrow table instead of overflowing. */
.actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.actions form { display: inline-flex; margin: 0; }
.actions a, .actions > button { margin: 0; }
.actions button { padding: 5px 12px; font-size: 12px; margin: 0; white-space: nowrap; }

.error { color: #ff8a80; font-size: 14px; }
.empty { color: var(--muted); font-style: italic; padding: 16px; }

/* Plain <a> tags outside a table (td a/table a above) had no color rule at
   all, so they fell back to the browser's default link blue -- unreadable
   against the dark card background. TAB M brand red instead. */
.ref-link { color: var(--brand); font-weight: 600; text-decoration: none; }
.ref-link:hover { text-decoration: underline; color: var(--brand-dark); }

/* Type-to-search combobox layered over every <select> (see
   public/searchable-select.js). .ss-input reuses the normal input/select
   styling above so it's visually identical to a plain dropdown until
   focused. .ss-dropdown is appended to <body> and positioned with `fixed`
   coordinates from JS -- deliberately NOT nested under .searchable-select-wrap,
   since several of these live inside a <table> (overflow: hidden) and would
   get clipped otherwise. */
.searchable-select-wrap { display: block; position: relative; }
.ss-dropdown {
  position: fixed; z-index: 1000; max-height: 280px; overflow-y: auto;
  background: var(--card); border: 1px solid var(--border); border-radius: 6px;
  box-shadow: var(--shadow-hover); display: none;
}
.ss-dropdown.open { display: block; }
.ss-option { padding: 8px 10px; font-size: 14px; cursor: pointer; color: var(--ink); }
.ss-option:hover { background: var(--card-raised); }
.ss-option.disabled { color: var(--muted); cursor: default; }
.ss-empty { padding: 8px 10px; font-size: 13px; color: var(--muted); font-style: italic; }
