/* Mygtukas Dashboard — palette aligned with Mygtukas/theme.css (--pyv-*) */

:root {
  color-scheme: light;
  --font: "Poppins", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;

  /* Surfaces */
  --bg: #f7f7f7;
  --bg-accent: none;
  --sidebar-bg: #ffffff;
  --surface: #ffffff;
  --surface-hover: #f2f2f2;
  --surface-muted: #f7f7f7;

  /* Borders */
  --border: #c8c8c8;
  --border-strong: #cccccc;

  /* Text */
  --text-primary: #111111;
  --text-secondary: #666666;
  --text-muted: #a3a3a3;

  /* Primary actions (Mygtukas send / choice-active) */
  --accent: #111111;
  --accent-hover: #333333;
  --accent-soft: #e8e8e8;
  --accent-fg: #ffffff;
  --focus-border: #111111;
  --focus-ring: transparent;

  /* Buttons */
  --btn-primary-bg: #111111;
  --btn-primary-fg: #ffffff;
  --btn-primary-hover-bg: #333333;
  --btn-secondary-bg: #f7f7f7;
  --btn-secondary-fg: #333333;
  --btn-secondary-border: #cccccc;
  --badge-bg: #ececec;
  --badge-fg: #666666;
  --toggle-track: #ececec;
  --toggle-track-on: #111111;
  --toggle-knob: #ffffff;

  /* Status */
  --online: #22c55e;
  --online-bg: rgba(34, 197, 94, 0.12);
  --offline: #888888;
  --offline-bg: #f0f0f0;
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.1);

  /* Elevation */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.12);
  --modal-scrim: rgba(255, 255, 255, 0.72);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 14px;
  --radius-xl: 14px;

  --sidebar-w: 240px;
  --topbar-h: 56px;
  --content-max: 1280px;

  /* Typography — aligned with Mygtukas/theme.css */
  --type-title-size: 14px;
  --type-title-weight: 600;
  --type-body-size: 13px;
  --type-body-weight: 400;
  --type-body-lh: 1.55;
  --type-hint-size: 12px;
  --type-hint-weight: 400;
  --type-hint-lh: 1.45;
  --btn-label-size: 12px;
  --btn-label-weight: 700;
  --btn-label-tracking: 0.05em;
  --control-h: 44px;
  --control-h-compact: 36px;

  /* Charts — neutral + Mygtukas accent blue */
  --chart-grid: rgba(0, 0, 0, 0.06);
  --chart-1: #111111;
  --chart-2: #007acc;
  --chart-3: #666666;
  --chart-4: #333333;
  --chart-5: #a3a3a3;

  /* 2026 refresh accents */
  --accent-blue: #007acc;
  --accent-blue-soft: rgba(0, 122, 204, 0.12);
  --bg-glow: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(0, 122, 204, 0.08), transparent 70%);
  --sidebar-w: 240px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #252528;
  --bg-accent: none;
  --sidebar-bg: #2d2d30;
  --surface: #2d2d30;
  --surface-hover: #3a3a3e;
  --surface-muted: #252528;

  --border: #505053;
  --border-strong: #505053;

  --text-primary: #e8e8e8;
  --text-secondary: #b0b0b5;
  --text-muted: #787880;

  --accent: #e0e0e5;
  --accent-hover: #ffffff;
  --accent-soft: #454549;
  --accent-fg: #1a1a1e;
  --focus-border: #ffffff;
  --focus-ring: transparent;

  --btn-primary-bg: #ffffff;
  --btn-primary-fg: #111111;
  --btn-primary-hover-bg: #f0f0f2;
  --btn-secondary-bg: #3a3a3e;
  --btn-secondary-fg: #e0e0e5;
  --btn-secondary-border: #505053;
  --badge-bg: #404044;
  --badge-fg: #b0b0b5;
  --toggle-track: #404044;
  --toggle-track-on: #ffffff;
  --toggle-knob: #111111;

  --online: #4ade80;
  --online-bg: rgba(74, 222, 128, 0.14);
  --offline: #909095;
  --offline-bg: #353538;
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
  --modal-scrim: rgba(0, 0, 0, 0.72);

  --chart-grid: rgba(255, 255, 255, 0.08);
  --chart-1: #e8e8e8;
  --chart-2: #6cb6ff;
  --chart-3: #b0b0b5;
  --chart-4: #787880;
  --chart-5: #505053;

  --accent-blue: #6cb6ff;
  --accent-blue-soft: rgba(108, 182, 255, 0.16);
  --bg-glow: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(108, 182, 255, 0.1), transparent 70%);
}

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

