/* ============================================================
   Crony Hardware Console — styles.css
   Production-ready, dark/light mode, fully responsive.
   Design system: Instrument Serif (display) + DM Sans (body)
   ============================================================ */


/* ─── Google Fonts ──────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&display=swap');


/* ─── Design Tokens ─────────────────────────────────────────── */
:root {
  /* Light mode */
  --bg:           #f5f3ee;
  --surface:      #faf9f6;
  --surface-alt:  #f0ede6;
  --border:       #ddd9d0;
  --border-soft:  #e8e4da;
  --text:         #1a1814;
  --text-mid:     #4a4540;
  --text-muted:   #7a7670;
  --text-faint:   #b0ab9e;
  --primary:      #1a1814;
  --gold:         #c8960a;
  --gold-soft:    #f5edce;
  --success:      #437a22;
  --success-soft: #ecf5e6;
  --warning:      #b5651e;
  --warning-soft: #fdf0e3;
  --err:          #a12c4d;
  --err-soft:     #fce8ee;
  --info:         #006494;
  --info-soft:    #e3f1f9;

  /* Spacing scale */
  --sp-1:  0.25rem;
  --sp-2:  0.5rem;
  --sp-3:  0.75rem;
  --sp-4:  1rem;
  --sp-5:  1.25rem;
  --sp-6:  1.5rem;
  --sp-8:  2rem;
  --sp-10: 2.5rem;
  --sp-12: 3rem;
  --sp-16: 4rem;

  /* Typography */
  --font-display: 'Instrument Serif', Georgia, serif;
  --font-body:    'DM Sans', system-ui, -apple-system, sans-serif;
  --t-xs:   0.75rem;
  --t-sm:   0.8125rem;
  --t-base: 0.9375rem;
  --t-md:   1.0625rem;
  --t-lg:   1.25rem;
  --t-xl:   1.5rem;
  --t-2xl:  2rem;
  --t-3xl:  2.5rem;

  /* Layout */
  --sidebar-w: 220px;
  --topbar-h:  56px;
  --radius:    8px;
  --radius-sm: 4px;
  --radius-lg: 12px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow:    0 2px 8px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.05);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.10), 0 2px 8px rgba(0,0,0,0.06);

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --t-fast: 120ms;
  --t-mid:  200ms;
  --t-slow: 320ms;
}


[data-theme="dark"] {
  --bg:           #1a1814;
  --surface:      #201e1a;
  --surface-alt:  #252220;
  --border:       #35322c;
  --border-soft:  #2e2b25;
  --text:         #e8e4da;
  --text-mid:     #b0ab9e;
  --text-muted:   #7a7670;
  --text-faint:   #4a4540;
  --primary:      #e8e4da;
  --gold:         #e8af34;
  --gold-soft:    #2a2410;
  --success:      #5ea835;
  --success-soft: #1a2510;
  --warning:      #d07a35;
  --warning-soft: #2a1c0a;
  --err:          #d04870;
  --err-soft:     #280d15;
  --info:         #3d9ecb;
  --info-soft:    #0a1f2a;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.30);
  --shadow:    0 2px 8px rgba(0,0,0,0.40);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.50);
}


/* ─── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  font-family: var(--font-body);
  font-size: var(--t-base);
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  overflow-x: hidden;
  transition: background var(--t-slow) var(--ease), color var(--t-slow) var(--ease);
}

a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; border: none; background: none; }
pre, code { font-family: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace; }


/* ─── Layout Shell ──────────────────────────────────────────── */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  min-height: 100vh;
}


/* ─── Topbar ────────────────────────────────────────────────── */
.topbar {
  grid-column: 1 / -1;
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: 0 var(--sp-6);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topbar-h);
}

.topbar-logo {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-shrink: 0;
  text-decoration: none;
}

.topbar-logo svg { color: var(--gold); }

.topbar-wordmark {
  font-family: var(--font-display);
  font-size: var(--t-xl);
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1;
}

.topbar-sub {
  font-size: var(--t-xs);
  color: var(--text-muted);
  font-weight: 400;
  margin-top: 1px;
}

.topbar-spacer { flex: 1; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.topbar-connect-status {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--t-sm);
  color: var(--text-muted);
  padding: var(--sp-1) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
}

.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
  transition: background var(--t-mid) var(--ease);
}
.conn-dot.connected    { background: var(--success); }
.conn-dot.disconnected { background: var(--err); }
.conn-dot.connecting   { background: var(--warning); animation: pulse-dot 1s infinite; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}


