/* ============================================================
   Hermes Control — Modern Dark Dashboard
   Mobile First, CSS Custom Properties, Light/Dark themes
   ============================================================ */

:root {
  --bg-primary: #0b1120;
  --bg-card: #111b2d;
  --bg-elevated: #17243a;
  --border-color: #263247;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --accent-primary: #3b82f6;
  --accent-contrast: #ffffff;
  --accent-soft: rgba(59, 130, 246, 0.14);
  --status-success: #22c55e;
  --status-warning: #f59e0b;
  --status-danger: #ef4444;

  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 9px;
  --shadow-card: 0 1px 0 rgba(255, 255, 255, 0.02) inset, 0 10px 30px rgba(0, 0, 0, 0.18);
  --shadow-pop: 0 24px 60px rgba(0, 0, 0, 0.45);

  --nav-height: 62px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  color-scheme: dark;
}

[data-theme="light"] {
  --bg-primary: #f4f6fb;
  --bg-card: #ffffff;
  --bg-elevated: #edf1f8;
  --border-color: #e2e8f0;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --accent-primary: #2563eb;
  --accent-contrast: #ffffff;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --status-success: #16a34a;
  --status-warning: #d97706;
  --status-danger: #dc2626;
  --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.04), 0 10px 24px rgba(15, 23, 42, 0.05);
  --shadow-pop: 0 24px 60px rgba(15, 23, 42, 0.18);

  color-scheme: light;
}

/* ---------- Reset ---------- */

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

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, p {
  margin: 0;
}

button, a {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
}

a {
  color: inherit;
}

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

::selection {
  background: color-mix(in srgb, var(--accent-primary) 32%, transparent);
  color: var(--text-primary);
}

.svg-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

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

.icon--logo {
  width: 26px;
  height: 26px;
  stroke-width: 1.9;
}

.icon--chevron {
  width: 16px;
  height: 16px;
  opacity: 0.45;
}

.muted {
  color: var(--text-secondary);
  font-size: 12px;
  white-space: nowrap;
}

/* ---------- App shell ---------- */

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

.app-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100dvh;
}

.sidebar {
  display: none;
}

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 56px;
  padding: calc(9px + var(--safe-top)) calc(16px + var(--safe-right)) 9px calc(16px + var(--safe-left));
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
}

.topbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  text-decoration: none;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 10px;
  color: var(--accent-primary);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent-primary) 24%, transparent);
}

.topbar-title {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-crumb {
  display: none;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  min-width: 0;
}

.topbar-crumb span:last-child {
  color: var(--text-primary);
  font-weight: 600;
}

.crumb-sep {
  opacity: 0.5;
}

.topbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

.conn-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 11px;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  transition: border-color 160ms ease, color 160ms ease, background 160ms ease;
}

.conn-pill[data-state="ok"] {
  color: var(--status-success);
  border-color: color-mix(in srgb, var(--status-success) 35%, transparent);
  background: color-mix(in srgb, var(--status-success) 10%, var(--bg-card));
}

.conn-pill[data-state="error"] {
  color: var(--status-danger);
  border-color: color-mix(in srgb, var(--status-danger) 35%, transparent);
  background: color-mix(in srgb, var(--status-danger) 10%, var(--bg-card));
}

.conn-pill[data-state="restricted"] {
  color: var(--status-warning);
  border-color: color-mix(in srgb, var(--status-warning) 35%, transparent);
  background: color-mix(in srgb, var(--status-warning) 10%, var(--bg-card));
}

.conn-pill[data-state="loading"] .dot {
  animation: pulse 1.4s ease-in-out infinite;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex: none;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 11px;
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  transition: transform 140ms ease, color 160ms ease, border-color 160ms ease, background 160ms ease;
}

.icon-btn:hover {
  color: var(--text-primary);
  border-color: color-mix(in srgb, var(--accent-primary) 32%, var(--border-color));
}

.icon-btn:active {
  transform: scale(0.96);
}

.icon-btn.is-loading {
  pointer-events: none;
  color: var(--accent-primary);
}

.icon-btn.is-loading .icon {
  animation: spin 0.8s linear infinite;
}

/* ---------- Content ---------- */

.content {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px calc(16px + var(--safe-right)) calc(var(--nav-height) + var(--safe-bottom) + 26px) calc(16px + var(--safe-left));
  min-width: 0;
}

.content:focus {
  outline: none;
}

.view:not([hidden]) {
  animation: viewIn 220ms ease both;
}

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

.eyebrow {
  margin-bottom: 3px;
  color: var(--accent-primary);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.page-head h1 {
  font-size: 26px;
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.025em;
}

.page-sub {
  margin-top: 4px;
  color: var(--text-secondary);
  font-size: 13px;
  max-width: 52ch;
}

/* ---------- Cards ---------- */

.card {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  box-shadow: var(--shadow-card);
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.metrics-grid--3 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.metrics-grid--3 > :last-child {
  grid-column: 1 / -1;
}

.metric-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 146px;
  transition: transform 170ms ease, border-color 170ms ease, background 170ms ease;
}

.metric-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.icon-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 9px;
  color: var(--accent-primary);
  background: var(--accent-soft);
}

