:root {
  --teal-700: #0f766e;
  --teal-800: #115e59;
  --teal-50: #f0fdfa;
  --teal-100: #ccfbf1;
  --slate-900: #0f172a;
  --slate-800: #1e293b;
  --slate-700: #334155;
  --slate-600: #475569;
  --slate-500: #64748b;
  --slate-400: #94a3b8;
  --slate-200: #e2e8f0;
  --slate-100: #f1f5f9;
  --slate-50: #f8fafc;
  --emerald-600: #059669;
  --emerald-100: #d1fae5;
  --amber-600: #d97706;
  --amber-100: #fef3c7;
  --red-600: #dc2626;
  --red-100: #fee2e2;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--slate-50);
  color: var(--slate-900);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

h1, h2, h3, h4, .brand-title, .kpi-value {
  font-family: 'Montserrat', sans-serif;
  margin: 0;
}

.hidden {
  display: none !important;
}

/* Auth Gate */
.auth-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top left, #ccfbf1 0%, #f8fafc 48%, #e2e8f0 100%);
}

.auth-card {
  width: 100%;
  max-width: 460px;
  background: #fff;
  border: 1px solid var(--slate-200);
  border-radius: 20px;
  padding: 32px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
}

.brand-row, .sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--teal-700);
  color: #fff;
  font-family: 'Montserrat', sans-serif;
  font-weight: 800;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-title {
  font-size: 18px;
  font-weight: 800;
  color: var(--slate-900);
}

.brand-sub {
  font-size: 12px;
  color: var(--slate-500);
}

.stack-16 > * + * { margin-top: 16px; }
.stack-14 > * + * { margin-top: 14px; }

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--slate-700);
  margin-bottom: 6px;
}

.field input, .field textarea, .search-input, .select-input, .inline-form input {
  width: 100%;
  padding: 10px 13px;
  border-radius: 10px;
  border: 1px solid var(--slate-200);
  background: #fff;
  font-family: inherit;
  font-size: 13px;
  color: var(--slate-900);
  outline: none;
  transition: border-color 0.15s;
}

.field input:focus, .field textarea:focus, .search-input:focus, .select-input:focus {
  border-color: var(--teal-700);
}

.divider {
  border: 0;
  border-top: 1px solid var(--slate-200);
  margin: 18px 0;
}

.local-bridge-card {
  margin-top: 20px;
  padding: 14px;
  border-radius: 12px;
  background: var(--teal-50);
  border: 1px solid var(--teal-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.local-bridge-text strong {
  display: block;
  font-size: 12px;
  color: var(--teal-800);
}

.local-bridge-text span {
  font-size: 11px;
  color: var(--slate-600);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-sm { padding: 7px 12px; font-size: 12px; border-radius: 8px; }
.btn-xs { padding: 4px 9px; font-size: 11px; border-radius: 7px; }
.btn-block { width: 100%; padding: 12px 16px; }

.btn-primary { background: var(--teal-700); color: #fff; }
.btn-primary:hover { background: var(--teal-800); }

.btn-outline { background: #fff; border-color: var(--slate-200); color: var(--slate-800); }
.btn-outline:hover { background: var(--slate-100); }

.btn-danger-outline { background: #fff; border-color: #fca5a5; color: var(--red-600); }
.btn-danger-outline:hover { background: var(--red-100); }

.btn-ghost { background: transparent; color: var(--slate-600); }
.btn-ghost:hover { background: rgba(148, 163, 184, 0.15); }

.text-danger { color: var(--red-600) !important; }
.text-emerald { color: var(--emerald-600) !important; }

/* App Shell */
.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--slate-900);
  color: #fff;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar .brand-title { color: #fff; font-size: 16px; }
.sidebar .brand-sub { color: var(--slate-400); }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.nav-item {
  width: 100%;
  background: transparent;
  border: 0;
  color: var(--slate-400);
  padding: 11px 14px;
  border-radius: 10px;
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-item:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav-item.active { background: var(--teal-700); color: #fff; }

.nav-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: currentColor;
}

.nav-badge {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
}

.sidebar-footer {
  border-top: 1px solid var(--slate-800);
  padding-top: 16px;
}

.conn-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 8px;
}

.conn-cloud { background: rgba(16, 185, 129, 0.18); color: #6ee7b7; }
.conn-local { background: rgba(245, 158, 11, 0.2); color: #fcd34d; }

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

.admin-identity {
  font-size: 12px;
  color: var(--slate-400);
  word-break: break-all;
  margin-bottom: 10px;
}

.sidebar-actions {
  display: flex;
  gap: 6px;
}
.sidebar-actions .btn-ghost { color: var(--slate-400); padding: 6px 8px; }

/* Main Content */
.main-area {
  padding: 24px 32px 48px;
  overflow-x: auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.page-title { font-size: 22px; font-weight: 800; }
.page-subtitle { margin: 3px 0 0; font-size: 12px; color: var(--slate-500); }

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

.auto-refresh-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--slate-700);
  padding: 6px 10px;
  background: #fff;
  border: 1px solid var(--slate-200);
  border-radius: 8px;
}

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

/* KPIs */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: #fff;
  border: 1px solid var(--slate-200);
  border-radius: 16px;
  padding: 18px 20px;
}

.kpi-highlight {
  border-color: #99f6e4;
  background: linear-gradient(180deg, #ffffff 0%, #f0fdfa 100%);
}

.kpi-label { font-size: 12px; font-weight: 600; color: var(--slate-500); }
.kpi-value { font-size: 28px; font-weight: 800; margin: 6px 0 4px; }
.kpi-meta { font-size: 11px; color: var(--slate-500); }

/* Panels & Tables */
.split-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 20px;
}

.panel-card, .table-card {
  background: #fff;
  border: 1px solid var(--slate-200);
  border-radius: 16px;
  padding: 20px;
}

.table-card { padding: 0; overflow-x: auto; }

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

.panel-header h3 { font-size: 15px; font-weight: 700; }
.sub-heading { font-size: 13px; font-weight: 700; margin-bottom: 10px; color: var(--slate-700); }

.muted-tag {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--slate-100);
  color: var(--slate-600);
}

.helper-copy {
  font-size: 12px;
  color: var(--slate-600);
  margin: 0 0 16px;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr 1.2fr auto;
  gap: 8px;
  margin-bottom: 14px;
}

.filter-bar {
  display: grid;
  grid-template-columns: 1fr 200px 190px;
  gap: 12px;
  margin-bottom: 16px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 13px 16px;
  background: var(--slate-50);
  border-bottom: 1px solid var(--slate-200);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--slate-500);
}

.data-table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--slate-100);
  vertical-align: middle;
}

.data-table tr:hover td {
  background: #f8fafc;
}

/* Pills */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.badge-online { background: var(--emerald-100); color: var(--emerald-600); }
.badge-idle { background: var(--amber-100); color: var(--amber-600); }
.badge-offline { background: var(--slate-100); color: var(--slate-600); }
.badge-suspended { background: var(--red-100); color: var(--red-600); }
.badge-teal { background: var(--teal-100); color: var(--teal-800); }

.cell-primary { font-weight: 600; color: var(--slate-900); }
.cell-secondary { font-size: 11px; color: var(--slate-500); margin-top: 2px; }

/* Breakdown bars */
.bar-row { margin-bottom: 10px; }
.bar-meta { display: flex; justify-content: space-between; font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.bar-track { height: 8px; background: var(--slate-100); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--teal-700); border-radius: 999px; }

/* Feed */
.feed-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--slate-100);
  gap: 12px;
}
.feed-item:last-child { border-bottom: 0; }

