/* Brightwave CRM: shared design system. Light default, dark via
   prefers-color-scheme. Every color used anywhere in the app is a token
   defined here so a new page only ever picks a token, never a literal. */

:root {
  --bg: #f5f6f7;
  --card-bg: #ffffff;
  --card-bg-raised: #ffffff;
  --text: #1b1b1f;
  --muted: #6b6b74;
  --border: #e2e2e6;
  /* Brightwave Capital brand navy/gold, sampled 2026-09-02 from
     reference/BrightwaveCapital/bwc_logo_final_darkblue_gold.png (task H2).
     Replaces the placeholder teal (#1f6f5c) that predated the real logo
     assets being on disk. */
  --brand: #16305a;
  --brand-fg: #ffffff;
  --brand-hover: #0f2245;
  --focus-ring: #3f6098;
  --shadow: 0 1px 2px rgba(20, 20, 24, 0.06), 0 1px 1px rgba(20, 20, 24, 0.04);
  --shadow-raised: 0 4px 14px rgba(20, 20, 24, 0.10);

  --ok-bg: #e3f5ea;   --ok-fg: #1a7a42;
  --warn-bg: #fdf3d8; --warn-fg: #9a6a00;
  --bad-bg: #fbe4e4;  --bad-fg: #b31d1d;

  --radius: 10px;
  --radius-sm: 6px;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15161a;
    --card-bg: #1e1f24;
    --card-bg-raised: #24262c;
    --text: #e8e8ea;
    --muted: #9a9aa2;
    --border: #313238;
    /* Dark mode uses the logo's GOLD, not a darkened navy: navy has too
       little contrast against a near-black background to work as an
       interactive/accent color, and gold is the other half of the same
       two-tone mark. */
    --brand: #d9bb72;
    --brand-fg: #1c1608;
    --brand-hover: #e6cd8f;
    --focus-ring: #d9bb72;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 1px 1px rgba(0, 0, 0, 0.25);
    --shadow-raised: 0 6px 20px rgba(0, 0, 0, 0.45);

    --ok-bg: #143523;   --ok-fg: #6fe0a0;
    --warn-bg: #3a2f0d; --warn-fg: #e8c34d;
    --bad-bg: #3a1717;  --bad-fg: #f18a8a;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

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

a { color: inherit; }

::selection { background: var(--brand); color: var(--brand-fg); }

/* Focus states: visible everywhere, never suppressed */
a:focus-visible,
button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------------------------------------------------------------------- */
/* Top nav                                                                  */
/* ---------------------------------------------------------------------- */

.topnav {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: nowrap;
  gap: var(--space-3);
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--card-bg);
  box-shadow: var(--shadow);
}

.topnav .brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  color: var(--brand);
  text-decoration: none;
  white-space: nowrap;
}

.brand-mark { width: 26px; height: 26px; flex: none; color: var(--brand); }
.brand-text { font-size: 1.05rem; }

.navlinks {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.navlinks a {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.7rem;
  min-height: 44px;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-size: 0.92rem;
}

.navlinks a:hover { color: var(--brand); background: var(--bg); }
.navlinks a.active { color: var(--brand-fg); background: var(--brand); }
.navicon { width: 20px; height: 20px; flex: none; }

/* Back button: the iPhone PWA has no browser chrome to go back with.
   Hidden by default (server-rendered), revealed by base.html's inline
   script when history.length suggests there's somewhere to go back to. */
.bw-back-btn {
  display: flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; flex: none;
  border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--text);
  cursor: pointer; padding: 0;
}
.bw-back-btn:hover { color: var(--brand); background: var(--bg); }

@media (max-width: 640px) {
  .brand-text { display: none; }
  .navlinks a { padding: 0.5rem; }
  .navlabel { display: none; }
  .navlinks { gap: 0.1rem; }
}

/* ---------------------------------------------------------------------- */
/* Layout                                                                   */
/* ---------------------------------------------------------------------- */

.content {
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--space-4) var(--space-5);
}

@media (max-width: 640px) {
  .content { padding: var(--space-3) var(--space-3); }
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-4);
}

.card h1, .card h2 { margin-top: 0; }
.card h1 { font-size: 1.4rem; }
.card h2 { font-size: 1.1rem; }
.card h3 { font-size: 1rem; margin-bottom: var(--space-2); }

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: var(--space-4);
  align-items: start;
}
.grid-cards .card { margin-bottom: 0; }

@media (max-width: 640px) {
  .grid-cards { grid-template-columns: 1fr; }
}

.login-card { max-width: 360px; margin: 3rem auto; }