/* ─── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  grid-column: 1;
  grid-row: 2;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: var(--sp-4) 0;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
}

.sidebar-section {
  padding: 0 var(--sp-4) var(--sp-2);
}

.sidebar-label {
  font-size: var(--t-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  padding: var(--sp-4) var(--sp-2) var(--sp-2);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius);
  font-size: var(--t-sm);
  font-weight: 500;
  color: var(--text-mid);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  margin: 1px 0;
}

.nav-item:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.nav-item.active {
  background: var(--gold-soft);
  color: var(--gold);
  font-weight: 600;
}

[data-theme="dark"] .nav-item.active {
  background: var(--gold-soft);
  color: var(--gold);
}

.nav-item .nav-icon {
  font-size: 1rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.nav-badge {
  margin-left: auto;
  font-size: var(--t-xs);
  font-weight: 700;
  background: var(--err);
  color: #fff;
  border-radius: 999px;
  padding: 0 var(--sp-1);
  min-width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-footer {
  margin-top: auto;
  padding: var(--sp-4);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}


/* ─── Main Content Area ─────────────────────────────────────── */
.main {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  overflow-y: auto;
  height: calc(100vh - var(--topbar-h));
}

.screen {
  display: none;
  padding: var(--sp-8);
  max-width: 1400px;
  animation: fadeInUp 180ms var(--ease) both;
}

.screen.active { display: block; }

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


/* ─── Page Header ───────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--sp-8);
  gap: var(--sp-4);
  flex-wrap: wrap;
}

.page-title {
  font-family: var(--font-display);
  font-size: var(--t-2xl);
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--text);
}

.page-subtitle {
  font-size: var(--t-sm);
  color: var(--text-muted);
  margin-top: var(--sp-1);
}

.page-actions {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
  flex-shrink: 0;
}


/* ─── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-6);
  box-shadow: var(--shadow-sm);
}

.card + .card { margin-top: var(--sp-4); }

.card-title {
  font-family: var(--font-display);
  font-size: var(--t-lg);
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--text);
  margin-bottom: var(--sp-4);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-4);
}

.card-header .card-title { margin-bottom: 0; }


/* ─── KPI / Stat Cards ──────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-5) var(--sp-6);
  box-shadow: var(--shadow-sm);
}

.kpi-label {
  font-size: var(--t-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: var(--sp-2);
}

.kpi-value {
  font-family: var(--font-display);
  font-size: var(--t-3xl);
  font-weight: 400;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.kpi-delta {
  font-size: var(--t-xs);
  margin-top: var(--sp-1);
  color: var(--text-muted);
}


/* ─── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius);
  font-size: var(--t-sm);
  font-weight: 500;
  line-height: 1.4;
  transition: all var(--t-fast) var(--ease);
  white-space: nowrap;
  cursor: pointer;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--primary);
  color: var(--bg);
  border-color: var(--primary);
}
.btn-primary:hover { opacity: 0.85; }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-ghost {
  background: transparent;
  color: var(--text-mid);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--surface-alt); color: var(--text); }

.btn-danger {
  background: var(--err-soft);
  color: var(--err);
  border-color: var(--err);
}
.btn-danger:hover { background: var(--err); color: #fff; }

.btn-gold {
  background: var(--gold);
  color: #fff;
  border-color: var(--gold);
  font-weight: 600;
}
.btn-gold:hover { opacity: 0.88; }
.btn-gold:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-sm {
  padding: var(--sp-1) var(--sp-3);
  font-size: var(--t-xs);
}

.btn-lg {
  padding: var(--sp-3) var(--sp-6);
  font-size: var(--t-md);
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  justify-content: center;
  border-radius: var(--radius);
}


/* ─── Badges & Tags ─────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: var(--t-xs);
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.badge-online  { background: var(--success-soft); color: var(--success); }
.badge-offline { background: var(--surface-alt);  color: var(--text-muted); }
.badge-warn    { background: var(--warning-soft);  color: var(--warning); }
.badge-err     { background: var(--err-soft);      color: var(--err); }

.tag {
  display: inline-flex;
  align-items: center;
  font-size: var(--t-xs);
  font-weight: 500;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  border: 1px solid transparent;
}

.tag-config  { background: var(--info-soft);    color: var(--info);    border-color: #c0dced; }
.tag-action  { background: var(--gold-soft);    color: var(--gold);    border-color: #e8d59a; }
.tag-risk    { background: var(--err-soft);     color: var(--err);     border-color: #f0c0cc; }
.tag-monitor { background: var(--success-soft); color: var(--success); border-color: #c8e0b8; }

[data-theme="dark"] .tag-config  { border-color: #1a3a4a; }
[data-theme="dark"] .tag-action  { border-color: #3a2e0a; }
[data-theme="dark"] .tag-risk    { border-color: #3a0e1a; }
[data-theme="dark"] .tag-monitor { border-color: #1a3a0a; }

.fw-chip {
  display: inline-block;
  font-size: var(--t-xs);
  font-weight: 600;
  font-family: monospace;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text-mid);
}


/* ─── Forms ─────────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
}

.field-label {
  font-size: var(--t-sm);
  font-weight: 600;
  color: var(--text-mid);
}

.field-hint {
  font-size: var(--t-xs);
  color: var(--text-muted);
}

input[type="text"],
input[type="email"],
input[type="number"],
input[type="url"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: var(--t-sm);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(200,150,10,0.12);
}

[data-theme="dark"] input:focus,
[data-theme="dark"] select:focus,
[data-theme="dark"] textarea:focus {
  box-shadow: 0 0 0 3px rgba(232,175,52,0.16);
}

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

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%237a7670' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}


/* ─── Tables ────────────────────────────────────────────────── */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--t-sm);
}

