:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1a2230;
  --ink-soft: #5a6879;
  --line: #e2e7ee;
  --brand: #0b5fa4;
  --accent: #0072c6;
  --shadow: 0 1px 3px rgba(20,30,50,.08), 0 6px 20px rgba(20,30,50,.06);

  --s-bidding: #16915c;
  --s-bidding-bg: #e4f6ec;
  --s-watching: #0b5fa4;
  --s-watching-bg: #e3eefb;
  --s-unseen: #8a97a8;
  --s-unseen-bg: #eef1f5;
  --s-no_bid: #b04a4a;
  --s-no_bid-bg: #f7e6e6;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --panel: #161d27;
    --ink: #e7edf5;
    --ink-soft: #9aa8ba;
    --line: #26303d;
    --brand: #3b9ae1;
    --accent: #4aa8e6;
    --shadow: 0 1px 3px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
    --s-bidding-bg: #123326;
    --s-watching-bg: #102740;
    --s-unseen-bg: #1c2530;
    --s-no_bid-bg: #35201f;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; flex: 1; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #fff; font-weight: 800; font-size: 14px;
  display: grid; place-items: center; letter-spacing: .5px;
}
.brand-name { font-weight: 700; font-size: 15px; }
.brand-sub { color: var(--ink-soft); font-size: 12px; }
.view-toggle { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 3px; }
.vt-btn {
  border: 0; background: transparent; color: var(--ink-soft);
  padding: 6px 16px; border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 13px;
}
.vt-btn.active { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.topbar-right { flex: 1; display: flex; justify-content: flex-end; }
.user-pill { background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; font-size: 12px; color: var(--ink-soft); }

/* Layout */
.layout { display: grid; grid-template-columns: 260px 1fr; min-height: calc(100vh - 55px); }
.filters { background: var(--panel); border-right: 1px solid var(--line); padding: 18px; overflow-y: auto; }
.content { padding: 18px 22px; overflow-x: auto; }

/* Filters */
.filter-group { margin-bottom: 20px; }
.filter-label { font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); margin-bottom: 8px; }
.hint { font-size: 11.5px; color: var(--ink-soft); margin: 6px 0 0; }
.switch { display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 600; }
.switch input { width: 16px; height: 16px; accent-color: var(--brand); }
select, input[type="text"], input[type="number"] {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--ink); font-size: 13px; font-family: inherit;
}
.range-row { display: flex; gap: 8px; }
.district-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.district-grid button {
  border: 1px solid var(--line); background: var(--bg); color: var(--ink-soft);
  border-radius: 6px; padding: 6px 0; font-size: 12px; font-weight: 600; cursor: pointer;
}
.district-grid button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-ghost { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 8px; padding: 7px 12px; cursor: pointer; font-weight: 600; font-size: 13px; }
.btn-ghost:hover { border-color: var(--brand); }

.legend { border-top: 1px solid var(--line); padding-top: 14px; display: grid; gap: 7px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink-soft); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.s-bidding { background: var(--s-bidding); }
.dot.s-watching { background: var(--s-watching); }
.dot.s-unseen { background: var(--s-unseen); }
.dot.s-no_bid { background: var(--s-no_bid); }