html {
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: var(--type-body-size);
  font-weight: var(--type-body-weight);
  line-height: var(--type-body-lh);
  background: var(--bg);
  background-image: var(--bg-glow);
  background-attachment: fixed;
  color: var(--text-primary);
}

/* ── App shell ── */

.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  border-right: 1px solid var(--border);
  background: var(--sidebar-bg);
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar__nav {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar__head {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-width: 0;
}

.brand-row .health-pill {
  flex-shrink: 0;
  max-width: 72px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-sidebar {
  width: 100%;
  justify-content: center;
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: var(--type-hint-size);
  font-weight: var(--type-title-weight);
  transition: background 0.15s, color 0.15s;
}

.sidebar__link:hover {
  background: var(--surface-muted);
  color: var(--text-primary);
}

.sidebar__link.is-active {
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: var(--type-title-weight);
}

.sidebar__icon {
  font-size: 15px;
  opacity: 0.85;
}

.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
}

.topbar__left {
  flex: 1;
  min-width: 0;
}

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

.main {
  flex: 1;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 24px 24px 48px;
}

.view.hidden {
  display: none !important;
}

/* ── Brand ── */

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  min-width: 0;
  flex: 1;
  color: var(--text-primary);
  text-decoration: none;
  font-weight: var(--type-title-weight);
  font-size: var(--type-title-size);
  letter-spacing: 0;
}

.brand__mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, #111111, #333333);
  box-shadow: var(--shadow-xs);
}

[data-theme="dark"] .brand__mark {
  background: linear-gradient(135deg, #e8e8e8, #ffffff);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--type-hint-size);
  line-height: var(--type-hint-lh);
  color: var(--text-muted);
}

.breadcrumb a {
  color: var(--text-secondary);
  text-decoration: none;
}

.breadcrumb a:hover {
  color: var(--text-primary);
}

.breadcrumb__current {
  color: var(--text-primary);
  font-weight: var(--type-title-weight);
}

/* ── Page head ── */

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

.page-head__title {
  margin: 0;
  font-size: var(--type-title-size);
  font-weight: var(--type-title-weight);
  letter-spacing: 0;
  line-height: 1.3;
}

.page-head__sub {
  margin: 6px 0 0;
  font-size: var(--type-body-size);
  font-weight: var(--type-body-weight);
  line-height: var(--type-body-lh);
  color: var(--text-muted);
}

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

/* ── Stats ── */

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

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

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-xs);
}

.stat-tile__label {
  margin: 0;
  font-size: var(--type-hint-size);
  font-weight: var(--type-hint-weight);
  line-height: var(--type-hint-lh);
  color: var(--text-secondary);
}

.stat-tile__value {
  margin: 4px 0 0;
  font-size: 18px;
  font-weight: var(--type-title-weight);
  letter-spacing: 0;
  line-height: 1.2;
}

.stat-tile__value--sm {
  font-size: var(--type-title-size);
  font-weight: var(--type-title-weight);
  line-height: var(--type-hint-lh);
}

/* ── Panel ── */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

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

.panel__toolbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel__title {
  margin: 0;
  font-size: var(--type-title-size);
  font-weight: var(--type-title-weight);
}

.panel__count {
  font-size: var(--type-hint-size);
  font-weight: var(--type-title-weight);
  color: var(--text-muted);
  background: var(--surface-muted);
  padding: 2px 8px;
  border-radius: 999px;
}

.search-field {
  flex: 1;
  max-width: 280px;
  min-width: 160px;
}

