/* ==========================================================================
   IOE WORKSPACE — PRECISION UI SYSTEM
   ========================================================================== */

:root {
  --bg-canvas: #09090b;
  --bg-surface: #111113;
  --bg-elevated: #17171a;
  --bg-subtle: #141417;
  --bg-hover: #1e1e23;
  --bg-input: #0c0c0e;
  --bg-console: #070709;

  --border: rgba(255, 255, 255, 0.075);
  --border-strong: rgba(255, 255, 255, 0.14);
  --border-focus: rgba(255, 255, 255, 0.32);

  --text-primary: #f4f4f5;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;

  --btn-primary-bg: #f4f4f5;
  --btn-primary-fg: #09090b;
  --btn-primary-hover: #ffffff;

  --emerald: #10b981;
  --emerald-bg: rgba(16, 185, 129, 0.1);
  --emerald-border: rgba(16, 185, 129, 0.24);

  --amber: #f59e0b;
  --amber-bg: rgba(245, 158, 11, 0.1);
  --amber-border: rgba(245, 158, 11, 0.24);

  --rose: #f43f5e;
  --rose-bg: rgba(244, 63, 94, 0.1);
  --rose-border: rgba(244, 63, 94, 0.24);

  --blue: #3b82f6;
  --blue-bg: rgba(59, 130, 246, 0.1);
  --blue-border: rgba(59, 130, 246, 0.24);

  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 20px 45px -10px rgba(0, 0, 0, 0.7), 0 0 0 1px var(--border-strong);

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Consolas, monospace;
}

html.light {
  --bg-canvas: #f8f8f9;
  --bg-surface: #ffffff;
  --bg-elevated: #f3f3f5;
  --bg-subtle: #f4f4f6;
  --bg-hover: #eaeaeef0;
  --bg-input: #ffffff;
  --bg-console: #0f0f12;

  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.15);
  --border-focus: rgba(0, 0, 0, 0.4);

  --text-primary: #18181b;
  --text-secondary: #52525b;
  --text-muted: #71717a;

  --btn-primary-bg: #18181b;
  --btn-primary-fg: #fafafa;
  --btn-primary-hover: #27272a;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 20px 45px -12px rgba(0, 0, 0, 0.15), 0 0 0 1px var(--border-strong);
}

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

html, body {
  height: 100%;
}

body {
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
}

/* Typography & Utility */
.mono-num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.mono-input, .mono-code {
  font-family: var(--font-mono);
  font-size: 12px;
}
.mono-code {
  color: var(--text-secondary);
  word-break: break-all;
}
.inline-code {
  font-family: var(--font-mono);
  font-size: 11.5px;
  padding: 1px 5px;
  border-radius: var(--radius-xs);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}
.text-emerald { color: var(--emerald) !important; }
.text-amber { color: var(--amber) !important; }
.text-rose { color: var(--rose) !important; }
.text-right { text-align: right !important; }

/* ==========================================================================
   TOP BAR
   ========================================================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 52px;
  padding: 0 20px;
  background: color-mix(in srgb, var(--bg-canvas) 85%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 600;
  font-size: 13.5px;
  letter-spacing: -0.02em;
}

.brand-mark {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  background: var(--text-primary);
  color: var(--bg-canvas);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.topbar-divider {
  width: 1px;
  height: 16px;
  background: var(--border);
  margin: 0 6px;
}

.telemetry-strip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

.telemetry-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.telemetry-label {
  color: var(--text-muted);
}

.telemetry-sep {
  color: var(--border-strong);
}

.status-led {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--emerald);
  display: inline-block;
  flex-shrink: 0;
}

.auth-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ==========================================================================
   BUTTONS & INPUTS
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 13px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.14s ease, border-color 0.14s ease, color 0.14s ease, opacity 0.14s ease;
  white-space: nowrap;
  user-select: none;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-xs {
  height: 26px;
  padding: 0 9px;
  font-size: 11.5px;
}

.btn-sm {
  height: 30px;
  padding: 0 11px;
  font-size: 12px;
}

.btn-lg {
  height: 38px;
  padding: 0 14px;
  font-size: 13px;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-fg);
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) {
  background: var(--btn-primary-hover);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
}

.btn-subtle {
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn-subtle:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--rose-bg);
  color: var(--rose);
  border-color: var(--rose-border);
}
.btn-danger:hover:not(:disabled) {
  background: rgba(244, 63, 94, 0.18);
}

.btn-icon {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.14s ease;
}
.btn-icon:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.btn-icon-sm {
  width: 26px;
  height: 26px;
}

.btn-kbd {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: var(--radius-xs);
  background: rgba(128, 128, 128, 0.16);
  opacity: 0.85;
}

.action-stack .btn-lg {
  justify-content: space-between;
}

/* Inputs */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field-label {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-secondary);
}

