:root {
  --bg-deep: #0f0a07;
  --bg: #16100b;
  --surface: #221910;
  --surface-2: #2c2116;
  --surface-3: #362818;
  --border: #5a4528;
  --border-soft: #3d2e1c;
  --gold: #e4b429;
  --gold-bright: #f5d061;
  --gold-dim: #a67c00;
  --text: #f8edd8;
  --muted: #a89578;
  --online: #45e08a;
  --offline: #e89555;
  --danger: #c94a4a;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

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

html { font-size: 15px; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg-deep);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* —— Login —— */
.login-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(228, 180, 41, 0.12), transparent),
    linear-gradient(180deg, #1a120c 0%, var(--bg-deep) 100%);
}

.login-card {
  width: min(420px, 100%);
  background: linear-gradient(165deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  padding: 2.25rem;
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-bottom: 2rem;
}

.login-logo {
  font-size: 2rem;
  color: var(--gold);
  filter: drop-shadow(0 0 12px rgba(228, 180, 41, 0.4));
}

.login-brand h1 {
  margin: 0;
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.login-brand p {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.login-fields label {
  display: block;
  margin-bottom: 1rem;
}

.login-fields label span {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.login-fields input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  background: var(--bg-deep);
  color: var(--text);
  font-size: 1rem;
}

.login-fields input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(228, 180, 41, 0.15);
}

.login-err {
  color: #ff7b7b;
  font-size: 0.9rem;
  margin-top: 1rem;
  text-align: center;
}

/* —— App shell —— */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse 100% 60% at 50% 0%, rgba(228, 180, 41, 0.06), transparent 55%),
    var(--bg-deep);
}

.app-header {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.85rem 1.75rem;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(34, 25, 16, 0.92);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand-block {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  min-width: 200px;
}

.brand-mark { color: var(--gold); font-size: 1.1rem; }
.brand-name { font-weight: 700; font-size: 1.15rem; letter-spacing: -0.02em; }
.brand-ver { color: var(--muted); font-size: 0.8rem; font-weight: 500; }

.main-nav {
  display: flex;
  gap: 0.35rem;
  flex: 1;
  justify-content: center;
  flex-wrap: wrap;
}

.nav-pill {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 0.45rem 1.1rem;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.nav-pill:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.nav-pill.active {
  color: var(--gold-bright);
  border-color: var(--gold);
  background: rgba(228, 180, 41, 0.08);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 200px;
  justify-content: flex-end;
}

.live-badge {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  color: var(--muted);
}

.live-badge.on {
  color: var(--online);
  border-color: rgba(69, 224, 138, 0.35);
  background: rgba(69, 224, 138, 0.08);
}

.live-badge.on::before {
  content: "● ";
}

.user-chip {
  font-size: 0.85rem;
  color: var(--muted);
  padding: 0.35rem 0.65rem;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
}

.app-body {
  flex: 1;
  padding: 1.5rem 1.75rem 2rem;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

.app-footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.75rem;
  color: var(--muted);
  border-top: 1px solid var(--border-soft);
  opacity: 0.7;
}

/* —— Metrics —— */
.metric-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.metric-row-3 {
  grid-template-columns: repeat(3, 1fr);
}

@media (max-width: 992px) {
  .metric-row { grid-template-columns: repeat(2, 1fr); }
  .metric-row-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .metric-row { grid-template-columns: 1fr; }
}

.metric-card {
  background: linear-gradient(145deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
}

.metric-card.highlight {
  border-color: rgba(69, 224, 138, 0.25);
  background: linear-gradient(145deg, #1a2e22, var(--surface));
}

.metric-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.metric-value {
  font-size: 2.75rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
}

.metric-value.accent { color: var(--gold); }
.metric-value.online { color: var(--online); }
.metric-value.warn { color: var(--offline); }

/* —— Cards —— */
.card {
  background: linear-gradient(180deg, var(--surface-2) 0%, var(--surface) 100%);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.card-head h2, .card-head h3 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.card-head-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--bg-deep);
  border: 1px solid var(--border-soft);
}

.segment {
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.35rem 0.85rem;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  background: transparent;
  color: var(--muted);
}

.segment.active {
  background: rgba(228, 180, 41, 0.15);
  color: var(--gold-bright);
}

.badge.deleted {
  background: rgba(201, 74, 74, 0.15);
  color: #ff8a8a;
  border: 1px solid rgba(201, 74, 74, 0.35);
}

.select-toolbar {
  min-width: 140px;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-deep);
  color: var(--text);
  font-family: inherit;
  font-size: 0.88rem;
}

/* Section divider — smooth ribbon, no center seam */
.devices-ribbon {
  --ribbon-h: 22px;
  height: var(--ribbon-h);
  margin: 1.75rem 0 1.35rem;
  border: none;
  border-radius: 3px;
  background: linear-gradient(
    180deg,
    #c9981a 0%,
    #f5d061 42%,
    #e4b429 58%,
    #a67c00 100%
  );
  box-shadow:
    0 1px 0 rgba(255, 236, 180, 0.25) inset,
    0 4px 18px rgba(0, 0, 0, 0.35),
    0 0 28px rgba(228, 180, 41, 0.15);
  clip-path: polygon(
    0.4rem 0,
    calc(100% - 0.4rem) 0,
    100% 50%,
    calc(100% - 0.4rem) 100%,
    0.4rem 100%,
    0 50%
  );
  opacity: 0.92;
}

.deleted-devices-block {
  padding-top: 0.25rem;
}

.subhead-row {
  margin-bottom: 0.75rem;
}

.subhead-row h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--gold-bright);
}