.search-field__input {
  width: 100%;
  min-height: var(--control-h);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 12px 0 32px;
  font-family: var(--font);
  font-size: var(--type-body-size);
  font-weight: var(--type-body-weight);
  line-height: var(--type-body-lh);
  background: var(--surface-muted) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23666666' stroke-width='2'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='M11 11l3 3'/%3E%3C/svg%3E") 10px center no-repeat;
  color: var(--text-primary);
}

.search-field__input:focus {
  outline: none;
  border-color: var(--focus-border);
  box-shadow: 0 0 0 2px var(--focus-ring);
}

/* ── Instance cards ── */

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

.instance-card {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}

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

.instance-card__title {
  margin: 0 0 4px;
  font-size: var(--type-title-size);
  font-weight: var(--type-title-weight);
  line-height: 1.3;
  letter-spacing: 0;
}

.instance-card__site {
  margin: 0 0 14px;
  font-size: var(--type-hint-size);
  line-height: var(--type-hint-lh);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.instance-card__metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.instance-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.instance-card__title a {
  color: inherit;
  text-decoration: none;
}

.instance-card__title a:hover {
  color: var(--text-primary);
}

.instance-card__site a {
  color: var(--text-secondary);
  text-decoration: none;
}

.metric-chip {
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  text-align: center;
}

.metric-chip__val {
  display: block;
  font-size: var(--type-title-size);
  font-weight: var(--type-title-weight);
  letter-spacing: 0;
  line-height: 1.2;
}

.metric-chip__lbl {
  display: block;
  margin-top: 4px;
  font-size: var(--type-hint-size);
  font-weight: var(--btn-label-weight);
  line-height: var(--type-hint-lh);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: var(--btn-label-tracking);
}

.instance-card__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.instance-card__meta {
  font-size: var(--type-hint-size);
  line-height: var(--type-hint-lh);
  color: var(--text-muted);
  white-space: nowrap;
}

.instance-card__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.instance-card__actions .btn {
  min-height: var(--control-h-compact);
  padding: 0 14px;
  font-size: 11px;
  letter-spacing: 0.04em;
}

.instance-card__actions .btn-secondary {
  background: var(--btn-secondary-bg);
  border-color: var(--btn-secondary-border);
  color: var(--btn-secondary-fg);
}

.instance-card__actions .btn-secondary:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.instance-card__actions .btn-danger {
  background: transparent;
  border-color: var(--border);
  color: var(--danger);
}

.instance-card__actions .btn-danger:hover {
  background: var(--danger-soft);
  border-color: transparent;
  color: var(--danger);
}

/* ── Cards (detail) ── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}

.card__head {
  padding: 16px 18px 0;
}

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

.card__title {
  margin: 0;
  font-size: var(--type-title-size);
  font-weight: var(--type-title-weight);
  line-height: 1.3;
}

.card__subtitle {
  margin: 4px 0 0;
  font-size: var(--type-hint-size);
  font-weight: var(--type-hint-weight);
  line-height: var(--type-hint-lh);
  color: var(--text-secondary);
}

.card__body {
  padding: 16px 18px 18px;
}

/* ── Instance detail ── */

.instance-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xs);
}

.instance-header__title {
  margin: 4px 0 0;
  font-size: var(--type-title-size);
  font-weight: var(--type-title-weight);
  letter-spacing: 0;
  line-height: 1.3;
}

.instance-header__id {
  margin: 6px 0 0;
  font-size: var(--type-hint-size);
  line-height: var(--type-hint-lh);
  color: var(--text-muted);
}

.instance-header__actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  flex-shrink: 0;
}

.instance-header__status-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.instance-header__copy {
  min-width: 120px;
}

.sticky-toolbar {
  position: sticky;
  top: var(--topbar-h);
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding: 10px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-muted);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.segmented__btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: var(--btn-label-size);
  font-weight: var(--btn-label-weight);
  letter-spacing: var(--btn-label-tracking);
  line-height: normal;
  font-kerning: none;
  font-variant-ligatures: none;
  text-transform: uppercase;
  padding: 0 14px;
  min-height: var(--control-h-compact);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

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

.segmented__btn.is-active {
  background: var(--accent);
  color: var(--accent-fg);
  box-shadow: var(--shadow-xs);
}

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

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

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

.span-12 { grid-column: span 12; }
.span-6 { grid-column: span 6; }

