/* ============================================================
   Premium light theme — mobile-first, field-ready.
   Refs: Linear / Notion / Procore. Amber accent, strong hierarchy,
   subtle glass, minimal motion, high outdoor readability.
   ============================================================ */

:root {
  /* Canvas + surfaces */
  --bg: #f4f5f7;
  --bg-2: #eceef1;
  --card: #ffffff;

  /* Ink */
  --ink: #15181e;
  --ink-soft: #5b6573;
  --ink-faint: #99a1ad;

  /* Lines */
  --line: #e5e7ec;
  --line-soft: #f0f1f4;

  /* Amber accent */
  --accent: #f59e0b;
  --accent-press: #d98a08;
  --on-accent: #1c1303;      /* near-black warm — text on amber (high contrast) */
  --accent-text: #b45309;    /* readable amber text on light */
  --accent-tint: #fef4e4;
  --accent-tint-2: #fdeccf;
  --accent-border: #f6d18a;

  /* Status */
  --danger: #dc2626;
  --danger-tint: #feecec;

  /* Elevation */
  --shadow-sm: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.05);
  --shadow-md: 0 6px 16px rgba(16,24,40,.08);
  --shadow-pop: 0 16px 40px rgba(16,24,40,.14);

  /* Radii */
  --r-lg: 16px;
  --r: 12px;
  --r-sm: 9px;
  --r-pill: 999px;

  /* Glass */
  --glass: rgba(255,255,255,.72);

  font-size: 16px;
}

[data-theme="dark"] {
  --bg: #0B0F17;
  --bg-2: #0e1320;
  --card: #131A24;
  --ink: #e8eef4;
  --ink-soft: #9fb0c0;
  --ink-faint: #6b7d8f;
  --line: #212a39;
  --line-soft: #1a2230;
  --accent: #f59e0b;
  --accent-press: #e08e08;
  --on-accent: #1c1303;
  --accent-text: #fbbf6b;
  --accent-tint: rgba(245,158,11,.14);
  --accent-tint-2: rgba(245,158,11,.22);
  --accent-border: rgba(245,158,11,.35);
  --input-bg: #0f1623;
  --glass: rgba(15,20,30,.72);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.5);
  --shadow-md: 0 8px 20px rgba(0,0,0,.45);
  --shadow-pop: 0 18px 44px rgba(0,0,0,.5);
  --tag-pc-bg: rgba(129,140,248,.18); --tag-pc-ink: #a5b4fc;
  --tag-quote-bg: rgba(148,163,184,.16); --tag-quote-ink: #cbd5e1;
  --danger-tint: rgba(220,38,38,.16);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden; /* panels scroll internally */
}
button { font-family: inherit; }

/* ---------- Top bar (subtle glass) ---------- */
.topbar {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px) saturate(1.15);
  backdrop-filter: blur(14px) saturate(1.15);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark { width: 38px; height: 38px; flex: 0 0 auto; display: block; border-radius: 11px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-text strong { font-size: 15px; font-weight: 700; letter-spacing: -.2px; }
.brand-text span { font-size: 11.5px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.badge {
  font-size: 12px; font-weight: 600; padding: 6px 11px; border-radius: var(--r-pill);
  background: var(--bg-2); color: var(--ink-soft);
}
@media (max-width: 880px) { .badge { display: none; } .brand-text span { display: none; } }

/* ---------- Buttons ---------- */
.btn {
  font-size: 13.5px; font-weight: 600; cursor: pointer; white-space: nowrap;
  border-radius: var(--r-sm); padding: 0 15px; height: 40px; border: 1px solid transparent;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .14s ease, border-color .14s ease, color .14s ease;
}
.btn:active { transform: translateY(.5px); }
.btn-primary { background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--accent-press); }
.btn-ghost { background: var(--card); color: var(--ink-soft); border-color: var(--line); }
.btn-ghost:hover { background: var(--bg-2); color: var(--ink); }

/* ---------- Mobile tab switch ---------- */
.mobile-tabs {
  flex: 0 0 auto; display: flex; gap: 6px; padding: 8px 12px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line); z-index: 15;
}
.mtab {
  flex: 1 1 0; height: 44px; border: 1px solid var(--line); background: var(--card);
  border-radius: var(--r-sm); font-size: 14px; font-weight: 600; color: var(--ink-soft);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
}
.mtab[aria-selected="true"] { background: var(--navy); color: #fff; border-color: var(--navy); }
.mtab-count {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--r-pill);
  background: var(--accent); color: var(--on-accent); font-size: 11.5px; font-weight: 700;
  display: none; align-items: center; justify-content: center;
}
.mtab-count.show { display: inline-flex; }

