/* AR — SoPoly Accounts Receivable. Plain CSS, no build step — matches Dash's look and feel. */

:root {
  --bg:        #eef1f6;
  --panel:     #ffffff;
  --panel-2:   #f6f8fb;
  --line:      #dbe1ea;
  --text:      #1a2233;
  --text-dim:  #5b6578;
  --accent:    #2c6fe0;
  --good:      #1f9d63;
  --warn:      #d98a10;
  --bad:       #d64545;
  --promise:   #7b4ce0;

  --shadow: 0 1px 3px rgba(20, 30, 50, 0.08), 0 8px 24px rgba(20, 30, 50, 0.06);
  --radius: 16px;
  --font-ui:   'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Consolas', 'SFMono-Regular', Menlo, monospace;
}

html[data-theme="night"] {
  --bg:        #0d1420;
  --panel:     #161f30;
  --panel-2:   #1c2740;
  --line:      #2a374f;
  --text:      #e7ecf5;
  --text-dim:  #93a1bb;
  --accent:    #5b9dff;
  --good:      #3ecf8e;
  --warn:      #f0ad3d;
  --bad:       #f0625f;
  --promise:   #b79bff;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font-ui); -webkit-font-smoothing: antialiased; }
body { display: flex; flex-direction: column; min-height: 100vh; }

.topbar { display: flex; align-items: center; gap: 20px; padding: 14px 28px; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar .brand { font-weight: 800; font-size: 22px; letter-spacing: 0.08em; color: var(--accent); }
.topbar .brand small { display: block; font-weight: 500; font-size: 11px; letter-spacing: 0.05em; color: var(--text-dim); }
.version-badge { font-family: var(--font-mono); font-size: 11px; font-weight: 600; color: var(--text-dim); vertical-align: middle; }

.tabs { display: flex; gap: 6px; margin-left: 12px; }
.tab-btn { border: none; background: transparent; color: var(--text-dim); font-weight: 600; font-size: 14px; padding: 8px 14px; border-radius: 10px; cursor: pointer; }
.tab-btn:hover { background: var(--panel-2); color: var(--text); }
.tab-btn.active { background: var(--accent); color: #fff; }
/* Shows a count only when there's something awaiting invoicing to chase —
   hidden (via the .hidden class in index.html) whenever the count is zero. */
.tab-alert-badge { display: inline-block; min-width: 18px; padding: 1px 6px; margin-left: 6px; border-radius: 999px; background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; line-height: 16px; text-align: center; }
.tab-alert-badge.hidden { display: none; }

.tab-intro { color: var(--text-dim); font-size: 13px; margin: 0 0 14px; }

.spacer { flex: 1; }
.updated { font-size: 12px; color: var(--text-dim); }
.theme-toggle { border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: 10px; padding: 8px 12px; cursor: pointer; font-size: 13px; }

main { flex: 1; padding: 22px 28px; max-width: 1400px; width: 100%; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

/* ── KPI tiles ─────────────────────────────────────────────────────────── */

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 22px; }
.kpi-tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.kpi-tile h3 { margin: 0 0 6px; font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-dim); }
.kpi-tile .big { font-size: 26px; font-weight: 800; line-height: 1.1; }
.kpi-tile .sub { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.kpi-tile .sub.good { color: var(--good); }
.kpi-tile .sub.warn { color: var(--warn); }
.kpi-tile .sub.bad  { color: var(--bad); }
.kpi-tile.good .big { color: var(--good); }
.kpi-tile.warn .big { color: var(--warn); }
.kpi-tile.bad  .big { color: var(--bad); }

/* ── Calendar ──────────────────────────────────────────────────────────── */

.cal-header { display: flex; align-items: center; gap: 14px; margin: 8px 0 12px; }
.cal-header h2 { margin: 0; font-size: 18px; min-width: 220px; white-space: nowrap; }
.cal-nav-btn { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 8px; width: 32px; height: 32px; cursor: pointer; font-size: 16px; }
.cal-today-btn { width: auto; height: auto; padding: 7px 14px; font-size: 13px; font-weight: 700; }
.cal-legend { display: flex; gap: 10px; margin-left: auto; flex-wrap: wrap; font-size: 12px; color: var(--text-dim); }
.cal-legend span { display: inline-flex; align-items: center; gap: 5px; }
.cal-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* Weekly-row calendar (FLOW Plan > Calendar style): a static header row of
   day-of-week labels (in index.html, never re-rendered), then #cal-grid — a
   fixed window of CAL_WINDOW_WEEKS .cal-row weeks (5 weekday cells + a
   narrower running-total cell), continuous with no blank leading/trailing
   days from a month grid. The window itself only changes via the Prev/
   Today/Next buttons (see renderCalendar()/shiftCalendarWindow() in ar.js);
   #cal-grid's own scrollbar (max-height below) is just for viewing a tall
   week's tiles, not for paging between weeks. */
.cal-grid { display: flex; flex-direction: column; gap: 6px; overflow: auto; max-height: 640px; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; background: var(--panel-2); }
.cal-row { display: grid; grid-template-columns: repeat(5, minmax(180px, 1fr)) 190px; gap: 6px; min-width: 1080px; align-items: start; }
.cal-week-header { padding-bottom: 2px; }
.cal-dow { text-align: center; font-size: 11px; font-weight: 700; color: var(--text-dim); text-transform: uppercase; padding: 4px 0; }
.cal-day { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; min-height: 64px; padding: 6px; display: flex; flex-direction: column; gap: 4px; }
.cal-day.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.cal-day-num { font-size: 12px; font-weight: 700; color: var(--text-dim); }
/* 2-up tile grid — shows every invoice for the day (see CAL_MAX_TILES_PER_DAY
   for the safety cap) rather than truncating to a handful + "N more". */
.cal-day-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; align-content: start; }
.cal-tile { font-size: 10.5px; padding: 3px 5px; border-radius: 6px; cursor: pointer; border-left: 3px solid var(--text-dim); background: var(--panel-2); min-width: 0; }
.cal-tile.tone-good    { border-left-color: var(--good); }
.cal-tile.tone-warn    { border-left-color: var(--warn); }
.cal-tile.tone-bad     { border-left-color: var(--bad); }
.cal-tile.tone-promise { border-left-color: var(--promise); }
.cal-tile-top { display: flex; justify-content: space-between; gap: 4px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-tile-sub { color: var(--text-dim); font-size: 9.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-more { grid-column: 1 / -1; font-size: 11px; color: var(--accent); cursor: pointer; font-weight: 600; }

.cal-week-total { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; gap: 8px; }
.cal-total-block h5 { margin: 0 0 4px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-dim); }
.cal-total-row { display: flex; justify-content: space-between; font-size: 12px; padding: 1px 0; }
.cal-total-row .num.good { color: var(--good); }
.cal-total-row .num.warn { color: var(--warn); }
.cal-total-row .num.bad  { color: var(--bad); font-weight: 700; }

/* The current week's whole row — not just a single .cal-day.today cell —
   gets a strong, unmissable treatment. This matters because a "today" that
   falls on a hidden weekend has no cell of its own at all; the row is the
   one landmark that's always present regardless of which weekday today is. */
.cal-week.is-current-week .cal-day,
.cal-week.is-current-week .cal-week-total {
  background: color-mix(in srgb, var(--accent) 10%, var(--panel));
  border-color: var(--accent);
}
.cal-this-week-badge {
  align-self: flex-start;
  background: var(--accent); color: #fff;
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 3px 8px; border-radius: 999px;
}

/* ── Status badges (shared: pipeline, calendar legend, detail drawer) ───── */

.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.badge.tone-good    { background: color-mix(in srgb, var(--good) 16%, transparent);    color: var(--good); }
.badge.tone-warn    { background: color-mix(in srgb, var(--warn) 18%, transparent);    color: var(--warn); }
.badge.tone-bad     { background: color-mix(in srgb, var(--bad) 16%, transparent);     color: var(--bad); }
.badge.tone-promise { background: color-mix(in srgb, var(--promise) 18%, transparent); color: var(--promise); }
.badge.tone-neutral { background: var(--panel-2); color: var(--text-dim); }
.hold-badge { background: color-mix(in srgb, var(--bad) 85%, black); color: #fff; }

/* ── Toolbars / filter chips / search ─────────────────────────────────── */

.pipeline-toolbar, .activity-toolbar, .exceptions-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.exceptions-toolbar { justify-content: space-between; }
.search-input { flex: 0 0 280px; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font-size: 13px; }
.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--panel); color: var(--text-dim); font-size: 12px; font-weight: 600; padding: 6px 12px; border-radius: 999px; cursor: pointer; }
.chip:hover { color: var(--text); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip .count { opacity: 0.75; margin-left: 4px; }

/* ── Tables ────────────────────────────────────────────────────────────── */

.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-dim); padding: 10px 12px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); white-space: nowrap; }
.data-table td { padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: var(--panel-2); }
.data-table tbody tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty-row td { text-align: center; color: var(--text-dim); padding: 28px; cursor: default; }
.empty-row td:hover { background: none; }