/* ---------------------------------------------------------------------- */
/* Stat tiles (home dashboard)                                             */
/* ---------------------------------------------------------------------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-3);
}

.stat-tile {
  display: block;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-4);
  text-decoration: none;
  color: var(--text);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.stat-tile:hover { box-shadow: var(--shadow-raised); transform: translateY(-1px); }
.stat-tile-value { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.stat-tile-value.warn { color: var(--warn-fg); }
.stat-tile-value.bad { color: var(--bad-fg); }
.stat-tile-value.ok { color: var(--ok-fg); }
.stat-tile-label { color: var(--muted); font-size: 0.85rem; margin-top: 0.3rem; }

/* ---------------------------------------------------------------------- */
/* Quick links row                                                         */
/* ---------------------------------------------------------------------- */

.quicklinks {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* ---------------------------------------------------------------------- */
/* Buttons                                                                 */
/* ---------------------------------------------------------------------- */

.btn, .file-card-actions .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 0.85rem;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
  cursor: pointer;
}
.btn:hover { border-color: var(--brand); color: var(--brand); }

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-fg);
}
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: var(--brand-fg); }

.btn-big { min-height: 48px; padding: 0.65rem 1.1rem; font-size: 1rem; }
.btn-small { min-height: 32px; padding: 0.3rem 0.6rem; font-size: 0.82rem; }

/* ---------------------------------------------------------------------- */
/* Forms                                                                   */
/* ---------------------------------------------------------------------- */

form label { display: block; margin-top: var(--space-2); font-size: 0.9rem; color: var(--muted); }

form input, form select, form textarea {
  width: 100%;
  padding: 0.55rem 0.6rem;
  min-height: 42px;
  margin-top: 0.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}
form textarea { min-height: 84px; }

form button {
  margin-top: var(--space-4);
  padding: 0.6rem 1.1rem;
  min-height: 44px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: var(--brand-fg);
  cursor: pointer;
  font-size: 0.95rem;
}
form button:hover { background: var(--brand-hover); }
form button:disabled { opacity: 0.5; cursor: not-allowed; }

.search-box {
  width: 100%;
  min-height: 48px;
  padding: 0.7rem 1rem;
  margin-top: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

/* ---------------------------------------------------------------------- */
/* Tabs                                                                    */
/* ---------------------------------------------------------------------- */

.tabbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin: var(--space-2) 0 var(--space-3);
  border-bottom: 1px solid var(--border);
}
.tabbar a {
  padding: 0.5rem 0.8rem;
  min-height: 40px;
  display: flex;
  align-items: center;
  text-decoration: none;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  font-size: 0.9rem;
}
.tabbar a:hover { color: var(--text); }
.tabbar a.tab-active, .tabbar a.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

/* ---------------------------------------------------------------------- */
/* Tables                                                                  */
/* ---------------------------------------------------------------------- */

.table-scroll { overflow-x: auto; }

table { border-collapse: collapse; width: 100%; min-width: 320px; }

th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.02em; }
.view-row:hover { background: var(--bg); }

/* ---------------------------------------------------------------------- */
/* Badges                                                                  */
/* ---------------------------------------------------------------------- */

.badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge-warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge-bad { background: var(--bad-bg); color: var(--bad-fg); }

.muted { color: var(--muted); font-size: 0.85rem; }

/* ---------------------------------------------------------------------- */
/* Flash banners (used by htmx swaps after a write)                        */
/* ---------------------------------------------------------------------- */

.flash {
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  margin-bottom: var(--space-3);
}
.flash-success { background: var(--ok-bg); color: var(--ok-fg); }
.flash-error { background: var(--bad-bg); color: var(--bad-fg); }

/* ---------------------------------------------------------------------- */
/* Results / queue / activity lists                                       */
/* ---------------------------------------------------------------------- */

.result-list { display: flex; flex-direction: column; gap: var(--space-2); }
.result-row {
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
}
.result-row:last-child { border-bottom: none; }
.result-title { font-weight: 600; text-decoration: none; }
.result-title:hover { color: var(--brand); }

.queue-card { display: flex; flex-direction: column; gap: 0.4rem; }
.queue-card-head { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.queue-rank { color: var(--muted); font-weight: 600; }

.call-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.call-btn {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: var(--brand-fg);
  text-decoration: none;
  font-size: 0.88rem;
}
.call-btn:hover { background: var(--brand-hover); }
.called-history { display: flex; flex-wrap: wrap; gap: 0.3rem; }

.contact-actions, .action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.linklist { padding-left: 1.2rem; }
.empty-state { color: var(--muted); font-size: 0.9rem; padding: var(--space-2) 0; }

/* ---------------------------------------------------------------------- */
/* Today panel / activity feed                                            */
/* ---------------------------------------------------------------------- */

.today-list { display: flex; flex-direction: column; gap: var(--space-2); }
.today-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}
.today-item:last-child { border-bottom: none; }
.today-item-due { color: var(--bad-fg); font-size: 0.8rem; white-space: nowrap; }

