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

:root {
  --blue: #002d56;
  --blue-dark: #1d4354;
  --blue-light: #e8eef4;
  --red: #c30e2e;
  --green: #1a7a3e;
  --border: #d1d5db;
  --bg: #e9ecef;
  --bg-admin: #f8f9fa;
  --surface: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --radius: 6px;
}

body {
  font-family: 'Open Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* Admin tab keeps the original, lighter background -- set on body (not
   scoped to #tab-admin) since the darker --bg shows through page gutters
   outside the tab sections themselves. */
body.admin-active { background: var(--bg-admin); }

/* ── Header ── */
header {
  background: var(--blue-dark);
  color: white;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
  border-bottom: 3px solid var(--red);
}
.header-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 52px;
}
.logo { height: 34px; width: auto; }
h1 { font-family: 'Rokkitt', serif; font-size: 18px; font-weight: 700; white-space: nowrap; margin-right: 16px; }

nav { display: flex; gap: 4px; }
.tab-btn {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.75);
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.tab-btn:hover { background: rgba(255,255,255,0.15); color: white; }
.tab-btn.active { background: var(--red); color: white; }

.header-inner .user-menu {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.user-menu button {
  padding: 5px 12px;
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,0.4);
  background: transparent;
  color: white;
  cursor: pointer;
  font-size: 12px;
}
.user-menu button:hover { background: rgba(255,255,255,0.15); }

/* ── Main ── */
main { padding: 20px 24px; }
.tab { display: none; }
.tab.active { display: block; }

/* ── Toolbar ── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters input:not([type="checkbox"]) {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 10px;
  font-size: 13px;
  background: var(--surface);
  min-width: 130px;
}
.filters button, .export-btn {
  padding: 6px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 13px;
  background: var(--surface);
}
.export-btn {
  background: var(--green);
  color: white;
  border-color: var(--green);
  font-weight: 600;
  white-space: nowrap;
}
.export-btn:hover { opacity: 0.9; }
/* Jobs-tab per-row Export only (icon, no text) -- the toolbar's "Export
   All"/"Export to Excel" buttons keep their text and don't carry this
   class. Fixed width for the same reason as .comments-btn-icon: a
   consistent size next to the other icon buttons on the row. Outlined
   rather than the toolbar buttons' solid fill, matching the outlined
   look of the other row-level icon buttons (Comments, Delete) next to it
   -- no documented reason for the toolbar's solid green, just left as-is
   since it wasn't part of this change. */
.export-btn-icon { width: 44px; display: inline-flex; align-items: center; justify-content: center; background: var(--surface); color: var(--green); border-color: var(--green); }
.export-btn-icon:hover { background: #d1fae5; opacity: 1; }

.filters button.filter-active {
  background: var(--blue);
  border-color: var(--blue);
  color: white;
  font-weight: 600;
}
.filters button.filter-active:hover { opacity: 0.9; }

/* ── Tables ── */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  font-size: 13px;
}
thead th {
  background: var(--blue);
  color: white;
  text-align: left;
  padding: 9px 12px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
thead th:hover { background: var(--blue-dark); }
.sort-icon { font-size: 10px; opacity: 0.7; }
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--blue-light); }
td { padding: 8px 12px; vertical-align: top; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.invoice-count-cell { text-align: center; }
td.job-link {
  color: var(--blue);
  cursor: pointer;
  font-weight: 500;
}
td.job-link:hover { text-decoration: underline; }

/* ── Summary cards ── */
.summary-cards {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
  min-width: 160px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.card-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.card-value { font-size: 22px; font-weight: 700; color: var(--blue); margin-top: 2px; }
/* Matches .review-badge's amber, not --red, since this reflects the same
   "needs a look" severity as the per-invoice flag, not a destructive action. */
.card-value.alert { color: #92400e; }
/* Jobs tab's summary row only -- borderless/flat so it reads as distinct
   from the bordered filter inputs on the same screen. Other .card users
   (e.g. Job Detail's Total Cost/Invoices cards) keep the default border. */
#jobs-summary .card { border: none; }
.card-clickable { cursor: pointer; }
.card-clickable:hover { box-shadow: 0 2px 5px rgba(0,0,0,0.12); }

/* ── Job detail ── */
#job-detail { background: var(--surface); border-radius: var(--radius); padding: 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.back-btn {
  background: none;
  border: none;
  color: var(--blue);
  cursor: pointer;
  font-size: 13px;
  padding: 0;
  margin-bottom: 12px;
  font-weight: 500;
}
.back-btn:hover { text-decoration: underline; }
.job-detail-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
#job-detail h2 { font-family: 'Rokkitt', serif; font-size: 20px; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 20px; }
.detail-section h3 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.supplier-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; }
.reassignment-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; color: var(--muted); }