/* ---------- Layout ---------- */
.layout { flex: 1 1 auto; min-height: 0; display: flex; }
.chat-col, .scope-col {
  flex: 1 1 0; min-height: 0; min-width: 0; display: flex; flex-direction: column; background: var(--card);
}

/* Mobile: one panel at a time (full-bleed) */
body[data-view="chat"] .scope-col { display: none; }
body[data-view="scope"] .chat-col { display: none; }

@media (min-width: 881px) {
  .mobile-tabs { display: none; }
  .layout { display: grid; grid-template-columns: minmax(390px, 44fr) 56fr; gap: 16px; padding: 16px; }
  .chat-col, .scope-col { display: flex !important; border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); overflow: hidden; }
}

/* ---------- Chat ---------- */
.messages { flex: 1 1 auto; overflow-y: auto; padding: 20px clamp(16px, 4vw, 26px); display: flex; flex-direction: column; gap: 16px; -webkit-overflow-scrolling: touch; }

.welcome { margin: auto 0; padding: 4px; }
.welcome h1 { font-size: clamp(22px, 5vw, 27px); margin: 0 0 10px; letter-spacing: -.5px; font-weight: 700; }
.welcome p { color: var(--ink-soft); margin: 0 0 20px; line-height: 1.55; font-size: 15.5px; }
.examples { display: flex; flex-direction: column; gap: 9px; align-items: stretch; }
.chip {
  font-size: 14px; text-align: left; cursor: pointer; line-height: 1.4;
  background: var(--card); color: var(--ink); border: 1px solid var(--line);
  padding: 13px 15px; border-radius: var(--r); min-height: 48px;
  transition: border-color .14s ease, background .14s ease;
}
.chip:hover { border-color: var(--accent); background: var(--accent-tint); }

.msg { display: flex; gap: 10px; max-width: 100%; }
.msg .bubble { padding: 12px 15px; border-radius: 15px; line-height: 1.55; white-space: pre-wrap; word-wrap: break-word; font-size: 15px; max-width: 88%; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--navy); color: #fff; border-bottom-right-radius: 5px; }
.msg.assistant .bubble { background: var(--bg-2); color: var(--ink); border-bottom-left-radius: 5px; }
.msg.assistant .bubble.scope-note { background: var(--accent-tint); color: var(--accent-text); font-weight: 600; }

