:root {
  color-scheme: dark;
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f2430;
  --panel-3: #262c3a;
  --line: #303746;
  --line-strong: #465064;
  --text: #f5f7fb;
  --text-2: #d9dee8;
  --muted: #99a3b5;
  --muted-2: #727d91;
  --accent: #38c787;
  --accent-2: #72a7ff;
  --warn: #e2b853;
  --danger: #ff6b73;
  --radius: 10px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, textarea, select { font: inherit; }
button { border: 0; cursor: pointer; }
a { color: var(--accent-2); }

/* Topbar */
.topbar {
  height: 64px; display: flex; align-items: center; justify-content: space-between;
  gap: 20px; padding: 0 22px; border-bottom: 1px solid var(--line);
  background: #12151b; position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { margin: 0; font-size: 17px; font-weight: 750; letter-spacing: 0.2px; }
.brand .logo {
  width: 28px; height: 28px; border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; font-weight: 800; color: #06140f; font-size: 14px;
}
.env-pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 22px; padding: 0 9px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); background: var(--panel-2);
  font-size: 11px; font-weight: 650; letter-spacing: 0.4px; text-transform: uppercase;
}
.env-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.authbar { display: flex; align-items: center; gap: 10px; }
.authbar .field { width: 280px; }

/* Layout */
.layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100vh - 64px); }
.sidebar {
  padding: 14px 12px; border-right: 1px solid var(--line); background: #11141a;
  position: sticky; top: 64px; align-self: start; height: calc(100vh - 64px); overflow-y: auto;
}
.tab-btn {
  width: 100%; display: flex; align-items: center; gap: 11px;
  min-height: 40px; padding: 0 12px; margin-bottom: 3px; border-radius: var(--radius-sm);
  background: transparent; color: var(--muted); text-align: left; font-weight: 650; font-size: 13.5px;
  transition: background 0.12s, color 0.12s;
}
.tab-btn:hover { background: var(--panel-2); color: var(--text-2); }
.tab-btn.active { background: var(--panel-3); color: var(--text); }
.tab-btn .tab-ico { width: 16px; height: 16px; flex: 0 0 auto; opacity: 0.85; display: grid; place-items: center; }
.tab-btn.active .tab-ico { opacity: 1; color: var(--accent); }
.sidebar-foot { margin-top: 14px; padding: 12px 12px 0; border-top: 1px solid var(--line); color: var(--muted-2); font-size: 11px; line-height: 1.6; }
.content { padding: 22px 24px 60px; overflow: auto; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Headings & panels */
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.panel-head h2 { margin: 0; font-size: 18px; font-weight: 750; }
.panel-head .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
h3 { margin: 0 0 12px; font-size: 13px; color: var(--text-2); font-weight: 700; letter-spacing: 0.3px; text-transform: uppercase; }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.six { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); padding: 16px; }
.panel + .panel { margin-top: 14px; }
.section-gap { margin-top: 18px; }

/* KPI stat cards */
.stat { min-height: 96px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.stat-label { color: var(--muted); font-size: 12px; font-weight: 600; }
.stat-value { font-size: 30px; line-height: 1; font-weight: 800; letter-spacing: -0.5px; }
.stat-foot { font-size: 11.5px; color: var(--muted-2); margin-top: 6px; }
.stat .stat-bar { position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); }
.stat.warn .stat-bar { background: var(--warn); }
.stat.danger .stat-bar { background: var(--danger); }
.stat.info .stat-bar { background: var(--accent-2); }
.dist { display: flex; height: 8px; border-radius: 999px; overflow: hidden; background: var(--panel-3); margin-top: 10px; }
.dist span { display: block; height: 100%; }
.dist-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.dist-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

/* Filter bar */
.filterbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.filterbar .field, .filterbar .select { width: auto; min-width: 150px; }
.filterbar .search { flex: 1 1 220px; min-width: 200px; }
.filterbar .spacer { flex: 1; }
.filterbar .count { color: var(--muted); font-size: 12.5px; }