.icon-chip .icon {
  width: 18px;
  height: 18px;
}

.metric-name {
  min-width: 0;
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  overflow-wrap: normal;
  word-break: normal;
}

.metric-state {
  flex-basis: 100%;
  font-size: 10.5px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.metric-value {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 5px;
  row-gap: 2px;
  margin-top: auto;
  font-variant-numeric: tabular-nums;
}

.metric-value .value {
  font-size: 30px;
  line-height: 1;
  font-weight: 650;
  letter-spacing: -0.03em;
}

.metric-value .unit {
  font-size: 13px;
  color: var(--text-secondary);
}

.progress {
  position: relative;
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid color-mix(in srgb, var(--border-color) 55%, transparent);
}

.progress-fill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent-primary);
  transition: width 320ms ease;
}

.metric-note {
  font-size: 11.5px;
  color: var(--text-secondary);
}

.metric-card--status {
  justify-content: flex-start;
}

.metric-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  font-size: 13px;
  font-weight: 550;
}

/* ---------- Dots & chips ---------- */

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--text-secondary);
}

.dot--muted { background: var(--text-secondary); opacity: 0.7; }
.dot--success { background: var(--status-success); }
.dot--warn { background: var(--status-warning); }
.dot--danger { background: var(--status-danger); }

.dot--success,
.dot--warn,
.dot--danger {
  box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 0%, transparent);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 9px;
  flex: none;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.chip .dot {
  width: 6px;
  height: 6px;
}

.chip--warn {
  color: var(--status-warning);
  border-color: color-mix(in srgb, var(--status-warning) 32%, transparent);
  background: color-mix(in srgb, var(--status-warning) 11%, transparent);
}
.chip--warn .dot { background: var(--status-warning); }

.chip--danger {
  color: var(--status-danger);
  border-color: color-mix(in srgb, var(--status-danger) 32%, transparent);
  background: color-mix(in srgb, var(--status-danger) 10%, transparent);
}
.chip--danger .dot { background: var(--status-danger); }

.chip--success {
  color: var(--status-success);
  border-color: color-mix(in srgb, var(--status-success) 32%, transparent);
  background: color-mix(in srgb, var(--status-success) 10%, transparent);
}
.chip--success .dot { background: var(--status-success); }

.chip--muted {
  color: var(--text-secondary);
  border-color: var(--border-color);
  background: var(--bg-elevated);
}
.chip--muted .dot { background: var(--text-secondary); opacity: 0.7; }

/* ---------- Sections & lists ---------- */

.section {
  margin-top: 22px;
  min-width: 0;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
  min-width: 0;
}

.section-head h2 {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.015em;
  min-width: 0;
  overflow-wrap: anywhere;
}

.list-card {
  padding: 0;
  overflow: hidden;
}

.service-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto 18px;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 62px;
  padding: 11px 14px;
  border: 0;
  border-top: 1px solid var(--border-color);
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 150ms ease;
}

.service-row:first-child {
  border-top: 0;
}

.service-row:hover {
  background: color-mix(in srgb, var(--bg-elevated) 60%, transparent);
}

.service-row:active {
  background: var(--bg-elevated);
}

.service-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.service-name {
  font-size: 14px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.service-sub {
  font-size: 11.5px;
  color: var(--text-secondary);
  overflow-wrap: anywhere;
}

/* ---------- Network ---------- */

.network-card {
  padding: 0;
  overflow: hidden;
}

.net-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 13px 14px;
  border-top: 1px solid var(--border-color);
  min-width: 0;
}

.net-row:first-child {
  border-top: 0;
}

.net-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.net-name {
  font-size: 13.5px;
  font-weight: 600;
}

.net-sub {
  font-size: 11.5px;
  color: var(--text-secondary);
}

.net-value {
  margin-left: auto;
  font-size: 19px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

/* ---------- Empty / placeholder ---------- */

.chart-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 210px;
  padding: 28px 18px;
  text-align: center;
  border-style: dashed;
  background: color-mix(in srgb, var(--bg-card) 72%, transparent);
}

.chart-empty__icon {
  width: 34px;
  height: 34px;
  color: var(--accent-primary);
  margin-bottom: 2px;
}

.chart-empty h3 {
  font-size: 15px;
  font-weight: 650;
}

.chart-empty p {
  max-width: 46ch;
  color: var(--text-secondary);
  font-size: 12.5px;
}

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

.section-head--chart {
  flex-wrap: wrap;
  align-items: flex-start;
}

.section-head--chart h2 {
  white-space: nowrap;
}

.section-head--chart .chart-controls {
  flex: 1 1 100%;
}

