:root {
  color-scheme: light;
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel-2: #f1f5f9;
  --line: #e2e8f0;
  --line-soft: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --sidebar-bg: #0f172a;
  --sidebar-sub: #0b1120;
  --sidebar-hover: #1e293b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-ink: #ffffff;
  --danger: #e11d48;
  --ok: #059669;
  --ok-dot: #10b981;
  --warn: #d97706;
  --radius: 12px;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, .05), 0 2px 4px -2px rgba(0, 0, 0, .04);
  --mono: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-family: 'Inter', -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
}

* { box-sizing: border-box; }
[x-cloak] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); overflow-x: hidden; }
.mono, code { font-family: var(--mono); }
.muted { color: var(--muted); }
.num { text-align: end; font-variant-numeric: tabular-nums; }
.spacer { flex: 1; }
.error, .login-error { color: var(--danger); }
.warn-text { color: var(--warn); font-weight: 600; }
.danger-text { color: var(--danger); font-weight: 600; }
.ok-text { color: var(--ok); font-weight: 600; }

/* ---------- Layout & Sidebar ---------- */
.tsms-layout { display: flex; min-block-size: 100dvh; }
.sidebar {
  inline-size: 260px; background-color: var(--sidebar-bg); color: #fff;
  min-block-size: 100dvh; position: fixed; inset-block-start: 0; inset-inline-start: 0; z-index: 100;
  display: flex; flex-direction: column;
  transition: transform .22s ease;
}
.sidebar-collapsed .sidebar { transform: translateX(-100%); }
.sidebar-brand {
  padding: 1.3rem 1.25rem 1.3rem 1.4rem; border-block-end: 1px solid #1e293b;
  display: flex; align-items: center; gap: 0.85rem;
}
.sidebar-brand .logo-placeholder img {
  inline-size: 40px; block-size: 40px; object-fit: contain;
  background: #fff; border-radius: 8px; padding: 3px;
}
.sidebar-brand .brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.sidebar-brand .brand-tsms { font-size: 1.35rem; font-weight: 800; letter-spacing: 1px; color: #fff; }
.sidebar-brand .brand-command { font-size: 0.78rem; font-weight: 700; letter-spacing: 1.8px; color: #38bdf8; }

.sidebar-selector {
  padding: 1rem 1.4rem; background-color: var(--sidebar-sub);
  border-block-end: 1px solid rgba(148, 163, 184, .18);
  display: grid; gap: 6px;
}
.selector-label {
  color: #94a3b8; font-size: 0.7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1px; margin-block-start: 4px;
}
.sidebar-selector select {
  inline-size: 100%; background-color: #1e293b; color: #fff;
  border: 1px solid #334155; border-radius: 6px; padding: 6px 10px;
  font-size: 0.85rem; font-weight: 500; cursor: pointer;
}
.plat-row { display: flex; align-items: center; gap: 8px; }
.plat-row select { flex: 1; }

.menu-label {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em;
  color: #64748b; margin: 1.2rem 1.4rem 0.4rem; font-weight: 700;
}
.sidebar-nav { display: flex; flex-direction: column; }
.menu-item {
  display: flex; align-items: center; gap: 10px; inline-size: 100%;
  padding: 0.72rem 1.4rem; color: #cbd5e1; background: none; border: 0;
  border-inline-start: 4px solid transparent; text-align: start;
  font: inherit; font-weight: 500; cursor: pointer; transition: 0.18s;
}
.menu-item i { inline-size: 20px; text-align: center; font-size: 0.95rem; }
.menu-item:hover, .menu-item.active {
  background-color: var(--sidebar-hover); color: #fff;
  border-inline-start-color: #38bdf8;
}
.badge {
  background: #f59e0b; color: #fff; border-radius: 999px;
  padding: 2px 8px; font-size: 11px; font-weight: 700; margin-inline-start: auto;
}
.badge-danger { background: var(--danger); }

.main-shell {
  margin-inline-start: 260px; flex: 1; display: flex; flex-direction: column; min-block-size: 100dvh;
  max-inline-size: calc(100vw - 260px);
}
.topbar {
  position: sticky; inset-block-start: 0; z-index: 50;
  background-color: rgba(255, 255, 255, 0.96); backdrop-filter: blur(6px);
  padding: 0.85rem 1.75rem; border-block-end: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.topbar-title { display: flex; align-items: center; gap: 12px; }
.topbar-title h2 { margin: 0; font-size: 1.15rem; font-weight: 700; }
.topbar-meta { display: flex; align-items: center; gap: 12px; font-size: 0.85rem; }

.content-area { padding: 1.5rem 1.75rem; display: flex; flex-direction: column; gap: 1.25rem; }

/* ---------- Global Visual Warning & Emergency Banners ---------- */
.visual-alerts-stack { display: flex; flex-direction: column; gap: 8px; }
.alert-banner {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  border-radius: 10px; font-weight: 600; font-size: 0.9rem;
  box-shadow: var(--shadow);
}
.alert-banner.warning {
  background: #fffbeb; border: 2px solid #f59e0b; color: #92400e;
}
.alert-banner.critical {
  background: #fef2f2; border: 2px solid #e11d48; color: #9f1239;
  animation: pulse-border 1.6s infinite;
}
@keyframes pulse-border {
  0%, 100% { box-shadow: 0 0 0 0 rgba(225, 29, 72, 0.35); }
  50% { box-shadow: 0 0 0 6px rgba(225, 29, 72, 0); }
}

/* ---------- Cards, Grids & Tables ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-block-end: 1rem; flex-wrap: wrap;
}
.card-header h3 { margin: 0; font-size: 1.02rem; font-weight: 700; display: flex; align-items: center; gap: 8px; }

.kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem;
}
.kpi-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 1rem 1.2rem; display: flex; flex-direction: column; gap: 4px;
}
.kpi-label { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; color: var(--muted); letter-spacing: 0.5px; }
.kpi-value { font-size: 1.45rem; font-weight: 800; color: var(--text); }
.kpi-sub { font-size: 0.78rem; color: var(--muted); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table.data-table { inline-size: 100%; border-collapse: collapse; font-size: 0.86rem; }
table.data-table th {
  background: var(--panel-2); color: #334155; font-weight: 700; text-align: start;
  padding: 10px 12px; border-block-end: 1px solid var(--line); white-space: nowrap;
}
table.data-table td {
  padding: 10px 12px; border-block-end: 1px solid var(--line-soft); vertical-align: middle;
}
table.data-table tr:hover td { background: #f8fafc; }
table.data-table tr.row-active-vip td { background: #f0fdf4; }
table.data-table tr.row-warn-50 td { background: #fffbeb; }
table.data-table tr.row-crit-100 td { background: #fef2f2; }

/* ---------- Session Limit Progress Bar ---------- */
.session-progress-box { min-inline-size: 210px; display: flex; flex-direction: column; gap: 4px; }
.session-progress-top { display: flex; justify-content: space-between; font-size: 0.78rem; font-weight: 600; }
.session-progress-bar {
  block-size: 8px; background: #e2e8f0; border-radius: 999px; overflow: hidden;
}
.session-progress-fill { block-size: 100%; transition: width .25s ease; border-radius: 999px; }
.fill-ok { background: #10b981; }
.fill-warn { background: #f59e0b; }
.fill-crit { background: #e11d48; }

/* ---------- Pills & Status Badges ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px; font-size: 0.74rem; font-weight: 700;
  white-space: nowrap;
}
.pill-on, .pill-success { background: #dcfce7; color: #166534; }
.pill-off { background: #f1f5f9; color: #475569; }
.pill-warn { background: #fef3c7; color: #92400e; }
.pill-danger { background: #ffe4e6; color: #9f1239; }
.pill-info { background: #dbeafe; color: #1e40af; }
.pill-trc { background: #f3e8ff; color: #6b21a8; }

.dot { inline-size: 9px; block-size: 9px; border-radius: 50%; display: inline-block; }
.dot-online { background: #10b981; box-shadow: 0 0 6px #10b981; }
.dot-offline { background: #ef4444; }

/* ---------- Buttons & Inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 13px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--text); font: inherit; font-size: 0.83rem; font-weight: 600;
  cursor: pointer; transition: .15s; text-decoration: none; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--panel-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-xs { padding: 4px 8px; font-size: 0.75rem; border-radius: 6px; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-success { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn-success:hover:not(:disabled) { background: #047857; }
.btn-warning { background: #f59e0b; color: #fff; border-color: #f59e0b; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-block { inline-size: 100%; }

input, select, textarea {
  padding: 7px 11px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; font-size: 0.86rem; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(37, 99, 235, 0.25); border-color: var(--primary);
}
input[readonly] { background: #f1f5f9; color: #334155; font-weight: 600; cursor: not-allowed; }

.form-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 0.76rem; font-weight: 700; color: #475569; text-transform: uppercase; }

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

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55);
  display: flex; align-items: center; justify-content: center; z-index: 200; padding: 1rem;
}
.modal-card {
  background: #fff; border-radius: 14px; inline-size: 100%; max-inline-size: 560px;
  padding: 1.4rem; box-shadow: 0 20px 25px -5px rgba(0,0,0,.15);
  display: flex; flex-direction: column; gap: 1rem; max-block-size: 90dvh; overflow-y: auto;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { margin: 0; font-size: 1.08rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-block-start: 0.5rem; }

/* ---------- Login ---------- */
.login-body {
  min-block-size: 100dvh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%); padding: 1rem;
}
.login-card {
  background: #fff; border-radius: 16px; inline-size: 100%; max-inline-size: 400px;
  padding: 2rem; box-shadow: 0 20px 30px rgba(0,0,0,.3);
}
.login-header { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-block-end: 1.2rem; }
.login-header h3 { margin: 0; font-size: 1.25rem; }

/* ---------- Toast ---------- */
.toast-container {
  position: fixed; inset-block-end: 20px; inset-inline-end: 20px; z-index: 300;
  display: flex; flex-direction: column; gap: 8px; max-inline-size: 400px;
}
.toast {
  padding: 12px 16px; border-radius: 10px; background: #0f172a; color: #fff;
  font-size: 0.85rem; font-weight: 600; box-shadow: 0 10px 15px -3px rgba(0,0,0,.2);
  display: flex; align-items: center; gap: 10px;
}
.toast.ok { border-inline-start: 4px solid #10b981; }
.toast.err { border-inline-start: 4px solid #e11d48; }
