/* =============================================================================
   Butte Fence Sales Portal — stylesheet

   Mobile-first (design doc S11): reps use this on phones in the field. Layout
   starts single-column and widens at 700px / 1024px.

   COLOR NOTES
   -----------
   Brand navy/rust below is PROVISIONAL — design doc Q5 has "confirm exact
   assets with Tom before finalizing theme". Every brand value is a custom
   property in :root, so swapping in the real palette is a one-block edit.

   The aging ramp is the validated single-hue blue ordinal ramp (steps 250-650).
   A green->red aging ramp was tried first and rejected: its yellow and orange
   steps measured ΔE 10.1 apart for normal vision, below the 15 floor, so the
   1-30 and 31-60 buckets would have been genuinely hard to tell apart. "How
   overdue" is carried by the always-visible bucket label plus a reserved
   status color on past-due figures, never by hue alone.

   Light mode only, deliberately: an internal business tool rendered on one
   known surface. Every color is stated explicitly rather than inherited.
   ============================================================================= */

:root {
  /* --- Brand (provisional — see Q5) --- */
  --brand:          #1B3A5C;
  --brand-dark:     #12293F;
  --brand-light:    #2C567F;
  --brand-wash:     #EEF3F8;
  --accent:         #C8542B;

  /* --- Surfaces & ink --- */
  --surface:        #FFFFFF;
  --plane:          #F5F7FA;
  --raised:         #FFFFFF;
  --ink:            #16202B;
  --ink-2:          #4A5A6B;
  --muted:          #7B8A9A;
  --line:           #E2E8F0;
  --line-strong:    #CBD5E1;

  /* --- Status (reserved; always paired with a label) --- */
  --good:           #0CA30C;
  --good-text:      #056B05;
  --warning:        #FAB219;
  --serious:        #EC835A;
  --critical:       #D03B3B;
  --critical-text:  #A32020;

  /* --- Aging ordinal ramp: validated one-hue blue, light -> dark --- */
  --age-0: #86B6EF;   /* Current */
  --age-1: #5598E7;   /* 1-30    */
  --age-2: #2A78D6;   /* 31-60   */
  --age-3: #1C5CAB;   /* 61-90   */
  --age-4: #104281;   /* 90+     */

  --radius:    10px;
  --radius-sm: 7px;
  --shadow:    0 1px 2px rgba(22,32,43,.06), 0 1px 3px rgba(22,32,43,.04);
  --shadow-lg: 0 4px 16px rgba(22,32,43,.10);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--plane);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-light); }
a:hover { color: var(--brand); }

/* =============================================================================
   App shell
   ============================================================================= */

.masthead {
  background: var(--brand);
  color: #fff;
  border-bottom: 3px solid var(--brand-dark);
}

.masthead-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  color: #fff;
  text-decoration: none;
  min-width: 0;
}

.brand-mark {
  width: 34px; height: 34px;
  flex: 0 0 34px;
  border-radius: 8px;
  background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.22);
  display: grid; place-items: center;
  font-weight: 700; font-size: 13px; letter-spacing: .02em;
}

