:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-input: #12151e;
  --border: #2a2f3d;
  --text: #e8eaef;
  --text-muted: #8b92a5;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --sidebar-w: 240px;
}

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

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

/* ── Login ─────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(99, 102, 241, 0.15) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(139, 92, 246, 0.1) 0%, transparent 40%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  box-shadow: var(--shadow);
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo h1 {
  font-size: 1.4rem;
  font-weight: 700;
  background: linear-gradient(135deg, #818cf8, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-logo p {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 6px;
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

input, select, textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 14px;
  font-size: 0.95rem;
  transition: border-color 0.2s;
  outline: none;
}

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

textarea { resize: vertical; min-height: 80px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover { border-color: var(--accent); color: var(--accent-hover); }

.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #000; }
.btn-danger  { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-sm { padding: 6px 14px; font-size: 0.8rem; }

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

.error-msg {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.875rem;
  margin-bottom: 16px;
  display: none;
}

.error-msg.show { display: block; }

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

.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
}

.sidebar-brand {
  padding: 24px 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand h2 {
  font-size: 0.95rem;
  font-weight: 700;
  background: linear-gradient(135deg, #818cf8, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-brand span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.nav { flex: 1; padding: 16px 12px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover { background: rgba(99, 102, 241, 0.1); color: var(--text); }
.nav-item.active { background: rgba(99, 102, 241, 0.2); color: var(--accent-hover); }

.nav-icon { font-size: 1.1rem; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}

.user-info {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.user-info strong { color: var(--text); }

.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 32px;
  max-width: 1100px;
}

.page-header {
  margin-bottom: 28px;
}

.page-header h1 {
  font-size: 1.6rem;
  font-weight: 700;
}

.page-header p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

/* ── Cards ───────────────────────────────────── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.card-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.card-value.ok   { color: var(--success); }
.card-value.warn { color: var(--warning); }
.card-value.err  { color: var(--danger); }

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}

.panel h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.form-row .form-group { margin-bottom: 0; }

/* ── Output ──────────────────────────────────── */
.output-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  font-family: "Cascadia Code", "Fira Code", monospace;
  font-size: 0.8rem;
  line-height: 1.6;
  max-height: 500px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: #a5f3fc;
}

.output-box.empty {
  color: var(--text-muted);
  font-family: inherit;
  font-style: italic;
}

.output-box.error { color: #fca5a5; }

.err-step { font-weight: 700; font-size: 1rem; margin-bottom: 10px; color: #f87171; }
.err-msg { font-size: 0.95rem; margin-bottom: 12px; line-height: 1.5; }
.err-hint {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.85rem;
  color: #fcd34d;
  margin-bottom: 10px;
  line-height: 1.5;
}
.err-meta { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 8px; }
.err-details { margin-top: 10px; font-size: 0.8rem; }
.err-details summary { cursor: pointer; color: var(--text-muted); margin-bottom: 6px; }
.err-details pre {
  background: #0a0c10;
  border-radius: 6px;
  padding: 10px;
  overflow: auto;
  max-height: 200px;
  font-family: monospace;
  font-size: 0.75rem;
  color: #94a3b8;
}

.form-hint {
  font-size: 0.75rem;
  color: var(--warning);
  margin-top: 4px;
}

input[type="file"] {
  padding: 8px;
  font-size: 0.85rem;
}

.image-preview {
  margin-top: 10px;
  display: none;
}

.image-preview.show {
  display: block;
}

.image-preview img {
  max-width: 100%;
  max-height: 160px;
  border-radius: 8px;
  border: 1px solid var(--border);
  object-fit: contain;
  background: var(--bg-input);
}

.image-preview span {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ── Section visibility ──────────────────────── */
.section { display: none; }
.section.active { display: block; }

/* ── Loader ──────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 999;
  align-items: center;
  justify-content: center;
}

.loading-overlay.show { display: flex; }

.loading-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 48px;
  text-align: center;
}

.loading-box p { margin-top: 12px; color: var(--text-muted); }

/* ── Responsive ──────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar-brand h2, .sidebar-brand span, .nav-item span, .user-info { display: none; }
  .nav-item { justify-content: center; padding: 12px; }
  .main { margin-left: 60px; padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
}
