/* ==========================================================================
   Design tokens
   Every color has a light and a dark value. `color-scheme` picks one:
   the system setting by default, or data-theme="light|dark" on <html>.
   ========================================================================== */

:root {
  color-scheme: light dark;

  --font-sans: "Inter", "Inter Variable", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

  --bg: light-dark(#f6f6f7, #09090b);
  --surface: light-dark(#ffffff, #111113);
  --surface-muted: light-dark(#f4f4f5, #18181b);
  --surface-hover: light-dark(#ececef, #1f1f23);
  --surface-raised: light-dark(#ffffff, #27272a);
  --border: light-dark(#e4e4e7, #232326);
  --border-strong: light-dark(#d4d4d8, #34343a);
  --border-hover: light-dark(#a1a1aa, #52525b);

  --text: light-dark(#18181b, #f4f4f5);
  --text-muted: light-dark(#5f5f6a, #a1a1aa);
  --text-subtle: light-dark(#8b8b96, #71717a);

  --primary: light-dark(#18181b, #fafafa);
  --primary-hover: light-dark(#34343a, #d4d4d8);
  --on-primary: light-dark(#ffffff, #18181b);

  --accent: light-dark(#059669, #34d399);
  --ring: light-dark(rgb(5 150 105 / 0.28), rgb(52 211 153 / 0.32));

  --success: light-dark(#047857, #34d399);
  --success-soft: light-dark(#ecfdf5, rgb(52 211 153 / 0.12));
  --warning: light-dark(#b45309, #fbbf24);
  --warning-soft: light-dark(#fffbeb, rgb(251 191 36 / 0.12));
  --danger: light-dark(#b91c1c, #f87171);
  --danger-soft: light-dark(#fef2f2, rgb(248 113 113 / 0.12));
  --info: light-dark(#1d4ed8, #60a5fa);
  --info-soft: light-dark(#eff6ff, rgb(96 165 250 / 0.1));

  --shadow-sm: 0 1px 2px light-dark(rgb(0 0 0 / 0.05), rgb(0 0 0 / 0.5));
  --shadow-lg: 0 16px 40px -12px light-dark(rgb(0 0 0 / 0.18), rgb(0 0 0 / 0.7));

  --radius-sm: 8px;
  --radius: 10px;
  --radius-lg: 14px;

  --sidebar-width: 244px;
  --bottom-nav-height: 0px;
  --ease: cubic-bezier(0.2, 0, 0, 1);
}

:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

/* ==========================================================================
   Base
   ========================================================================== */

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, p, ol, dl, dd { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

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

::selection { background: var(--ring); }

.sprite { display: none; }

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon--xs { width: 13px; height: 13px; }

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

.link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--accent);
  font-weight: 500;
  text-decoration: none;
}

.link:hover { text-decoration: underline; }

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 100;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: var(--on-primary);
  transform: translateY(-200%);
}

.skip-link:focus { transform: none; }

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease);
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn[aria-busy="true"] { cursor: progress; }

.btn--primary { background: var(--primary); color: var(--on-primary); }
.btn--primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn--secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.btn--secondary:hover:not(:disabled) { background: var(--surface-muted); border-color: var(--border-hover); }

.btn--ghost { background: transparent; color: var(--text-muted); }
.btn--ghost:hover:not(:disabled) { background: var(--surface-hover); color: var(--text); }

.btn--sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn--lg { height: 42px; padding: 0 18px; }
.btn--icon { width: 36px; padding: 0; }
.btn--icon.btn--sm { width: 30px; }

.btn[aria-busy="true"] .icon--spin { animation: spin 0.8s linear infinite; }

/* ==========================================================================
   Form controls
   ========================================================================== */

.input {
  width: 100%;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.input::placeholder { color: var(--text-subtle); }
.input:hover { border-color: var(--border-hover); }

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

.input[readonly] { background: var(--surface-muted); }
.input--mono { font-family: var(--font-mono); font-size: 13px; }

textarea.input {
  min-height: 84px;
  line-height: 1.55;
  resize: vertical;
}

select.input {
  appearance: none;
  padding-right: 36px;
  text-overflow: ellipsis;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b8b96' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
}

.input-group { display: flex; gap: 8px; }
.input-group > .input { flex: 1; min-width: 0; }

.field { display: grid; gap: 6px; }
.field + .field { margin-top: 18px; }

.field__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.field__label { font-size: 13px; font-weight: 500; }

.field__count {
  flex: none;
  font-size: 12px;
  color: var(--text-subtle);
  font-variant-numeric: tabular-nums;
}

.field__hint { font-size: 12.5px; color: var(--text-muted); }
.field__error { font-size: 13px; color: var(--danger); }
.field__error:empty { display: none; }

/* A checkbox with role="switch" drawn as a toggle. */
.switch {
  position: relative;
  flex: none;
  width: 36px;
  height: 20px;
  margin: 0;
  border-radius: 999px;
  background: var(--border-strong);
  appearance: none;
  cursor: pointer;
  transition: background-color 0.2s var(--ease);
}

.switch::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.25);
  transition: transform 0.2s var(--ease);
}

.switch:checked { background: var(--accent); }
.switch:checked::before { transform: translateX(16px); }

.switch-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

/* ==========================================================================
   Small components
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge--success { background: var(--success-soft); color: var(--success); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.badge--danger { background: var(--danger-soft); color: var(--danger); }
.badge--info { background: var(--info-soft); color: var(--info); }

.status-dot {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
}

.status-dot--success { background: var(--success); }
.status-dot--warning { background: var(--warning); }
.status-dot--danger { background: var(--danger); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.card--padded { padding: 20px 22px; }
.card__title { font-size: 15px; font-weight: 600; }
.card__text { margin: 6px 0 16px; color: var(--text-muted); }

.code {
  margin: 8px 0 0;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.empty {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
}

.empty__title {
  margin-bottom: 4px;
  color: var(--text);
  font-weight: 500;
}

.alert {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 20px;
  padding: 12px 16px;
  border: 1px solid color-mix(in srgb, var(--warning) 30%, transparent);
  border-radius: var(--radius);
  background: var(--warning-soft);
  color: var(--warning);
}

.alert p { color: var(--text); }

.callout {
  display: flex;
  gap: 12px;
  padding: 16px 18px;
  border: 1px solid color-mix(in srgb, var(--info) 22%, transparent);
  border-radius: var(--radius-lg);
  background: var(--info-soft);
  color: var(--info);
}

.callout__title { color: var(--text); font-weight: 600; }
.callout p + p { margin-top: 6px; }
.callout p:not(.callout__title) { color: var(--text-muted); }

/* ==========================================================================
   Login
   ========================================================================== */

.login {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px;
}

.login__card {
  display: grid;
  gap: 24px;
  width: min(400px, 100%);
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

.login__title { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.login__text { margin-top: 4px; color: var(--text-muted); }

/* ==========================================================================
   App layout: sidebar + main
   ========================================================================== */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 28px;
  height: 100vh;
  height: 100dvh;
  padding: 20px 14px 16px;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px;
}

.brand__mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: 9px;
  background: var(--primary);
  color: var(--on-primary);
}

.brand__mark .icon { width: 16px; height: 16px; }
.brand__mark--lg { width: 44px; height: 44px; border-radius: 12px; }
.brand__mark--lg .icon { width: 20px; height: 20px; }

.brand__name { font-weight: 600; line-height: 1.25; }

.brand__name small {
  display: block;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
}

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

.nav__link {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 36px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
  text-decoration: none;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}

.nav__link:hover { background: var(--surface-hover); color: var(--text); }
.nav__link[aria-current="page"] { background: var(--surface-muted); color: var(--text); }
.nav__link[aria-current="page"] .icon { color: var(--accent); }

.nav__count {
  display: grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  margin-left: auto;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--warning-soft);
  color: var(--warning);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.sidebar__footer {
  display: grid;
  gap: 10px;
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.account {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 0 6px;
}

.account__avatar {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #f58529, #dd2a7b 55%, #8134af);
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
}

.account__name {
  overflow: hidden;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.theme-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 3px;
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
}

.theme-switch button {
  display: grid;
  place-items: center;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.theme-switch button:hover { color: var(--text); }

.theme-switch button[aria-pressed="true"] {
  background: var(--surface-raised);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.theme-switch .icon { width: 16px; height: 16px; }

.sidebar__logout { justify-content: flex-start; padding: 0 10px; }

.main {
  width: 100%;
  max-width: 1360px;
  min-width: 0;
  margin: 0 auto;
  padding: 32px 40px 56px;
}

.main:focus { outline: none; }

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

.page-header__title { font-size: 26px; font-weight: 600; letter-spacing: -0.025em; line-height: 1.2; }
.page-header__subtitle { max-width: 680px; margin-top: 6px; color: var(--text-muted); }
.page-header__actions { display: flex; flex: none; gap: 8px; }

/* ==========================================================================
   Stats
   ========================================================================== */

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat {
  display: grid;
  gap: 6px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  text-decoration: none;
  transition: border-color 0.15s var(--ease);
}

a.stat:hover { border-color: var(--border-hover); }

.stat__label { font-size: 13px; color: var(--text-muted); }

.stat__value {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat--warning { border-color: color-mix(in srgb, var(--warning) 35%, var(--border)); }
.stat--warning .stat__value { color: var(--warning); }

/* ==========================================================================
   Campaigns
   ========================================================================== */

.campaigns {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.campaign-list {
  position: sticky;
  top: 24px;
  display: grid;
  gap: 8px;
}

.campaign-item {
  display: grid;
  gap: 6px;
  width: 100%;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.campaign-item:hover { border-color: var(--border-hover); }

.campaign-item[aria-current="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.campaign-item__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.campaign-item__name { font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }

.campaign-item__keywords {
  overflow: hidden;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.campaign-item__meta { font-size: 12px; color: var(--text-subtle); }

/* Editor */

.editor {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.editor__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}

.editor__heading { display: flex; align-items: center; gap: 10px; min-width: 0; }

.editor__title {
  overflow: hidden;
  font-size: 16px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor__body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
}

.editor__fields { min-width: 0; padding: 0 22px; }

.editor__preview {
  padding: 20px;
  border-left: 1px solid var(--border);
  background: var(--surface-muted);
}

.editor__footer {
  position: sticky;
  bottom: var(--bottom-nav-height);
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
}

.editor__save-state { margin-left: auto; font-size: 13px; color: var(--text-muted); }
.editor__save-state[data-dirty="true"] { color: var(--warning); }

.section { padding: 22px 0; }
.section + .section { border-top: 1px solid var(--border); }

.section__title { display: block; font-size: 14px; font-weight: 600; }
h3.section__title { margin-bottom: 16px; }

.section__toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  cursor: pointer;
}

.section__desc {
  display: block;
  margin-top: 2px;
  font-size: 13px;
  color: var(--text-muted);
}

.section__body {
  margin-top: 18px;
  padding-left: 16px;
  border-left: 2px solid var(--border);
}

/* Preview: a Direct chat mock-up */

.preview { position: sticky; top: 24px; }

.preview__label {
  margin-bottom: 12px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.chat {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 180px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
}

.chat__step {
  margin: 6px 0 2px;
  color: var(--text-subtle);
  font-size: 11.5px;
  text-align: center;
}

.chat__bubble,
.chat__button,
.chat__comment {
  align-self: flex-start;
  max-width: 92%;
  overflow-wrap: anywhere;
  font-size: 13.5px;
  line-height: 1.45;
}

.chat__bubble {
  padding: 9px 13px;
  border-radius: 18px 18px 18px 6px;
  background: var(--surface-muted);
  white-space: pre-wrap;
}

.chat__button {
  padding: 7px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  color: var(--info);
  font-weight: 500;
}

.chat__comment {
  padding: 2px 0 2px 10px;
  border-left: 2px solid var(--border-strong);
  color: var(--text-muted);
}

.chat :empty::before { content: "…"; color: var(--text-subtle); }

/* ==========================================================================
   Toolbar, segmented control, search
   ========================================================================== */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.toolbar__actions { display: flex; gap: 8px; margin-left: auto; }

.segmented {
  display: inline-flex;
  gap: 2px;
  max-width: 100%;
  padding: 3px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
  scrollbar-width: none;
}

.segmented button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}

.segmented button:hover { color: var(--text); }

.segmented button[aria-pressed="true"] {
  background: var(--surface-raised);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.segmented__count {
  color: var(--text-subtle);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.search { position: relative; flex: 1 1 240px; max-width: 360px; }
.search .input { padding-left: 34px; }

.search .icon {
  position: absolute;
  top: 50%;
  left: 11px;
  width: 16px;
  height: 16px;
  color: var(--text-subtle);
  pointer-events: none;
  translate: 0 -50%;
}

.load-more { width: 100%; margin-top: 12px; }

/* ==========================================================================
   Table
   ========================================================================== */

.table-wrap { overflow-x: auto; border-radius: inherit; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.table th {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
}

.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background-color 0.15s var(--ease); }
.table tbody tr:hover { background: color-mix(in srgb, var(--surface-muted) 60%, transparent); }

.cell-primary { font-weight: 500; }
.cell-secondary { margin-top: 2px; color: var(--text-muted); font-size: 12.5px; }

.cell-code {
  margin-top: 6px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  overflow-wrap: break-word;
}

.table time { white-space: nowrap; }

.row-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

/* ==========================================================================
   Journal
   ========================================================================== */

.timeline { padding: 0; list-style: none; }

.log {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) auto;
  gap: 4px 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.log:last-child { border-bottom: 0; }

.log__dot {
  width: 8px;
  height: 8px;
  margin-top: 7px;
  border-radius: 50%;
  background: var(--border-hover);
}

.log--warn .log__dot { background: var(--warning); }
.log--error .log__dot { background: var(--danger); }

.log__title { font-weight: 500; }

.log__time {
  color: var(--text-subtle);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.log__summary,
.log__details {
  grid-column: 2 / -1;
}

.log__summary { color: var(--text-muted); font-size: 13px; overflow-wrap: anywhere; }
.log--warn .log__summary { color: var(--warning); }
.log--error .log__summary { color: var(--danger); }

.log__details summary,
.result summary {
  width: fit-content;
  color: var(--text-subtle);
  font-size: 12px;
  cursor: pointer;
}

.log__details summary:hover,
.result summary:hover { color: var(--text); }

/* ==========================================================================
   Connection
   ========================================================================== */

.connection { display: grid; gap: 16px; max-width: 860px; }

.facts { margin-top: 8px; }

.facts__row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.facts__row:last-child { border-bottom: 0; padding-bottom: 0; }
.facts dt { color: var(--text-muted); }

.facts dd {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  text-align: right;
}

.button-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.result { margin-top: 16px; }

.steps {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.steps li {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 12px;
  color: var(--text-muted);
  counter-increment: step;
}

.steps li::before {
  content: counter(step);
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-muted);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
}

/* ==========================================================================
   Toasts and dialog
   ========================================================================== */

.toasts {
  position: fixed;
  right: 20px;
  bottom: calc(20px + var(--bottom-nav-height));
  z-index: 60;
  display: grid;
  gap: 8px;
  width: min(380px, calc(100vw - 32px));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 8px 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-raised);
  box-shadow: var(--shadow-lg);
  animation: rise 0.2s var(--ease);
}

.toast__dot {
  width: 8px;
  height: 8px;
  flex: none;
  margin-top: 7px;
  border-radius: 50%;
  background: var(--success);
}

.toast--error .toast__dot { background: var(--danger); }
.toast__text { flex: 1; padding-top: 3px; overflow-wrap: anywhere; }

.dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

.dialog[open] { animation: rise 0.18s var(--ease); }
.dialog::backdrop { background: rgb(0 0 0 / 0.5); }

.dialog__body { padding: 22px 22px 20px; }
.dialog__title { font-size: 16px; font-weight: 600; }
.dialog__text { margin-top: 8px; color: var(--text-muted); }

.dialog__footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  background: var(--surface-muted);
}

@keyframes spin { to { transform: rotate(360deg); } }

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 1280px) {
  .editor__body { grid-template-columns: minmax(0, 1fr); }

  .editor__preview {
    border-top: 1px solid var(--border);
    border-left: 0;
  }
}

@media (max-width: 1024px) {
  .main { padding: 28px 24px 48px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .campaigns { grid-template-columns: minmax(0, 1fr); }

  /* The campaign list turns into a horizontal strip above the editor. */
  .campaign-list {
    position: static;
    display: flex;
    overflow-x: auto;
    padding-bottom: 4px;
    scroll-snap-type: x mandatory;
    scrollbar-width: thin;
  }

  .campaign-item {
    flex: 0 0 260px;
    scroll-snap-align: start;
  }
}

@media (max-width: 760px) {
  :root { --bottom-nav-height: calc(60px + env(safe-area-inset-bottom)); }

  .layout { display: block; }

  /* The sidebar becomes a top bar, and the navigation moves to a bottom tab bar. */
  .sidebar {
    top: 0;
    z-index: 20;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    height: auto;
    padding: 10px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .brand { padding: 0; }
  .brand__name small { display: none; }

  .nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 20;
    grid-template-columns: repeat(4, 1fr);
    height: var(--bottom-nav-height);
    padding: 6px 8px env(safe-area-inset-bottom);
    border-top: 1px solid var(--border);
    background: var(--surface);
  }

  .nav__link {
    position: relative;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    height: 48px;
    padding: 0 4px;
    font-size: 11px;
  }

  .nav__link[aria-current="page"] { background: transparent; }

  .nav__count {
    position: absolute;
    top: 2px;
    left: calc(50% + 6px);
    min-width: 16px;
    height: 16px;
    margin: 0;
    padding: 0 4px;
    font-size: 10px;
  }

  .sidebar__footer {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0 0 0 auto;
    padding: 0;
    border: 0;
  }

  .account__name,
  .sidebar__logout span { display: none; }

  .theme-switch { grid-template-columns: repeat(3, 30px); }
  .sidebar__logout { width: 36px; padding: 0; justify-content: center; }

  .main { padding: 20px 16px calc(32px + var(--bottom-nav-height)); }

  .page-header { align-items: flex-start; margin-bottom: 20px; }
  .page-header__title { font-size: 22px; }
  .page-header__subtitle { font-size: 13px; }

  /* Header buttons become icon-only. */
  #new-campaign { width: 36px; padding: 0; }
  #new-campaign .btn__label { display: none; }

  .stats { gap: 8px; margin-bottom: 20px; }
  .stat { gap: 2px; padding: 10px 12px; }
  .stat__label { font-size: 12px; line-height: 1.35; }
  .stat__value { font-size: 20px; }

  .editor__header,
  .editor__footer { padding-inline: 16px; }

  .editor__fields { padding: 0 16px; }
  .editor__preview { padding: 16px; }
  .editor__footer { flex-wrap: wrap; row-gap: 8px; }
  .editor__save-state { order: 3; width: 100%; margin: 0; }
  .editor__save-state[data-dirty="false"] { display: none; }
  .editor__header { align-items: flex-start; }
  .editor__heading { flex-wrap: wrap; }
  .editor__title { white-space: normal; }
  .editor__footer .btn--primary { margin-left: auto; }

  .input-group { flex-wrap: wrap; }
  .input-group > .btn { flex: 1; }

  .search { max-width: none; }
  .toolbar__actions { width: 100%; margin: 0; }
  .toolbar__actions .btn { flex: 1; }

  /* Table rows become cards. */
  .table thead { display: none; }

  .table,
  .table tbody,
  .table tr,
  .table td { display: block; }

  .table tr {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
  }

  .table tbody tr:last-child { border-bottom: 0; }

  .table td {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 4px 12px;
    padding: 4px 0;
    border: 0;
  }

  .table td:first-child { display: block; padding-bottom: 8px; }

  .table td[data-label]::before {
    content: attr(data-label);
    color: var(--text-muted);
    font-size: 12.5px;
  }

  .table td .cell-code { width: 100%; margin-top: 0; text-align: right; }
  .row-actions { justify-content: flex-start; padding-top: 8px; }

  .log { grid-template-columns: 8px minmax(0, 1fr); padding: 12px 14px; }
  .log__time { grid-column: 2; }

  .facts dd { text-align: right; }
}