/* Forms */
.field, .textarea, .select {
  width: 100%; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--panel-2); color: var(--text); padding: 10px 11px; outline: none; transition: border-color 0.12s;
}
.field:focus, .textarea:focus, .select:focus { border-color: var(--accent); }
.textarea { min-height: 220px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
label { display: block; margin: 0 0 6px; color: var(--muted); font-size: 12px; font-weight: 650; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.full { grid-column: 1 / -1; }
.hint { color: var(--muted-2); font-size: 11.5px; margin-top: 6px; line-height: 1.5; }

/* Buttons */
.btn {
  min-height: 38px; border-radius: var(--radius-sm); padding: 0 13px;
  background: var(--panel-2); color: var(--text-2); border: 1px solid var(--line);
  font-weight: 700; font-size: 13px; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { border-color: var(--line-strong); color: var(--text); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06140f; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.primary.danger { background: var(--danger); border-color: var(--danger); color: #1a0608; }
.btn.danger { color: var(--danger); border-color: rgba(255, 107, 115, 0.4); }
.btn.danger:hover { background: rgba(255, 107, 115, 0.12); }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 30px; padding: 0 9px; font-size: 12px; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.toolbar.right { justify-content: flex-end; }

/* Status / log / progress */
.status { margin-top: 10px; min-height: 20px; white-space: pre-wrap; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.status.error { color: var(--danger); }
.status.success { color: var(--accent); }
.progress { height: 8px; border-radius: 999px; background: var(--panel-3); overflow: hidden; margin-top: 12px; }
.progress > span { display: block; height: 100%; background: var(--accent); transition: width 0.2s; }
.log-list { margin-top: 12px; max-height: 240px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #11141a; }
.log-list .log-item { padding: 7px 12px; border-bottom: 1px solid var(--line); font-size: 12px; font-family: ui-monospace, Consolas, monospace; }
.log-list .log-item:last-child { border-bottom: 0; }
.log-item.ok { color: var(--accent); }
.log-item.fail { color: var(--danger); }
.log-item.skip { color: var(--warn); }
.log-item.info { color: var(--muted); }

/* Tables */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-weight: 700; background: #151922; position: sticky; top: 0; z-index: 1; font-size: 11.5px; letter-spacing: 0.3px; text-transform: uppercase; }
tbody tr:hover { background: rgba(255, 255, 255, 0.02); }
tr:last-child td { border-bottom: 0; }
td.check, th.check { width: 36px; text-align: center; }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn { margin-left: 4px; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.muted { color: var(--muted-2); }
.truncate { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 28px; color: var(--muted); text-align: center; }
.quota { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.quota .quota-bar { flex: 1; height: 6px; border-radius: 999px; background: var(--panel-3); overflow: hidden; }
.quota .quota-bar > span { display: block; height: 100%; }
.quota .quota-text { font-size: 11.5px; color: var(--muted); white-space: nowrap; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--muted); font-size: 11.5px; font-weight: 650;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.8; }
.badge.status-available { color: var(--accent); border-color: rgba(56, 199, 135, 0.4); }
.badge.status-assigned { color: var(--warn); border-color: rgba(226, 184, 83, 0.4); }
.badge.status-revoked, .badge.status-disabled, .badge.status-exhausted { color: var(--danger); border-color: rgba(255, 107, 115, 0.4); }
.badge.status-active { color: var(--accent-2); border-color: rgba(114, 167, 255, 0.4); }
.pill { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 6px; background: var(--panel-3); color: var(--text-2); font-size: 11px; }

/* Responsive */
@media (max-width: 1100px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 12px; gap: 10px; }
  .authbar .field { width: 180px; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; display: flex; gap: 6px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .tab-btn { min-width: 120px; }
  .sidebar-foot { display: none; }
  .grid.two, .grid.four, .grid.six, .form-grid { grid-template-columns: 1fr; }
  .content { padding: 16px; }
}
