:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1d2733;
  --muted: #66727f;
  --line: #e2e7ec;
  --brand: #14507a;
  --brand-ink: #ffffff;
  --error: #b3261e;
  --radius: 10px;
}

* { box-sizing: border-box; }

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1rem;
  background: var(--brand);
  color: var(--brand-ink);
}
.brand { color: var(--brand-ink); text-decoration: none; font-weight: 600; }
.logout { display: flex; align-items: center; gap: 0.6rem; margin: 0; }
.who { font-size: 0.9rem; opacity: 0.9; }
.logout button {
  background: transparent; color: var(--brand-ink);
  border: 1px solid rgba(255,255,255,0.5); border-radius: 6px;
  padding: 0.3rem 0.7rem; cursor: pointer; font-size: 0.85rem;
}

.container { max-width: 880px; margin: 0 auto; padding: 1rem; }

h1 { font-size: 1.5rem; margin: 0.6rem 0 0.2rem; }
h2 { font-size: 1.1rem; margin: 0 0 0.4rem; }
.muted { color: var(--muted); }
.error { color: var(--error); font-weight: 500; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin: 1rem 0;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.8rem;
  margin: 1rem 0;
}
.stat { text-align: center; margin: 0; }
.stat-num { font-size: 1.8rem; font-weight: 700; color: var(--brand); }
.stat-label { color: var(--muted); font-size: 0.9rem; }

.login-card { max-width: 360px; margin: 3rem auto; }
.login-card h1 { margin-top: 0; }
form label { display: block; margin: 0.8rem 0 0; font-size: 0.9rem; color: var(--muted); }
form input {
  width: 100%; margin-top: 0.25rem; padding: 0.6rem 0.7rem;
  border: 1px solid var(--line); border-radius: 8px; font-size: 1rem;
}
button.primary, .btn {
  display: inline-block; margin-top: 1rem; padding: 0.6rem 1rem;
  background: var(--brand); color: var(--brand-ink);
  border: none; border-radius: 8px; font-size: 1rem; cursor: pointer; text-decoration: none;
}
.btn.disabled { opacity: 0.5; pointer-events: none; }
.btn.danger { background: var(--error); }
.quote-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.quote-actions .btn { margin-top: 0; }

/* breadcrumbs */
.crumb { margin: 0.2rem 0 0; font-size: 0.9rem; }
.crumb a { color: var(--brand); text-decoration: none; }

/* search form */
.search-form .field { margin-bottom: 0.7rem; }
.search-form label { color: var(--muted); font-size: 0.85rem; }
.search-form select,
.search-form input[type="text"],
.search-form input[type="date"] {
  width: 100%; padding: 0.55rem 0.7rem; margin-top: 0.25rem;
  border: 1px solid var(--line); border-radius: 8px; font-size: 1rem; background: #fff;
}
.field-row { display: flex; gap: 0.8rem; flex-wrap: wrap; }
.field-row .field { flex: 1 1 12rem; margin-bottom: 0; }
.field-row .field.grow { flex: 2 1 12rem; }
.field-row .field.shrink { flex: 0 1 7rem; }

.sgroup { margin-bottom: 0.7rem; }
.sgroup .label { display: block; color: var(--muted); font-size: 0.85rem; margin-bottom: 0.2rem; }
.radios { display: inline-flex; flex-wrap: wrap; gap: 0.2rem 0.9rem; align-items: center; }
.radios label.radio { display: inline-flex; align-items: center; gap: 0.3rem; margin: 0;
  width: auto; white-space: nowrap; font-size: 0.9rem; color: var(--ink); }
.radios input[type="radio"] { width: auto !important; min-width: 0; margin: 0; padding: 0; border: none;
  box-shadow: none; -webkit-appearance: radio; appearance: radio; flex: none; }

/* keep search inputs a sensible width on wide screens (full-width on mobile) */
.search-form select { max-width: 24rem; }
.search-form .sgroup input[type="text"] { max-width: 22rem; }
.search-form .sgroup input[type="date"] { max-width: 12rem; }
.search-form .sgroup input[type="number"] { max-width: 7rem; }
.search-form #state { max-width: 5rem; }
.search-form #zip { max-width: 9rem; }
.search-form .field-row { max-width: 36rem; }
.note {
  background: #eef4f9; border: 1px solid #d4e2ee; color: #2a4a63;
  padding: 0.6rem 0.85rem; border-radius: 8px; margin: 1rem 0;
}