.brand-text { min-width: 0; }
.brand-name {
  font-weight: 650; font-size: 15px; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-sub {
  font-size: 11.5px; color: rgba(255,255,255,.72); line-height: 1.3;
}

.masthead-spacer { flex: 1 1 auto; }

.user-chip {
  display: flex; align-items: center; gap: 9px;
  color: #fff; text-decoration: none;
  padding: 5px 8px; border-radius: var(--radius-sm);
}
.user-chip:hover { background: rgba(255,255,255,.10); color: #fff; }
.avatar {
  width: 30px; height: 30px; flex: 0 0 30px;
  border-radius: 50%;
  background: rgba(255,255,255,.18);
  border: 1px solid rgba(255,255,255,.25);
  display: grid; place-items: center;
  font-size: 11.5px; font-weight: 650;
}
.user-meta { display: none; }
.user-name { font-size: 13px; font-weight: 550; line-height: 1.2; }
.user-role {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em;
  color: rgba(255,255,255,.7);
}

.linkbtn {
  background: none; border: 1px solid rgba(255,255,255,.28);
  color: #fff; font: inherit; font-size: 13px;
  padding: 6px 12px; border-radius: var(--radius-sm); cursor: pointer;
}
.linkbtn:hover { background: rgba(255,255,255,.12); }

/* --- Navigation --- */

.nav {
  background: var(--brand-dark);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }

.nav-inner {
  max-width: 1360px; margin: 0 auto;
  display: flex; gap: 2px; padding: 0 8px;
  min-width: max-content;
}

.nav a {
  color: rgba(255,255,255,.76);
  text-decoration: none;
  padding: 11px 14px;
  font-size: 13.5px; font-weight: 550;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
}
.nav a:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav a.on {
  color: #fff;
  border-bottom-color: var(--accent);
  background: rgba(255,255,255,.08);
}

/* --- Main --- */

.wrap {
  max-width: 1360px;
  margin: 0 auto;
  padding: 18px 14px 40px;
}

.page-head {
  display: flex; flex-wrap: wrap; align-items: baseline;
  gap: 8px 14px; margin-bottom: 16px;
}
.page-head h1 {
  margin: 0; font-size: 21px; font-weight: 650; letter-spacing: -.01em;
}
.page-head .sub { color: var(--muted); font-size: 13.5px; }
.page-head-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* =============================================================================
   Stat tiles — a bare number is the right form here, no chart
   ============================================================================= */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.tile {
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px 16px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.tile::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--brand-light);
}
.tile.tile-accent::before  { background: var(--accent); }
.tile.tile-good::before    { background: var(--good); }
.tile.tile-neutral::before { background: var(--line-strong); }

.tile-label {
  font-size: 11.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .055em; color: var(--muted); margin-bottom: 7px;
}
.tile-value {
  font-size: 25px; font-weight: 660; letter-spacing: -.02em;
  line-height: 1.15; color: var(--ink);
}
.tile-value.sm { font-size: 21px; }
.tile-note { font-size: 12.5px; color: var(--ink-2); margin-top: 5px; }

/* =============================================================================
   Cards & panels
   ============================================================================= */

.card {
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  overflow: hidden;
}

.card-head {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: #FCFDFE;
}
.card-head h2 {
  margin: 0; font-size: 14.5px; font-weight: 640; letter-spacing: -.005em;
}
.card-head .spacer { flex: 1 1 auto; }
.card-body { padding: 16px; }
.card-body.flush { padding: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 18px; }

/* =============================================================================
   Tables
   ============================================================================= */

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;   /* columns must align vertically */
}

table.data thead th {
  position: sticky; top: 0; z-index: 2;
  background: #F7F9FC;
  text-align: left;
  font-size: 11px; font-weight: 660;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-2);
  padding: 9px 12px;
  border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
}

/* Sortable column headers. The whole header cell is the hit target, so it stays
   usable on a phone where a text-sized link would not be. */
table.data thead th.sortable { padding: 0; }
table.data thead th.sortable > a {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 9px 12px;
  color: inherit;
  text-decoration: none;
  white-space: nowrap;
}
table.data thead th.sortable.num > a { justify-content: flex-end; }
table.data thead th.sortable > a:hover { background: var(--brand-wash); color: var(--brand); }
table.data thead th.sortable > a:focus-visible {
  outline: 2px solid var(--brand-light);
  outline-offset: -2px;
}
/* Direction arrow: shown solid on the active column, ghosted on hover elsewhere
   so the column reads as sortable before you click it. */
table.data thead th.sortable .caret { font-size: 9px; line-height: 1; opacity: 0; }
table.data thead th.sortable > a:hover .caret { opacity: .45; }
table.data thead th.sortable.on > a { color: var(--brand); }
table.data thead th.sortable.on .caret { opacity: 1; }