@media (min-width: 720px) {
  .section-head--chart {
    flex-wrap: nowrap;
    align-items: center;
  }

  .section-head--chart .chart-controls {
    flex: 0 0 auto;
    justify-content: flex-end;
  }
}

.range-switch {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-elevated);
}

.range-btn {
  height: 30px;
  padding: 0 9px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}

.range-btn:hover {
  color: var(--text-primary);
}

.range-btn.is-active {
  background: var(--bg-card);
  color: var(--accent-primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.chart-select {
  height: 36px;
  padding: 0 8px;
  border: 1px solid var(--border-color);
  border-radius: 9px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  font: inherit;
  font-size: 12px;
  outline: none;
}

.chart-card {
  padding: 12px 12px 8px;
}

.chart-canvas-wrap {
  position: relative;
  height: 260px;
  min-width: 0;
}

.chart-canvas-wrap canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.chart-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 230px;
  text-align: center;
  color: var(--text-secondary);
}

.chart-placeholder .icon {
  width: 30px;
  height: 30px;
  color: var(--accent-primary);
  opacity: 0.8;
}

.chart-placeholder h3 {
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 650;
}

.chart-placeholder p {
  max-width: 42ch;
  font-size: 12px;
}

.chart-foot {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding-top: 7px;
  color: var(--text-secondary);
  font-size: 10.5px;
}

@media (min-width: 1024px) {
  .chart-canvas-wrap {
    height: 300px;
  }
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-primary);
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 22px 10px;
  text-align: center;
}

.empty-state .icon {
  width: 28px;
  height: 28px;
  color: var(--text-secondary);
  opacity: 0.8;
  margin-bottom: 2px;
}

.empty-state h3 {
  font-size: 14px;
  font-weight: 650;
}

.empty-state p {
  max-width: 42ch;
  color: var(--text-secondary);
  font-size: 12.5px;
}

/* ---------- Hermes ---------- */

.hermes-hero {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.hermes-hero__main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  flex: none;
  border-radius: 14px;
  color: var(--accent-primary);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent-primary) 22%, transparent);
}

.avatar .icon {
  width: 24px;
  height: 24px;
}

.hermes-hero__text {
  min-width: 0;
}

.hermes-hero__text h2 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.hermes-hero__text p {
  color: var(--text-secondary);
  font-size: 12.5px;
}

.hermes-hero__main .chip {
  margin-left: auto;
}

.meta-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.meta-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  min-width: 0;
}

.meta-label {
  color: var(--text-secondary);
  font-size: 12px;
}

.meta-value {
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  overflow-wrap: anywhere;
}

.card-note {
  margin-top: 10px;
  color: var(--text-secondary);
  font-size: 12px;
}

.card-foot {
  display: flex;
  justify-content: flex-end;
  padding: 10px 14px;
  border-top: 1px solid var(--border-color);
}

.model-chip {
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  cursor: pointer;
  font: inherit;
}

.model-chip:hover {
  color: var(--text-primary);
  border-color: color-mix(in srgb, var(--accent-primary) 35%, var(--border-color));
}

.model-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.model-actions .btn {
  width: 100%;
  min-width: 0;
}

.model-search {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  margin-bottom: 12px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  font: inherit;
  font-size: 13.5px;
  outline: none;
}

.model-search:focus {
  border-color: color-mix(in srgb, var(--accent-primary) 45%, var(--border-color));
}

.model-group {
  margin-top: 14px;
}

.model-group:first-of-type {
  margin-top: 0;
}

.model-group h4 {
  margin: 0 0 6px;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.model-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.model-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: 9px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}

.model-option:hover {
  border-color: color-mix(in srgb, var(--accent-primary) 40%, var(--border-color));
}

.model-option--active {
  border-color: var(--accent-primary);
  background: var(--accent-soft);
}

.model-option small {
  color: var(--text-secondary);
  font-size: 10.5px;
  white-space: nowrap;
}

.model-empty {
  padding: 14px 0;
  color: var(--text-secondary);
  font-size: 12.5px;
  text-align: center;
}

.btn--small {
  min-height: 34px;
  padding: 0 10px;
  font-size: 12px;
}

.cron-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.cron-job {
  padding: 12px 0;
  border-top: 1px solid var(--border-color);
}

.cron-job:first-child {
  padding-top: 2px;
  border-top: 0;
}

.cron-job-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.cron-job-title {
  min-width: 0;
  font-size: 13.5px;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.cron-job-meta {
  margin-top: 3px;
  color: var(--text-secondary);
  font-size: 11px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.cron-job-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.job-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  cursor: pointer;
}

.job-action:hover {
  color: var(--text-primary);
  border-color: color-mix(in srgb, var(--accent-primary) 35%, var(--border-color));
}

.job-action--danger:hover {
  color: var(--status-danger);
  border-color: color-mix(in srgb, var(--status-danger) 35%, var(--border-color));
}

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

.cron-form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 600;
}

