/* ── Base font size — all em units scale from this ──────────────────────── */
body { font-size: 16px; }

/* ── Spirit base theme ─────────────────────────────────────────────────────
   Light by default. Dark when system prefers it, or when [data-theme="dark"].
   Manual override stored in localStorage key "spirit-theme": "light" | "dark".
   ───────────────────────────────────────────────────────────────────────── */

:root {
  --bg:          #f5f5f5;
  --surface:     #ffffff;
  --surface-2:   #ebebeb;
  --border:      #d8d8d8;
  --text:        #1a1a1a;
  --text-muted:  #6b6b6b;
  --accent:      #2563eb;
  --accent-text: #ffffff;
  --header-bg:   #1e293b;
  --header-text: #ffffff;
  --danger:      #dc2626;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #111111;
    --surface:     #1e1e1e;
    --surface-2:   #2a2a2a;
    --border:      #333333;
    --text:        #e8e8e8;
    --text-muted:  #888888;
    --accent:      #3b82f6;
    --accent-text: #ffffff;
    --header-bg:   #0d1117;
    --header-text: #ffffff;
    --danger:      #ef4444;
  }
}

:root[data-theme="dark"] {
  --bg:          #111111;
  --surface:     #1e1e1e;
  --surface-2:   #2a2a2a;
  --border:      #333333;
  --text:        #e8e8e8;
  --text-muted:  #888888;
  --accent:      #3b82f6;
  --accent-text: #ffffff;
  --header-bg:   #0d1117;
  --header-text: #ffffff;
  --danger:      #ef4444;
}

/* ── Theme toggle button ────────────────────────────────────────────────── */
.theme-toggle {
  background: none;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 5px;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 4px 7px;
  transition: border-color 0.15s, color 0.15s;
  flex-shrink: 0;
}
.theme-toggle:hover {
  border-color: rgba(255,255,255,0.6);
  color: #fff;
}

/* ── Data tables ────────────────────────────────────────────────────────── */
.table-card {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,.1);
  overflow-x: auto;
}
.data-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 1em;
}
.data-table thead tr {
  background: #1a1a2e;
  color: #ffffff;
}
.data-table th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 500;
  white-space: nowrap;
  letter-spacing: 0.02em;
}
.data-table th[onclick] { cursor: pointer; user-select: none; }
.data-table th[onclick]:hover { background: rgba(255,255,255,0.1); }
.data-table th[onclick]::after { content: ''; display: inline-block; width: 1.1em; text-align: right; opacity: 0.5; }
.data-table th[onclick].sort-asc::after { content: ' ↑'; }
.data-table th[onclick].sort-desc::after { content: ' ↓'; }
.data-table td {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table tr:last-child td {
  border-bottom: none;
}
.data-table tr:nth-child(even) {
  background: var(--surface-2);
}
.data-table tr:hover td {
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}

/* ── Part lookup autocomplete ────────────────────────────────────────────── */
.ef-ac       { position: relative; }
.ef-ac-list  {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 100;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 4px; max-height: 200px; overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}
.ef-ac-item  {
  padding: 6px 10px; cursor: pointer; font-size: 0.9em;
  border-bottom: 1px solid var(--border);
}
.ef-ac-item:last-child { border-bottom: none; }
.ef-ac-item:hover { background: var(--surface-2); }

/* ── Field macros ────────────────────────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 1em;
}
.field-label {
  font-size: 0.8em;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.field-label .req { color: #e53e3e; }
.field-input {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.95em;
}
.field-input:focus {
  outline: none;
  border-color: #0a84ff;
  box-shadow: 0 0 0 2px rgba(10, 132, 255, 0.2);
}

/* ── Form header ─────────────────────────────────────────────────────────── */
.fh-wrap { margin-bottom: 1.5em; }
.fh-back {
  display: inline-block;
  font-size: 0.8em;
  color: var(--text-muted);
  text-decoration: none;
  margin-bottom: 0.5em;
}
.fh-back:hover { color: var(--text); }
.fh-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1em;
}
.fh-title {
  font-size: 1.2em;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}
.fh-actions { display: flex; gap: 0.5em; }