thead tr {
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
}

th {
  padding: var(--sp-3) var(--sp-4);
  text-align: left;
  font-size: var(--t-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  white-space: nowrap;
}

td {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border-soft);
  color: var(--text);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }

tbody tr {
  transition: background var(--t-fast) var(--ease);
  cursor: pointer;
}
tbody tr:hover { background: var(--surface-alt); }

.device-name-cell {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.device-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: var(--t-xs);
  font-weight: 700;
  color: var(--text-mid);
  font-family: monospace;
}

.device-name-text {
  font-weight: 600;
  color: var(--text);
  font-size: var(--t-base);
}

.device-id-text {
  font-size: var(--t-xs);
  color: var(--text-muted);
  font-family: monospace;
}


/* ─── Fleet Filter Bar ──────────────────────────────────────── */
.fleet-bar {
  display: flex;
  gap: var(--sp-3);
  margin-bottom: var(--sp-6);
  align-items: center;
  flex-wrap: wrap;
}

.fleet-search-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
}

.fleet-search-wrap input {
  padding-left: var(--sp-8);
}

.fleet-search-icon {
  position: absolute;
  left: var(--sp-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  pointer-events: none;
  font-size: var(--t-sm);
}

.filter-tabs {
  display: flex;
  gap: var(--sp-1);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
}

.filter-tab {
  padding: var(--sp-1) var(--sp-3);
  border-radius: calc(var(--radius) - 2px);
  font-size: var(--t-xs);
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--t-fast) var(--ease);
  border: none;
  background: none;
}

.filter-tab:hover { color: var(--text); }
.filter-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}


/* ─── Prompt Textarea (Workbench) ───────────────────────────── */
.prompt-area {
  width: 100%;
  min-height: 120px;
  padding: var(--sp-4);
  font-size: var(--t-base);
  line-height: 1.6;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  resize: vertical;
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
  outline: none;
  font-family: var(--font-body);
}

.prompt-area:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(200,150,10,0.12);
}

.prompt-area::placeholder { color: var(--text-faint); }


/* ─── Workbench / Firmware layout ───────────────────────────── */
.workbench-layout,
.firmware-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: var(--sp-6);
  align-items: flex-start;
}

@media (max-width: 900px) {
  .workbench-layout,
  .firmware-layout {
    grid-template-columns: minmax(0, 1.4fr) minmax(260px, 300px);
  }
}

@media (max-width: 720px) {
  .workbench-layout,
  .firmware-layout {
    grid-template-columns: 1fr;
  }
}


/* ─── Workbench Plan Output ─────────────────────────────────── */
.plan-output {
  margin-top: var(--sp-6);
}

.plan-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--sp-4);
  gap: var(--sp-4);
  flex-wrap: wrap;
}

.plan-intent {
  font-family: var(--font-display);
  font-size: var(--t-xl);
  font-weight: 400;
  color: var(--text);
  line-height: 1.3;
}

.plan-meta {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
  margin-top: var(--sp-2);
}

.plan-steps {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  margin-bottom: var(--sp-6);
}