.activity-list { display: flex; flex-direction: column; gap: var(--space-2); }
.activity-item {
  display: flex;
  gap: var(--space-2);
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.activity-item:last-child { border-bottom: none; }
.activity-kind { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; min-width: 3.5rem; }

/* ---------------------------------------------------------------------- */
/* Files panel                                                             */
/* ---------------------------------------------------------------------- */

.files-panel { display: flex; flex-direction: column; gap: var(--space-4); }
.files-section h3 { margin-bottom: var(--space-2); }
.files-cards { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.file-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.8rem;
  background: var(--bg);
  min-width: 200px;
}
.file-card-name { font-weight: 500; margin-bottom: 0.3rem; }
.file-card-date { color: var(--muted); font-size: 0.8rem; margin-left: 0.4rem; }
.file-card-actions { margin-top: var(--space-2); display: flex; gap: var(--space-2); }
.file-card-actions .btn:hover, .btn:hover { border-color: var(--brand); }

/* ---------------------------------------------------------------------- */
/* Viewer + modal                                                          */
/* ---------------------------------------------------------------------- */

.viewer-panel { display: flex; flex-direction: column; gap: var(--space-3); }
.viewer-toolbar { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.viewer-title { font-weight: 600; }
.viewer-image-wrap img, .viewer-pdf { max-width: 100%; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.viewer-md { white-space: pre-wrap; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 12, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 5vh 1rem;
  z-index: 100;
}
.modal-card, .modal-panel {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-raised);
  max-width: 560px;
  width: 100%;
  padding: var(--space-5);
  position: relative;
}
.modal-close {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.2rem;
  cursor: pointer;
  min-width: 32px;
  min-height: 32px;
}
.modal-close:hover { color: var(--text); }

/* ---------------------------------------------------------------------- */
/* Error pages                                                             */
/* ---------------------------------------------------------------------- */

.error-code { font-size: 3rem; font-weight: 700; color: var(--brand); margin: 0; }

/* ---------------------------------------------------------------------- */
/* Canonical modal wrapper (A1, 2026-09-03). ONE copy: base.html renders    */
/* <div id="modal" class="modal"> on every page; pages never restyle it.    */
/* ---------------------------------------------------------------------- */
.modal { display: none; position: fixed; inset: 0; z-index: 100; }
.modal.open { display: block; }
.modal > .modal-backdrop { position: absolute; inset: 0; display: block; padding: 0; }
.modal > .modal-panel {
  position: relative; margin: 5vh auto; max-width: 520px; width: 92%;
  max-height: 88vh; overflow-y: auto;
}
.modal-err { color: var(--bad, #b00020); }
.viewer-pdf { width: 100%; height: calc(100vh - 150px); min-height: 70vh; }

/* ---------------------------------------------------------------------- */
/* Activity queue rows (Q, 2026-09-03): one row = one next action           */
/* ---------------------------------------------------------------------- */
.card-head-row { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-2); }
.card-head-row h2 { margin: 0; flex: 1 1 auto; }
.act-list { display: flex; flex-direction: column; gap: 0; }
.act-row { display: flex; align-items: flex-start; gap: var(--space-2); padding: 0.55rem 0; border-bottom: 1px solid var(--border); border-left: 3px solid transparent; padding-left: 0.4rem; }
.act-row:last-child { border-bottom: none; }
.act-row.prio-1 { border-left-color: var(--bad-fg); }
.act-row.act-lead { background: var(--warn-bg); }
.act-type { flex: 0 0 1.6rem; text-align: center; font-size: 1.05rem; color: var(--muted); padding-top: 0.1rem; }
.act-main { flex: 1 1 auto; min-width: 0; }
.act-title { font-weight: 600; }
.act-meta { display: flex; flex-wrap: wrap; gap: 0.25rem 0.8rem; font-size: 0.85rem; }
.act-due.overdue { color: var(--bad-fg); font-weight: 600; }
.act-actions { display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: center; justify-content: flex-end; flex: 0 0 auto; }
.act-snooze select { min-height: 32px; font-size: 0.85rem; }
.form-row { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.form-row label { flex: 1 1 120px; }
@media (max-width: 640px) { .act-row { flex-wrap: wrap; } .act-actions { width: 100%; justify-content: flex-start; } }