/* ── Reassign Job ── */
.reassign-btn {
  padding: 6px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--blue);
  background: var(--surface);
  color: var(--blue);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.reassign-btn:hover { background: var(--blue-light); }
td.actions-cell { white-space: nowrap; }
/* vertical-align: middle -- without it, the icon buttons (Export/Comments,
   both display: inline-flex) establish a different inline baseline than
   the plain-text buttons (Reassign, Delete) next to them, so the default
   baseline alignment visibly offsets them top/bottom within the row. */
td.actions-cell button { margin-right: 6px; vertical-align: middle; }
td.actions-cell button:last-child { margin-right: 0; }
.job-detail-actions { display: flex; gap: 8px; }

/* ── Comments ── */
/* Dark yellow/gold, same everywhere the button appears (Jobs tab, Job Detail
   panel, Invoices tab) -- distinct from the blue Reassign button next to it
   and, being yellow rather than orange/amber, doesn't read as a second red
   next to the Delete button. */
.comments-btn {
  padding: 6px 14px;
  border-radius: var(--radius);
  border: 1px solid #a16207;
  background: var(--surface);
  color: #a16207;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.comments-btn:hover { background: #fef9c3; }
/* Jobs/Invoices rows only (icon + optional single-digit count, no
   "Comments" text) -- fixed width so the button doesn't visibly shrink
   when a job/invoice has zero comments vs. 1-9. Job Detail's text-label
   "Comments" button is unaffected since it doesn't carry this class. */
.comments-btn-icon { width: 52px; display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
/* Count next to the icon -- .comments-btn sets font-weight: 600 for the
   button's own (now icon-only) label, but the number reads better lighter. */
.comments-count { font-weight: 400; }

/* ── Delete Invoice ── */
.delete-invoice-btn {
  padding: 6px 14px;
  border-radius: var(--radius);
  border: 1px solid #c30e2e;
  background: var(--surface);
  color: #c30e2e;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  /* Icon only (inline SVG, DELETE_ICON_SVG in app.js), no text -- only
     used in this one spot (Invoices-tab row, admin-only), so a fixed
     width/flex-centering lives directly on the base class rather than a
     separate -icon modifier like .export-btn-icon. */
  width: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.delete-invoice-btn:hover { background: #fdecec; }
.comments-modal { width: 480px; }
.comments-list {
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 4px;
}
.comment-row { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.comment-row:last-child { border-bottom: none; }
.comment-date { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.comment-text { font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.comments-list .modal-hint { padding: 10px; }
.modal textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
}

/* ── Landing / login page ── */
.landing-page {
  min-height: calc(100vh - 55px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  background:
    linear-gradient(180deg, rgba(10, 20, 30, 0.6), rgba(0, 45, 86, 0.8)),
    url('/img/background.jpg') center / cover no-repeat,
    var(--blue-dark);
}
.landing-content {
  text-align: center;
  color: white;
  max-width: 420px;
  width: 100%;
}
.landing-content h1 {
  font-family: 'Rokkitt', serif;
  font-size: 30px;
  margin-bottom: 10px;
  text-shadow: 0 2px 6px rgba(0,0,0,0.4);
}
.landing-tagline {
  font-size: 14px;
  color: rgba(255,255,255,0.9);
  margin-bottom: 28px;
  text-shadow: 0 1px 4px rgba(0,0,0,0.4);
}
.landing-signin-card {
  background: rgba(255,255,255,0.97);
  color: var(--text);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.4);
}
.landing-signin-card h3 { font-family: 'Rokkitt', serif; font-size: 17px; margin-bottom: 8px; }
.landing-signin-card p { font-size: 13px; color: var(--muted); margin-bottom: 16px; }
#google-signin-button { display: flex; justify-content: center; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  width: 380px;
  max-width: 90vw;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
.modal h3 { font-family: 'Rokkitt', serif; font-size: 17px; margin-bottom: 10px; }
.modal p { font-size: 13px; margin-bottom: 6px; }
.modal-hint { color: var(--muted); }
.modal label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; }
.modal input[type="text"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 13px;
}
.modal-error {
  color: #991b1b;
  background: #fee2e2;
  border: 1px solid #fca5a5;
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 12px;
  margin-top: 10px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}
.modal-actions button {
  padding: 6px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 13px;
}
.modal-actions button.primary {
  background: var(--blue);
  color: white;
  border-color: var(--blue);
  font-weight: 600;
}
.modal-actions button.primary:hover { opacity: 0.9; }

/* ── Admin ── */
#tab-admin {
  margin: -20px -24px;
  padding: 40px 24px;
  min-height: calc(100vh - 55px);
  background:
    linear-gradient(180deg, rgba(10, 20, 30, 0.55), rgba(0, 45, 86, 0.75)),
    url('/img/commercial-electric.jpg') center / cover no-repeat,
    var(--blue-dark);
}
.admin-section {
  max-width: 540px;
  margin: 24px auto;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.admin-section-wide { max-width: 700px; }
.admin-section h2 { font-family: 'Rokkitt', serif; margin-bottom: 8px; }
.admin-section p { color: var(--muted); margin-bottom: 20px; }
.admin-section label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; }
.admin-section label.checkbox-filter { display: flex; margin-top: 10px; }
.admin-section input[type="number"] {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 13px;
  width: 140px;
}
.admin-section input[type="number"]:disabled { background: var(--bg); color: var(--muted); }
.admin-section code {
  background: var(--blue-light);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
}
.admin-actions { margin-top: 18px; }
.admin-actions button.primary {
  padding: 6px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--blue);
  background: var(--blue);
  color: white;
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
}
.admin-actions button.primary:hover { opacity: 0.9; }
.admin-success {
  color: #065f46;
  background: #d1fae5;
  border: 1px solid #6ee7b7;
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 12px;
  margin-top: 10px;
}
.admin-run-status {
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}
.admin-run-status.running { color: var(--blue); }
.admin-run-status.success { color: #065f46; }
.admin-run-status.failed { color: #991b1b; }
.admin-table { width: 100%; margin-top: 8px; }
.admin-table input[type="text"], .admin-table select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
  font-size: 13px;
}
.admin-table select { min-width: 90px; }
.admin-table input[type="text"].user-name { min-width: 120px; }
.forwarder-add-row {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}
.forwarder-add-row input[type="text"] {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 13px;
}
.forwarder-add-row select {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 13px;
}
.forwarder-add-row button.primary {
  padding: 6px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--blue);
  background: var(--blue);
  color: white;
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
}

/* ── Upload ── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  color: var(--muted);
  transition: border-color 0.2s, background 0.2s;
}
.drop-zone.over { border-color: var(--blue); background: var(--blue-light); }
.file-label {
  display: inline-block;
  margin-top: 10px;
  padding: 7px 18px;
  background: var(--blue);
  color: white;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.file-label input { display: none; }
.upload-result {
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
}
.upload-result.success { background: #d1fae5; border: 1px solid #6ee7b7; color: #065f46; }
.upload-result.error { background: #fee2e2; border: 1px solid #fca5a5; color: #991b1b; }
.upload-result.loading { background: var(--blue-light); border: 1px solid #93c5fd; color: var(--blue); }

/* ── Comment presence badge ── */
.comment-badge {
  display: inline-block;
  background: #e0f2fe;
  color: #075985;
  border: 1px solid #7dd3fc;
  border-radius: var(--radius);
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

/* ── Manual review flag ── */
.checkbox-filter { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); }
tr.needs-review { background: #fffbeb; }
tr.needs-review:hover { background: #fef3c7; }
.review-badge {
  display: inline-block;
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fcd34d;
  border-radius: var(--radius);
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.clear-review-btn {
  padding: 2px 8px;
  border-radius: var(--radius);
  border: 1px solid #92400e;
  background: var(--surface);
  color: #92400e;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  margin-left: 4px;
}
.clear-review-btn:hover { background: #fef3c7; }
.flag-review-btn {
  padding: 2px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
}
.flag-review-btn:hover { background: #fef3c7; color: #92400e; border-color: #fcd34d; }

.hidden { display: none !important; }