/* ── Activity Log ──────────────────────────────────────────────────────── */

.activity-layout { display: grid; grid-template-columns: 1fr 300px; gap: 18px; align-items: start; }
.activity-feed { display: flex; flex-direction: column; gap: 10px; }
.activity-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 12px 14px; }
.activity-card .row1 { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; font-weight: 700; }
.activity-card .meta { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.activity-card .notes { font-size: 13px; margin-top: 6px; white-space: pre-wrap; }
.activity-side { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; position: sticky; top: 14px; }
.activity-side h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-dim); }
.followup-item { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; cursor: pointer; }
.followup-item:last-child { border-bottom: none; }
.followup-item .fu-name { font-weight: 700; }
.followup-item .fu-meta { font-size: 12px; color: var(--text-dim); }

/* ── Modals / drawer ───────────────────────────────────────────────────── */

.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 16, 28, 0.55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal-backdrop.hidden { display: none; }
.modal { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; width: 480px; max-width: 100%; max-height: 88vh; overflow-y: auto; }
.modal-wide { width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-x { border: none; background: none; color: var(--text-dim); font-size: 16px; cursor: pointer; }
.modal-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; gap: 10px; }
.modal label { display: block; font-size: 12px; font-weight: 700; color: var(--text-dim); margin: 10px 0 4px; }
.modal input, .modal select, .modal textarea { width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font-family: var(--font-ui); font-size: 13px; }
.modal textarea { min-height: 80px; resize: vertical; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.checkbox-row input { width: auto; }

.btn { border: none; background: var(--accent); color: #fff; font-weight: 700; font-size: 13px; padding: 9px 16px; border-radius: 10px; cursor: pointer; }
.btn.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.btn:disabled { opacity: 0.5; cursor: default; }

/* ── Detail drawer content ────────────────────────────────────────────── */

.detail-grid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 18px; }
.detail-section { margin-bottom: 16px; }
.detail-section h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-dim); }
.kv-list { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.kv-list dt { color: var(--text-dim); }
.kv-list dd { margin: 0; font-weight: 600; text-align: right; }
.timeline { display: flex; flex-direction: column; gap: 8px; max-height: 360px; overflow-y: auto; }
.related-invoice { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; cursor: pointer; }
.related-invoice:last-child { border-bottom: none; }

.tv-footer { text-align: center; font-size: 11px; color: var(--text-dim); padding: 10px; }

@media print {
  .topbar, .tv-footer, .exceptions-toolbar { display: none !important; }
  main { padding: 0; max-width: none; }
}

@media (max-width: 900px) {
  .activity-layout { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
}