.plan-step {
  display: flex;
  gap: var(--sp-4);
  padding: var(--sp-4);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  align-items: flex-start;
}

.step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--bg);
  font-size: var(--t-xs);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.step-content { flex: 1; min-width: 0; }

.step-label {
  font-weight: 600;
  font-size: var(--t-sm);
  color: var(--text);
}

.step-desc {
  font-size: var(--t-xs);
  color: var(--text-muted);
  margin-top: 2px;
}

.step-params {
  margin-top: var(--sp-2);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.param-item {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: var(--sp-2);
  align-items: baseline;
}

.param-key {
  font-size: var(--t-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: capitalize;
}

.param-val {
  font-size: var(--t-sm);
  color: var(--text);
  font-family: monospace;
}

.param-desc {
  font-size: var(--t-xs);
  color: var(--text-faint);
  grid-column: 2;
  margin-top: -2px;
}


/* ─── Risk Badge ────────────────────────────────────────────── */
.risk-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: var(--t-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 10px;
  border-radius: 999px;
}
.risk-low      { background: var(--success-soft); color: var(--success); }
.risk-medium   { background: var(--warning-soft); color: var(--warning); }
.risk-high     { background: var(--err-soft);     color: var(--err); }
.risk-critical { background: var(--err);          color: #fff; }


/* ─── Command Log / Timeline ────────────────────────────────── */
.timeline-filters {
  display: flex;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
  align-items: center;
  flex-wrap: wrap;
}

.timeline-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.cmd-row {
  display: grid;
  grid-template-columns: 36px 1fr auto auto 36px;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: background var(--t-fast) var(--ease);
}

.cmd-row:hover { background: var(--surface-alt); }

.cmd-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.cmd-info { min-width: 0; }

.cmd-name {
  font-size: var(--t-sm);
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cmd-device {
  font-size: var(--t-xs);
  color: var(--text-muted);
  font-family: monospace;
}

.cmd-time {
  font-size: var(--t-xs);
  color: var(--text-faint);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.cmd-payload-toggle {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-faint);
  font-size: var(--t-sm);
  transition: all var(--t-fast) var(--ease);
  user-select: none;
}
.cmd-payload-toggle:hover { background: var(--surface-alt); color: var(--text); }

.cmd-payload {
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  font-size: var(--t-xs);
  overflow-x: auto;
}

.cmd-payload pre {
  color: var(--text-mid);
  white-space: pre-wrap;
  word-break: break-all;
}

.console-ts {
  font-size: var(--t-xs);
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  font-family: monospace;
}


/* ─── Firmware Console ──────────────────────────────────────── */
.firmware-output {
  min-height: 200px;
}

.fw-plan {
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
}

.fw-section {
  padding: var(--sp-5);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.fw-section-title {
  font-family: var(--font-display);
  font-size: var(--t-lg);
  font-weight: 400;
  color: var(--text);
  margin-bottom: var(--sp-3);
  letter-spacing: -0.01em;
}

.fw-plan-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
}

.fw-spec-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--sp-3) var(--sp-6);
}

.fw-spec-label {
  font-size: var(--t-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.fw-artifacts {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.fw-artifact {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--t-sm);
}

.fw-artifact a {
  color: var(--gold);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.fw-artifact .artifact-size {
  margin-left: auto;
  font-size: var(--t-xs);
  color: var(--text-muted);
  font-family: monospace;
}

.fw-build-steps {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  counter-reset: build-step;
}

.fw-tests {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.fw-test-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius);
  font-size: var(--t-sm);
  background: var(--surface);
  border: 1px solid var(--border);
}

.fw-test-icon {
  color: var(--success);
  font-size: var(--t-sm);
}


/* ─── Device Detail ─────────────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-6);
  margin-bottom: var(--sp-6);
}

.detail-hero {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
  padding-bottom: var(--sp-6);
  border-bottom: 1px solid var(--border);
}

.detail-device-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-lg);
  background: var(--gold-soft);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--t-md);
  font-weight: 700;
  color: var(--gold);
  font-family: monospace;
  flex-shrink: 0;
}

[data-theme="dark"] .detail-device-icon {
  background: var(--gold-soft);
  color: var(--gold);
}

.detail-name {
  font-family: var(--font-display);
  font-size: var(--t-2xl);
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.detail-id {
  font-size: var(--t-xs);
  color: var(--text-muted);
  font-family: monospace;
  margin-top: 2px;
}

.detail-meta {
  display: flex;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-top: var(--sp-2);
  align-items: center;
}

.detail-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-3);
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.info-label {
  font-size: var(--t-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.info-val {
  font-size: var(--t-sm);
  color: var(--text);
  font-family: monospace;
}


/* ─── Chart Container ───────────────────────────────────────── */
.chart-wrap {
  position: relative;
  height: 220px;
  margin-top: var(--sp-4);
}

.chart-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--text-muted);
  font-size: var(--t-sm);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
}


/* ─── Log Entries ───────────────────────────────────────────── */
.log-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: var(--t-xs);
  font-family: monospace;
  max-height: 300px;
  overflow-y: auto;
}

.log-row {
  display: grid;
  grid-template-columns: 80px 50px 1fr;
  gap: var(--sp-2);
  padding: 3px var(--sp-2);
  border-radius: var(--radius-sm);
  align-items: baseline;
  line-height: 1.4;
}

.log-row:hover { background: var(--surface-alt); }

.log-ts    { color: var(--text-faint); }
.log-level { font-weight: 700; text-transform: uppercase; }
.log-level.info  { color: var(--info); }
.log-level.warn  { color: var(--warning); }
.log-level.error { color: var(--err); }
.log-level.debug { color: var(--text-muted); }
.log-msg { color: var(--text-mid); word-break: break-word; }


/* ─── Code / Pre ────────────────────────────────────────────── */
pre {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-4);
  font-size: var(--t-xs);
  line-height: 1.7;
  overflow-x: auto;
  color: var(--text-mid);
  white-space: pre;
}

