/* ============================================================================
   Deck'd Out — Command Centre
   Server-rendered Jinja2 + HTMX. No build step.
   Dark-first, gold accent. Light mode via [data-theme="light"].
   ========================================================================== */

/* ---- Theme tokens --------------------------------------------------------- */
:root,
[data-theme="dark"] {
  color-scheme: dark;
  --bg:        #0f1116;
  --bg-2:      #0b0d11;
  --card:      #171a21;
  --card-2:    #1d212a;
  --fg:        #e9eaee;
  --fg-soft:   #c4c8d0;
  --muted:     #868c98;
  --border:    #262b35;
  --border-2:  #313846;
  --gold:      #d4af5f;
  --gold-2:    #e6c578;
  --gold-soft: rgba(212, 175, 95, 0.12);
  --ok:        #3fb27f;
  --warn:      #e0a73a;
  --error:     #e2614f;
  --info:      #5b8def;
  --unknown:   #6b7280;
  --shadow:    0 6px 24px rgba(0, 0, 0, 0.35);
}

[data-theme="light"] {
  color-scheme: light;
  --bg:        #f3f4f7;
  --bg-2:      #ffffff;
  --card:      #ffffff;
  --card-2:    #f6f7f9;
  --fg:        #1a1d24;
  --fg-soft:   #3a3f4a;
  --muted:     #6a7080;
  --border:    #e5e7ec;
  --border-2:  #d8dbe2;
  --gold:      #a87d28;
  --gold-2:    #b8923a;
  --gold-soft: rgba(168, 125, 40, 0.10);
  --ok:        #1f9d63;
  --warn:      #c0851d;
  --error:     #cf4536;
  --info:      #2f6fe0;
  --unknown:   #8b909c;
  --shadow:    0 4px 18px rgba(20, 25, 40, 0.08);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

/* ---- App shell ------------------------------------------------------------ */
.app { display: flex; min-height: 100vh; }

.sidebar {
  flex: 0 0 240px;
  width: 240px;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 18px 12px 12px;
  display: flex;
  flex-direction: column;
  z-index: 30;
}

.brand { padding: 6px 10px 18px; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(145deg, var(--gold-2), var(--gold));
  color: #1a160a; font-weight: 800; font-size: 18px;
  vertical-align: middle; margin-right: 10px;
}
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: .2px; }
.brand-sub  { display: block; margin: 6px 0 0 44px; font-size: 11px;
              text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-group {
  margin: 16px 12px 6px; font-size: 10.5px; font-weight: 700;
  letter-spacing: 1.4px; text-transform: uppercase; color: var(--muted);
}
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: 8px; color: var(--fg-soft);
  font-size: 13.5px; font-weight: 500; transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--card); color: var(--fg); }
.nav-item.active {
  background: var(--gold-soft); color: var(--gold-2);
  box-shadow: inset 2px 0 0 var(--gold);
}
.nav-ico { width: 18px; text-align: center; opacity: .8; font-size: 13px; }
.nav-item.active .nav-ico { opacity: 1; }

.sidebar-foot {
  margin-top: 10px; padding: 10px 12px; font-size: 12px; color: var(--muted);
  border-top: 1px solid var(--border); display: flex; align-items: center; gap: 8px;
}