/* ── Form card — standalone create/edit forms ───────────────────────────── */
.form-card {
  max-width: 560px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
}
.form-card h1 {
  font-size: 1.0625em;
  font-weight: 600;
  margin-bottom: 1.25em;
  color: var(--text);
}
.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 0.5em;
  align-items: center;
}
.success-banner {
  background: #1c3a2a;
  border: 1px solid #2d6a4f;
  border-radius: 8px;
  color: #74c69d;
  font-size: 0.8125em;
  padding: 10px 14px;
  margin-bottom: 1em;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  padding: 6px 14px;
  border-radius: 4px;
  border: none;
  font-size: 0.875em;
  font-weight: 500;
  cursor: pointer;
}
.btn-primary { background: #1a1a2e; color: #fff; }
.btn-primary:hover { background: #2d2d4e; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #d0d0d8; }

/* ── Clickable table rows ────────────────────────────────────────────────── */
tr.clickable { cursor: pointer; }
tr.clickable td { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }

/* ── Card groups — hub pages, portal-style layouts ──────────────────────── */
.card-groups {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.4em;
}
.card-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.2em 1.4em;
}
.card-group-title {
  font-size: 0.68em;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 0.75em;
  padding-bottom: 0.5em;
  border-bottom: 1px solid var(--border);
}
.card-links {
  list-style: none;
  margin: 0;
  padding: 0;
}
.card-link-item {
  padding: 0.4em 0;
  border-bottom: 1px solid var(--surface-2);
}
.card-link-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}
.card-link-item a {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  font-size: 1.125em;
}
.card-link-item a:hover { text-decoration: underline; }
.card-link-desc {
  display: block;
  font-size: 0.77em;
  color: var(--text-muted);
  margin-top: 0.1em;
}
.card-link-ext {
  font-size: 0.72em;
  color: var(--text-muted);
  margin-left: 0.2em;
}

/* ── Record / detail pages ───────────────────────────────────────────────── */
.rec-wrap      { padding: 2em; }
.rec-header    { display: flex; align-items: baseline; gap: 1em; margin-bottom: 0.3em; }
.rec-header h1 { font-size: 1.3em; font-weight: 700; margin: 0; }
.rec-sub       { font-size: 0.95em; color: var(--text-muted); }
.rec-customer  { font-size: 1em; color: var(--text-muted); }
.rec-meta      { font-size: 0.8em; color: var(--text-muted); margin-bottom: 2em; }
.rec-meta a    { color: var(--text-muted); }
.rec-grid      { display: grid; grid-template-columns: 1fr 1fr; gap: 2em; margin-bottom: 2em; }
.rec-section, .rec-fields { margin-bottom: 2em; }
.rec-section h2, .rec-fields h2 {
  font-size: 0.7em; font-weight: 700; text-transform: uppercase;
  letter-spacing: .1em; color: var(--text-muted);
  border-bottom: 1px solid var(--border); padding-bottom: 5px; margin-bottom: 10px;
}
.rec-field {
  display: flex; gap: 0.5em; padding: 4px 0;
  font-size: 0.9em; border-bottom: 1px solid var(--surface-2);
}
.rec-field:last-child { border-bottom: none; }
.rec-label   { width: 140px; flex-shrink: 0; color: var(--text-muted); font-size: 0.85em; }
.rec-value   { font-weight: 500; }
.rec-notes-text {
  font-size: 0.85em; color: var(--text); white-space: pre-wrap;
  background: var(--surface-2); border-radius: 4px;
  padding: 8px 10px; margin-top: 4px;
}