.cron-form input,
.cron-form select,
.cron-form textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: 9px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  font: inherit;
  font-size: 13.5px;
  outline: none;
}

.cron-form textarea {
  min-height: 92px;
  resize: vertical;
}

.cron-form input:focus,
.cron-form select:focus,
.cron-form textarea:focus {
  border-color: color-mix(in srgb, var(--accent-primary) 45%, var(--border-color));
}

.cron-form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.cron-preview {
  padding: 9px 10px;
  border: 1px dashed var(--border-color);
  border-radius: 9px;
  color: var(--text-secondary);
  font-size: 11.5px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.cron-preview strong {
  color: var(--text-primary);
}

.cron-warning {
  color: var(--status-warning);
}

.cron-runs {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cron-run {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 9px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-elevated);
  font-size: 11px;
}

.cron-run span {
  color: var(--text-secondary);
  overflow-wrap: anywhere;
}

.cron-run strong {
  font-size: 11px;
}

.info-row--plain {
  grid-template-columns: minmax(0, 1fr) auto;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.field-label {
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 550;
}

.select-mock {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 13.5px;
  opacity: 0.85;
}

.select-mock span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.select-mock .icon {
  transform: rotate(90deg);
  opacity: 0.5;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--accent-primary);
  color: var(--accent-contrast);
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  transition: transform 140ms ease, background 150ms ease, opacity 150ms ease;
}

.btn:hover {
  background: color-mix(in srgb, var(--accent-primary) 88%, #000);
}

.btn:active {
  transform: scale(0.98);
}

.btn--ghost {
  background: transparent;
  border-color: var(--border-color);
  color: var(--text-secondary);
}

.btn--ghost:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn--danger {
  margin-top: 14px;
  background: color-mix(in srgb, var(--status-danger) 12%, transparent);
  border-color: color-mix(in srgb, var(--status-danger) 35%, transparent);
  color: var(--status-danger);
}

.btn--danger:hover {
  background: color-mix(in srgb, var(--status-danger) 20%, transparent);
}

/* ---------- Auth gate ---------- */

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) calc(20px + var(--safe-right)) calc(24px + var(--safe-bottom)) calc(20px + var(--safe-left));
  background: var(--bg-primary);
}

.auth-card {
  width: 100%;
  max-width: 360px;
  padding: 30px 22px 26px;
  border: 1px solid var(--border-color);
  border-radius: 20px;
  background: var(--bg-card);
  box-shadow: var(--shadow-card);
  text-align: center;
}

.auth-mark {
  width: 54px;
  height: 54px;
  margin: 0 auto 12px;
  border-radius: 16px;
}

.auth-mark .icon {
  width: 30px;
  height: 30px;
}

.auth-card .eyebrow {
  margin-bottom: 4px;
}

.auth-card h1 {
  font-size: 24px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.02em;
}

#authText {
  margin-top: 8px;
  color: var(--text-secondary);
  font-size: 13.5px;
  line-height: 1.5;
}

.auth-retry {
  margin-top: 18px;
}

.auth-foot {
  margin-top: 22px;
  color: var(--text-secondary);
  font-size: 11px;
  opacity: 0.8;
}

.auth-gate[data-state="checking"] .auth-mark {
  animation: pulse 1.4s ease-in-out infinite;
}

.btn .badge {
  margin-left: 2px;
}

/* ---------- Settings ---------- */

.theme-switch {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
  padding: 4px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--bg-elevated);
}

.theme-option {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease, border-color 150ms ease;
}

.theme-option .icon {
  width: 17px;
  height: 17px;
}

.theme-option:hover {
  color: var(--text-primary);
}

.theme-option[aria-checked="true"] {
  background: var(--bg-card);
  border-color: var(--border-color);
  color: var(--text-primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .theme-option[aria-checked="true"] {
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.info-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--border-color);
  min-width: 0;
}

.info-row:first-child {
  border-top: 0;
}

.info-row__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.info-name {
  font-size: 14px;
  font-weight: 600;
}

.info-sub {
  color: var(--text-secondary);
  font-size: 11.5px;
  overflow-wrap: anywhere;
}

.info-row--disabled {
  opacity: 0.72;
}

.switch {
  position: relative;
  width: 42px;
  height: 25px;
  padding: 0;
  flex: none;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background: var(--bg-elevated);
  cursor: not-allowed;
}

.switch span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--text-secondary);
  opacity: 0.7;
}

.kv {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-top: 1px solid var(--border-color);
  font-size: 13px;
  min-width: 0;
}

.kv:first-child {
  border-top: 0;
  padding-top: 2px;
}

.kv:last-child {
  padding-bottom: 2px;
}

.kv span {
  color: var(--text-secondary);
  min-width: 0;
}