table.data tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

table.data tbody tr:hover { background: var(--brand-wash); }
table.data tbody tr:last-child td { border-bottom: none; }

table.data tfoot td {
  padding: 11px 12px;
  border-top: 2px solid var(--line-strong);
  font-weight: 650;
  background: #F7F9FC;
}

.num { text-align: right; white-space: nowrap; }
.neg { color: var(--critical-text); }
.strong { font-weight: 640; }
.dim { color: var(--muted); }
.nowrap { white-space: nowrap; }

.cell-main { font-weight: 550; }
.cell-sub  { font-size: 12px; color: var(--muted); }

/* =============================================================================
   Badges & status
   ============================================================================= */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 100px;
  font-size: 11.5px; font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; flex: none; }

.badge-paid    { background: #E7F6E7; color: var(--good-text);     border-color: #C4E9C4; }
.badge-paid    .dot { background: var(--good); }
.badge-partial { background: #FDF1E9; color: #8A4218;              border-color: #F7D9C6; }
.badge-partial .dot { background: var(--serious); }
.badge-unpaid  { background: #EEF3F8; color: var(--brand);         border-color: #D3E0EC; }
.badge-unpaid  .dot { background: var(--brand-light); }
.badge-flag    { background: #FBE9E9; color: var(--critical-text); border-color: #F3CDCD; }
.badge-flag    .dot { background: var(--critical); }
.badge-muted   { background: #F1F4F8; color: var(--ink-2);         border-color: var(--line); }
.badge-muted   .dot { background: var(--muted); }

.role-pill {
  display: inline-block; padding: 2px 8px; border-radius: 5px;
  font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em;
}
.role-ADMIN       { background: #EDE9FB; color: #3F2E9E; }
.role-MANAGER     { background: #E4EEF9; color: var(--brand); }
.role-SALESPERSON { background: #EFF2F5; color: var(--ink-2); }

/* --- Aging bucket cue: the label always shows, color is reinforcement --- */
.age {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 570; white-space: nowrap;
}
.age .swatch { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.age-CURRENT .swatch { background: var(--age-0); }
.age-1-30    .swatch { background: var(--age-1); }
.age-31-60   .swatch { background: var(--age-2); }
.age-61-90   .swatch { background: var(--age-3); }
.age-90plus  .swatch { background: var(--age-4); }
.age-90plus  { color: var(--critical-text); }

/* --- Aging distribution: single stacked bar, 2px surface gaps --- */
.agebar {
  display: flex; width: 100%; height: 14px;
  border-radius: 4px; overflow: hidden; gap: 2px; background: var(--plane);
}
.agebar span { display: block; height: 100%; }
.agebar span:first-child { border-radius: 4px 0 0 4px; }
.agebar span:last-child  { border-radius: 0 4px 4px 0; }

.agelegend {
  display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 12px;
  font-size: 12.5px;
}
.agelegend .item { display: flex; align-items: center; gap: 6px; }
.agelegend .swatch { width: 10px; height: 10px; border-radius: 2px; flex: none; }
.agelegend .amt { font-weight: 620; font-variant-numeric: tabular-nums; }

/* =============================================================================
   Forms & controls
   ============================================================================= */

.toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin-bottom: 14px;
}

input[type=text], input[type=email], input[type=password],
input[type=date], input[type=search], select, textarea {
  font: inherit; font-size: 14px;
  padding: 8px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  min-width: 0;
  max-width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand-light);
  outline-offset: 1px;
  border-color: var(--brand-light);
}

label.field { display: block; margin-bottom: 13px; }
label.field > .lbl {
  display: block; font-size: 12.5px; font-weight: 600;
  color: var(--ink-2); margin-bottom: 5px;
}
label.field > input, label.field > select, label.field > textarea { width: 100%; }
.field-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

.checkline {
  display: flex; align-items: center; gap: 8px;
  font-size: 13.5px; cursor: pointer;
}
.checkline input { width: 16px; height: 16px; accent-color: var(--brand); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: inherit; font-size: 13.5px; font-weight: 570;
  padding: 8px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer; text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: #F3F6FA; color: var(--ink); }
.btn-primary {
  background: var(--brand); border-color: var(--brand); color: #fff;
}
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn-danger { color: var(--critical-text); border-color: #F0C8C8; background: #FDF4F4; }
.btn-danger:hover { background: #FBE9E9; color: var(--critical-text); }
.btn-sm { font-size: 12.5px; padding: 5px 10px; }
.btn-block { width: 100%; }

.seg {
  display: inline-flex; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); overflow: hidden; background: var(--surface);
}
.seg a {
  padding: 7px 13px; font-size: 13px; font-weight: 550;
  color: var(--ink-2); text-decoration: none;
  border-right: 1px solid var(--line);
}
.seg a:last-child { border-right: none; }
.seg a.on { background: var(--brand); color: #fff; }
.seg a:not(.on):hover { background: #F3F6FA; }

/* =============================================================================
   Banners & empty states
   ============================================================================= */

.banner {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 14px; border-radius: var(--radius);
  font-size: 13.5px; margin-bottom: 16px;
  border: 1px solid transparent;
}
.banner .ico { flex: none; font-size: 15px; line-height: 1.3; }
.banner-warn   { background: #FEF6E7; border-color: #F7E3B5; color: #7A5406; }
.banner-error  { background: #FBE9E9; border-color: #F3CDCD; color: var(--critical-text); }
.banner-ok     { background: #E7F6E7; border-color: #C4E9C4; color: var(--good-text); }
.banner-info   { background: var(--brand-wash); border-color: #D3E0EC; color: var(--brand); }

.empty {
  padding: 44px 20px; text-align: center; color: var(--muted);
}
.empty .big { font-size: 30px; margin-bottom: 10px; opacity: .5; }
.empty .msg { font-size: 14.5px; color: var(--ink-2); font-weight: 550; }
.empty .hint { font-size: 13px; margin-top: 5px; }

/* =============================================================================
   Footer
   ============================================================================= */

.foot {
  max-width: 1360px; margin: 0 auto;
  padding: 18px 16px 30px;
  color: var(--muted); font-size: 12.5px;
  display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center;
}
.foot .sep { color: var(--line-strong); }

/* =============================================================================
   Auth pages
   ============================================================================= */

.auth-plane {
  min-height: 100vh;
  display: grid; place-items: center;
  padding: 24px 16px;
  background:
    radial-gradient(1100px 500px at 50% -10%, #E8EFF7 0%, transparent 70%),
    var(--plane);
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 30px 26px;
}
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-brand .mark {
  width: 48px; height: 48px; margin: 0 auto 12px;
  border-radius: 12px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 17px;
}
.auth-brand h1 { margin: 0; font-size: 18px; font-weight: 650; }
.auth-brand p  { margin: 5px 0 0; font-size: 13px; color: var(--muted); }
.auth-foot {
  margin-top: 18px; text-align: center; font-size: 13px;
}

/* =============================================================================
   Utilities & responsive
   ============================================================================= */

.stack-sm > * + * { margin-top: 8px; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.hide-sm { display: none; }
.text-sm { font-size: 13px; }

@media (min-width: 700px) {
  .wrap { padding: 22px 20px 48px; }
  .user-meta { display: block; }
  /* `revert` restores the element's OWN default display -- table-cell for a td,
     inline for a span. `initial` would compute to `inline` for every element,
     which knocks table cells out of the grid and misaligns the whole column. */
  .hide-sm { display: revert; }
  .page-head h1 { font-size: 23px; }
  .tile-value { font-size: 28px; }
}

@media (min-width: 1024px) {
  .grid-2 { grid-template-columns: 3fr 2fr; }
}

@media print {
  .masthead, .nav, .page-head-actions, .toolbar, .foot .noprint { display: none; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #999; }
}
