:root {
  --bg: #060a12;
  --panel: #0d1525;
  --card: #111d32;
  --card-hover: #142340;
  --line: #1e3050;
  --line-soft: #172843;
  --text: #e8eef6;
  --muted: #8da2c0;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.12);
  --accent-hover: #5a9bff;
  --ok: #34d399;
  --ok-bg: #0d3325;
  --ok-text: #a7f3d0;
  --warn: #fbbf24;
  --warn-bg: #3b2e12;
  --warn-text: #fde68a;
  --err: #f87171;
  --err-bg: #3b1414;
  --err-text: #fecaca;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

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

html {
  font-size: 14px;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 4px 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  flex-shrink: 0;
}

.brand h1 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.2;
}

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

.menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.menu-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.menu-item:hover {
  background: var(--accent-soft);
  color: var(--text);
}

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

.sidebar-footer {
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--muted);
  opacity: 0.6;
  text-align: center;
}

/* ── Main area ── */
.main {
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 1440px;
}

/* ── Topbar ── */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.topbar h2 {
  font-size: 20px;
  font-weight: 700;
}

.topbar p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

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

.auth-chip {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}

/* ── Tab panels ── */
.tab-panel {
  display: none;
  flex-direction: column;
  gap: 16px;
}

.tab-panel.active {
  display: flex;
}

/* ── Cards ── */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.card-header h3 {
  font-size: 15px;
  font-weight: 600;
}

.card-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 16px;
}

.card-form {
  background: var(--panel);
}

.card-narrow {
  max-width: 720px;
}

.form-hint {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
  line-height: 1.5;
}

.meta-line {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
}

/* ── Fields ── */
.field {
  margin-bottom: 12px;
}

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

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

input,
select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  transition: border-color 0.15s;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

input::placeholder {
  color: #4a5f7f;
}

select option {
  background: var(--panel);
}

/* ── Buttons ── */
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
}

.btn-primary {
  width: 100%;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, var(--accent), #2563eb);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  transition: opacity 0.15s;
}

.btn-primary:hover {
  opacity: 0.9;
}

.btn-sm {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  transition: background 0.15s;
}

.btn-sm:hover {
  background: rgba(59, 130, 246, 0.2);
}

.btn-outline {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s;
}

.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-danger-outline:hover {
  border-color: var(--err);
  color: var(--err);
}

/* ── Inline form ── */
.inline-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin-bottom: 14px;
}

.inline-form select {
  flex: 1;
}

.inline-form .btn-primary {
  width: auto;
  white-space: nowrap;
}

/* ── KPI grid ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}

.kpi {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.kpi .label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.kpi .value {
  font-size: 22px;
  font-weight: 700;
}

/* ── Sensor grid ── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
}

.sensor {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  line-height: 1.55;
}

.sensor strong {
  color: var(--accent);
  font-size: 13px;
}

.sensor small {
  color: var(--muted);
  font-size: 11px;
}

/* ── Tables ── */
.table-wrap {
  overflow-x: auto;
}

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

thead th {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 8px 10px;
  border-bottom: 2px solid var(--line);
  text-align: left;
}

tbody td {
  padding: 9px 10px;
  font-size: 13px;
  border-bottom: 1px solid var(--line-soft);
}

tbody tr:hover {
  background: rgba(59, 130, 246, 0.04);
}

/* ── Badges ── */
.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-acknowledged,
.status-online,
.status-active {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.status-queued,
.status-provisioning {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.status-offline,
.status-failed,
.status-disabled {
  background: var(--err-bg);
  color: var(--err-text);
}

/* ── Result box ── */
.result-box {
  white-space: pre-wrap;
  font-size: 12px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 10px;
  margin-top: 10px;
  max-height: 160px;
  overflow-y: auto;
  min-height: 0;
}

.result-box:empty {
  display: none;
}

/* ── Responsive ── */
@media (max-width: 1024px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .menu {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
  }

  .sidebar-footer {
    display: none;
  }

  .card-row {
    grid-template-columns: 1fr;
  }

  .field-row {
    grid-template-columns: 1fr;
  }
}
