:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  color: #17253a;
  background: #f3f6fa;
  font-synthesis: none;
  --navy: #073765;
  --navy-deep: #052a4f;
  --blue: #0969c3;
  --blue-electric: #1697e8;
  --blue-soft: #e9f3fc;
  --green: #17815d;
  --green-soft: #e8f6f0;
  --amber: #b86909;
  --amber-soft: #fff5e7;
  --red: #b83a42;
  --red-soft: #fceced;
  --text: #17253a;
  --muted: #657386;
  --line: #dce3eb;
  --surface: #ffffff;
  --page: #f3f6fa;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--page);
  color: var(--text);
  letter-spacing: 0;
}

button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { letter-spacing: 0; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 28px 18px 20px;
  color: #dcecff;
  background: var(--navy-deep);
  border-right: 1px solid #0c467d;
}

.brand {
  display: flex;
  align-items: flex-start;
  flex-direction: column;
  gap: 8px;
  padding: 0 10px 32px;
}

.brand-logo {
  width: 104px;
  height: 42px;
  object-fit: contain;
  object-position: left center;
  filter: brightness(0) invert(1);
}

.brand-product { color: #9fc4e8; font-size: 12px; font-weight: 700; }

.nav { display: grid; gap: 7px; }

.nav-item {
  width: 100%;
  min-height: 46px;
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: #aec9e4;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.nav-item:hover { color: #fff; background: #0b4276; }
.nav-item.is-active { color: #fff; background: #0c4e89; border-color: #17649f; }
.nav-icon { width: 24px; color: #7fb8e9; font-weight: 700; text-align: center; }
.nav-count { min-width: 24px; padding: 2px 6px; border-radius: 999px; background: #164f7d; color: #d9ebfb; font-size: 11px; text-align: center; }
.nav-item.is-active .nav-count { background: #fff; color: var(--navy); }

.sidebar-foot {
  margin-top: auto;
  padding: 18px 10px 0;
  border-top: 1px solid #17476f;
  color: #8fb4d6;
  font-size: 12px;
}
.sidebar-foot p { margin: 10px 0 0; }
.sidebar-foot strong { color: #dcecff; }
.environment { display: flex; align-items: center; gap: 8px; }
.environment > span { width: 8px; height: 8px; border-radius: 50%; background: #39c88a; box-shadow: 0 0 0 4px rgba(57, 200, 138, .14); }

.main-content { min-width: 0; }

.topbar {
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 30px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar h1 { margin: 2px 0 0; font-size: 23px; line-height: 1.2; }
.eyebrow { margin: 0; color: var(--blue); font-size: 11px; font-weight: 800; }
.user-menu { display: flex; align-items: center; gap: 13px; }
.user-copy { text-align: right; }
.user-copy strong { display: block; font-size: 13px; }
.user-copy span { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }

.icon-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--navy);
  cursor: pointer;
  font-size: 18px;
}
.icon-button:hover { border-color: #8db8dc; background: var(--blue-soft); }

.view { display: none; padding: 26px 30px 40px; }
.view.is-active { display: block; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}
.segmented button {
  min-height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
}
.segmented button:hover { color: var(--blue); }
.segmented button.is-active { background: var(--navy); color: #fff; }

.button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 15px;
  border-radius: 7px;
  border: 1px solid transparent;
  font-weight: 700;
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
}
.button:disabled { opacity: .55; cursor: wait; }
.button-primary { background: var(--blue); color: #fff; }
.button-primary:hover { background: #0759a6; }
.button-secondary { border-color: var(--line); background: #fff; color: var(--navy); }
.button-secondary:hover { border-color: #8db8dc; background: var(--blue-soft); }
.button-danger { background: var(--red); color: #fff; }
.button-wide { width: 100%; min-height: 46px; }

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.metric {
  min-height: 118px;
  padding: 18px 19px;
  border-radius: 8px;
  border: 1px solid var(--line);
  border-top-width: 3px;
  background: #fff;
}
.metric span { display: block; color: var(--muted); font-size: 12px; font-weight: 700; }
.metric strong { display: block; margin: 8px 0 4px; font-size: 29px; line-height: 1; }
.metric small { color: var(--muted); font-size: 12px; }
.metric-blue { border-top-color: var(--blue); }
.metric-blue strong { color: var(--blue); }
.metric-green { border-top-color: var(--green); }
.metric-green strong { color: var(--green); }
.metric-red { border-top-color: var(--red); }
.metric-red strong { color: var(--red); }
.metric-amber { border-top-color: var(--amber); }
.metric-amber strong { color: var(--amber); }

.overview-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(280px, .75fr); gap: 18px; margin-bottom: 18px; }
.section-block { border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 17px 19px; border-bottom: 1px solid var(--line); }
.section-heading h2 { margin: 0; font-size: 16px; }
.section-heading p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.section-heading-row { align-items: center; }
.legend { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.legend-sent, .legend-failed { width: 8px; height: 8px; display: inline-block; border-radius: 2px; }
.legend-sent { background: var(--blue); }
.legend-failed { margin-left: 5px; background: var(--red); }

.daily-chart {
  min-height: 222px;
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 22px 20px 16px;
  overflow-x: auto;
  background-image: linear-gradient(to bottom, transparent 24%, #edf1f5 25%, transparent 26%, transparent 49%, #edf1f5 50%, transparent 51%, transparent 74%, #edf1f5 75%, transparent 76%);
}
.chart-day { min-width: 38px; flex: 1; display: grid; grid-template-rows: 1fr 24px; gap: 7px; }
.chart-bars { min-height: 150px; display: flex; align-items: flex-end; justify-content: center; gap: 4px; }
.chart-bar { width: min(16px, 42%); min-height: 2px; border-radius: 3px 3px 0 0; }
.chart-bar.sent { background: var(--blue); }
.chart-bar.failed { background: var(--red); }
.chart-label { align-self: center; color: var(--muted); font-size: 10px; text-align: center; white-space: nowrap; }
.chart-empty { margin: auto; color: var(--muted); font-size: 13px; }

.status-summary { display: grid; grid-template-columns: repeat(3, 1fr); min-height: 222px; }
.status-summary > div { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; border-right: 1px solid var(--line); }
.status-summary > div:last-child { border-right: 0; }
.status-summary strong { font-size: 25px; }
.status-summary small { color: var(--muted); font-size: 10px; text-align: center; }
.dot { width: 9px; height: 9px; border-radius: 50%; }
.dot-connected { background: var(--green); }
.dot-waiting { background: var(--amber); }
.dot-disconnected { background: var(--red); }

.search-field input {
  width: min(290px, 36vw);
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  outline: none;
  color: var(--text);
  background: #fff;
}
.search-field input:focus, .field-label input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(9, 105, 195, .12); }

.table-scroll { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { height: 42px; padding: 0 12px; color: #526174; background: #f7f9fb; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; font-size: 11px; }
td { padding: 12px; border-bottom: 1px solid #e8edf2; vertical-align: middle; }
tbody tr:hover { background: #f6faff; }
tbody tr:last-child td { border-bottom: 0; }
.number { text-align: right; font-variant-numeric: tabular-nums; }
.adviser-name { display: grid; gap: 2px; min-width: 210px; }
.adviser-name strong { font-size: 12px; }
.adviser-name span { color: var(--muted); font-size: 10px; }
.port-cell { display: grid; gap: 2px; }
.port-cell strong { font-variant-numeric: tabular-nums; }
.port-cell span { color: var(--muted); font-size: 10px; }
.status-badge { display: inline-flex; align-items: center; gap: 6px; min-height: 25px; padding: 0 8px; border-radius: 999px; font-size: 10px; font-weight: 700; white-space: nowrap; }
.status-connected { color: #116b4e; background: var(--green-soft); }
.status-waiting, .status-initializing { color: #92530a; background: var(--amber-soft); }
.status-disconnected, .status-error { color: #9d3037; background: var(--red-soft); }
.process-down { display: block; margin-top: 3px; color: var(--red); font-size: 9px; }
.row-action { min-height: 31px; padding: 0 10px; }
.empty-state { padding: 36px; color: var(--muted); text-align: center; }
.error-detail { max-width: 560px; min-width: 270px; line-height: 1.45; word-break: break-word; }

.notice { margin: 18px 30px 0; padding: 11px 13px; border: 1px solid #9cc5e8; border-radius: 7px; color: #135584; background: var(--blue-soft); font-size: 13px; }
.notice-error { border-color: #e8b5b8; color: #962e35; background: var(--red-soft); }
.notice-success { border-color: #9bd2bd; color: #106348; background: var(--green-soft); }

.docs-layout { display: grid; grid-template-columns: 220px minmax(0, 820px); gap: 24px; align-items: start; }
.docs-nav { position: sticky; top: 24px; display: grid; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.docs-nav a { padding: 10px 11px; border-radius: 5px; color: var(--muted); text-decoration: none; font-size: 12px; }
.docs-nav a:hover { color: var(--blue); background: var(--blue-soft); }
.docs-content { overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.docs-content section { padding: 24px; border-bottom: 1px solid var(--line); scroll-margin-top: 20px; }
.docs-content section:last-child { border-bottom: 0; }
.docs-content h2 { margin: 5px 0 10px; font-size: 24px; }
.docs-content h3 { margin: 0 0 10px; font-size: 17px; }
.docs-content h4 { margin: 18px 0 8px; font-size: 13px; }
.docs-content p { color: var(--muted); line-height: 1.65; font-size: 13px; }
.docs-content code { font-family: "SFMono-Regular", Consolas, monospace; }
pre { margin: 14px 0 0; padding: 16px; overflow: auto; border-radius: 7px; color: #e8f3ff; background: #082d53; font-size: 11px; line-height: 1.65; }
.endpoint-title { display: flex; align-items: center; gap: 10px; }
.endpoint-title code { color: var(--navy); font-size: 14px; font-weight: 700; }
.method { min-width: 48px; padding: 5px 8px; border-radius: 5px; color: #fff; font-size: 10px; font-weight: 800; text-align: center; }
.method-get { background: var(--blue); }
.method-post { background: var(--green); }
.endpoint-base { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; margin-top: 17px; padding: 11px 12px; border: 1px solid #b8d6ef; border-radius: 7px; background: var(--blue-soft); }
.endpoint-base span { color: var(--muted); font-size: 11px; font-weight: 700; }
.endpoint-base code { overflow: auto; color: var(--navy); font-size: 12px; white-space: nowrap; }
.copy-button { border: 0; background: transparent; color: var(--blue); font-size: 11px; font-weight: 800; cursor: pointer; }
.warning-box { margin-top: 14px; padding: 11px 13px; border-left: 3px solid var(--amber); color: #7d4a0d; background: var(--amber-soft); font-size: 12px; line-height: 1.5; }
.response-list { display: grid; margin: 15px 0 0; }
.response-list > div { display: grid; grid-template-columns: 52px 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.response-list > div:last-child { border-bottom: 0; }
.response-list dt { color: var(--blue); font-weight: 800; }
.response-list dd { margin: 0; color: var(--muted); font-size: 13px; }

.admin-only { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.keys-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.keys-heading h4 { margin: 0; }
.keys-heading p { margin: 3px 0 0; }
.keys-list { display: grid; margin-top: 12px; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.key-row { display: grid; grid-template-columns: minmax(160px, 1fr) 150px 145px auto; align-items: center; gap: 12px; padding: 11px 12px; border-bottom: 1px solid var(--line); font-size: 11px; }
.key-row:last-child { border-bottom: 0; }
.key-row span { color: var(--muted); }
.key-row button { border: 0; color: var(--red); background: transparent; cursor: pointer; font-weight: 700; }
.secret-box { margin-top: 12px; padding: 12px; border: 1px solid #94cbb6; border-radius: 7px; color: #105e46; background: var(--green-soft); font-size: 12px; word-break: break-all; }

.modal { width: min(520px, calc(100vw - 30px)); padding: 0; border: 0; border-radius: 8px; color: var(--text); background: transparent; box-shadow: 0 30px 80px rgba(5, 32, 59, .3); }
.modal::backdrop { background: rgba(5, 32, 59, .55); }
.modal-small { width: min(440px, calc(100vw - 30px)); }
.modal-shell { display: grid; gap: 18px; margin: 0; padding: 21px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.modal-header h2 { margin: 4px 0 0; font-size: 19px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; }
.qr-content { min-height: 310px; display: grid; place-items: center; padding: 16px; border: 1px solid var(--line); border-radius: 7px; background: #f8fafc; text-align: center; }
.qr-content img { width: min(290px, 75vw); height: min(290px, 75vw); object-fit: contain; image-rendering: pixelated; }
.qr-message { color: var(--muted); line-height: 1.55; }
.qr-message strong { display: block; margin-bottom: 5px; color: var(--text); }
.field-label { display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
.field-label input { height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 7px; outline: none; }
.field-label select { min-width: 220px; height: 42px; padding: 0 34px 0 12px; border: 1px solid var(--line); border-radius: 7px; color: var(--text); background: #fff; }

.nav-admin { margin: 0; padding: 0 13px; border-top: 1px solid transparent; }
.conversation-toolbar, .summary-toolbar { display: flex; align-items: end; gap: 12px; margin-bottom: 18px; padding: 16px; }
.field-grow { flex: 1; }
.field-grow input { width: 100%; }
.conversation-layout { min-height: calc(100vh - 180px); display: grid; grid-template-columns: minmax(310px, .82fr) minmax(440px, 1.6fr); gap: 18px; }
.conversation-list-block, .conversation-thread-block { min-height: 650px; overflow: hidden; }
.conversation-list { max-height: calc(100vh - 290px); overflow-y: auto; }
.conversation-row { width: 100%; display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 13px 14px; border: 0; border-bottom: 1px solid var(--line); color: var(--text); background: #fff; text-align: left; cursor: pointer; }
.conversation-row:hover, .conversation-row.is-active { background: var(--blue-soft); }
.conversation-row.is-active { box-shadow: inset 3px 0 var(--blue); }
.conversation-avatar { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; color: #fff; background: var(--navy); font-weight: 800; }
.conversation-copy { min-width: 0; display: grid; gap: 2px; }
.conversation-copy strong, .conversation-copy small, .conversation-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-copy small, .conversation-copy span, .conversation-row time { color: var(--muted); font-size: 10px; }
.conversation-row time { align-self: start; white-space: nowrap; }
.conversation-thread-block { display: grid; grid-template-rows: auto 1fr auto; }
.thread-messages { min-height: 460px; max-height: calc(100vh - 360px); display: flex; flex-direction: column; gap: 9px; overflow-y: auto; padding: 20px; background: #eef4f8; }
.message-bubble { max-width: min(78%, 720px); padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: 0 2px 5px rgba(5,42,79,.05); }
.message-out { align-self: flex-end; border-color: #abd4c3; background: var(--green-soft); }
.message-in { align-self: flex-start; }
.message-bubble p { margin: 0; line-height: 1.45; white-space: normal; word-break: break-word; }
.message-bubble a { display: block; margin-bottom: 6px; color: var(--blue); font-size: 11px; }
.message-bubble time { display: block; margin-top: 6px; color: var(--muted); font-size: 9px; text-align: right; }
.conversation-composer { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding: 13px; border-top: 1px solid var(--line); }
.conversation-composer textarea { min-height: 66px; max-height: 170px; padding: 10px 12px; resize: vertical; border: 1px solid var(--line); border-radius: 7px; color: var(--text); outline: none; }
.summary-copy { min-width: 300px; max-width: 620px; line-height: 1.45; }
.summary-copy small, .table-subline { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; font-weight: 400; }

.login-page { display: grid; place-items: center; padding: 30px; background: #eaf1f8; }
.login-shell { width: min(900px, 100%); min-height: 520px; display: grid; grid-template-columns: 1.1fr .9fr; overflow: hidden; border: 1px solid #cbd8e5; border-radius: 10px; background: #fff; box-shadow: 0 24px 70px rgba(5, 42, 79, .16); }
.login-copy { display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-end; padding: 44px; color: #fff; background: var(--navy-deep); }
.login-copy .brand-logo { width: 150px; height: 64px; margin-bottom: auto; }
.login-copy h1 { max-width: 420px; margin: 8px 0 12px; font-size: 38px; line-height: 1.08; }
.login-copy p:not(.eyebrow) { max-width: 420px; margin: 0; color: #b7d1e8; line-height: 1.6; }
.login-copy .eyebrow { color: #71c4f4; }
.login-panel { display: flex; flex-direction: column; justify-content: center; gap: 24px; padding: 46px; }
.login-panel h2 { margin: 5px 0 0; font-size: 27px; }
.login-panel .muted { margin: 7px 0 0; color: var(--muted); font-size: 13px; }
.login-domain { margin: -7px 0 0; color: var(--muted); text-align: center; font-size: 11px; }

.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; }

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 210px minmax(0, 1fr); }
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .overview-grid { grid-template-columns: 1fr; }
  .status-summary { min-height: 150px; }
  .docs-layout { grid-template-columns: 180px minmax(0, 1fr); }
  .conversation-layout { grid-template-columns: 330px minmax(0, 1fr); }
  .summary-toolbar { flex-wrap: wrap; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 14px; }
  .brand { padding: 0 4px 13px; }
  .nav { grid-template-columns: repeat(3, 1fr); }
  .nav-item { min-width: 0; grid-template-columns: 20px 1fr; padding: 0 8px; }
  .nav-count { display: none; }
  .sidebar-foot { display: none; }
  .topbar { min-height: 72px; padding: 13px 16px; }
  .topbar h1 { font-size: 19px; }
  .user-copy { display: none; }
  .view { padding: 18px 14px 30px; }
  .notice { margin: 14px 14px 0; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .segmented { display: grid; grid-template-columns: repeat(4, 1fr); }
  .segmented button { padding: 0 7px; font-size: 11px; }
  .metrics-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .metric { min-height: 105px; padding: 15px; }
  .metric strong { font-size: 24px; }
  .section-heading-row { align-items: stretch; flex-direction: column; }
  .search-field input { width: 100%; }
  .docs-layout { grid-template-columns: 1fr; }
  .docs-nav { position: static; grid-template-columns: repeat(2, 1fr); }
  .endpoint-base { grid-template-columns: 1fr auto; }
  .endpoint-base span { grid-column: 1 / -1; }
  .key-row { grid-template-columns: 1fr auto; }
  .key-row span:nth-of-type(2) { display: none; }
  .login-page { padding: 15px; }
  .login-shell { min-height: 0; grid-template-columns: 1fr; }
  .login-copy { min-height: 270px; padding: 28px; }
  .login-copy h1 { font-size: 30px; }
  .login-panel { padding: 28px; }
  .conversation-toolbar, .summary-toolbar { align-items: stretch; flex-direction: column; }
  .field-label select { width: 100%; }
  .conversation-layout { min-height: 0; grid-template-columns: 1fr; }
  .conversation-list-block, .conversation-thread-block { min-height: 500px; }
  .conversation-list, .thread-messages { max-height: 500px; }
}

@media (max-width: 480px) {
  .metrics-grid { grid-template-columns: 1fr; }
  .nav-item { grid-template-columns: 1fr; text-align: center; }
  .nav-icon { display: none; }
  .status-summary { grid-template-columns: 1fr; }
  .status-summary > div { min-height: 94px; border-right: 0; border-bottom: 1px solid var(--line); }
  .status-summary > div:last-child { border-bottom: 0; }
  .modal-actions { align-items: stretch; flex-direction: column; }
}