.admins-list { display: flex; flex-direction: column; gap: 8px; }
.admin-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--slate-200);
  border-radius: 10px;
}

/* Alerts & Toast */
.alert { padding: 11px 14px; border-radius: 10px; font-size: 12px; margin-bottom: 16px; }
.alert-error { background: var(--red-100); color: #991b1b; }
.alert-info { background: var(--teal-50); color: var(--teal-800); border: 1px solid var(--teal-100); }

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 60;
  background: var(--slate-900);
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.25);
}

/* Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 50;
  display: flex;
  justify-content: flex-end;
}

.drawer-panel {
  width: 100%;
  max-width: 480px;
  background: #fff;
  height: 100%;
  display: flex;
  flex-direction: column;
  box-shadow: -12px 0 32px rgba(15, 23, 42, 0.15);
}

.drawer-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--slate-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.drawer-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.kv-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 10px 12px;
  font-size: 13px;
  margin-bottom: 20px;
}
.kv-key { color: var(--slate-500); font-weight: 600; }
.kv-val { color: var(--slate-900); word-break: break-word; }

.print-only { display: none; }

@media (max-width: 960px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .filter-bar, .two-col, .inline-form { grid-template-columns: 1fr; }
}

@media print {
  .no-print { display: none !important; }
  .print-only { display: block !important; margin-bottom: 16px; }
  .app-shell { display: block; }
  .main-area { padding: 0; }
  .tab-panel { display: block !important; margin-bottom: 28px; }
  #tab-controls { display: none !important; }
  body { background: #fff; }
}


/* Action Reason Modal & Badges */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  width: 100%;
  max-width: 460px;
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 20px 44px rgba(15, 23, 42, 0.25);
  border: 1px solid var(--slate-200);
}

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

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.badge-warn {
  background: #fef3c7;
  color: #92400e;
}

.badge-info {
  background: #e0f2fe;
  color: #0369a1;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--slate-700);
  cursor: pointer;
}

.timeline-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.timeline-item {
  padding: 10px 12px;
  border: 1px solid var(--slate-200);
  border-left: 3px solid var(--teal-700);
  border-radius: 8px;
  background: #f8fafc;
}

.timeline-item.timeline-danger {
  border-left-color: #dc2626;
  background: #fef2f2;
}

.timeline-item.timeline-warn {
  border-left-color: #d97706;
  background: #fffbeb;
}

.drawer-actions-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

.text-amber {
  color: #b45309;
}
