:root {
  --bg: #090d16;
  --surface: #111827;
  --surface-2: #161f33;
  --surface-hover: #1c2840;
  --border: #24324c;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --primary: #38bdf8;
  --primary-dim: rgba(56, 189, 248, 0.14);
  --success: #34d399;
  --success-dim: rgba(52, 211, 153, 0.14);
  --warning: #fbbf24;
  --warning-dim: rgba(251, 191, 36, 0.14);
  --danger: #fb7185;
  --danger-dim: rgba(251, 113, 133, 0.14);
  --purple: #a78bfa;
  --purple-dim: rgba(167, 139, 250, 0.14);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
}

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

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--text-muted); }

/* Login Screen */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(600px circle at 20% 20%, rgba(56, 189, 248, 0.10), transparent 60%),
    radial-gradient(500px circle at 80% 80%, rgba(167, 139, 250, 0.08), transparent 60%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
}

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

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #38bdf8, #6366f1);
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #090d16;
  font-size: 15px;
  letter-spacing: -0.5px;
  flex-shrink: 0;
}

.brand-title { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }
.brand-sub { font-size: 12px; color: var(--text-muted); }

.tabs-inline {
  display: flex;
  gap: 6px;
  background: var(--bg);
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 18px;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 7px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
}

.tab-btn.active {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* App Shell */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 244px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-header {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  width: 100%;
  text-align: left;
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.14s;
}

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

.nav-item.active {
  background: var(--primary-dim);
  color: var(--primary);
  border-color: rgba(56, 189, 248, 0.25);
}

.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }

.sidebar-footer {
  padding: 14px;
  border-top: 1px solid var(--border);
  background: rgba(9, 13, 22, 0.35);
}

.operator-chip {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 10px;
}

.operator-name { font-weight: 600; font-size: 13.5px; }
.operator-role { font-size: 11.5px; color: var(--primary); }

.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 58px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-title { font-size: 16px; font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.content {
  padding: 22px 24px 40px;
  max-width: 1440px;
  width: 100%;
}

/* Cards & Grids */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(195px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.kpi-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.kpi-value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; }
.kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

@media (max-width: 980px) {
  .grid-2 { grid-template-columns: 1fr; }
  .sidebar { width: 200px; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 18px;
}

.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.card-title { font-size: 14.5px; font-weight: 600; }
.card-body { padding: 16px 18px; }

/* Toolbar & Filters */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.spacer { flex: 1; }

/* Form controls */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 5px;
  font-weight: 500;
}

input[type="text"], input[type="password"], input[type="number"], input[type="datetime-local"],
select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 8px 11px;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
}

.toolbar input[type="text"], .toolbar select {
  width: auto;
  min-width: 160px;
}

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

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.14s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover { background: var(--surface-hover); border-color: #364b70; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #07131e; border-color: var(--primary); font-weight: 600; }
.btn-primary:hover { background: #67cdfa; border-color: #67cdfa; }
.btn-danger { background: var(--danger-dim); color: var(--danger); border-color: rgba(251, 113, 133, 0.3); }
.btn-danger:hover { background: rgba(251, 113, 133, 0.24); }
.btn-success { background: var(--success-dim); color: var(--success); border-color: rgba(52, 211, 153, 0.3); }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-block { width: 100%; padding: 9px 14px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(36, 50, 76, 0.65);
  vertical-align: middle;
}
th {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  font-weight: 600;
  background: rgba(9, 13, 22, 0.4);
  white-space: nowrap;
}
tbody tr:hover { background: rgba(28, 40, 64, 0.35); }
.actions-cell { display: flex; gap: 5px; flex-wrap: wrap; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.badge-green { background: var(--success-dim); color: var(--success); }
.badge-red { background: var(--danger-dim); color: var(--danger); }
.badge-amber { background: var(--warning-dim); color: var(--warning); }
.badge-blue { background: var(--primary-dim); color: var(--primary); }
.badge-purple { background: var(--purple-dim); color: var(--purple); }
.badge-gray { background: rgba(148, 163, 184, 0.14); color: var(--text-muted); }

/* Charts */
.chart-box {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}
.legend-list { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 140px; }
.legend-row { display: flex; align-items: center; justify-content: space-between; font-size: 13px; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 8px; }

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 150px;
  padding-top: 16px;
}
.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
  gap: 6px;
}
.bar-fill {
  width: 100%;
  max-width: 34px;
  background: linear-gradient(180deg, #38bdf8, #3b82f6);
  border-radius: 5px 5px 2px 2px;
  min-height: 4px;
  transition: height 0.25s ease;
}
.bar-val { font-size: 11px; color: var(--text-muted); font-family: var(--mono); }
.bar-lbl { font-size: 11px; color: var(--text-muted); }

/* Permission Matrix */
.perm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.perm-group {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.perm-group-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 8px;
}
.perm-check {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  margin-bottom: 5px;
  cursor: pointer;
}
.perm-check input { width: auto; accent-color: var(--primary); }

/* Code / Key block */
.code-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 12px;
  word-break: break-all;
  max-height: 120px;
  overflow-y: auto;
  color: #cbd5e1;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 13, 0.72);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 18px;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
}
.modal-lg { max-width: 760px; }
.modal-header {
  padding: 15px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-size: 15px; font-weight: 600; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-footer {
  padding: 13px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Toast */
.toast-container {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  min-width: 220px;
}
.toast.ok { border-left: 3px solid var(--success); }
.toast.err { border-left: 3px solid var(--danger); }

.kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}
.kv-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.kv-k { font-size: 11.5px; color: var(--text-muted); }
.kv-v { font-size: 13px; font-weight: 600; margin-top: 2px; word-break: break-all; }

.empty-state {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-muted);
  font-size: 13.5px;
}