.typing { display: inline-flex; gap: 5px; padding: 4px 2px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-faint); animation: blink 1.2s infinite both; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ---------- Composer ---------- */
.composer {
  flex: 0 0 auto; display: flex; align-items: flex-end; gap: 9px;
  padding: 12px clamp(12px, 3vw, 16px);
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--glass);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.composer textarea {
  flex: 1 1 auto; resize: none; font: inherit; font-size: 16px; line-height: 1.45;
  border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; max-height: 168px; min-height: 50px;
  color: var(--ink); background: var(--bg); outline: none; transition: border-color .14s ease, background .14s ease;
}
.composer textarea:focus { border-color: var(--accent); background: var(--card); box-shadow: 0 0 0 3px var(--accent-tint); }
.composer textarea::placeholder { color: var(--ink-faint); }
.icon-btn {
  flex: 0 0 auto; width: 50px; height: 50px; border-radius: var(--r); border: 1px solid var(--line);
  background: var(--bg); color: var(--ink-soft); cursor: pointer; display: grid; place-items: center;
  transition: background .14s ease, color .14s ease, border-color .14s ease;
}
.icon-btn:hover { background: var(--bg-2); color: var(--ink); }
.icon-btn.send { background: var(--accent); color: var(--on-accent); border-color: var(--accent); box-shadow: var(--shadow-sm); }
.icon-btn.send:hover { background: var(--accent-press); }
.icon-btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn.recording { background: var(--danger-tint); color: var(--danger); border-color: #f7caca; animation: pulse 1.4s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(220,38,38,.3);} 50% { box-shadow: 0 0 0 7px rgba(220,38,38,0);} }
.hint { margin: 0; padding: 0 16px 10px; font-size: 12.5px; color: var(--ink-faint); min-height: 4px; }

/* ---------- Scope panel ---------- */
.scope-head { flex: 0 0 auto; display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 16px clamp(16px,3vw,22px); border-bottom: 1px solid var(--line); }
.scope-title { flex: 1 1 auto; min-width: 0; }
.job-title-input { font: inherit; font-size: 19px; font-weight: 700; letter-spacing: -.3px; color: var(--ink); border: none; outline: none; width: 100%; padding: 2px 0; background: transparent; }
.job-title-input::placeholder { color: var(--ink-faint); }
.scope-meta { display: flex; gap: 12px; margin-top: 5px; flex-wrap: wrap; }
.scope-meta input { font: inherit; font-size: 13px; color: var(--ink-soft); border: none; outline: none; background: transparent; border-bottom: 1px dashed var(--line); padding: 3px 0; min-width: 120px; }
.scope-meta input:focus { border-bottom-color: var(--accent); color: var(--ink); }
.scope-head-actions { display: flex; gap: 8px; flex: 0 0 auto; }

.scope-body { flex: 1 1 auto; overflow-y: auto; padding: 16px clamp(14px,3vw,22px); -webkit-overflow-scrolling: touch; }
.scope-empty { height: 100%; min-height: 320px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--ink-faint); text-align: center; gap: 6px; }
.scope-empty-icon { font-size: 38px; opacity: .7; }

.section { margin-bottom: 16px; border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: var(--r); overflow: hidden; background: var(--card); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 12px 14px; background: var(--line-soft); border-bottom: 1px solid var(--line); }
.section-head .sec-title { font-size: 12.5px; font-weight: 800; letter-spacing: .6px; color: var(--ink); text-transform: uppercase; }
.section-head .sec-sub { font-size: 13px; font-weight: 700; color: var(--ink-soft); }
.section-note { font-size: 13px; color: var(--ink-soft); padding: 10px 14px 0; line-height: 1.45; }