.input, .select-input {
  width: 100%;
  height: 34px;
  padding: 0 11px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 12.5px;
  transition: border-color 0.15s ease;
}

.input:focus, .select-input:focus {
  outline: none;
  border-color: var(--border-focus);
}

.input::placeholder {
  color: var(--text-muted);
}

.input-sm {
  height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.feedback-msg {
  font-size: 11.5px;
  line-height: 1.4;
  min-height: 4px;
  color: var(--text-secondary);
}

/* ==========================================================================
   USER DROPDOWN
   ========================================================================== */
.user-menu-wrap {
  position: relative;
}

.user-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 9px 0 5px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.14s ease, background-color 0.14s ease;
}

.user-trigger:hover, .user-trigger.active {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
}

.user-avatar {
  width: 20px;
  height: 20px;
  border-radius: var(--radius-xs);
  background: var(--text-primary);
  color: var(--bg-canvas);
  font-size: 10.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.user-name {
  font-weight: 500;
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-quota-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 5px;
  border-radius: var(--radius-xs);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.dropdown-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 250px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: none;
  z-index: 100;
  overflow: hidden;
}

.dropdown-panel.active {
  display: block;
}

.dropdown-section {
  padding: 6px;
  border-bottom: 1px solid var(--border);
}
.dropdown-section:last-child {
  border-bottom: none;
}

.account-summary {
  padding: 6px 8px;
  font-size: 12px;
}

.uwd-summary-grid {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.uwd-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.uwd-label {
  color: var(--text-muted);
  font-size: 11.5px;
}

.uwd-value {
  color: var(--text-primary);
  font-size: 12px;
  font-family: var(--font-mono);
}

.uwd-pill {
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: var(--radius-xs);
  background: var(--emerald-bg);
  color: var(--emerald);
  border: 1px solid var(--emerald-border);
}
.uwd-pill.is-warn {
  background: var(--amber-bg);
  color: var(--amber);
  border-color: var(--amber-border);
}
.uwd-pill.is-error {
  background: var(--rose-bg);
  color: var(--rose);
  border-color: var(--rose-border);
}

.dropdown-link {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  background: transparent;
  border: none;
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease;
}
.dropdown-link:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}
.dropdown-link.danger {
  color: var(--rose);
}
.dropdown-link.danger:hover {
  background: var(--rose-bg);
}

/* ==========================================================================
   MAIN WORKSPACE GRID
   ========================================================================== */
.workspace {
  max-width: 1360px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  grid-template-columns: 350px 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 960px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .telemetry-strip {
    display: none;
  }
}

.sidebar-col, .content-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

/* Surface Cards */
.surface-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.surface-header {
  height: 44px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.header-with-meta {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.surface-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.surface-subtitle {
  font-size: 11.5px;
  color: var(--text-muted);
}

.surface-body {
  padding: 16px;
}

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stack-md {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.divider {
  height: 1px;
  background: var(--border);
}

.status-pill {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: var(--radius-xs);
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.status-pill.connected {
  background: var(--emerald-bg);
  color: var(--emerald);
  border-color: var(--emerald-border);
}

/* ==========================================================================
   STUDENT PROFILE & ROUND PICKER
   ========================================================================== */
.student-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.student-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.student-initials {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.student-info {
  min-width: 0;
  flex: 1;
}

.student-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.student-sub {
  font-size: 11.5px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.student-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.metric-cell {
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.metric-label {
  font-size: 11px;
  color: var(--text-muted);
}

.metric-val {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

/* Round Stepper */
.round-stepper {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-step {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.14s ease;
}
.btn-step:hover:not(:disabled) {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

/* Pacing Row */
.pacing-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.pacing-meta {
  display: flex;
  flex-direction: column;
}

.pacing-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
}

.pacing-hint {
  font-size: 11px;
  color: var(--text-muted);
}

.pacing-control {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pacing-control .input {
  width: 64px;
  text-align: center;
}

.unit-label {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
}

.action-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ==========================================================================
   STATE BANNERS & EXERCISES LIST
   ========================================================================== */
.state-banner {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.banner-body {
  display: flex;
  align-items: center;
  gap: 12px;
}

.banner-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-muted);
}

.banner-success {
  border-color: var(--emerald-border);
  background: var(--emerald-bg);
}
.banner-success .banner-dot {
  background: var(--emerald);
}

.banner-locked {
  border-color: var(--amber-border);
  background: var(--amber-bg);
}
.banner-locked .banner-dot {
  background: var(--amber);
}

.banner-neutral {
  border-color: var(--border-strong);
}

.banner-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.banner-desc {
  font-size: 11.5px;
  color: var(--text-secondary);
}

/* Exercises List */
.exercises-list {
  display: flex;
  flex-direction: column;
}

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

.game-card-item {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  transition: background-color 0.12s ease;
}
.game-card-item:last-child {
  border-bottom: none;
}
.game-card-item:hover {
  background: var(--bg-subtle);
}

.game-info-col {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.game-icon-badge {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-xs);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.game-card-item.passed .game-icon-badge {
  background: var(--emerald-bg);
  border-color: var(--emerald-border);
  color: var(--emerald);
}

.game-title-text {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.game-meta-text {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

.game-actions-col {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.score-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-secondary);
}

.score-badge.passed {
  background: var(--emerald-bg);
  border-color: var(--emerald-border);
  color: var(--emerald);
}

.score-badge.failed {
  background: var(--rose-bg);
  border-color: var(--rose-border);
  color: var(--rose);
}

.btn-game-solve {
  height: 28px;
  padding: 0 11px;
  border-radius: var(--radius-xs);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.14s ease;
}
.btn-game-solve:hover {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-fg);
  border-color: transparent;
}

/* ==========================================================================
   CONSOLE LOG
   ========================================================================== */
.console-card {
  background: var(--bg-console);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.console-header {
  height: 40px;
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.console-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.console-status-text {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
  color: #d4d4d8;
}

.console-output {
  height: 320px;
  padding: 12px 14px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.65;
  color: #d4d4d8;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

. console-output:empty::before,
.console-output:empty::before {
  content: "Nhật ký phiên giải sẽ hiển thị tại đây.";
  color: #52525b;
}

.log-block {
  padding: 2px 0;
}

.log-line {
  display: flex;
  align-items: baseline;
  gap: 10px;
  word-break: break-word;
}

.log-icon {
  font-size: 10.5px;
  font-weight: 600;
  flex-shrink: 0;
  width: 36px;
  color: #71717a;
}
.log-block.success .log-icon { color: var(--emerald); }
.log-block.error .log-icon { color: var(--rose); }
.log-block.waiting .log-icon { color: var(--amber); }
.log-block.process .log-icon { color: #60a5fa; }

.log-time {
  color: #52525b;
  font-size: 11px;
  flex-shrink: 0;
}

.log-message {
  color: #e4e4e7;
}
.log-block.error .log-message {
  color: #fda4af;
}
.log-block.success .log-message {
  color: #6ee7b7;
}

.console-footer {
  padding: 8px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.015);
  font-size: 11.5px;
  color: #71717a;
}

.noti-empty {
  color: #52525b;
  font-size: 11.5px;
}

.noti-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #d4d4d8;
  padding: 2px 0;
}

.noti-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: #71717a;
}

/* ==========================================================================
   MODALS
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.hidden {
  display: none;
}

.modal-box {
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-box.modal-xl {
  max-width: 1120px;
}

.modal-header {
  height: 48px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.modal-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-close {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-xs);
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.modal-lead {
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.modal-footer-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.guide-steps {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: var(--text-secondary);
  font-size: 12.5px;
  line-height: 1.6;
}
.guide-steps strong {
  color: var(--text-primary);
}

.inline-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ==========================================================================
   ADMIN PANEL & TABLES
   ========================================================================== */
.adm-metrics-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
  flex-shrink: 0;
}

@media (max-width: 720px) {
  .adm-metrics-row {
    grid-template-columns: repeat(2, 1fr);
  }
}

.adm-metric {
  padding: 12px 16px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.adm-metric:last-child {
  border-right: none;
}

.adm-metric-label {
  font-size: 11px;
  color: var(--text-muted);
}

.adm-metric-val {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
}

.adm-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  overflow-x: auto;
  flex-shrink: 0;
}

.adm-tab {
  height: 38px;
  padding: 0 12px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.adm-tab:hover {
  color: var(--text-primary);
}
.adm-tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--text-primary);
}

.tab-count {
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 1px 5px;
  border-radius: var(--radius-xs);
  background: var(--bg-elevated);
  color: var(--text-secondary);
}

.adm-body {
  min-height: 360px;
}

.table-toolbar {
  margin-bottom: 12px;
  max-width: 320px;
}

.syskey-add-bar {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  margin-bottom: 8px;
}

.ipban-add-bar {
  display: grid;
  grid-template-columns: 1.15fr 0.75fr 1.35fr auto;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}

@media (max-width: 780px) {
  .ipban-add-bar {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .syskey-add-bar {
    grid-template-columns: 1fr;
  }
}

.adm-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin: 12px 0 8px;
}

.adm-section-head h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

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

.ipban-toolbar .input {
  width: 220px;
}

.ipban-checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.ip-accounts-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-width: 320px;
}

.ip-account-chip {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: var(--radius-xs);
  font-size: 11px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  text-align: left;
}

.data-table th {
  padding: 8px 12px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 11px;
  white-space: nowrap;
}

.data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  vertical-align: middle;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.adm-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: var(--radius-xs);
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-secondary);
}

.adm-badge-online {
  background: var(--emerald-bg);
  color: var(--emerald);
  border-color: var(--emerald-border);
}

.adm-badge-admin {
  background: var(--amber-bg);
  color: var(--amber);
  border-color: var(--amber-border);
}

.adm-badge-danger {
  background: rgba(244, 63, 94, 0.12);
  color: var(--rose);
  border-color: var(--rose-border);
}

/* Search & Credit Recharge */
.search-results {
  max-height: 130px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.admin-credit-result {
  width: 100%;
  padding: 7px 10px;
  border-radius: var(--radius-xs);
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  cursor: pointer;
}
.admin-credit-result:hover, .admin-credit-result.active {
  border-color: var(--border-focus);
  background: var(--bg-elevated);
}
.admin-credit-result-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

.selected-user-box {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font-size: 12px;
  line-height: 1.6;
}

.credit-history {
  max-height: 110px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  padding-top: 8px;
  font-size: 11.5px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Key Stats Modal */
.key-meta-box {
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.key-meta-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stats-grid-4 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.stats-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.stat-cell {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-cell-label {
  font-size: 11px;
  color: var(--text-muted);
}

.stat-cell-val {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.stat-cell-sub {
  font-size: 10.5px;
  color: var(--text-secondary);
}

.detail-list {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11.5px;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--text-secondary);
}

/* ==========================================================================
   TOAST NOTIFICATIONS
   ========================================================================== */
.toast-stack {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 240px;
  max-width: 360px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 500;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast--success { border-left: 3px solid var(--emerald); }
.toast--error { border-left: 3px solid var(--rose); }
.toast--warning { border-left: 3px solid var(--amber); }
.toast--info { border-left: 3px solid var(--text-secondary); }