.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 56px; flex: 0 0 56px;
  display: flex; align-items: center; gap: 14px;
  padding: 0 24px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(8px);
}
.crumbs { font-weight: 600; font-size: 15px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.menu-btn { display: none; }

.icon-btn {
  border: 1px solid var(--border-2); background: var(--card);
  color: var(--fg-soft); cursor: pointer; border-radius: 8px;
  width: 34px; height: 34px; font-size: 15px; display: inline-flex;
  align-items: center; justify-content: center; transition: background .12s;
}
.icon-btn:hover { background: var(--card-2); color: var(--fg); }

main { padding: 24px; flex: 1; max-width: 1240px; width: 100%; }

/* ---- Sections & cards ----------------------------------------------------- */
section { margin-bottom: 26px; }
section > h2 {
  margin: 0 0 12px; font-size: 11.5px; font-weight: 700;
  letter-spacing: 1.3px; text-transform: uppercase; color: var(--muted);
}
section > h3 { font-size: 12px; color: var(--muted); margin: 14px 0 8px;
               text-transform: uppercase; letter-spacing: .8px; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px; margin-bottom: 12px;
}
.card.muted { color: var(--muted); }
.muted { color: var(--muted); }

/* ---- KPI strip ------------------------------------------------------------ */
.kpi-band-title {
  display: flex; align-items: center; gap: 10px; margin: 0 0 10px;
  font-size: 11.5px; font-weight: 700; letter-spacing: 1.3px;
  text-transform: uppercase; color: var(--muted);
}
.kpi-band-title::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.kpi-grid {
  display: grid; gap: 14px; margin-bottom: 24px;
  grid-template-columns: repeat(auto-fit, minmax(176px, 1fr));
}
.kpi-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 15px 16px; position: relative; overflow: hidden;
}
.kpi-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--gold); opacity: .65;
}
.kpi-label { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.kpi-num { font-size: 26px; font-weight: 700; letter-spacing: -.5px; line-height: 1; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 7px; }
.kpi-delta { font-size: 12px; font-weight: 600; margin-top: 7px; }
.kpi-delta.up { color: var(--ok); }
.kpi-delta.down { color: var(--error); }
.kpi-card.alert::before { background: var(--error); opacity: 1; }
.kpi-card.warn::before { background: var(--warn); opacity: 1; }

/* ---- Action Centre (ACTION PROMPTS) --------------------------------------- */
#prompts-section .prompt-row,
.prompt-row {
  display: flex; align-items: center; gap: 13px;
  padding: 13px 15px; margin-bottom: 8px; border-radius: 10px;
  background: var(--card); border: 1px solid var(--border);
  border-left: 3px solid var(--info);
  transition: transform .1s, border-color .12s, background .12s;
}
.prompt-row:hover { transform: translateX(2px); background: var(--card-2); }
.prompt-row.urgency-high { border-left-color: var(--error); }
.prompt-row.urgency-med  { border-left-color: var(--warn); }
.prompt-row.urgency-low  { border-left-color: var(--info); }
.prompt-icon { font-size: 18px; width: 24px; text-align: center; }
.prompt-text { flex: 1; font-weight: 500; }
.prompt-arrow { color: var(--muted); font-size: 16px; }

/* ---- Two-column layout for home ------------------------------------------- */
.cols-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; align-items: start; }

/* ---- Drafts --------------------------------------------------------------- */
.draft-card { border-left: 3px solid var(--gold); }
.draft-card h2 {
  text-transform: none; letter-spacing: 0; font-size: 15px; color: var(--fg);
  margin: 0 0 10px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.msg {
  padding: 9px 12px; border-radius: 9px; margin: 4px 0;
  max-width: 90%; font-size: 13.5px;
}
.msg.inbound  { background: var(--card-2); border: 1px solid var(--border); }
.msg.outbound { background: var(--gold-soft); border: 1px solid var(--gold-soft); }

/* ---- Badges --------------------------------------------------------------- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .3px;
  border: 1px solid var(--border-2); color: var(--muted); text-transform: lowercase;
}
.badge.auto { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.badge.paused { color: var(--muted); }
.badge.needs_review { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); background: color-mix(in srgb, var(--warn) 12%, transparent); }

/* ---- Tasks ---------------------------------------------------------------- */
.task-group { margin-bottom: 14px; }
.task-row {
  display: flex; align-items: center; gap: 14px;
  padding: 11px 14px; border-radius: 9px; background: var(--card);
  border: 1px solid var(--border); margin-bottom: 6px;
}
.task-customer { font-weight: 600; color: var(--gold-2); }
.task-suburb { color: var(--muted); }
.task-kind {
  font-size: 11.5px; padding: 2px 8px; border-radius: 6px;
  background: var(--card-2); border: 1px solid var(--border); color: var(--fg-soft);
}
.task-age { margin-left: auto; color: var(--muted); font-size: 12.5px; }
.task-row button {
  border: 1px solid var(--border-2); background: var(--card-2); color: var(--fg-soft);
  border-radius: 7px; padding: 5px 10px; cursor: pointer; font-size: 12.5px;
}
.task-row button:hover { background: var(--gold-soft); color: var(--gold-2); border-color: var(--gold); }

/* ---- Pipeline / Kanban ---------------------------------------------------- */
#kanban-board {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px;
}
.kanban-col {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px; min-height: 120px;
}
.kanban-col-head {
  font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase;
  color: var(--muted); padding: 4px 4px 10px; border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.kanban-cards { display: flex; flex-direction: column; gap: 8px; min-height: 40px; }
.kanban-card {
  background: var(--card-2); border: 1px solid var(--border);
  border-radius: 9px; padding: 10px 11px; cursor: pointer; font-size: 13px;
  transition: border-color .12s, transform .1s;
}
.kanban-card:hover { border-color: var(--border-2); transform: translateY(-1px); }
.kanban-card strong { font-weight: 600; }
.kanban-meta { color: var(--muted); font-size: 11.5px; margin-top: 4px; }
.kanban-card.mode-auto   { box-shadow: inset 2px 0 0 var(--ok); }
.kanban-card.mode-paused { box-shadow: inset 2px 0 0 var(--unknown); }
.kanban-card.mode-needs_review { box-shadow: inset 2px 0 0 var(--warn); }

/* ---- Health strip --------------------------------------------------------- */
#health-strip {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px;
  padding: 14px 16px; margin-top: 8px; border-radius: 12px;
  background: var(--card); border: 1px solid var(--border); color: var(--muted);
  font-size: 12.5px;
}
.health-dot { display: inline-flex; align-items: center; gap: 5px; }
.health-dot.status-ok    { color: var(--ok); }
.health-dot.status-warn  { color: var(--warn); }
.health-dot.status-error { color: var(--error); }
.health-dot.status-unknown { color: var(--unknown); }
.health-refresh {
  border: none; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 13px; padding: 0 4px; margin-right: 6px;
}
.health-refresh:hover { color: var(--gold-2); }