code {
  font-size: 0.9em;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1px 5px;
  color: var(--text-mid);
}


/* ─── Modals ────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  animation: fadeIn var(--t-mid) var(--ease);
}

.modal-overlay.is-open {
  display: flex;
}

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

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp var(--t-mid) var(--ease);
}

.modal-lg { max-width: 760px; }
.modal-xl { max-width: 960px; }

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-5) var(--sp-6);
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-family: var(--font-display);
  font-size: var(--t-xl);
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--text);
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  transition: all var(--t-fast) var(--ease);
  border: none;
  background: none;
}
.modal-close:hover { background: var(--surface-alt); color: var(--text); }

.modal-body {
  padding: var(--sp-6);
}

.modal-footer {
  padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-3);
}


/* ─── Onboarding Steps ──────────────────────────────────────── */
.onboard-step-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}

.onboard-step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--gold);
  color: #fff;
  font-size: var(--t-xs);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.onboard-step-label {
  font-size: var(--t-sm);
  font-weight: 600;
  color: var(--text);
}

.sketch-block {
  position: relative;
}

.sketch-lang-badge {
  position: absolute;
  top: var(--sp-2);
  right: var(--sp-2);
  font-size: var(--t-xs);
  font-weight: 600;
  background: var(--gold);
  color: #fff;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}

.sketch-code {
  max-height: 340px;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-4);
  font-size: var(--t-xs);
  font-family: monospace;
  white-space: pre;
  color: var(--text-mid);
  margin-top: var(--sp-3);
}

.device-id-display {
  font-family: monospace;
  font-size: var(--t-sm);
  font-weight: 700;
  color: var(--gold);
  background: var(--gold-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-2) var(--sp-3);
  margin-bottom: var(--sp-4);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.type-notes {
  font-size: var(--t-xs);
  color: var(--text-muted);
  margin-top: var(--sp-1);
  font-style: italic;
}


/* ─── Toast Notifications ───────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: var(--sp-6);
  right: var(--sp-6);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  font-size: var(--t-sm);
  font-weight: 500;
  color: var(--text);
  pointer-events: all;
  animation: toastIn 220ms var(--ease) both;
  max-width: 380px;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

.toast.fade-out {
  animation: toastOut 180ms var(--ease) both;
}

@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(20px); }
}

.toast-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.toast.success .toast-dot { background: var(--success); }
.toast.error   .toast-dot { background: var(--err); }
.toast.warn    .toast-dot { background: var(--warning); }
.toast.info    .toast-dot { background: var(--info); }


/* ─── Alert Count Badge ─────────────────────────────────────── */
.alert-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--t-xs);
  font-weight: 700;
  background: var(--err);
  color: #fff;
  border-radius: 999px;
  padding: 0 var(--sp-1);
  min-width: 18px;
  height: 18px;
}


