/* OpenOutbound dashboard. No external fonts or assets; light and dark themes. */
:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --text: #16191d;
  --muted: #5d6673;
  --border: #dde1e6;
  --accent: #2357d6;
  --accent-text: #ffffff;
  --ok: #17803d;
  --warn: #a86400;
  --bad: #c02b2b;
  --info: #2a6fb0;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 6%);
  --radius: 8px;
  --nav-width: 220px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0f1216;
  --panel: #171b21;
  --panel-2: #1e232a;
  --text: #e7eaee;
  --muted: #9aa4b1;
  --border: #2b313a;
  --accent: #6d97ff;
  --accent-text: #0b0e12;
  --ok: #4cc27a;
  --warn: #e6a23c;
  --bad: #ff6b6b;
  --info: #6fb3ff;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 4px 16px rgb(0 0 0 / 30%);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216;
    --panel: #171b21;
    --panel-2: #1e232a;
    --text: #e7eaee;
    --muted: #9aa4b1;
    --border: #2b313a;
    --accent: #6d97ff;
    --accent-text: #0b0e12;
    --ok: #4cc27a;
    --warn: #e6a23c;
    --bad: #ff6b6b;
    --info: #6fb3ff;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 4px 16px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font:
    14px / 1.45 system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    sans-serif;
}

a {
  color: var(--accent);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--panel);
  padding: 8px;
  z-index: 100;
}

.skip-link:focus {
  left: 8px;
}

/* Layout */
.shell {
  display: grid;
  grid-template-columns: var(--nav-width) 1fr;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  font-weight: 700;
  white-space: nowrap;
}

.command-bar-wrap {
  flex: 1;
  min-width: 0;
}

.command-bar {
  flex: 1;
  display: flex;
  gap: 8px;
  min-width: 0;
}

.sidenav {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 12px 8px;
}

.sidenav ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidenav a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
}

.sidenav a:hover {
  background: var(--panel-2);
}

.sidenav a[aria-current="page"] {
  background: var(--accent);
  color: var(--accent-text);
}

.nav-toggle {
  display: none;
}

main {
  padding: 20px 24px 48px;
  min-width: 0;
}

@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
  }
  .sidenav {
    display: none;
    position: fixed;
    top: 52px;
    left: 0;
    bottom: 0;
    width: 240px;
    z-index: 30;
    box-shadow: var(--shadow);
  }
  .sidenav.open {
    display: block;
  }
  .nav-toggle {
    display: inline-flex;
  }
  .brand-name {
    display: none;
  }
  main {
    padding: 14px 12px 40px;
  }
}

/* Components */
h1 {
  font-size: 22px;
  margin: 0 0 4px;
}

h2 {
  font-size: 17px;
  margin: 0 0 10px;
}

h3 {
  font-size: 15px;
  margin: 14px 0 8px;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 16px;
}