.empty-inline {
  padding: 1.25rem;
  font-style: italic;
}

.table-wrap-compact {
  border-color: rgba(90, 69, 40, 0.5);
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  flex: 1;
  justify-content: flex-end;
  min-width: 280px;
}

.lead {
  color: var(--muted);
  margin: -0.5rem 0 1.25rem;
  font-size: 0.92rem;
  max-width: 720px;
}

.subhead {
  margin: 1.25rem 0 0.5rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

/* —— Forms —— */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.field span {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.field input,
.field select,
.input,
.select-sm {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  background: var(--bg-deep);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}

.field.readonly input {
  opacity: 0.85;
  cursor: default;
}

.field input:focus,
.input:focus,
.field select:focus {
  outline: none;
  border-color: var(--gold);
}

.input.grow { flex: 1; min-width: 200px; }

.btn-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }

.file-drop {
  display: block;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 1.5rem;
  text-align: center;
  margin-bottom: 1rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.file-drop:hover {
  border-color: var(--gold);
  background: rgba(228, 180, 41, 0.04);
}

.file-drop input { display: none; }

.file-drop-label { color: var(--muted); font-size: 0.9rem; }

.split-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

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

/* —— Buttons —— */
.btn {
  font-family: inherit;
  font-weight: 600;
  font-size: 0.88rem;
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: transform 0.1s, filter 0.15s;
}

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

.btn-primary {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold-dim));
  color: #1a1008;
  box-shadow: 0 2px 8px rgba(228, 180, 41, 0.25);
}

.btn-primary:hover { filter: brightness(1.05); }

.btn-secondary {
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border-soft);
}

.btn-ghost:hover { color: var(--text); border-color: var(--border); }

.btn-danger {
  background: linear-gradient(180deg, #d65555, #9e3333);
  color: #fff;
  font-size: 0.78rem;
  padding: 0.35rem 0.7rem;
}

.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.78rem; }
.btn-block { width: 100%; margin-top: 0.5rem; padding: 0.7rem; }
.btn-icon { font-size: 1.35rem; line-height: 1; padding: 0.25rem 0.5rem; }

/* —— Tables —— */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--border-soft); }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.data-table thead {
  background: rgba(0, 0, 0, 0.25);
}

.data-table th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  border-bottom: 1px solid var(--border-soft);
}

.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(61, 46, 28, 0.6);
  vertical-align: middle;
}

.data-table tbody tr:hover td {
  background: rgba(228, 180, 41, 0.03);
}

.data-table.compact td,
.data-table.compact th { padding: 0.55rem 0.75rem; font-size: 0.82rem; }

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.badge.on {
  background: rgba(69, 224, 138, 0.15);
  color: var(--online);
  border: 1px solid rgba(69, 224, 138, 0.35);
}

.badge.off {
  background: rgba(232, 149, 85, 0.12);
  color: var(--offline);
  border: 1px solid rgba(232, 149, 85, 0.3);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.row-actions .btn-primary,
.row-actions .btn-secondary {
  font-size: 0.75rem;
  padding: 0.3rem 0.65rem;
}

.row-actions button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.empty-state {
  text-align: center;
  padding: 2.5rem 1.5rem;
  color: var(--muted);
  font-size: 0.92rem;
  margin: 0;
}

.empty-state.hidden { display: none; }

/* —— Code blocks —— */
.code-block {
  font-family: var(--mono);
  font-size: 0.82rem;
  background: var(--bg-deep);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 1rem 1.15rem;
  overflow-x: auto;
  margin: 0;
  line-height: 1.55;
}

.code-block.terminal { min-height: 120px; max-height: 280px; overflow-y: auto; }

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

.result-panel {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-soft);
}

.result-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

/* —— Shell modal —— */
.shell-modal {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  width: min(860px, 94vw);
  padding: 0;
  box-shadow: var(--shadow);
}

.shell-modal::backdrop {
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
}

.shell-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-soft);
}

.shell-label {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.shell-host { font-weight: 600; font-size: 1rem; }

.shell-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1.25rem;
  border-bottom: 1px solid var(--border-soft);
}

.shell-screen {
  min-height: 320px;
  max-height: 480px;
  padding: 0.5rem;
  background: #0a0705;
}

.hint-inline { color: var(--muted); font-size: 0.82rem; }

.mono-id {
  font-family: var(--mono);
  color: var(--muted);
  font-size: 0.75rem;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  border: 1px solid var(--gold);
  color: var(--text);
  font-size: 0.88rem;
  box-shadow: var(--shadow);
  max-width: min(420px, 90vw);
  text-align: center;
}

.file-drop.dragover {
  border-color: var(--gold-bright);
  background: rgba(228, 180, 41, 0.08);
}

.file-drop.has-file .file-drop-label {
  color: var(--gold-bright);
}