.result-count { margin: 1rem 0 0.4rem; }

.refine { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.7rem 0.9rem; margin: 1rem 0; }
.refine label { display: block; color: var(--muted); font-size: 0.85rem; margin-bottom: 0.35rem; }
.refine-row { display: flex; gap: 0.5rem; max-width: 26rem; }
.refine-row input { flex: 1; padding: 0.5rem 0.7rem; border: 1px solid var(--line); border-radius: 8px; font-size: 1rem; }
.refine-row button { padding: 0.5rem 1rem; background: var(--brand); color: var(--brand-ink);
  border: none; border-radius: 8px; cursor: pointer; }

/* results table */
.table-wrap { overflow-x: auto; }
table.results { width: 100%; border-collapse: collapse; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.results th, table.results td {
  text-align: left; padding: 0.55rem 0.7rem; border-bottom: 1px solid var(--line);
  font-size: 0.92rem; white-space: nowrap;
}
table.results td.wrap { white-space: normal; min-width: 16rem; }
table.results td.txt { white-space: normal; }
table.results tbody tr.promo-line { background: #fdf6e9; }
table.results tbody tr.promo-line .cell-name { color: #8a6312; }
table.results tfoot td { font-weight: 700; border-top: 2px solid var(--line); padding: 0.5rem 0.7rem; }
table.results tfoot .tfoot-label { text-align: right; color: var(--muted); }

.report-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
@media print {
  .topbar, .crumb, .no-print { display: none !important; }
  body { background: #fff; }
  .card { border: none; }
}
table.results thead th { background: #eef2f6; font-weight: 600; }
table.results tbody tr.clickable { cursor: pointer; }
table.results tbody tr.clickable:hover { background: #f1f6fa; }
.lr { display: inline-block; min-width: 1.2rem; text-align: center; font-weight: 700; border-radius: 4px; }
.lr-l { color: #1f7a3d; }
.lr-r { color: #8a5a12; }
.cell-name a { color: var(--brand); text-decoration: none; font-weight: 600; }
a.sort { color: inherit; text-decoration: none; }
a.sort.active { color: var(--brand); }
a.sort .arrow { font-size: 0.7rem; margin-left: 0.2rem; }

/* numeric columns line up; keep figures monospaced so dollars align */
table.results { font-variant-numeric: tabular-nums; }
table.results th.num, table.results td.num { text-align: right; }
/* keep the header row visible while scrolling long lists (desktop/tablet) */
table.results thead th { position: sticky; top: 0; z-index: 2; }

/* key/value detail */
.kv { display: grid; gap: 0.6rem; margin-top: 0.6rem; }
.kv.kv-grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.kv .k { display: block; color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
.kv .v { display: block; }
.card.subtle { background: #f7f9fb; }

.acct-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.3rem 0 0.9rem; }

form textarea { width: 100%; padding: 0.55rem 0.7rem; border: 1px solid var(--line);
  border-radius: 8px; font: inherit; resize: vertical; }

/* quote line-entry table inputs */
table.results input { width: 100%; padding: 0.35rem 0.45rem; border: 1px solid var(--line);
  border-radius: 6px; font-size: 0.92rem; }
table.results .q-qty { max-width: 5rem; }
table.results .q-code { max-width: 9rem; text-transform: uppercase; }
table.results .q-price { max-width: 7rem; }
table.results .q-desc { min-width: 11rem; }
table.results td .rm { background: none; border: none; color: var(--error);
  font-size: 1.2rem; line-height: 1; cursor: pointer; padding: 0 0.3rem; }

.quick-add { display: flex; flex-wrap: wrap; gap: 0.9rem 1.6rem; padding: 0.6rem 0.9rem; }
.qa-form { display: flex; flex-direction: column; gap: 0.3rem; flex: 1 1 22rem; }
.qa-form .label { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
.qa-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.qa-row input, .qa-row select { padding: 0.4rem 0.55rem; border: 1px solid var(--line); border-radius: 8px; font-size: 0.92rem; background: #fff; }
.qa-row .qa-date { width: 9rem; flex: 0 0 auto; }
.qa-row .qa-note { flex: 1 1 14rem; min-width: 8rem; }
.qa-note-row { align-items: flex-end; }
textarea.qa-note { resize: vertical; min-height: 3rem; font: inherit; }
.qa-row .radios { flex: 0 0 auto; }
.qa-row button { padding: 0.4rem 0.9rem; background: var(--brand); color: var(--brand-ink); border: none; border-radius: 8px; cursor: pointer; }

/* collapsible quick-add (Add note / call back) — collapsed on phones, open elsewhere */
details.quick-add-wrap { padding: 0; }
details.quick-add-wrap > summary {
  cursor: pointer; list-style: none; padding: 0.55rem 0.9rem;
  font-weight: 600; color: var(--brand); user-select: none;
}
details.quick-add-wrap > summary::-webkit-details-marker { display: none; }
details.quick-add-wrap > summary::before { content: "+ "; font-weight: 700; }
details.quick-add-wrap[open] > summary::before { content: "– "; }
details.quick-add-wrap[open] > summary { border-bottom: 1px solid var(--line); }

table.results tbody tr.mine { background: #f3f9f4; }
.tag-you { background: #d7eede; color: #1f7a3d; border-radius: 4px; padding: 0 0.35rem; font-size: 0.72rem; font-weight: 700; }

.acct-head { display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; }
.acct-head h2 { margin: 0; }
.assigned { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; padding: 0.6rem 0.9rem; }
.rep-chip { background: #e7eef4; color: var(--brand); border-radius: 999px; padding: 0.15rem 0.6rem; font-size: 0.85rem; font-weight: 600; }
.last-po { margin-left: auto; font-size: 0.9rem; }

.po-list { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.4rem; }
.po-chip { display: inline-block; padding: 0.3rem 0.7rem; border-radius: 999px; background: #eef4f9;
  color: var(--brand); text-decoration: none; font-size: 0.85rem; border: 1px solid #d4e2ee; }
.po-chip.order { background: #fdf3da; color: #8a6312; border-color: #f0e0b8; }
.po-chip.warr { background: #fbe4e3; color: #b3261e; border-color: #f3cfcd; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem 1.4rem; align-items: start; }
@media (max-width: 700px) { .two-col { grid-template-columns: 1fr; } }
/* tablet: drop low-priority columns so wide tables fit without sideways scroll */
@media (min-width: 601px) and (max-width: 980px) {
  table.results .hide-tablet { display: none; }
}
table.results.compact th, table.results.compact td { padding: 0.34rem 0.5rem; font-size: 0.86rem; }

/* tabs */
.tabs { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 1.2rem 0 0.4rem; border-bottom: 2px solid var(--line); }
.tabs .tab { padding: 0.45rem 0.8rem; font-size: 0.92rem; border-radius: 8px 8px 0 0; text-decoration: none; color: var(--muted); }
.tabs a.tab:hover { color: var(--brand); }
.tabs .tab.active { background: var(--card); border: 1px solid var(--line); border-top: 3px solid var(--brand); border-bottom: 2px solid var(--card); margin-bottom: -2px; font-weight: 700; color: var(--brand); }
.tabs .tab.disabled { color: #aab3bc; }
.section-h { margin: 1rem 0 0.4rem; }

/* status badges */
.badge { display: inline-block; padding: 0.12rem 0.5rem; border-radius: 999px; font-size: 0.78rem; font-weight: 600; }
.badge.s-complete { background: #e3f1e6; color: #1f7a3d; }
.badge.s-pending  { background: #fdf3da; color: #8a6312; }
.badge.s-cancelled { background: #fbe4e3; color: #b3261e; }

/* ===== theme toggle ===== */
.topbar-right { display: flex; align-items: center; gap: 0.9rem; }
.theme-toggle { display: flex; border: 1px solid rgba(255,255,255,0.5); border-radius: 999px; overflow: hidden; }
.theme-toggle a { padding: 0.2rem 0.62rem; font-size: 0.76rem; color: var(--brand-ink); text-decoration: none; opacity: 0.85; }
.theme-toggle a.on { background: rgba(255,255,255,0.92); color: var(--brand); opacity: 1; font-weight: 600; }

/* ===== Classic skin (Lion-faithful) ===== */
[data-theme="classic"] {
  --brand: #0c6b7a;
  --bg: #e9edf0;
  --ink: #1b2a2e;
  --line: #c5d3d8;
}
[data-theme="classic"] .topbar {
  background: linear-gradient(180deg, #1aa5b8 0%, #0c6b7a 100%);
  border-bottom: 1px solid #095663;
}
/* Lion-style titled header bars */
[data-theme="classic"] h1 {
  background: linear-gradient(180deg, #2bb3c6 0%, #0e8294 100%);
  color: #fff; padding: 0.45rem 0.8rem; border-radius: 5px; font-size: 1.2rem;
  box-shadow: inset 0 -1px 0 rgba(0,0,0,0.18);
}
[data-theme="classic"] .login-card h1 { background: none; color: var(--brand); padding: 0; box-shadow: none; }
[data-theme="classic"] h2 { color: #0c6b7a; }
[data-theme="classic"] .card { border-color: #c5d3d8; border-radius: 5px; }
[data-theme="classic"] .section-h {
  background: linear-gradient(180deg, #d6edf1 0%, #bfe0e6 100%);
  color: #0b4f5a; padding: 0.35rem 0.7rem; border: 1px solid #a9ccd3; border-radius: 4px;
  font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.04em;
}
/* denser, striped data grids like Lion */
[data-theme="classic"] table.results { border-radius: 4px; }
[data-theme="classic"] table.results th,
[data-theme="classic"] table.results td { padding: 0.32rem 0.55rem; font-size: 0.82rem; }
[data-theme="classic"] table.results thead th {
  background: linear-gradient(180deg, #bfe0e6 0%, #a9ccd3 100%); color: #0b4f5a;
  border-bottom: 1px solid #8fb9c1;
}
[data-theme="classic"] table.results tbody tr:nth-child(even) { background: #f1f7f9; }
[data-theme="classic"] table.results tbody tr:hover { background: #e2f0f3; }
[data-theme="classic"] .cell-name a { color: #0c6b7a; }
[data-theme="classic"] a.sort.active { color: #0b4f5a; }
[data-theme="classic"] .tabs { border-bottom-color: #0c6b7a; }
[data-theme="classic"] .tabs .tab.active { color: #0c6b7a; border-color: #c5d3d8; }

/* stacked results on phones */
@media (max-width: 600px) {
  .theme-toggle { display: none; }
  .topbar { padding: 0.6rem 0.8rem; }
  .brand { font-size: 0.95rem; }
  table.results, table.results thead, table.results tbody,
  table.results th, table.results td, table.results tr { display: block; }
  table.results thead { display: none; }
  table.results tbody tr {
    border: 1px solid var(--line); border-radius: 8px; margin-bottom: 0.7rem; padding: 0.3rem 0.6rem;
  }
  table.results td {
    border: none; white-space: normal; padding: 0.3rem 0;
    display: flex; justify-content: space-between; gap: 1rem; align-items: baseline;
  }
  table.results td::before {
    content: attr(data-label); color: var(--muted); font-size: 0.8rem; font-weight: 600;
    flex: 0 0 auto;
  }
  /* hide rows with no value so empty labels (Age, Future Ship, Cell, Call Back) don't show */
  table.results td:empty { display: none; }
  /* lead identifier (name / order # / item code / date) becomes a left-aligned card header */
  table.results td.cell-name {
    justify-content: flex-start; font-size: 1.05rem; font-weight: 600;
    border-bottom: 1px solid var(--line); margin-bottom: 0.3rem; padding-bottom: 0.35rem;
  }
  table.results td.cell-name::before { content: ""; }
  /* long text values (notes, descriptions) stack under the label, left-aligned */
  table.results td.wrap, table.results td.txt {
    flex-direction: column; align-items: stretch; min-width: 0; gap: 0.1rem; text-align: left;
  }
  /* Line-entry forms (quote/order): stack label above a full-width input */
  table.results td.inp {
    flex-direction: column; align-items: stretch; gap: 0.2rem; padding: 0.4rem 0;
  }
  table.results td.inp::before { font-size: 0.78rem; }
  table.results td.inp input, table.results td.inp select {
    width: 100%; max-width: none; box-sizing: border-box;
  }
  table.results td.rm-cell { align-items: flex-end; }
  table.results td.rm-cell::before { content: ""; }
  table.results td.rm-cell .rm { align-self: flex-end; }
  /* bigger tap targets on phones */
  .qa-row input, .qa-row select, .qa-row button,
  .search-form select, .search-form input[type="text"],
  .search-form input[type="date"], .search-form input[type="number"],
  .refine-row input, .refine-row button,
  table.results td.inp input, table.results td.inp select,
  .btn, button.primary { min-height: 44px; }
  .radios input[type="radio"] { width: 20px; height: 20px; }
  .tabs .tab { padding: 0.55rem 0.85rem; }
}