.subtitle {
  color: var(--muted);
  margin: 0;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.grid.two {
  grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
}

@media (max-width: 600px) {
  .grid.two {
    grid-template-columns: 1fr;
  }
}

.kpis {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  margin-bottom: 16px;
}

.kpi {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.kpi .label {
  color: var(--muted);
  font-size: 12px;
}

.kpi .value {
  font-size: 22px;
  font-weight: 700;
}

.kpi .note {
  font-size: 12px;
  color: var(--muted);
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.row.end {
  justify-content: flex-end;
}

.row.between {
  justify-content: space-between;
}

.stack > * + * {
  margin-top: 10px;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.pre {
  white-space: pre-wrap;
  word-break: break-word;
}

button,
.button {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

button:hover {
  filter: brightness(0.97);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

button.danger {
  background: var(--bad);
  border-color: var(--bad);
  color: #fff;
}

button.ghost {
  background: transparent;
}

input,
select,
textarea {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  max-width: 100%;
}

textarea {
  width: 100%;
  min-height: 80px;
  resize: vertical;
}

label.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

label.field > .field-label {
  font-size: 12px;
  color: var(--muted);
}

label.check {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin: 0 0 12px;
}

legend {
  padding: 0 4px;
  font-weight: 600;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 7px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

tr.clickable {
  cursor: pointer;
}

tr.clickable:hover {
  background: var(--panel-2);
}

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.badge.ok {
  color: var(--ok);
  border-color: var(--ok);
}

.badge.warn {
  color: var(--warn);
  border-color: var(--warn);
}

.badge.bad {
  color: var(--bad);
  border-color: var(--bad);
}

.badge.info {
  color: var(--info);
  border-color: var(--info);
}

.count {
  background: var(--bad);
  color: #fff;
  border-radius: 999px;
  font-size: 11px;
  padding: 0 7px;
}

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.tabs button {
  border: none;
  background: transparent;
  border-bottom: 2px solid transparent;
  border-radius: 0;
}

.tabs button[aria-selected="true"] {
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.empty,
.notice {
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.notice.not-installed {
  text-align: left;
  border-style: solid;
  border-color: var(--warn);
}

.error-box {
  border: 1px solid var(--bad);
  color: var(--bad);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin: 8px 0;
}

.bar {
  height: 10px;
  background: var(--panel-2);
  border-radius: 999px;
  overflow: hidden;
}

.funnel-row {
  display: grid;
  grid-template-columns: 140px 1fr 70px;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}

.kanban {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(230px, 1fr);
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.kanban .column {
  background: var(--panel-2);
  border-radius: var(--radius);
  padding: 10px;
  min-height: 120px;
}

.kanban .item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  margin-top: 8px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  display: block;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  max-width: 85%;
}

.message.inbound {
  align-self: flex-start;
  background: var(--panel-2);
}

.message.outbound {
  align-self: flex-end;
}

.untrusted-note {
  font-size: 11px;
  color: var(--warn);
}

.split {
  display: grid;
  grid-template-columns: minmax(260px, 360px) 1fr;
  gap: 16px;
}

@media (max-width: 900px) {
  .split {
    grid-template-columns: 1fr;
  }
}

.list-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  padding: 10px 8px;
}

.list-item[aria-current="true"] {
  background: var(--panel-2);
}

dl.kv {
  display: grid;
  grid-template-columns: minmax(110px, max-content) 1fr;
  gap: 4px 12px;
  margin: 0;
}

dl.kv dt {
  color: var(--muted);
}

dl.kv dd {
  margin: 0;
  word-break: break-word;
}

/* Drawer and dialog */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  padding: 0;
  max-width: min(720px, 96vw);
  width: 100%;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgb(0 0 0 / 45%);
}

dialog.drawer {
  margin: 0 0 0 auto;
  height: 100vh;
  max-height: 100vh;
  max-width: min(760px, 100vw);
  border-radius: 0;
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 1;
}

.dialog-body {
  padding: 16px;
}

.dialog-foot {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}

.toast {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--info);
  padding: 10px 14px;
  border-radius: 6px;
  box-shadow: var(--shadow);
  max-width: 420px;
}

.toast.ok {
  border-left-color: var(--ok);
}

.toast.bad {
  border-left-color: var(--bad);
}

.toast.warn {
  border-left-color: var(--warn);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  background: var(--muted);
}

.status-dot.ok {
  background: var(--ok);
}

.status-dot.warn {
  background: var(--warn);
}

.status-dot.bad {
  background: var(--bad);
}

.markdown h1,
.markdown h2,
.markdown h3 {
  margin-top: 12px;
}

.markdown code {
  background: var(--panel-2);
  padding: 0 4px;
  border-radius: 4px;
}

/* Login */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 380px;
}

.login-card input {
  width: 100%;
}

.command-bar input {
  flex: 1;
  min-width: 0;
}

.bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.bar.over > span {
  background: var(--bad);
}