/* ─── Tour Overlay ──────────────────────────────────────────── */
#tour-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 800;
  pointer-events: none;
  background: rgba(0,0,0,0.35);
}

#tour-tooltip {
  position: fixed;
  bottom: var(--sp-8);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--sp-6);
  max-width: 420px;
  width: calc(100vw - 2rem);
  pointer-events: all;
  z-index: 801;
}

#tour-title {
  font-family: var(--font-display);
  font-size: var(--t-xl);
  font-weight: 400;
  color: var(--text);
  margin-bottom: var(--sp-2);
}

#tour-body {
  font-size: var(--t-sm);
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: var(--sp-5);
}

.tour-actions {
  display: flex;
  gap: var(--sp-3);
  justify-content: flex-end;
}


/* ─── Empty & Loading States ────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-4);
  padding: var(--sp-16);
  text-align: center;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 2.5rem;
  opacity: 0.4;
}

.empty-title {
  font-family: var(--font-display);
  font-size: var(--t-xl);
  color: var(--text);
}

.empty-desc {
  font-size: var(--t-sm);
  color: var(--text-muted);
  max-width: 340px;
}

.skeleton {
  background: linear-gradient(90deg, var(--surface-alt) 25%, var(--border-soft) 50%, var(--surface-alt) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
}

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


/* ─── Dividers ──────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
  margin: var(--sp-6) 0;
}


/* ─── Utility ───────────────────────────────────────────────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border-width: 0;
}

.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); }
.gap-4 { gap: var(--sp-4); }
.mt-2  { margin-top: var(--sp-2); }
.mt-4  { margin-top: var(--sp-4); }
.mt-6  { margin-top: var(--sp-6); }
.mb-4  { margin-bottom: var(--sp-4); }
.mb-6  { margin-bottom: var(--sp-6); }
.text-sm     { font-size: var(--t-sm); }
.text-xs     { font-size: var(--t-xs); }
.text-muted  { color: var(--text-muted); }
.text-faint  { color: var(--text-faint); }
.text-gold   { color: var(--gold); }
.text-success { color: var(--success); }
.text-err    { color: var(--err); }
.font-mono   { font-family: monospace; }
.font-bold   { font-weight: 700; }
.truncate    { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden      { display: none !important; }


/* ─── Scrollbar Styling ─────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }


/* ─── Focus Visible ─────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}


/* ─── Responsive ────────────────────────────────────────────── */
@media (max-width: 900px) {
  :root { --sidebar-w: 200px; }
}

@media (max-width: 720px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: var(--topbar-h) auto 1fr;
  }

  .sidebar {
    grid-column: 1;
    grid-row: 2;
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    padding: var(--sp-2) var(--sp-3);
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    gap: var(--sp-1);
  }

  .sidebar-label { display: none; }
  .sidebar-footer { display: none; }
  .sidebar-section { padding: 0; display: contents; }

  .nav-item {
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--radius);
    flex-shrink: 0;
  }

  .main {
    grid-column: 1;
    grid-row: 3;
  }

  .screen { padding: var(--sp-5) var(--sp-4); }

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

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

  .page-header { flex-direction: column; align-items: flex-start; }

  .cmd-row {
    grid-template-columns: 32px 1fr auto auto;
  }
  .cmd-time { display: none; }

  .modal { max-width: 100%; margin: var(--sp-4); border-radius: var(--radius); }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .topbar-sub { display: none; }
  .screen { padding: var(--sp-4) var(--sp-3); }
  .page-title { font-size: var(--t-xl); }
}


/* ─── Print ─────────────────────────────────────────────────── */
@media print {
  .sidebar,
  .topbar,
  .btn,
  .modal-overlay { display: none !important; }
  .main { grid-column: 1 / -1; }
  .screen.active { display: block !important; }
  body { background: #fff; color: #000; }
}


/* ─── Mobile screen switcher ────────────────────────────────── */
.mobile-screen-switcher {
  display: none;
  margin-bottom: var(--sp-4);
}

/* Icon-like styling for the dropdown */
.mobile-screen-switcher select {
  max-width: 260px;
  font-size: var(--t-sm);
}

/* When below 720px: hide sidebar completely and use dropdown only */
@media (max-width: 720px) {
  .sidebar {
    display: none;
  }

  .mobile-screen-switcher {
    display: block;
    padding: 0 var(--sp-4);
  }

  .mobile-screen-switcher select {
    width: 100%;
  }
}