:root {
  --bg: #f3f4f6;
  --bg-deep: #eef0f3;
  --surface: #fff;
  --ink: #0c1222;
  --ink-2: #1a2332;
  --ink-3: #3d4a5c;
  --mute: #6b778c;
  --line: #e2e6ed;
  --line-2: #d5dbe5;
  --navy: #0f2744;
  --accent: #0f6b5c;
  --accent-soft: #e6f5f1;
  --amber: #c2410c;
  --amber-soft: #fff4ed;
  --amber-line: #fdba74;
  --red: #b91c1c;
  --red-soft: #fef2f2;
  --red-line: #fecaca;
  --blue: #1d4ed8;
  --blue-soft: #eff6ff;
  --violet: #6d28d9;
  --violet-soft: #f5f3ff;
  --wa: #0f766e;
  --radius: 10px;
  --font: Inter, system-ui, -apple-system, sans-serif;
  --shadow-sm: 0 1px 2px rgba(12, 18, 34, 0.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; font-family: var(--font); background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; font-weight: 600; }
a:hover { text-decoration: underline; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 8px; font: 600 12.5px var(--font);
  padding: 8px 14px; cursor: pointer; white-space: nowrap;
}
.btn-primary { background: var(--navy); color: #fff; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-ghost { background: #fff; color: var(--ink-2); border: 1px solid var(--line-2); font-weight: 550; }
.btn-danger { background: #fff; color: var(--red); border: 1px solid var(--red-line); font-weight: 600; }
.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn-lg { padding: 11px 16px; font-size: 13.5px; width: 100%; }
.btn:disabled, .btn.is-off { opacity: 0.35; pointer-events: none; }

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px;
}
.pill-high { background: var(--red-soft); color: var(--red); }
.pill-med { background: var(--amber-soft); color: var(--amber); }
.pill-low { background: var(--accent-soft); color: var(--accent); }
.pill-neutral { background: var(--bg-deep); color: var(--ink-3); }
.pill-wa { background: var(--accent-soft); color: var(--wa); }
.pill-int { background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa; }
.pill-role-ctl { background: var(--violet-soft); color: var(--violet); }
.pill-role-sol { background: var(--blue-soft); color: var(--blue); }
.pill-role-rep { background: var(--accent-soft); color: var(--accent); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.mute { color: var(--mute); font-size: 12px; font-weight: 500; }
.ref { font-variant-numeric: tabular-nums; font-weight: 650; font-size: 12px; color: var(--ink-3); }

.field { margin-bottom: 12px; }
.field label { display: block; margin-bottom: 5px; font-size: 11.5px; font-weight: 600; color: var(--ink-3); }
.field input, .field textarea, .field select {
  width: 100%; border: 1px solid var(--line-2); border-radius: 8px;
  padding: 10px 12px; font: 500 13.5px var(--font); color: var(--ink); background: #fff;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none; border-color: #94a8c4; box-shadow: 0 0 0 3px rgba(15, 39, 68, 0.08);
}
.field textarea { min-height: 88px; resize: vertical; }
.phone-row { display: flex; gap: 8px; align-items: stretch; }
.phone-row select { width: 7.6rem; flex: 0 0 7.6rem; }
.phone-row input { flex: 1; min-width: 0; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-size: 13px; font-weight: 550; }
.flash-ok { background: var(--accent-soft); color: var(--accent); }
.flash-err { background: var(--red-soft); color: var(--red); }

/* Shell for non-canvas pages */
.shell { max-width: 1080px; margin: 0 auto; padding: 16px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 750; font-size: 15px; color: var(--navy); letter-spacing: -0.02em; }
.brand .m { width: 28px; height: 28px; border-radius: 8px; background: var(--navy); color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 800; }

.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
@media (max-width: 700px) { .metrics { grid-template-columns: repeat(2, 1fr); } }
.metric { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.metric .k { font-size: 11px; font-weight: 600; color: var(--mute); }
.metric .v { margin-top: 4px; font-size: 24px; font-weight: 700; letter-spacing: -0.03em; }
.metric.warn { border-color: var(--amber-line); background: linear-gradient(180deg,#fff,var(--amber-soft)); }
.metric.warn .v { color: var(--amber); }
.metric.risk { border-color: var(--red-line); background: linear-gradient(180deg,#fff,var(--red-soft)); }
.metric.risk .v { color: var(--red); }

.list { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row {
  display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: none; }
.row h3 { margin: 0 0 5px; font-size: 13.5px; font-weight: 650; }
.row .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.row a.rowlink { color: inherit; text-decoration: none; display: block; }
.row:hover { background: #f8fafc; }

.seg { display: flex; background: #fff; border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px; }
.seg a { font-size: 12px; font-weight: 550; color: var(--mute); padding: 6px 12px; border-radius: 7px; text-decoration: none; }
.seg a.on { background: var(--navy); color: #fff; font-weight: 600; }

/* Auth / report */
.center-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: min(400px, 100%); padding: 28px 26px; }
.report-grid { max-width: 960px; margin: 0 auto; display: grid; grid-template-columns: 1.05fr 0.95fr; gap: 16px; padding: 24px 16px; }
@media (max-width: 800px) { .report-grid { grid-template-columns: 1fr; } }
.report-hero {
  border-radius: var(--radius); padding: 28px 26px; color: #fff; min-height: 300px;
  background: radial-gradient(ellipse 80% 60% at 100% 0%, rgba(15,107,92,.35), transparent 55%),
    linear-gradient(155deg, #0f2744 0%, #152f4f 50%, #0f3d36 100%);
}
.report-hero h1 { margin: 0 0 10px; font-size: 26px; letter-spacing: -0.03em; line-height: 1.15; }
.report-hero p { color: rgba(255,255,255,.72); font-size: 14px; max-width: 34ch; }
.report-form { padding: 22px; position: relative; }
.report-form.is-submitting form,
.report-form.is-submitting > .mute { visibility: hidden; pointer-events: none; }
.report-progress {
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, 0.97);
  border-radius: inherit;
  padding: 28px 22px;
}
.report-progress[hidden] { display: none !important; }
.report-progress-inner { width: 100%; max-width: 280px; text-align: center; }
.report-progress-ring {
  width: 48px; height: 48px; margin: 0 auto 16px;
  border: 3px solid #e2e8f0;
  border-top-color: var(--navy, #0f2744);
  border-radius: 50%;
  animation: spin-busy 0.75s linear infinite;
}
.report-progress-title {
  margin: 0 0 10px; font-size: 18px; font-weight: 700; letter-spacing: -0.02em; color: var(--ink);
}
.report-progress-copy {
  margin: 0; font-size: 14px; font-weight: 500; color: var(--ink-3, #475569); line-height: 1.45;
}
.report-progress-hint { margin: 18px 0 0; font-size: 12px; }


/* Fixed-frame canvas */
body.canvas-page { height: 100vh; overflow: hidden; }
body.canvas-page .canvas-app { height: 100vh; display: flex; flex-direction: column; }
.canvas {
  flex: 1; min-height: 0; display: grid;
  grid-template-columns: minmax(0, 1fr) 272px;
  grid-template-rows: auto auto minmax(0, 1fr);
  grid-template-areas: "head head" "signal signal" "main rail";
  background: var(--bg-deep);
}
.canvas.reporter { grid-template-columns: minmax(0, 1fr) 240px; }
@media (max-width: 880px) {
  .canvas {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-areas: "head" "signal" "main" "rail";
  }
  .rail { max-height: 28vh; border-left: none !important; border-top: 1px solid var(--line); }
}
.c-head {
  grid-area: head; background: #fff; border-bottom: 1px solid var(--line);
  padding: 8px 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.c-head h2 { margin: 3px 0 0; font-size: 15px; font-weight: 700; letter-spacing: -0.025em; }
.c-head .line { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.c-acts { display: flex; gap: 6px; flex-wrap: wrap; }
.signal {
  grid-area: signal; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 14px; background: var(--amber-soft); border-bottom: 1px solid var(--amber-line);
}
.signal strong { display: block; font-size: 12.5px; font-weight: 700; color: var(--amber); }
.signal span { font-size: 12px; color: #9a3412; font-weight: 500; }
.signal.calm { background: var(--accent-soft); border-bottom-color: #99d5c6; }
.signal.calm strong { color: var(--accent); }
.signal.calm span { color: #0f5c4f; }
.signal.signal-closeout { background: #f5f3ff; border-bottom-color: #c4b5fd; }
.signal.signal-closeout strong { color: #5b21b6; }
.signal.signal-closeout span { color: #6d28d9; }
.signal.signal-breach { background: #fef2f2; border-bottom-color: #fca5a5; }
.signal.signal-breach strong { color: #b91c1c; }
.signal.signal-breach span { color: #991b1b; }
.main {
  grid-area: main; min-height: 0; min-width: 0; display: flex; flex-direction: column;
  background: #fff; border-right: 1px solid var(--line);
}
.thread {
  flex: 1; min-height: 0; overflow-y: auto; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 10px;
  background: linear-gradient(180deg, #f6f7f9, #f0f2f5);
  overflow-anchor: none; /* we control pin-to-newest in JS */
  scroll-behavior: auto;
}
#thread-end { height: 1px; width: 100%; flex-shrink: 0; }
.bubble {
  max-width: 86%; padding: 10px 12px; border-radius: 12px;
  background: #fff; border: 1px solid var(--line); align-self: flex-start; box-shadow: var(--shadow-sm);
}
.bubble.out { align-self: flex-end; background: #f0f5fb; border-color: #c9daf0; }
.bubble.wa { border-left: 3px solid var(--wa); }
.bubble.sys {
  align-self: center; max-width: 96%;
  background: #f8fafc; border: 1px solid var(--line); border-left: 3px solid var(--amber, #d97706);
  box-shadow: none; border-radius: 10px;
  font-size: 12px; font-weight: 500; color: var(--ink-3, #475569);
  padding: 10px 12px; line-height: 1.45;
}
.bubble.sys .sys-body { white-space: pre-wrap; margin-top: 2px; }
.bubble.sys .b-top { margin-bottom: 4px; }
.bubble.sys .b-who { font-size: 11px; font-weight: 650; color: var(--mute); }
.bubble .b-time {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-size: 10.5px;
}

/* Form busy / action in progress */
form.is-busy button[type="submit"],
form.is-busy input[type="submit"] {
  opacity: 0.75;
  cursor: wait;
  pointer-events: none;
}
.action-busy-bar {
  flex-shrink: 0;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 650;
  color: #1e3a5f;
  background: linear-gradient(90deg, #e0f2fe, #f0f9ff);
  border-bottom: 1px solid #bae6fd;
  display: flex;
  align-items: center;
  gap: 8px;
}
.action-busy-bar::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid #38bdf8;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin-busy 0.7s linear infinite;
}
@keyframes spin-busy {
  to { transform: rotate(360deg); }
}
.page-busy .c-acts { opacity: 0.85; }
.btn:disabled {
  opacity: 0.7;
  cursor: wait;
}
.bubble.int { background: #fffbeb; border: 1px solid #fcd34d; border-left: 3px solid #f59e0b; max-width: 90%; }
.bubble .lock { font-size: 10px; font-weight: 650; color: #b45309; text-transform: uppercase; letter-spacing: .03em; margin-bottom: 4px; }
.b-top { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.b-who { font-size: 11.5px; font-weight: 650; }
.b-who.rep { color: var(--accent); }
.b-who.ctl { color: var(--violet); }
.b-who.sol { color: var(--blue); }
.b-time { font-size: 10.5px; color: var(--mute); font-weight: 500; }
.bubble p { margin: 0; font-size: 13px; font-weight: 450; white-space: pre-wrap; }
.composer { flex-shrink: 0; border-top: 1px solid var(--line); background: #fff; padding: 10px 12px 12px; }
.composer-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; align-items: center; }
.waiting-sel {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 550;
  background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 5px 10px; color: var(--ink-3);
}
.waiting-sel select { border: none; background: transparent; font: 650 11.5px var(--font); color: var(--amber); outline: none; }
.composer textarea {
  width: 100%; border: 1px solid var(--line-2); border-radius: 8px; padding: 10px 12px;
  font: 450 13px var(--font); min-height: 52px; max-height: 100px; resize: none; margin-bottom: 8px;
}
.composer-bar { display: flex; justify-content: space-between; align-items: center; }
.rail { grid-area: rail; min-height: 0; overflow-y: auto; background: #fff; display: flex; flex-direction: column; }
.block { padding: 14px; border-bottom: 1px solid var(--line); }
.block h4 { margin: 0 0 10px; font-size: 10.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .07em; color: var(--mute); }
.person { display: grid; grid-template-columns: 76px 1fr; gap: 2px 8px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.person:last-child { border-bottom: none; }
.person .r { font-size: 10.5px; font-weight: 600; color: var(--mute); text-transform: uppercase; }
.person .n { font-size: 13px; font-weight: 650; }
.person .p { font-size: 11.5px; font-weight: 550; color: var(--wa); grid-column: 2; }
.block.sla { background: linear-gradient(180deg,#fff,var(--red-soft)); }
.sla-num { font-size: 26px; font-weight: 750; letter-spacing: -0.03em; color: var(--red); line-height: 1; margin-bottom: 6px; }
.kv { display: flex; justify-content: space-between; font-size: 12.5px; padding: 3px 0; font-weight: 550; color: var(--ink-2); }
.kv span:first-child { color: var(--mute); font-weight: 500; }
.bar { height: 5px; background: #fecaca; border-radius: 99px; overflow: hidden; margin-top: 10px; }
.bar > i { display: block; height: 100%; background: var(--red); border-radius: 99px; }
.guide-title { font-size: 12.5px; font-weight: 650; margin-bottom: 8px; }
.block.guide pre, .work-guide {
  margin: 0; font-size: 12.5px; color: var(--ink-3); white-space: pre-wrap; font-family: var(--font); font-weight: 450;
}
.block.ok { background: linear-gradient(180deg,#fff,var(--accent-soft)); }
.status-big { font-size: 15px; font-weight: 700; color: var(--accent); margin-bottom: 4px; }