.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

/* ── Tables ── */

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

.data-table th,
.data-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: var(--type-hint-size);
  line-height: var(--type-hint-lh);
}

.data-table th {
  font-size: var(--type-hint-size);
  font-weight: var(--btn-label-weight);
  text-transform: uppercase;
  letter-spacing: var(--btn-label-tracking);
  color: var(--text-secondary);
  background: var(--surface-muted);
}

.data-table tbody tr:hover {
  background: var(--surface-hover);
}

.table-panel {
  max-height: 360px;
  overflow: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.chart-empty {
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: var(--type-body-size);
  font-weight: var(--type-body-weight);
  line-height: var(--type-body-lh);
  text-align: center;
  padding: 20px;
}

.chart-wrap {
  position: relative;
  height: 240px;
}

.chart-wrap--short {
  height: 200px;
}

.chart-card {
  min-height: 280px;
}

/* ── Status & tags ── */

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: var(--type-hint-size);
  font-weight: var(--btn-label-weight);
  letter-spacing: var(--btn-label-tracking);
  text-transform: uppercase;
  line-height: normal;
}

.status-pill.online {
  background: var(--online-bg);
  color: var(--online);
}

.status-pill.offline {
  background: var(--offline-bg);
  color: var(--offline);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}

.tag-pill {
  padding: 3px 8px;
  border-radius: 999px;
  font-size: var(--type-hint-size);
  font-weight: var(--type-title-weight);
  color: var(--badge-fg);
  background: var(--badge-bg);
}

.tag-pill--sm {
  font-size: 11px;
}

.health-pill {
  display: inline-block;
  font-size: 11px;
  font-weight: var(--type-title-weight);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.health-pill.is-ok {
  color: var(--online);
  background: var(--online-bg);
  border-color: transparent;
}

.health-pill.is-bad {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: transparent;
}

.mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
}

/* ── Buttons ── */

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  padding: 0 16px;
  min-height: var(--control-h);
  font-family: var(--font);
  font-size: var(--btn-label-size);
  font-weight: var(--btn-label-weight);
  letter-spacing: var(--btn-label-tracking);
  line-height: normal;
  font-kerning: none;
  font-variant-ligatures: none;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

a.btn,
a.btn:hover,
a.btn:focus,
a.btn:active {
  text-decoration: none;
}

.btn:hover {
  background: var(--surface-hover);
}

.btn-primary {
  background: var(--btn-primary-bg);
  border-color: transparent;
  color: var(--btn-primary-fg);
}

.btn-primary:hover {
  background: var(--btn-primary-hover-bg);
}

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

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

.btn-small {
  min-height: var(--control-h-compact);
  padding: 0 12px;
  font-size: var(--btn-label-size);
}

.btn-danger {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: transparent;
}

.btn__plus {
  font-size: 14px;
  line-height: 1;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--surface-muted);
  color: var(--text-primary);
}

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

[data-theme="light"] .icon-moon,
[data-theme="dark"] .icon-sun {
  display: none;
}

.toggle {
  position: relative;
  width: 40px;
  height: 24px;
  border: none;
  border-radius: 999px;
  background: var(--toggle-track);
  cursor: pointer;
}

.toggle.on {
  background: var(--toggle-track-on);
}

.toggle::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--toggle-knob);
  box-shadow: var(--shadow-xs);
  transition: transform 0.18s ease;
}

.toggle.on::after {
  transform: translateX(16px);
}

/* ── Settings & models ── */

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.settings-grid .span-12 {
  grid-column: span 2;
}

.settings-section-title {
  margin: 20px 0 8px;
  font-size: var(--type-title-size);
  font-weight: var(--type-title-weight);
  color: var(--text-primary);
}

.settings-hint {
  margin: 0 0 10px;
  font-size: var(--type-hint-size);
  font-weight: var(--type-hint-weight);
  line-height: var(--type-hint-lh);
  color: var(--text-secondary);
}

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

.model-card {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-muted);
}

.model-card__title {
  margin: 0;
  font-size: var(--type-title-size);
  font-weight: var(--type-title-weight);
  line-height: 1.3;
}