/* ── Badges ──────────────────────────────────────────────────────────────── */
.rec-badge {
  display: inline-block; font-size: 0.7em; font-weight: 700;
  padding: 2px 8px; border-radius: 10px; text-transform: uppercase;
  letter-spacing: .05em; margin-left: 0.5em; vertical-align: middle;
}
.badge-open      { background: #d1fae5; color: #065f46; }
.badge-active    { background: #d1fae5; color: #065f46; }
.badge-closed    { background: var(--surface-2); color: var(--text-muted); }
.badge-complete  { background: var(--surface-2); color: var(--text-muted); }
.badge-cancelled { background: #fee2e2; color: #991b1b; }
.badge-shipped   { background: #dbeafe; color: #1e40af; }
.badge-burning   { background: #fef3c7; color: #92400e; }
[data-theme="dark"] .badge-open, [data-theme="dark"] .badge-active { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .badge-cancelled { background: #450a0a; color: #fca5a5; }
[data-theme="dark"] .badge-shipped   { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .badge-burning   { background: #451a03; color: #fed7aa; }

/* ── Inventory identifier badges ────────────────────────────────────────── */
.tag-badge, .plate-id {
  display: inline-block; font-family: monospace; font-size: 0.85em;
  border: 1px solid; border-radius: 3px; padding: 1px 5px; white-space: nowrap;
}
.tag-badge  { background: #eef; border-color: #aac; color: #334; }
.plate-id   { background: #f0f4e8; border-color: #99b87a; color: #3a5a1a; }
[data-theme="dark"] .tag-badge  { background: #1e2a4a; border-color: #4a6a9a; color: #b0c4e8; }
[data-theme="dark"] .plate-id   { background: #1a2e10; border-color: #4a7a2a; color: #9ec86a; }

/* ── Button variants ─────────────────────────────────────────────────────── */
.btn-danger        { background: var(--danger); color: #fff; }
.btn-danger:hover  { background: #b91c1c; }
.btn-success       { background: #059669; color: #fff; }
.btn-success:hover { background: #047857; }
.btn-sm            { padding: 4px 10px; font-size: 0.8em; }
[data-theme="dark"] .btn-danger:hover  { background: #dc2626; }
[data-theme="dark"] .btn-success:hover { background: #10b981; }

/* ── Priority markers ────────────────────────────────────────────────────── */
.priority-hot  { color: #dc2626; font-weight: 700; }
.priority-high { color: #d97706; font-weight: 600; }

/* ── Page layout — shared across table, workflow, and scan pages ─────────── */
.pt-wrap { padding: 2em; font-size: 16px; }
.pt-wrap h1 {
  font-size: 1.2em; font-weight: 600; color: var(--text); margin-bottom: 0.4em;
}
.pt-meta { font-size: 0.8em; color: var(--text-muted); margin-bottom: 1em; }

/* ── Toolbar — search bar, filter controls, match count ─────────────────── */
.pt-toolbar {
  display: flex; flex-wrap: wrap; gap: 0.75em;
  margin-bottom: 1.2em; align-items: center;
}
.pt-search {
  flex: 1; min-width: 180px; max-width: 320px;
  font-size: 0.9em; padding: 0.35em 0.75em;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text);
}
.pt-search:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 15%, transparent);
}
.pt-filter { display: flex; align-items: center; gap: 0.5em; }
.pt-filter-label {
  font-size: 0.85em; font-weight: 600;
  color: var(--text-muted); white-space: nowrap;
}
.pt-filter-select {
  font-size: 0.9em; padding: 0.3em 0.6em;
  border: 1px solid var(--border); border-radius: 4px;
  background: var(--surface); color: var(--text); cursor: pointer;
}
.pt-match-count {
  font-size: 0.8em; color: var(--text-muted);
  margin-left: auto; white-space: nowrap;
}

/* ── Tab bar ─────────────────────────────────────────────────────────────── */
.tab-bar {
  display: flex; gap: 0; margin-bottom: 1.2em;
  border-bottom: 2px solid var(--border);
}
.tab-bar-btn {
  padding: 0.4em 1em; font-size: 0.85em; font-weight: 600;
  color: var(--text-muted); cursor: pointer; background: none;
  border: none; border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.tab-bar-btn:hover { color: var(--text); }
.tab-bar-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-bar-btn .tab-count {
  font-size: 0.8em; font-weight: 400; margin-left: 0.3em; opacity: 0.7;
}

/* ── Empty / no-session state ────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 4em 1em; color: var(--text-muted);
}
.empty-state-icon { font-size: 2.5em; margin-bottom: 0.5em; }
.empty-state-title { font-weight: 600; margin-bottom: 0.3em; }
.empty-state-body { font-size: 0.85em; margin-bottom: 1.5em; }

/* ── Print stylesheet ─────────────────────────────────────────────────────── */

/* Page margins apply to all print output. */
@page { margin: 0.5in; }

/* Screen-only utility — toggled visible inside @media print. */
.print-only { display: none; }

@media print {
  /* Visibility isolation: suppress screen chrome and extension injections.
     Pages using this pattern wrap their printable content in .print-body;
     everything else (nav, banners, extension UI) is hidden automatically. */
  body       { visibility: hidden; }
  .print-body {
    visibility: visible;
    position: absolute; left: 0; top: 0; width: 100%;
    font-family: Arial, sans-serif;
    font-size: 11px;
    color: #000;
  }

  /* Utilities */
  .no-print   { display: none !important; }
  .print-only { display: block !important; }

  /* Force paper colors — override dark mode and surface variables. */
  .print-body, .print-body * { background: #fff !important; box-shadow: none !important; }
  .print-body a { color: #000 !important; text-decoration: none; }

  /* Tables */
  .print-body table { width: 100%; border-collapse: collapse; }
  .print-body th {
    background: #222 !important; color: #fff !important;
    padding: 5px 8px; text-align: left;
    font-size: 9px; text-transform: uppercase; white-space: nowrap;
  }
  .print-body td { padding: 5px 8px; border-bottom: 1px solid #ddd; }
  .print-body tr:nth-child(even) td { background: #f5f5f5 !important; }

  /* Document helpers used by print templates */
  .print-label { font-size: 8px; text-transform: uppercase; color: #888; margin-bottom: 2px; }
  .print-sig   { flex: 1; border-top: 1px solid #333; padding-top: 4px; font-size: 8px; text-transform: uppercase; }
  .print-footer { margin-top: 20px; font-size: 9px; color: #999; }
  .print-b { font-weight: 700; }
  .print-r { text-align: right; }
}