.kv strong {
  font-weight: 600;
  text-align: right;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

/* ---------- Notice ---------- */

.notice {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-top: 20px;
  padding: 12px 14px;
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.45;
}

.notice .icon {
  width: 17px;
  height: 17px;
  flex: none;
  margin-top: 1px;
  color: var(--accent-primary);
}

.notice p {
  min-width: 0;
}

/* ---------- Tasks ---------- */

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

.tasks-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 10px;
}

.task-stat {
  min-width: 0;
  padding: 8px 5px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--bg-card);
  color: var(--text-secondary);
  text-align: center;
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease;
}

.task-stat:hover {
  border-color: var(--text-secondary);
}

.task-stat.is-active {
  border-color: var(--accent-primary);
  background: var(--accent-soft);
  color: var(--accent-primary);
}

.task-stat__count {
  display: block;
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.15;
}

.task-stat.is-active .task-stat__count {
  color: var(--accent-primary);
}

.task-stat__label {
  display: block;
  margin-top: 2px;
  font-size: 9.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.task-stat--failed .task-stat__count { color: var(--status-danger); }
.task-stat--completed .task-stat__count { color: var(--status-success); }
.task-stat--waiting .task-stat__count { color: var(--status-warning); }

.tasks-toolbar {
  padding: 8px 10px;
  margin-bottom: 13px;
}

.task-search {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
}

.task-search input {
  flex: 1;
  min-width: 0;
  height: 34px;
  border: 0;
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: 12.5px;
  outline: none;
}

.task-search input::placeholder {
  color: var(--text-secondary);
}

.task-row {
  display: grid;
  grid-template-columns: 9px minmax(0, 1fr) auto;
  align-items: flex-start;
  gap: 9px;
  width: 100%;
  padding: 11px 0;
  border: 0;
  border-top: 1px solid var(--border-color);
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  min-width: 0;
}

.task-row:first-child {
  border-top: 0;
  padding-top: 2px;
}

.task-row:hover .task-row__title {
  color: var(--accent-primary);
}

.task-dot {
  width: 8px;
  height: 8px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--text-secondary);
}

.task-dot--active { background: var(--accent-primary); box-shadow: 0 0 0 3px var(--accent-soft); }
.task-dot--waiting { background: var(--status-warning); }
.task-dot--completed { background: var(--status-success); }
.task-dot--failed { background: var(--status-danger); }
.task-dot--cancelled { background: var(--text-secondary); }

.task-row__body {
  min-width: 0;
}