.model-card__time {
  font-size: var(--type-hint-size);
  line-height: var(--type-hint-lh);
  color: var(--text-muted);
}

.model-card__theme {
  margin: 8px 0;
  font-size: var(--type-hint-size);
  font-weight: var(--type-hint-weight);
  line-height: var(--type-hint-lh);
  color: var(--text-secondary);
}

.model-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: var(--type-hint-size);
  line-height: var(--type-hint-lh);
  color: var(--text-muted);
}

.model-card__head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--type-body-size);
  font-weight: var(--type-body-weight);
  line-height: var(--type-body-lh);
  color: var(--text-secondary);
}

.vehicle-check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 6px;
  max-height: 260px;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-muted);
}

.page-url-cell {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.code-block {
  width: 100%;
  min-height: 100px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  background: var(--surface-muted);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
  resize: vertical;
}

.copy-row {
  display: flex;
  gap: 10px;
}

.copy-row .code-block {
  flex: 1;
}

/* ── Modal ── */

.modal {
  border: none;
  padding: 0;
  width: min(400px, calc(100vw - 32px));
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.modal::backdrop {
  background: var(--modal-scrim);
  backdrop-filter: blur(4px);
}

.modal__body {
  padding: 20px;
}

.modal__head h3 {
  margin: 0;
  font-size: var(--type-title-size);
  font-weight: var(--type-title-weight);
  line-height: 1.3;
}

.modal__hint {
  margin: 6px 0 0;
  font-size: var(--type-body-size);
  font-weight: var(--type-body-weight);
  line-height: var(--type-body-lh);
  color: var(--text-muted);
}

.field {
  display: block;
  margin-top: 14px;
}

.field--inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 0;
}

.field--inline .field__label {
  margin-bottom: 0;
  white-space: nowrap;
}

.field__input--sm {
  width: auto;
  min-width: 108px;
  min-height: var(--control-h-compact);
  padding: 0 10px;
  font-size: var(--btn-label-size);
  font-weight: var(--btn-label-weight);
  letter-spacing: var(--btn-label-tracking);
  text-transform: uppercase;
}

.field__label {
  display: block;
  margin-bottom: 6px;
  font-size: var(--type-hint-size);
  font-weight: var(--type-title-weight);
  line-height: var(--type-hint-lh);
  color: var(--text-secondary);
}

.field__optional {
  font-weight: 500;
  color: var(--text-muted);
}

.field__input,
.field__textarea {
  width: 100%;
  min-height: var(--control-h);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 12px;
  font-family: var(--font);
  font-size: var(--type-body-size);
  font-weight: var(--type-body-weight);
  line-height: var(--type-body-lh);
  background: var(--surface-muted);
  color: var(--text-primary);
}

.field__input:focus,
.field__textarea:focus {
  outline: none;
  border-color: var(--focus-border);
  box-shadow: 0 0 0 2px var(--focus-ring);
}

.field__textarea {
  min-height: 96px;
  padding: 12px;
  resize: vertical;
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.login-error {
  min-height: 1.2em;
  margin: 8px 0 0;
  font-size: var(--type-hint-size);
  line-height: var(--type-hint-lh);
  color: var(--danger);
}

.empty-state {
  grid-column: 1 / -1;
  padding: 48px 20px;
  text-align: center;
  font-size: var(--type-body-size);
  line-height: var(--type-body-lh);
  color: var(--text-muted);
}

.eyebrow {
  margin: 0 0 4px;
  font-size: var(--type-hint-size);
  font-weight: var(--btn-label-weight);
  letter-spacing: var(--btn-label-tracking);
  text-transform: uppercase;
  line-height: var(--type-hint-lh);
  color: var(--text-muted);
}

/* ── Responsive ── */

@media (max-width: 1100px) {
  .stats-grid,
  .detail-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .span-6 {
    grid-column: span 12;
  }
}

@media (max-width: 768px) {
  .sidebar {
    display: none;
  }

  .main {
    padding: 16px;
  }

  .stats-grid--compact {
    grid-template-columns: repeat(2, 1fr);
  }

  .detail-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .segmented {
    width: 100%;
    overflow-x: auto;
  }

  .sticky-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .settings-grid .span-12 {
    grid-column: span 1;
  }
}

@media (max-width: 480px) {
  .stats-grid--compact,
  .detail-stats {
    grid-template-columns: 1fr;
  }

  .instance-card__metrics {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ── 2026 refresh: navigation, stats, command palette ── */

.sidebar__section {
  margin: 16px 0 6px;
  padding: 0 12px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.sidebar__section:first-child {
  margin-top: 0;
}

.sidebar__foot {
  margin-top: auto;
  padding-top: 12px;
}

.sidebar__search {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-muted);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: var(--type-hint-size);
  font-weight: var(--type-title-weight);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.sidebar__search:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
  color: var(--text-primary);
}

.sidebar__search-kbd {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
}

.page-head__subtitle {
  margin: 6px 0 0;
  max-width: 560px;
  font-size: var(--type-body-size);
  line-height: var(--type-body-lh);
  color: var(--text-secondary);
}

.stat-tile {
  position: relative;
  overflow: hidden;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.stat-tile:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
  border-color: var(--border-strong);
}

.stat-tile__label {
  margin: 0;
  font-size: var(--type-hint-size);
  font-weight: var(--type-hint-weight);
  line-height: var(--type-hint-lh);
  color: var(--text-secondary);
}

.stat-tile__hint {
  margin: 6px 0 0;
  font-size: 11px;
  line-height: 1.35;
  color: var(--text-muted);
}

.stat-tile--skeleton {
  pointer-events: none;
}

.skeleton {
  border-radius: 8px;
  background: linear-gradient(
    90deg,
    var(--surface-muted) 0%,
    var(--surface-hover) 50%,
    var(--surface-muted) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.2s ease-in-out infinite;
}

.skeleton--line {
  height: 12px;
  margin-bottom: 10px;
}

.skeleton--sm {
  width: 45%;
}

.skeleton--lg {
  width: 70%;
  height: 22px;
}

@keyframes skeleton-shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.empty-state-box {
  grid-column: 1 / -1;
  padding: 56px 24px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface-muted);
}

.empty-state-box__title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.empty-state-box__body {
  margin: 8px auto 16px;
  max-width: 420px;
  color: var(--text-secondary);
  font-size: var(--type-body-size);
  line-height: var(--type-body-lh);
}

.detail-list {
  display: grid;
  gap: 0;
}

.detail-list__row {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.detail-list__row:last-child {
  border-bottom: none;
}

.detail-list__row dt {
  margin: 0;
  font-size: var(--type-hint-size);
  font-weight: 600;
  color: var(--text-muted);
}

.detail-list__row dd {
  margin: 0;
  font-size: var(--type-body-size);
  color: var(--text-primary);
}

.toast-host {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 200;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  font-size: var(--type-body-size);
  animation: toast-in 0.22s ease;
}

.toast--success {
  border-color: var(--online);
  background: var(--online-bg);
}

.toast--info {
  border-color: var(--accent-blue);
  background: var(--accent-blue-soft);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal--command {
  width: min(560px, calc(100vw - 32px));
}

.command-palette__input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 14px;
  font-family: var(--font);
  font-size: 15px;
  background: var(--surface-muted);
  color: var(--text-primary);
}

.command-palette__input:focus {
  outline: none;
  border-color: var(--accent-blue);
}

.command-results {
  margin-top: 10px;
  max-height: 320px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.command-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font);
  text-align: left;
  cursor: pointer;
}

.command-item:hover,
.command-item.is-active {
  background: var(--accent-blue-soft);
}

.command-item__label {
  font-size: var(--type-body-size);
  font-weight: 600;
}

.command-item__hint {
  font-size: var(--type-hint-size);
  color: var(--text-muted);
  white-space: nowrap;
}

.command-empty,
.command-palette__hint {
  margin: 8px 0 0;
  font-size: var(--type-hint-size);
  color: var(--text-muted);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.topbar__menu {
  display: none;
}

.instance-card {
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.instance-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

@media (max-width: 768px) {
  .topbar__menu {
    display: inline-flex;
  }

  .sidebar {
    display: flex;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 120;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow-md);
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar.is-open::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: -1;
  }
}
