:root {
  --bg: #0f0f13;
  --surface: #1a1a24;
  --surface2: #242433;
  --border: #2d2d42;
  --accent: #7c5cfc;
  --accent-hover: #6a4de0;
  --accent-light: #a590ff;
  --text: #e8e8f0;
  --text-muted: #8888aa;
  --danger: #e05c6a;
  --success: #4eca8b;
  --warning: #f0a840;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Login ── */
.login-page { display: flex; align-items: center; justify-content: center; }
.login-container { width: 100%; max-width: 400px; padding: 24px; }
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  box-shadow: var(--shadow);
}
.login-logo { font-size: 48px; text-align: center; margin-bottom: 12px; }
.login-card h1 { text-align: center; font-size: 22px; font-weight: 700; }
.login-subtitle { text-align: center; color: var(--text-muted); margin-bottom: 28px; }

/* ── Layout ── */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}
.sidebar-logo {
  padding: 22px 20px 14px;
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo span { font-size: 24px; }
.sidebar-nav { padding: 12px 10px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: 2px;
  text-decoration: none;
  font-size: 13.5px;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: rgba(124,92,252,0.18); color: var(--accent-light); }
.nav-item .icon { font-size: 17px; width: 20px; text-align: center; }
.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}
.sidebar-footer strong { color: var(--text); display: block; }

.main-content {
  margin-left: 220px;
  flex: 1;
  padding: 28px 32px;
  max-width: calc(100vw - 220px);
}

/* ── Page header ── */
.page-header { margin-bottom: 24px; }
.page-header h2 { font-size: 20px; font-weight: 700; }
.page-header p { color: var(--text-muted); margin-top: 4px; }

/* ── Cards / Panels ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 20px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-title { font-size: 15px; font-weight: 600; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12.5px; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
input, textarea, select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }
select option { background: var(--surface2); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.15s;
  text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: rgba(224,92,106,0.12); }
.btn-success { background: var(--success); color: #000; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent-light); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(255,255,255,0.02); }

/* ── Badges / Tags ── */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-green { background: rgba(78,202,139,0.18); color: var(--success); }
.badge-red { background: rgba(224,92,106,0.18); color: var(--danger); }
.badge-yellow { background: rgba(240,168,64,0.18); color: var(--warning); }
.badge-purple { background: rgba(124,92,252,0.18); color: var(--accent-light); }

/* ── Toggle ── */
.toggle-wrap { display: flex; align-items: center; gap: 10px; }
.toggle {
  position: relative;
  width: 42px; height: 22px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--border);
  border-radius: 22px;
  cursor: pointer;
  transition: 0.2s;
}
.toggle-slider:before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider:before { transform: translateX(20px); }

/* ── Alerts ── */
.alert {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  margin-bottom: 12px;
}
.alert-danger { background: rgba(224,92,106,0.15); border: 1px solid rgba(224,92,106,0.3); color: var(--danger); }
.alert-success { background: rgba(78,202,139,0.15); border: 1px solid rgba(78,202,139,0.3); color: var(--success); }

/* ── Stats grid ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.stat-value { font-size: 28px; font-weight: 700; color: var(--accent-light); }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ── Tabs ── */
.tabs { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 1px solid var(--border); padding-bottom: 0; }
.tab {
  padding: 10px 16px;
  cursor: pointer;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  font-size: 13.5px;
  transition: all 0.15s;
  margin-bottom: -1px;
}
.tab.active { color: var(--accent-light); border-bottom-color: var(--accent); }
.tab:hover:not(.active) { color: var(--text); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Modal ── */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  align-items: center;
  justify-content: center;
  pointer-events: none; /* clicks on backdrop are ignored */
}
.modal-backdrop.open { display: flex; }
.modal-backdrop .modal { pointer-events: all; } /* clicks inside modal work normally */
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 30px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal-title { font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 20px; padding: 0; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ── Logs ── */
.log-list { font-family: 'Consolas', monospace; font-size: 12px; }
.log-entry {
  padding: 8px 12px;
  border-radius: 6px;
  margin-bottom: 6px;
  background: var(--surface2);
}
.log-entry .log-time { color: var(--text-muted); }
.log-entry.done { border-left: 3px solid var(--success); }
.log-entry.failed { border-left: 3px solid var(--danger); }
.log-entry.running { border-left: 3px solid var(--warning); }

/* ── Info box ── */
.info-box {
  background: rgba(124,92,252,0.08);
  border: 1px solid rgba(124,92,252,0.25);
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 13px;
  line-height: 1.7;
}
.info-box strong { color: var(--accent-light); }
.info-box ol { color: var(--text-muted); }
.info-box code { background: var(--surface2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ── External link ── */
.link-external {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--accent-light);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: color 0.15s;
}
.link-external:hover { color: #fff; text-decoration: underline; }

/* ── API Key hint block ── */
.api-key-hint {
  margin-bottom: 14px;
}
.api-key-hint:empty { display: none; }
.api-key-hint a {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(124,92,252,0.12);
  border: 1px solid rgba(124,92,252,0.3);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--accent-light);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.api-key-hint a:hover { background: rgba(124,92,252,0.22); color: #fff; }

/* ── Assign item ── */
.assign-item {
  padding: 8px 12px;
  background: var(--surface2);
  border-radius: 7px;
  margin-bottom: 6px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar-logo .logo-text, .nav-item span:not(.icon) { display: none; }
  .main-content { margin-left: 60px; padding: 16px; max-width: calc(100vw - 60px); }
  .form-row { grid-template-columns: 1fr; }
}