/* ---- Generic dot ---------------------------------------------------------- */
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.ok { background: var(--ok); }

/* ---- Placeholder ("planned") panels --------------------------------------- */
.planned {
  text-align: center; padding: 56px 24px; border: 1px dashed var(--border-2);
  border-radius: 14px; background: var(--card); color: var(--muted);
}
.planned .planned-ico { font-size: 30px; opacity: .5; }
.planned h3 { color: var(--fg); margin: 12px 0 6px; text-transform: none; letter-spacing: 0; font-size: 17px; }
.planned .pill {
  display: inline-block; margin-top: 14px; padding: 4px 12px; border-radius: 999px;
  font-size: 12px; font-weight: 600; color: var(--gold-2);
  background: var(--gold-soft); border: 1px solid var(--gold);
}

/* ---- Jarvis floating chat ------------------------------------------------- */
.jarvis-fab {
  position: fixed; right: 24px; bottom: 24px; z-index: 50;
  width: 58px; height: 58px; border-radius: 50%; border: none; cursor: pointer;
  background: linear-gradient(145deg, var(--gold-2), var(--gold));
  color: #1a160a; font-size: 24px; box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s;
}
.jarvis-fab:hover { transform: scale(1.06); }
.jarvis-badge {
  position: absolute; top: -2px; right: -2px; min-width: 20px; height: 20px;
  border-radius: 999px; background: var(--error); color: #fff; font-size: 11px;
  font-weight: 700; display: flex; align-items: center; justify-content: center;
  padding: 0 5px; border: 2px solid var(--bg);
}
body.jarvis-open .jarvis-fab { transform: scale(0); opacity: 0; pointer-events: none; }