.task-row__title {
  display: block;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.task-row__meta {
  display: block;
  margin-top: 3px;
  color: var(--text-secondary);
  font-size: 10.5px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.task-row__error {
  color: var(--status-danger);
}

.task-row__right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.task-source {
  color: var(--text-secondary);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.task-detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.task-detail-head h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.task-detail-id {
  margin-top: 3px;
  color: var(--text-secondary);
  font-size: 10.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow-wrap: anywhere;
}

.task-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.task-meta {
  min-width: 0;
  padding: 8px 9px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-primary);
}

.task-meta__label {
  display: block;
  color: var(--text-secondary);
  font-size: 9.5px;
}

.task-meta__value {
  display: block;
  margin-top: 2px;
  color: var(--text-primary);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.task-block {
  margin-top: 12px;
}

.task-block h4 {
  margin: 0 0 6px;
  color: var(--text-secondary);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.task-text {
  margin: 0;
  color: var(--text-primary);
  font-size: 12.5px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

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

.task-text--danger {
  color: var(--status-danger);
}

.task-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.task-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.task-tools .chip {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
}

.task-timeline {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.task-event {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr);
  gap: 8px;
}

.task-event__dot {
  width: 7px;
  height: 7px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--border-color);
}

.task-event__label {
  font-size: 12px;
  font-weight: 600;
}

.task-event__time,
.task-event__detail {
  display: block;
  margin-top: 1px;
  color: var(--text-secondary);
  font-size: 10.5px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.task-runs {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.task-run {
  padding: 8px 9px;
  border: 1px solid var(--border-color);
  border-radius: 9px;
  background: var(--bg-primary);
}

.task-run__head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
}

.task-run__meta {
  margin-top: 3px;
  color: var(--text-secondary);
  font-size: 10px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.task-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
}

.task-actions .btn {
  min-height: 36px;
}

.task-actions .btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.task-cancel-note {
  margin: 8px 0 0;
  color: var(--text-secondary);
  font-size: 10.5px;
  line-height: 1.45;
}

.task-action-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.task-action-row {
  padding: 8px 9px;
  border: 1px solid var(--border-color);
  border-radius: 9px;
  background: var(--bg-primary);
}

/* ---------- Events & notifications ---------- */

.events-head-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.event-row {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  gap: 9px;
  align-items: flex-start;
  width: 100%;
  padding: 10px 0;
  border: 0;
  border-top: 1px solid var(--border-color);
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  min-width: 0;
}

.event-row:first-child {
  border-top: 0;
  padding-top: 2px;
}

.event-row.is-unread {
  background: color-mix(in srgb, var(--accent-primary) 5%, transparent);
}

.event-severity {
  width: 8px;
  height: 8px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--text-secondary);
}

.event-severity--warning { background: var(--status-warning); }
.event-severity--critical { background: var(--status-danger); }
.event-severity--info { background: var(--accent-primary); }

.event-body {
  min-width: 0;
}

.event-title {
  font-size: 13px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.event-message {
  margin-top: 2px;
  color: var(--text-secondary);
  font-size: 11.5px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.event-meta {
  margin-top: 3px;
  color: var(--text-secondary);
  font-size: 10px;
  opacity: 0.85;
}

.event-time {
  color: var(--text-secondary);
  font-size: 10px;
  white-space: nowrap;
  padding-top: 2px;
}

.events-filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.events-filter {
  height: 30px;
  padding: 0 9px;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
}

.events-filter.is-active {
  color: var(--accent-primary);
  border-color: var(--accent-primary);
  background: var(--accent-soft);
}

.switch:not(:disabled) {
  cursor: pointer;
}

.switch[aria-checked="true"] {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
}

.switch[aria-checked="true"] span {
  left: 21px;
  background: #fff;
  opacity: 1;
}

.notify-block {
  padding: 10px 0;
  border-top: 1px solid var(--border-color);
}

.notify-categories {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px 10px;
  margin-top: 7px;
}

.notify-cat {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
}

.notify-cat input {
  accent-color: var(--accent-primary);
}

#notifyNote {
  margin-top: 8px;
}

/* ---------- Chat ---------- */

.chat-head-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chat-head-actions .btn {
  min-height: 38px;
  padding: 0 12px;
}

.chat-shell {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 310px);
  min-height: 360px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  box-shadow: var(--shadow-card);
}

.chat-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 40px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-color);
  min-width: 0;
}

.chat-topline .muted {
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding: 14px 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: color-mix(in srgb, var(--bg-primary) 28%, var(--bg-card));
}

.chat-empty {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 28px 18px;
  text-align: center;
  color: var(--text-secondary);
}

.chat-empty .icon {
  width: 32px;
  height: 32px;
  margin-bottom: 2px;
  opacity: 0.7;
}

.chat-empty h3 {
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 650;
}

.chat-empty p {
  max-width: 38ch;
  font-size: 12.5px;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: 92%;
  min-width: 0;
}

.msg--user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg--assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.msg-bubble {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 13.5px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.msg--user .msg-bubble {
  background: var(--accent-primary);
  border-color: transparent;
  color: var(--accent-contrast);
  border-bottom-right-radius: 5px;
}

.msg--assistant .msg-bubble {
  border-bottom-left-radius: 5px;
}

.msg-meta {
  padding: 0 3px;
  color: var(--text-secondary);
  font-size: 10.5px;
}

.msg-error {
  border-color: color-mix(in srgb, var(--status-danger) 40%, transparent);
  background: color-mix(in srgb, var(--status-danger) 8%, var(--bg-card));
}

.msg-retry {
  margin-top: 8px;
}

.msg-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 7px;
}

.tool-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 10.5px;
  white-space: nowrap;
}

.tool-chip .dot {
  width: 6px;
  height: 6px;
}

.tool-chip--error {
  color: var(--status-danger);
  border-color: color-mix(in srgb, var(--status-danger) 35%, transparent);
}

.typing {
  display: inline-flex;
  gap: 4px;
  padding: 2px 0;
}

.typing span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-secondary);
  animation: typing 1s ease-in-out infinite;
}

.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}

.chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-card);
}

.chat-composer textarea {
  flex: 1;
  min-width: 0;
  min-height: 42px;
  max-height: 120px;
  padding: 10px 11px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  font: inherit;
  font-size: 14px;
  line-height: 1.4;
  resize: none;
  outline: none;
}

.chat-composer textarea:focus {
  border-color: color-mix(in srgb, var(--accent-primary) 45%, var(--border-color));
}

.chat-composer textarea::placeholder {
  color: var(--text-secondary);
}

.chat-send {
  width: 42px;
  height: 42px;
  border-color: transparent;
  background: var(--accent-primary);
  color: var(--accent-contrast);
}