/* Content head */
.content-head { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.result-count { font-weight: 700; flex: 1; }
.cal-nav { display: flex; align-items: center; gap: 12px; font-weight: 700; }
.cal-nav .btn-ghost { padding: 4px 12px; font-size: 16px; line-height: 1; }
.sort-wrap { display: flex; align-items: center; gap: 8px; color: var(--ink-soft); font-size: 13px; }
.sort-wrap select { width: auto; }

/* Calendar */
.calendar-view { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.month { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.month-title { font-weight: 700; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.dow { display: grid; grid-template-columns: repeat(7, 1fr); background: var(--bg); }
.dow span { text-align: center; font-size: 11px; font-weight: 700; color: var(--ink-soft); padding: 6px 0; }
.grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.cell { min-height: 78px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 4px; position: relative; }
.cell:nth-child(7n) { border-right: 0; }
.cell.out { background: var(--bg); opacity: .5; }
.cell.today { background: var(--s-watching-bg); }
.cell .daynum { font-size: 11px; color: var(--ink-soft); font-weight: 700; }
.cell.today .daynum { color: var(--brand); }
.chip {
  display: block; width: 100%; text-align: left; border: 0; cursor: pointer;
  border-radius: 5px; padding: 3px 6px; margin-top: 3px; font-size: 11px; font-weight: 600;
  background: var(--s-unseen-bg); color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-left: 3px solid var(--s-unseen);
}
.chip.s-bidding { background: var(--s-bidding-bg); border-left-color: var(--s-bidding); }
.chip.s-watching { background: var(--s-watching-bg); border-left-color: var(--s-watching); }
.chip.s-no_bid { background: var(--s-no_bid-bg); border-left-color: var(--s-no_bid); text-decoration: line-through; opacity: .7; }
.chip-more { font-size: 10.5px; color: var(--ink-soft); padding: 2px 6px; cursor: pointer; }

/* List view */
.list-view { display: grid; gap: 10px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
  display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; cursor: pointer;
  box-shadow: var(--shadow); border-left: 4px solid var(--s-unseen);
}
.card.s-bidding { border-left-color: var(--s-bidding); }
.card.s-watching { border-left-color: var(--s-watching); }
.card.s-no_bid { border-left-color: var(--s-no_bid); opacity: .72; }
.card:hover { border-color: var(--brand); }
.card-district { width: 44px; height: 44px; border-radius: 10px; background: var(--bg); display: grid; place-items: center; font-weight: 800; color: var(--brand); }
.card-main { min-width: 0; }
.card-title { font-weight: 700; display: flex; gap: 10px; align-items: baseline; }
.card-cid { font-family: ui-monospace, Menlo, monospace; }
.card-desc { color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { display: flex; gap: 14px; font-size: 12px; color: var(--ink-soft); margin-top: 3px; }
.card-right { text-align: right; }
.card-est { font-weight: 800; font-size: 16px; }
.card-countdown { font-size: 12px; color: var(--ink-soft); }
.badge { font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; padding: 2px 7px; border-radius: 999px; }
.badge.new { background: var(--s-bidding-bg); color: var(--s-bidding); }
.badge.changed { background: var(--s-no_bid-bg); color: var(--s-no_bid); }
.badge.updated { background: #fff2dd; color: #9a6a12; }
.badge.addenda { background: var(--s-watching-bg); color: var(--s-watching); }
@media (prefers-color-scheme: dark) { .badge.updated { background: #3a2f16; color: #d8a24a; } }

/* Calendar chip badges (addendum count + updated dot) */
.chip { display: flex; align-items: center; gap: 3px; }
.chip-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.chip-badge { font-size: 9px; font-weight: 800; flex: none; }
.chip-badge.addenda { background: var(--s-watching); color: #fff; border-radius: 4px; padding: 0 3px; }
.chip-badge.update { color: #e08a1e; font-size: 11px; }

/* Change banner (top of drawer) */
.change-banner { background: #fff2dd; color: #7a520c; border: 1px solid #e9cf9a; border-radius: 8px; padding: 8px 12px; margin: 12px 0; font-size: 12.5px; font-weight: 600; }
@media (prefers-color-scheme: dark) { .change-banner { background: #33290f; color: #e0b972; border-color: #5a4a1e; } }

/* Undo toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--panel); padding: 12px 16px; border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,.3); display: flex; align-items: center; gap: 14px;
  z-index: 80; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; font-size: 13px; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.toast-action { background: none; border: 0; color: var(--brand); font-weight: 800; cursor: pointer; font-size: 13px; }
@media (prefers-color-scheme: dark) { .toast { background: #e7edf5; color: #10151c; } .toast-action { color: #0b5fa4; } }

/* Drawer */
.drawer-scrim { position: fixed; inset: 0; background: rgba(10,15,25,.45); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: min(560px, 94vw);
  background: var(--panel); border-left: 1px solid var(--line); z-index: 50;
  box-shadow: -8px 0 40px rgba(10,20,40,.2); overflow-y: auto; padding: 22px;
}
.drawer h2 { margin: 0 0 4px; font-size: 18px; }
.drawer .cid { font-family: ui-monospace, Menlo, monospace; color: var(--brand); font-weight: 700; }
.drawer-close { position: absolute; top: 16px; right: 18px; border: 0; background: var(--bg); border-radius: 8px; width: 32px; height: 32px; cursor: pointer; font-size: 18px; color: var(--ink-soft); }
.est-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0; }
.est-box { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.est-box .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); font-weight: 700; }
.est-box .val { font-size: 20px; font-weight: 800; margin-top: 2px; }
.status-row { display: flex; gap: 8px; margin: 16px 0; flex-wrap: wrap; }
.status-btn { flex: 1; min-width: 90px; border: 1px solid var(--line); background: var(--bg); border-radius: 9px; padding: 9px; cursor: pointer; font-weight: 700; font-size: 13px; color: var(--ink-soft); }
.status-btn.active.watching { background: var(--s-watching); color: #fff; border-color: var(--s-watching); }
.status-btn.active.bidding { background: var(--s-bidding); color: #fff; border-color: var(--s-bidding); }
.status-btn.active.no_bid { background: var(--s-no_bid); color: #fff; border-color: var(--s-no_bid); }
.links-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 16px 0; }
.link-btn { display: block; text-align: center; text-decoration: none; border: 1px solid var(--brand); color: var(--brand); border-radius: 9px; padding: 10px; font-weight: 700; font-size: 13px; }
.link-btn.solid { background: var(--brand); color: #fff; }
.detail-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.detail-table th { text-align: left; color: var(--ink-soft); font-weight: 600; padding: 6px 8px; width: 42%; vertical-align: top; font-size: 12.5px; }
.detail-table td { padding: 6px 8px; font-size: 13px; }
.detail-table tr { border-bottom: 1px solid var(--line); }
.section-title { font-weight: 800; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); margin: 20px 0 6px; }
.notes-area { width: 100%; min-height: 70px; margin-top: 6px; resize: vertical; }

.est-breakdown { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--s-unseen-bg); color: var(--ink-soft); }
.pill.s-bidding { background: var(--s-bidding-bg); color: var(--s-bidding); }
.pill.s-watching { background: var(--s-watching-bg); color: var(--s-watching); }
.pill.s-warn { background: #fff2dd; color: #9a6a12; }
.pill.s-danger { background: var(--s-no_bid-bg); color: var(--s-no_bid); }
@media (prefers-color-scheme: dark) { .pill.s-warn { background: #3a2f16; color: #d8a24a; } }

.card-ourest { font-size: 11.5px; color: var(--ink-soft); margin-top: 2px; }

/* Section subtotal table (in drawer) */
.section-table { margin-top: 4px; }
.section-table th { font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
.section-bar-row td { padding: 0 8px 8px; border-bottom: 1px solid var(--line); }
.section-bar { height: 4px; border-radius: 2px; background: var(--bg); overflow: hidden; }
.section-bar-fill { height: 100%; background: var(--brand); border-radius: 2px; }

/* Full-detail overlay (line-item breakdown) */
.full-scrim { position: fixed; inset: 0; background: rgba(10,15,25,.5); z-index: 60; }
.full-panel {
  position: fixed; top: 3vh; left: 50%; transform: translateX(-50%);
  width: min(920px, 94vw); height: 94vh; background: var(--panel);
  border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.35); z-index: 61;
  overflow: hidden; display: flex; flex-direction: column;
}
/* An author-stylesheet `display` rule on an element beats the browser's
   default `[hidden] { display: none }` UA rule even at equal specificity —
   without this override .full-panel rendered as a big empty box on every
   page load regardless of the hidden attribute. */
.full-panel[hidden] { display: none; }
.full-head { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 14px; }
.full-head h2 { margin: 0; font-size: 17px; flex: 1; }
.full-body { flex: 1; overflow-y: auto; padding: 0 22px 22px; }
.full-summary { display: flex; gap: 18px; padding: 14px 0; flex-wrap: wrap; font-size: 13px; color: var(--ink-soft); border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.full-summary b { color: var(--ink); }
.section-group { margin-top: 18px; }
.section-group-head {
  display: flex; justify-content: space-between; align-items: baseline;
  background: var(--bg); border-radius: 8px; padding: 8px 12px; cursor: pointer; position: sticky; top: 0;
}
.section-group-head h3 { margin: 0; font-size: 13.5px; }
.section-group-head .amt { font-weight: 800; }
.item-table { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 12.5px; }
.item-table th { text-align: left; color: var(--ink-soft); font-weight: 600; padding: 5px 8px; border-bottom: 1px solid var(--line); font-size: 11px; text-transform: uppercase; }
.item-table td { padding: 5px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.item-table tr.flag-none { background: var(--s-no_bid-bg); }
.item-table tr.flag-textsearch { background: var(--s-watching-bg); }
.item-table tr.flag-mismatch { background: #fff2dd; }
.item-desc { max-width: 260px; }
.item-src { font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 5px; background: var(--bg); color: var(--ink-soft); white-space: nowrap; }
.filter-bar-full { display: flex; gap: 8px; padding: 10px 0; align-items: center; flex-wrap: wrap; position: sticky; top: 0; background: var(--panel); z-index: 2; }
.filter-bar-full select, .filter-bar-full input { width: auto; }
.view-toggle.mini { padding: 2px; }
.view-toggle.mini .vt-btn { padding: 5px 10px; font-size: 12px; }
.item-table th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.item-table th.sortable:hover { color: var(--brand); }
.flat-item-table thead th { position: sticky; top: 44px; background: var(--bg); z-index: 1; }

/* Estimate-generation progress bar */
.progress-wrap { padding: 4px 0; }
.progress-track { height: 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--brand), var(--accent)); border-radius: 999px; transition: width .3s ease; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .filters { border-right: 0; border-bottom: 1px solid var(--line); }
  .calendar-view { grid-template-columns: 1fr; }
}

/* Login gate */
.login-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: grid; place-items: center; padding: 20px;
}
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 28px; width: min(360px, 92vw);
  display: flex; flex-direction: column; gap: 12px;
}
.login-brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; }
.login-sub { color: var(--ink-soft); font-size: 13px; margin: 0; }
.login-card input[type="password"] {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--bg); color: var(--ink); font-size: 15px;
}
.login-error { color: var(--s-no_bid); font-size: 13px; min-height: 16px; font-weight: 600; }
.login-btn {
  border: 0; background: linear-gradient(135deg, var(--brand), var(--accent)); color: #fff;
  padding: 11px; border-radius: 9px; font-weight: 800; font-size: 14px; cursor: pointer;
}
.login-btn:disabled { opacity: .6; cursor: default; }