.jarvis-panel {
  position: fixed; right: 24px; bottom: 24px; z-index: 51;
  width: 370px; max-width: calc(100vw - 32px); height: 540px; max-height: calc(100vh - 48px);
  background: var(--card); border: 1px solid var(--border-2); border-radius: 16px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden;
  opacity: 0; transform: translateY(16px) scale(.98); pointer-events: none;
  transition: opacity .16s, transform .16s;
}
body.jarvis-open .jarvis-panel { opacity: 1; transform: none; pointer-events: auto; }
.jarvis-head {
  display: flex; align-items: center; gap: 11px; padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--gold-soft), transparent);
}
.jarvis-avatar {
  width: 34px; height: 34px; border-radius: 9px; display: flex;
  align-items: center; justify-content: center; font-size: 16px;
  background: linear-gradient(145deg, var(--gold-2), var(--gold)); color: #1a160a;
}
.jarvis-head strong { font-size: 14px; }
.jarvis-status { font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.jarvis-head .icon-btn { margin-left: auto; width: 30px; height: 30px; }
.jarvis-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.jarvis-msg {
  padding: 10px 13px; border-radius: 12px; font-size: 13px; max-width: 86%; line-height: 1.4;
}
.jarvis-msg.bot { background: var(--card-2); border: 1px solid var(--border); align-self: flex-start; border-bottom-left-radius: 4px; }
.jarvis-msg.me  { background: var(--gold-soft); border: 1px solid var(--gold); color: var(--fg);
                  align-self: flex-end; border-bottom-right-radius: 4px; }
.jarvis-chips { display: flex; flex-wrap: wrap; gap: 7px; padding: 0 16px 12px; }
.chip {
  border: 1px solid var(--border-2); background: var(--card-2); color: var(--fg-soft);
  border-radius: 999px; padding: 6px 12px; font-size: 12px; cursor: pointer;
}
.chip:hover { border-color: var(--gold); color: var(--gold-2); }
.jarvis-proposal-ctx { display: flex; flex-direction: column; gap: 6px; padding: 0 16px 12px; }
.jarvis-proposal-ctx select {
  width: 100%; background: var(--bg); border: 1px solid var(--border-2); color: var(--fg);
  border-radius: 9px; padding: 9px 10px; font-size: 13px; outline: none; cursor: pointer;
}
.jarvis-proposal-ctx select:focus { border-color: var(--gold); }
.jarvis-input { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
.jarvis-input input {
  flex: 1; background: var(--bg); border: 1px solid var(--border-2); color: var(--fg);
  border-radius: 9px; padding: 10px 12px; font-size: 13px; outline: none;
}
.jarvis-input input:focus { border-color: var(--gold); }
.jarvis-send {
  border: none; border-radius: 9px; width: 40px; cursor: pointer; font-size: 15px;
  background: linear-gradient(145deg, var(--gold-2), var(--gold)); color: #1a160a;
}

/* ---- Theme toggle legacy hook --------------------------------------------- */
.theme-toggle { font-size: 15px; }

/* ---- Responsive ----------------------------------------------------------- */
@media (max-width: 980px) {
  #kanban-board { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cols-2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .sidebar {
    position: fixed; left: 0; top: 0; transform: translateX(-100%);
    transition: transform .2s; box-shadow: var(--shadow); z-index: 50;
  }
  body.nav-open .sidebar { transform: none; }
  /* Tap-anywhere backdrop when the drawer is open */
  body.nav-open::after {
    content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.4);
    z-index: 49; backdrop-filter: blur(2px);
  }
  .menu-btn { display: inline-flex; }
  #kanban-board { grid-template-columns: 1fr; }
  main { padding: 16px; }

  /* ── Forms — single column, full-width inputs, touch-friendly */
  .proposal-form .grid-2 { grid-template-columns: 1fr; }
  .proposal-form label,
  .proposal-form .card,
  .proposal-form input,
  .proposal-form select,
  .proposal-form textarea { width: 100%; box-sizing: border-box; }
  input, select, textarea, button { font-size: 16px; }  /* iOS — prevents zoom-on-focus */
  .btn-primary, .btn-secondary, button[type="submit"] {
    min-height: 44px; padding: 12px 16px;   /* WCAG touch target */
  }

  /* ── Tables — wrap in a scrolling shell instead of squashing columns */
  .proposals-table, .line-items, .extras-table {
    display: block; overflow-x: auto; white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .proposals-table th, .proposals-table td { padding: 10px 8px; font-size: 13px; }

  /* ── KPI rows stack */
  .kpi-row { flex-direction: column; gap: 12px; }
  .kpi { width: 100%; }

  /* ── Page heads (title + actions) stack and full-width actions */
  .page-head { flex-direction: column; align-items: stretch; gap: 12px; }
  .page-head-actions { display: flex; flex-wrap: wrap; gap: 8px; }
  .page-head-actions > * { flex: 1 1 auto; }

  /* ── Action row buttons on the proposal detail page */
  .actions-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .actions-row form, .actions-row a { display: block; width: 100%; }
  .actions-row form button { width: 100%; }

  /* ── Jarvis chat panel — full-screen sheet on phones */
  .jarvis-panel {
    position: fixed; right: 0; bottom: 0; left: 0; top: 10vh;
    width: 100%; max-width: none; border-radius: 14px 14px 0 0;
  }
  .jarvis-fab { right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); }
  .jarvis-input input { font-size: 16px; }   /* prevent iOS zoom */

  /* ── Filter chips wrap nicely instead of overflowing */
  .filter-chips { flex-wrap: wrap; gap: 8px; }
  .filter-chips label, .filter-chips input, .filter-chips select { flex: 1 1 100%; }

  /* ── Topbar — tighter on phones */
  .topbar { padding: 8px 12px; gap: 8px; }
}