.chat-send:hover {
  background: color-mix(in srgb, var(--accent-primary) 88%, #000);
  color: var(--accent-contrast);
}

.chat-stop {
  width: 42px;
  height: 42px;
  border-color: transparent;
  background: var(--status-danger);
  color: #fff;
}

.chat-stop:hover {
  background: color-mix(in srgb, var(--status-danger) 88%, #000);
  color: #fff;
}

.chat-foot {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 0 12px 8px;
  color: var(--text-secondary);
  font-size: 10.5px;
  min-height: 18px;
}

.chat-foot span:last-child {
  font-variant-numeric: tabular-nums;
}

/* Markdown inside assistant bubbles */

.md {
  min-width: 0;
}

.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }

.md p {
  margin: 0 0 8px;
}

.md h1, .md h2, .md h3, .md h4 {
  margin: 12px 0 6px;
  line-height: 1.25;
  font-weight: 700;
}

.md h1 { font-size: 18px; }
.md h2 { font-size: 16px; }
.md h3 { font-size: 15px; }
.md h4 { font-size: 14px; }

.md ul, .md ol {
  margin: 0 0 8px;
  padding-left: 20px;
}

.md li { margin: 2px 0; }

.md blockquote {
  margin: 8px 0;
  padding: 6px 10px;
  border-left: 3px solid var(--accent-primary);
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border-radius: 0 7px 7px 0;
}

.md a {
  color: var(--accent-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.msg--user .md a {
  color: var(--accent-contrast);
}

.md code {
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--bg-elevated);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

.msg--user .md code {
  background: rgba(255, 255, 255, 0.18);
}

.code-block {
  margin: 8px 0;
  overflow: hidden;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-elevated);
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 9px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.code-copy {
  padding: 2px 6px;
  border: 1px solid var(--border-color);
  border-radius: 5px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 10px;
  cursor: pointer;
}

.code-copy:hover {
  color: var(--text-primary);
}

.code-block pre {
  margin: 0;
  padding: 10px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
}

.code-block code {
  padding: 0;
  background: transparent;
  font-size: inherit;
}

.tok-key { color: #c792ea; }
.tok-str { color: #a5d6a7; }
.tok-num { color: #f0b37e; }
.tok-com { color: var(--text-secondary); font-style: italic; }

[data-theme="light"] .tok-key { color: #7c3aed; }
[data-theme="light"] .tok-str { color: #15803d; }
[data-theme="light"] .tok-num { color: #b45309; }

.session-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 0;
  border-top: 1px solid var(--border-color);
  min-width: 0;
}

.session-row:first-child {
  border-top: 0;
}

.session-open {
  flex: 1;
  min-width: 0;
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.session-open strong {
  display: block;
  overflow: hidden;
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-open span {
  color: var(--text-secondary);
  font-size: 10.5px;
}

.session-actions {
  display: flex;
  gap: 4px;
  flex: none;
}

.session-actions .icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
}

@media (min-width: 600px) {
  .chat-shell {
    height: calc(100dvh - 285px);
  }
}

@media (min-width: 720px) {
  .chat-shell {
    height: calc(100dvh - 250px);
  }
}

@media (min-width: 1024px) {
  .chat-shell {
    height: calc(100dvh - 200px);
  }
}

@media (max-width: 359px) {
  .chat-head-actions {
    width: 100%;
  }

  .chat-head-actions .btn {
    flex: 1;
    font-size: 11px;
  }

  .chat-shell {
    height: calc(100dvh - 335px);
    min-height: 330px;
  }

  .msg {
    max-width: 96%;
  }
}

/* ---------- Bottom navigation ---------- */

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding: 4px calc(6px + var(--safe-right)) var(--safe-bottom) calc(6px + var(--safe-left));
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.16);
}

[data-theme="light"] .bottom-nav {
  box-shadow: 0 -10px 30px rgba(15, 23, 42, 0.06);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  min-height: 48px;
  border-radius: 10px;
  color: var(--text-secondary);
  font-size: 9.5px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: color 150ms ease, background 150ms ease;
}

.nav-item .icon {
  width: 20px;
  height: 20px;
}

.nav-item:hover {
  color: var(--text-primary);
}

.nav-item.is-active {
  color: var(--accent-primary);
}

.nav-item.is-active .icon {
  stroke-width: 2.1;
}

/* ---------- Modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal[hidden] {
  display: none;
}

body.modal-open {
  overflow: hidden;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3, 7, 18, 0.62);
  animation: fadeIn 180ms ease both;
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 86dvh;
  overflow-y: auto;
  padding: 18px calc(18px + var(--safe-right)) calc(18px + var(--safe-bottom)) calc(18px + var(--safe-left));
  border: 1px solid var(--border-color);
  border-bottom: 0;
  border-radius: 20px 20px 0 0;
  background: var(--bg-card);
  box-shadow: var(--shadow-pop);
  animation: slideUp 220ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.modal-head h2 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  min-width: 0;
  overflow-wrap: anywhere;
}

.modal-head .icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
}

.modal-body {
  color: var(--text-secondary);
  font-size: 13.5px;
}

.modal-body p + p {
  margin-top: 8px;
}

.modal-body strong {
  color: var(--text-primary);
  font-weight: 600;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 14px);
  z-index: 90;
  max-width: calc(100vw - 32px);
  padding: 9px 15px;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 12.5px;
  font-weight: 550;
  box-shadow: var(--shadow-card);
  transform: translateX(-50%);
  animation: toastIn 180ms ease both;
}

.toast[hidden] {
  display: none;
}

/* ---------- Animations ---------- */

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

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

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

@keyframes pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

@media (hover: hover) {
  .metric-card:hover {
    transform: translateY(-1px);
    border-color: color-mix(in srgb, var(--accent-primary) 26%, var(--border-color));
  }

  .card {
    transition: transform 170ms ease, border-color 170ms ease;
  }

  .list-card:hover,
  .network-card:hover {
    transform: none;
  }
}

/* ---------- Tablet ---------- */

@media (min-width: 600px) {
  .meta-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .metrics-grid--3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .metrics-grid--3 > :last-child {
    grid-column: auto;
  }

  .modal {
    align-items: center;
    padding: 20px;
  }

  .modal-card {
    border-bottom: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    animation: fadeIn 180ms ease both;
  }
}

@media (min-width: 720px) {
  .content {
    padding: 24px 24px calc(var(--nav-height) + var(--safe-bottom) + 30px);
  }

  .page-head {
    margin-bottom: 18px;
  }

  .page-head h1 {
    font-size: 28px;
  }

  .metric-card {
    min-height: 152px;
  }
}

/* ---------- Desktop ---------- */

@media (min-width: 1024px) {
  .app-shell {
    grid-template-columns: 248px minmax(0, 1fr);
  }

  .sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    gap: 22px;
    height: 100dvh;
    padding: 22px 14px 18px;
    border-right: 1px solid var(--border-color);
    background: var(--bg-card);
  }

  .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 8px;
    text-decoration: none;
    min-width: 0;
  }

  .brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
    min-width: 0;
  }

  .brand-text strong {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.01em;
  }

  .brand-text span {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .side-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .side-link {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    padding: 0 11px;
    border-radius: 10px;
    color: var(--text-secondary);
    font-size: 13.5px;
    font-weight: 600;
    text-decoration: none;
    transition: color 150ms ease, background 150ms ease;
  }

  .side-link .icon {
    width: 19px;
    height: 19px;
  }

  .side-link:hover {
    color: var(--text-primary);
    background: var(--bg-elevated);
  }

  .side-link.is-active {
    color: var(--accent-primary);
    background: var(--accent-soft);
  }

  .side-footer {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: auto;
    padding: 12px 10px 0;
    border-top: 1px solid var(--border-color);
  }

  .side-conn {
    display: flex;
    align-items: center;
    gap: 7px;
    color: var(--text-secondary);
    font-size: 11.5px;
    font-weight: 600;
    min-width: 0;
  }

  .side-conn span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .side-version {
    color: var(--text-secondary);
    font-size: 10.5px;
    opacity: 0.8;
    white-space: nowrap;
  }

  .topbar-brand {
    display: none;
  }

  .topbar-crumb {
    display: flex;
  }

  .topbar {
    padding: calc(10px + var(--safe-top)) 32px 10px;
    min-height: 58px;
  }

  .content {
    padding: 26px 32px 48px;
  }

  .bottom-nav {
    display: none;
  }

  .metrics-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
  }

  .metrics-grid--3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .section {
    margin-top: 26px;
  }
}

/* ---------- Small phones ---------- */

@media (max-width: 359px) {
  .topbar {
    gap: 6px;
    padding-left: calc(12px + var(--safe-left));
    padding-right: calc(12px + var(--safe-right));
  }

  .topbar-title {
    font-size: 13px;
  }

  .nav-item {
    font-size: 9px;
    letter-spacing: -0.02em;
  }

  .nav-item .icon {
    width: 20px;
    height: 20px;
  }

  .conn-pill {
    padding: 0 9px;
    font-size: 11px;
  }

  .icon-btn {
    width: 38px;
    height: 38px;
  }

  .metric-head {
    gap: 6px;
  }

  .metric-head .icon-chip {
    width: 30px;
    height: 30px;
  }

  .metric-head .icon-chip .icon {
    width: 16px;
    height: 16px;
  }

  .metric-name {
    font-size: 12.5px;
  }

  .metric-value .value {
    font-size: 26px;
  }

  .theme-option {
    font-size: 11px;
    gap: 5px;
  }

  .service-row {
    grid-template-columns: 34px minmax(0, 1fr) auto;
  }

  .service-row .icon--chevron {
    display: none;
  }

  .chip {
    font-size: 10px;
    padding: 0 7px;
  }
}

/* ---------- Compact tasks / six-tab nav ---------- */

@media (max-width: 380px) {
  .nav-item {
    gap: 2px;
    font-size: 8.5px;
  }

  .nav-item .icon {
    width: 18px;
    height: 18px;
  }

  .nav-item span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .tasks-summary {
    gap: 4px;
  }

  .task-stat {
    padding: 7px 3px;
  }

  .task-stat__label {
    font-size: 8.5px;
  }

  .task-meta-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .task-detail-head {
    flex-direction: column;
  }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Scrollbar ---------- */

* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 999px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

/* ---------- Utilities ---------- */

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