:root {
  --ink: #15283b;
  --muted: #607185;
  --navy: #10283d;
  --navy-deep: #0a1d2d;
  --blue: #1768ac;
  --blue-soft: #eaf3fb;
  --green: #2d7964;
  --green-soft: #e9f5f0;
  --amber: #a66c08;
  --amber-soft: #fff4dc;
  --red: #a4463d;
  --red-soft: #fbecea;
  --paper: #ffffff;
  --canvas: #edf2f6;
  --line: #d5dfe7;
  --line-strong: #b7c6d2;
  --shadow: 0 12px 30px rgba(17, 43, 65, 0.08);
  --radius: 10px;
  font-family: "Segoe UI Variable", "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; min-height: 100vh; background: var(--canvas); color: var(--ink); }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
button:disabled, select:disabled { cursor: not-allowed; opacity: .55; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 3px solid #78b7ee;
  outline-offset: 2px;
}

.skip-link { position: fixed; z-index: 100; left: 12px; top: -60px; color: #fff; background: var(--blue); padding: 10px 14px; }
.skip-link:focus { top: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

.login-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(260px, .7fr) minmax(420px, 1.3fr); background: var(--navy-deep); }
.login-mark { display: grid; place-items: center; color: rgba(255,255,255,.08); font-size: clamp(92px, 18vw, 260px); font-weight: 800; letter-spacing: -.09em; overflow: hidden; }
.login-card { align-self: center; width: min(520px, calc(100% - 48px)); margin: 48px; padding: clamp(30px, 5vw, 58px); background: var(--paper); box-shadow: var(--shadow); }
.login-card h1 { font-size: clamp(30px, 4vw, 46px); line-height: 1.02; letter-spacing: -.035em; margin: 8px 0 18px; max-width: 10ch; }
.login-card p { color: var(--muted); line-height: 1.55; max-width: 55ch; }
.login-card label { display: block; margin: 28px 0 7px; font-size: 13px; font-weight: 650; }
.login-card input { width: 100%; height: 46px; border: 1px solid var(--line-strong); border-radius: 6px; padding: 0 12px; }
.login-card .button { width: 100%; margin-top: 12px; }
.form-error { min-height: 1.4em; color: var(--red) !important; font-weight: 600; }

.topbar { height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 0 28px; color: #fff; background: var(--navy-deep); border-bottom: 1px solid rgba(255,255,255,.14); }
.brand-block { display: flex; align-items: center; gap: 13px; }
.brand-mark { display: grid; place-items: center; width: 47px; height: 42px; border: 1px solid rgba(255,255,255,.45); font-size: 14px; font-weight: 800; letter-spacing: -.02em; }
.brand-block strong, .brand-block span { display: block; }
.brand-block strong { font-size: 15px; }
.brand-block div span { margin-top: 2px; color: #b9cad8; font-size: 12px; }
.topbar-status { display: flex; align-items: center; gap: 12px; }
.connection-state { position: relative; padding-left: 14px; color: #c7d5e0; font-size: 12px; }
.connection-state::before { content: ""; position: absolute; left: 0; top: 50%; width: 7px; height: 7px; margin-top: -3px; border-radius: 50%; background: #d3a856; }
.connection-state[data-state="online"]::before { background: #62b795; }
.connection-state[data-state="offline"]::before { background: #db7469; }
.role-chip { border: 1px solid rgba(255,255,255,.22); padding: 5px 9px; font-size: 11px; color: #dbe6ee; }

.campaign-frame { display: grid; grid-template-columns: 218px minmax(0, 1fr); min-height: calc(100vh - 72px); }
.sidebar { display: flex; flex-direction: column; justify-content: space-between; padding: 24px 16px; background: var(--navy); color: #fff; }
.sidebar nav { display: grid; gap: 5px; }
.sidebar nav button { border: 0; border-left: 3px solid transparent; border-radius: 0; color: #cfdae3; background: transparent; padding: 11px 12px; text-align: left; }
.sidebar nav button:hover { background: rgba(255,255,255,.06); }
.sidebar nav button[aria-current="page"] { color: #fff; background: rgba(255,255,255,.1); border-left-color: #62b795; }
.sidebar nav span, .sidebar nav small { display: block; }
.sidebar nav span { font-weight: 680; }
.sidebar nav small { color: #91a9bb; margin-top: 2px; font-size: 10px; }
.sidebar-note { border-top: 1px solid rgba(255,255,255,.15); padding: 16px 10px 0; }
.sidebar-note strong { font-size: 12px; }
.sidebar-note p { color: #9fb2c1; font-size: 11px; line-height: 1.45; }

main { min-width: 0; padding: 34px clamp(22px, 4vw, 54px) 54px; }
.view { width: min(1500px, 100%); margin: 0 auto; }
.page-heading { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 24px; }
.page-heading h1 { margin: 4px 0 7px; font-size: clamp(28px, 3vw, 42px); line-height: 1.05; letter-spacing: -.035em; }
.page-heading p:not(.context-label) { color: var(--muted); margin: 0; max-width: 68ch; }
.page-heading time { color: var(--muted); font-size: 11px; white-space: nowrap; }
.context-label { margin: 0; color: var(--blue); font-size: 11px; font-weight: 750; }

.notice { margin-bottom: 18px; padding: 11px 14px; border-left: 3px solid var(--amber); background: var(--amber-soft); font-size: 13px; }
.notice[data-tone="error"] { border-left-color: var(--red); background: var(--red-soft); }
.notice[data-tone="success"] { border-left-color: var(--green); background: var(--green-soft); }

.status-rail { display: grid; grid-template-columns: repeat(4, 1fr); margin-bottom: 20px; color: #fff; background: var(--navy-deep); box-shadow: var(--shadow); }
.status-rail div { min-width: 0; padding: 20px 22px; border-right: 1px solid rgba(255,255,255,.13); }
.status-rail div:last-child { border-right: 0; }
.status-rail span, .status-rail strong { display: block; }
.status-rail span { color: #aec1d0; font-size: 11px; }
.status-rail strong { margin-top: 4px; font-size: 30px; line-height: 1; letter-spacing: -.04em; }

.overview-grid, .content-grid { display: grid; grid-template-columns: minmax(360px, 1.1fr) minmax(320px, .9fr); gap: 20px; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 4px 18px rgba(17,43,65,.035); padding: 20px; }
.panel-heading { display: flex; align-items: start; justify-content: space-between; gap: 20px; margin-bottom: 14px; }
.panel-heading h2 { margin: 2px 0 0; font-size: 19px; letter-spacing: -.02em; }
.panel-heading p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.activity-panel { margin-top: 20px; }
.runtime-panel { border-top: 4px solid var(--blue); }
.funnel-panel { border-top: 4px solid var(--green); }
.state-pill { flex: none; padding: 5px 9px; border: 1px solid var(--line-strong); border-radius: 999px; color: var(--muted); font-size: 11px; font-weight: 700; }
.state-pill[data-tone="good"] { color: var(--green); border-color: #9ac9b9; background: var(--green-soft); }
.state-pill[data-tone="warn"] { color: var(--amber); border-color: #dfc48a; background: var(--amber-soft); }
.state-pill[data-tone="bad"] { color: var(--red); border-color: #deb2ac; background: var(--red-soft); }
.guard-copy { margin: 14px 0 0; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; line-height: 1.45; }
.facts { display: grid; grid-template-columns: minmax(160px, 1fr) auto; gap: 7px 18px; margin: 18px 0; font-size: 12px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; text-align: right; font-weight: 650; }
.action-row { display: flex; flex-wrap: wrap; gap: 9px; }
.runtime-start { margin: 15px 0; padding: 13px; background: var(--blue-soft); border-left: 3px solid var(--blue); }
.runtime-start > strong { display: block; margin-bottom: 9px; font-size: 12px; }
.runtime-start > div { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-bottom: 9px; }
.runtime-start label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; }
.runtime-start input { width: 62px; height: 34px; padding: 0 8px; border: 1px solid var(--line-strong); border-radius: 5px; color: var(--ink); background: #fff; }

.funnel-list { display: grid; gap: 9px; }
.funnel-row { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(80px, 2fr) auto; gap: 12px; align-items: center; }
.funnel-row span { min-width: 0; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.funnel-row strong { min-width: 32px; text-align: right; font-size: 12px; }
.funnel-bar { width: 100%; height: 8px; border: 0; border-radius: 0; background: #e5ebf0; overflow: hidden; appearance: none; }
.funnel-bar::-webkit-progress-bar { background: #e5ebf0; }
.funnel-bar::-webkit-progress-value { background: var(--green); }
.funnel-bar::-moz-progress-bar { background: var(--green); }

.button, .quiet-button, .text-button { border: 0; border-radius: 6px; font-weight: 680; }
.button { min-height: 40px; padding: 9px 14px; color: var(--ink); background: #e4ebf0; }
.button-primary { color: #fff; background: var(--blue); }
.button-danger { color: #fff; background: var(--red); }
.quiet-button { padding: 7px 10px; color: inherit; background: transparent; border: 1px solid currentColor; font-size: 11px; }
.topbar .quiet-button { color: #cbd9e3; border-color: rgba(255,255,255,.25); }
.text-button { padding: 4px 0; color: var(--blue); background: transparent; font-size: 12px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { padding: 9px 10px; color: var(--muted); border-bottom: 1px solid var(--line-strong); text-align: left; font-weight: 650; }
td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
.empty { color: var(--muted); font-size: 12px; line-height: 1.45; }

.conversation-layout { display: grid; grid-template-columns: minmax(420px, .9fr) minmax(420px, 1.1fr); gap: 20px; align-items: start; }
.batch-layout { display: grid; grid-template-columns: minmax(280px, .55fr) minmax(400px, 1fr); gap: 20px; align-items: start; }
.batch-create { border-top: 4px solid var(--blue); }
.batch-create > p { font-size: 12px; }
.batch-create select { width: 100%; min-height: 40px; margin-bottom: 12px; padding: 7px 10px; border: 1px solid var(--line-strong); border-radius: 6px; color: var(--ink); background: #fff; }
.batch-create .button { width: 100%; }
.field-label { display: block; margin: 11px 0 5px; color: var(--muted); font-size: 11px; font-weight: 700; }
.batch-detail { grid-column: 1 / -1; }
.batch-items { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.conversation-detail { position: sticky; top: 20px; max-height: calc(100vh - 130px); overflow: auto; }
.toolbar { display: grid; grid-template-columns: minmax(170px, 1fr) 150px 150px auto; gap: 8px; margin-bottom: 14px; }
.toolbar input, .toolbar select { width: 100%; height: 39px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 6px; color: var(--ink); background: #fff; }
.record-list { display: grid; gap: 8px; }
.record { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 5px 16px; padding: 12px; color: var(--ink); background: #fff; border: 1px solid var(--line); border-left: 3px solid var(--line-strong); text-align: left; }
.record[data-tone="good"] { border-left-color: var(--green); }
.record[data-tone="warn"] { border-left-color: var(--amber); }
.record[data-tone="bad"] { border-left-color: var(--red); }
.record strong, .record span { min-width: 0; overflow-wrap: anywhere; }
.record small { color: var(--muted); }
.history-record time { color: var(--muted); font-size: 11px; white-space: nowrap; }
.history-record .message-text { grid-column: 1 / -1; margin: 3px 0 0; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.history-record small { grid-column: 1 / -1; }
.attention-box { margin: 14px 0; padding: 12px 14px; border-left: 3px solid var(--amber); background: var(--amber-soft); }
.attention-box strong { font-size: 12px; }
.attention-box p { margin: 6px 0 0; font-size: 12px; line-height: 1.4; }
.conversation-actions { margin: 14px 0; }
.conversation-record { display: grid; grid-template-columns: auto minmax(0,1fr); align-items: stretch; gap: 8px; }
.conversation-record.no-selector { grid-template-columns: minmax(0,1fr); }
.conversation-record > label { display: grid; place-items: center; width: 34px; border: 1px solid var(--line); background: #f7f9fb; }
.conversation-record > label input { width: 17px; height: 17px; }
.conversation-record .record { min-width: 0; }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.channel-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.channel-register { margin-bottom: 20px; border-top: 4px solid var(--amber); }
.channel-register-form { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) auto; gap: 10px; align-items: end; }
.channel-register-form label span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; font-weight: 700; }
.channel-register-form input, .channel-register-form select { width: 100%; min-height: 40px; padding: 7px 10px; border: 1px solid var(--line-strong); border-radius: 6px; color: var(--ink); background: #fff; }
.channel-card { border-left: 3px solid var(--line-strong); padding: 12px 14px; background: #f7f9fb; }
.channel-card[data-ingress="true"] { border-left-color: var(--green); }
.channel-card h3 { margin: 0 0 8px; font-size: 15px; }
.channel-card p { margin: 4px 0; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.channel-card strong { color: var(--ink); }

@media (max-width: 1080px) {
  .campaign-frame { grid-template-columns: 180px minmax(0,1fr); }
  .overview-grid, .content-grid, .conversation-layout, .batch-layout { grid-template-columns: 1fr; }
  .batch-detail { grid-column: auto; }
  .conversation-detail { position: static; max-height: none; }
  .toolbar { grid-template-columns: 1fr 1fr; }
  .channel-register-form { grid-template-columns: 1fr; }
  .search-field { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-mark { display: none; }
  .login-card { width: calc(100% - 28px); margin: 14px; padding: 28px 22px; }
  .topbar { height: auto; min-height: 68px; padding: 12px 15px; align-items: flex-start; }
  .topbar-status { justify-content: flex-end; flex-wrap: wrap; }
  .role-chip { display: none; }
  .campaign-frame { display: block; }
  .sidebar { position: sticky; z-index: 5; top: 0; display: block; padding: 0; overflow-x: auto; }
  .sidebar nav { display: flex; width: max-content; min-width: 100%; }
  .sidebar nav button { min-width: 128px; border-left: 0; border-bottom: 3px solid transparent; }
  .sidebar nav button[aria-current="page"] { border-left-color: transparent; border-bottom-color: #62b795; }
  .sidebar-note { display: none; }
  main { padding: 24px 14px 42px; }
  .page-heading { display: block; }
  .page-heading time { display: block; margin-top: 10px; }
  .status-rail { grid-template-columns: 1fr 1fr; }
  .status-rail div:nth-child(2) { border-right: 0; }
  .status-rail div:nth-child(-n+2) { border-bottom: 1px solid rgba(255,255,255,.13); }
  .channel-grid { grid-template-columns: 1fr; }
  .batch-items { grid-template-columns: 1fr; }
}

@media (max-width: 470px) {
  .brand-block div { display: none; }
  .connection-state { max-width: 126px; }
  .status-rail { grid-template-columns: 1fr; }
  .status-rail div { border-right: 0; border-bottom: 1px solid rgba(255,255,255,.13); }
  .status-rail div:last-child { border-bottom: 0; }
  .toolbar { grid-template-columns: 1fr; }
  .search-field { grid-column: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
}