table.items { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.items th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--ink-faint); font-weight: 700; padding: 9px 10px; border-bottom: 1px solid var(--line); }
table.items td { padding: 10px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
table.items tr:last-child td { border-bottom: none; }
.col-desc { width: 46%; }
.col-num { text-align: right; white-space: nowrap; }
.li-desc { color: var(--ink); line-height: 1.45; }
.li-trade { display: inline-block; font-size: 10.5px; font-weight: 800; letter-spacing: .4px; text-transform: uppercase; color: var(--accent-text); background: var(--accent-tint); padding: 2px 7px; border-radius: 5px; margin-bottom: 4px; }
.li-note { color: var(--ink-faint); font-size: 12px; margin-top: 4px; }
.tag { font-size: 10.5px; font-weight: 800; padding: 2px 7px; border-radius: 5px; letter-spacing: .3px; }
.tag.pc { background: var(--accent-tint); color: var(--accent-text); }
.tag.quote { background: var(--bg-2); color: var(--ink-soft); }

.cell-input { font: inherit; font-size: 14px; width: 76px; text-align: right; color: var(--ink); border: 1px solid transparent; border-radius: 8px; padding: 7px 8px; background: var(--bg-2); min-height: 38px; }
.cell-input.qty { width: 62px; }
.cell-input:focus { outline: none; border-color: var(--accent); background: var(--card); box-shadow: 0 0 0 3px var(--accent-tint); }
.li-total { font-weight: 700; }
.row-del { cursor: pointer; color: var(--ink-faint); border: none; background: none; font-size: 19px; padding: 2px 6px; line-height: 1; border-radius: 6px; }
.row-del:hover { color: var(--danger); background: var(--danger-tint); }

.scope-foot { flex: 0 0 auto; border-top: 1px solid var(--line); padding: 14px clamp(16px,3vw,22px); padding-bottom: max(14px, env(safe-area-inset-bottom)); background: var(--card); }
.totals { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.totals span { font-size: 13.5px; color: var(--ink-soft); }
.totals strong { font-size: 25px; letter-spacing: -.6px; font-weight: 700; }
.disclaimer { margin: 7px 0 0; font-size: 11.5px; color: var(--ink-faint); line-height: 1.45; }

/* ---------- Print / PDF (always light) ---------- */
.pdf-doc { font-family: 'Inter', Arial, sans-serif; color: #15181e; padding: 32px 36px; width: 760px; }
.pdf-doc h1 { font-size: 22px; margin: 0 0 2px; }
.pdf-doc .pdf-meta { color: #5b6573; font-size: 12.5px; margin-bottom: 18px; }
.pdf-doc .pdf-section { margin-bottom: 16px; page-break-inside: avoid; }
.pdf-doc .pdf-section h2 { font-size: 12.5px; letter-spacing: .5px; background: #15181e; color: #fff; padding: 8px 11px; margin: 0; border-radius: 6px; border-left: 3px solid #f59e0b; }
.pdf-doc table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 6px; }
.pdf-doc th { text-align: left; color: #99a1ad; font-size: 10px; text-transform: uppercase; padding: 5px 8px; border-bottom: 1px solid #e5e7ec; }
.pdf-doc td { padding: 6px 8px; border-bottom: 1px solid #f0f1f4; }
.pdf-doc .num { text-align: right; white-space: nowrap; }
.pdf-doc .pdf-total { text-align: right; font-size: 16px; font-weight: 700; margin-top: 14px; padding-top: 10px; border-top: 2px solid #15181e; }
.pdf-doc .pdf-disclaimer { font-size: 10px; color: #99a1ad; margin-top: 18px; line-height: 1.5; }

/* ---------- PDF option card (A/B/C) ---------- */
.option-card { max-width: 100% !important; }
.option-q { font-size: 14.5px; margin-bottom: 10px; line-height: 1.45; }
.option-file { font-weight: 700; color: var(--accent-text); }
.option-btns { display: flex; flex-direction: column; gap: 8px; }
.option-btn {
  display: flex; align-items: center; gap: 11px; text-align: left; width: 100%;
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; line-height: 1.35; color: var(--ink);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 12px 13px; min-height: 48px; transition: border-color .14s ease, background .14s ease;
}
.option-btn:hover { border-color: var(--accent); background: var(--accent-tint); }
.option-btn .option-key {
  flex: 0 0 auto; width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: var(--on-accent); font-weight: 800; font-size: 12px;
  display: grid; place-items: center;
}
.option-btn.chosen { border-color: var(--accent); background: var(--accent-tint); }
.option-btn.dim { opacity: .45; }
.option-btn:disabled { cursor: default; }

/* ---------- Scope-only view (hide quantities + pricing) ---------- */
.scope-col.no-pricing table.items th:nth-child(n+2):nth-child(-n+5),
.scope-col.no-pricing table.items td:nth-child(n+2):nth-child(-n+5) { display: none; }
.scope-col.no-pricing .scope-foot .totals { display: none; }
.scope-col.no-pricing .section-head .sec-sub { display: none; }

/* ---------- Generic app modal (export options, settings) ---------- */
.app-modal { position: fixed; inset: 0; z-index: 80; display: none; align-items: center; justify-content: center; padding: 18px;
  background: rgba(8,12,18,.5); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.app-modal.open { display: flex; }
.app-modal-card { width: 100%; max-width: 440px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop); padding: 22px; }
.app-modal-card h3 { margin: 0 0 4px; font-size: 18px; letter-spacing: -.3px; }
.app-modal-card p.sub { margin: 0 0 16px; color: var(--ink-soft); font-size: 13.5px; }
.opt-row { display: flex; flex-direction: column; gap: 9px; }
.opt { text-align: left; width: 100%; font: inherit; cursor: pointer; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 13px 14px; transition: border-color .14s, background .14s; }
.opt:hover { border-color: var(--accent); background: var(--accent-tint); }
.opt strong { display: block; font-size: 14.5px; }
.opt span { display: block; font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }
.app-modal .modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.field-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 13px; }
.field-row label { font-size: 12.5px; color: var(--ink-soft); }
.field-row input { height: 44px; background: var(--input-bg); border: 1px solid var(--line); border-radius: 9px; color: var(--ink); font: inherit; font-size: 15px; padding: 0 13px; }
.field-row input:focus { outline: none; border-color: var(--accent); }

/* ---------- Burger menu ---------- */
.menu-wrap { position: relative; }
.menu-btn { width: 42px; height: 42px; }
.menu-pop { position: absolute; right: 0; top: calc(100% + 8px); width: 264px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow-pop); padding: 8px; display: none; z-index: 60; }
.menu-pop.open { display: block; }
.menu-id { display: flex; align-items: center; gap: 11px; padding: 8px 8px 12px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.menu-logo { width: 40px; height: 40px; border-radius: 10px; background: var(--navy); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 17px; flex: 0 0 auto; }
.menu-id .who { min-width: 0; }
.menu-id .who strong { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-id .who span { display: block; font-size: 12px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; text-align: left; font: inherit;
  font-size: 14px; font-weight: 500; color: var(--ink); background: none; border: none; border-radius: 8px; padding: 11px 10px; cursor: pointer; }
.menu-item:hover { background: var(--line-soft); }
.switch { width: 42px; height: 24px; border-radius: 999px; background: var(--line); border: none; position: relative; cursor: pointer; flex: 0 0 auto; transition: background .15s; }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(18px); }

/* ---------- Exclusions / clarifications note lists ---------- */
.note-section .note-list { padding: 6px 8px 10px; }
.note-row { display: flex; align-items: flex-start; gap: 8px; }
.note-dot { flex: 0 0 auto; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin-top: 13px; }
.note-input {
  flex: 1 1 auto; font: inherit; font-size: 13.5px; line-height: 1.45; color: var(--ink);
  border: 1px solid transparent; border-radius: 7px; padding: 7px 8px; background: transparent;
  resize: none; overflow: hidden; min-height: 20px;
}
.note-input:hover { background: var(--bg-2); }
.note-input:focus { outline: none; background: var(--card); border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.note-input::placeholder { color: var(--ink-faint); }
.note-add { margin: 6px 0 0 14px; font: inherit; font-size: 13px; font-weight: 600; color: var(--accent-text); background: none; border: none; cursor: pointer; padding: 4px 4px; border-radius: 6px; }
.note-add:hover { background: var(--accent-tint); }

/* PDF notes */
.pdf-doc .pdf-notes h2 { background: #5b6573; }
.pdf-doc .pdf-notes ul { margin: 8px 0 0; padding-left: 18px; }
.pdf-doc .pdf-notes li { font-size: 11px; color: #51647a; margin: 3px 0; line-height: 1.4; }
