:root {
  --bg: #0f1117;
  --bg2: #1a1d27;
  --bg3: #22263a;
  --border: #2e3350;
  --primary: #4f6ef7;
  --primary-hover: #3d5ce0;
  --text: #e8eaf6;
  --text-muted: #8b90b0;
  --success: #22c55e;
  --error: #ef4444;
  --warning: #f59e0b;
  --radius: 10px;
  --radius-sm: 6px;
}

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

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

/* ── UTILITIES ── */
.hidden { display: none !important; }
.required { color: var(--error); }
.mt-2 { margin-top: 8px; }

/* ── LOGIN ── */
.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 0%, #1e2a5e 0%, var(--bg) 70%);
}

.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.login-logo {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 20px;
  color: white;
}

.login-card h1 { font-size: 24px; font-weight: 700; margin-bottom: 6px; }
.login-subtitle { color: var(--text-muted); margin-bottom: 28px; }
.login-card form { text-align: left; }

/* ── TOPBAR ── */
.topbar {
  height: 56px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-title { font-size: 16px; font-weight: 700; }
.topbar-right { display: flex; gap: 8px; }

/* ── LAYOUT ── */
.app-layout {
  display: flex;
  min-height: calc(100vh - 56px);
}

.sidebar {
  width: 220px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex; flex-direction: column; gap: 4px;
  flex-shrink: 0;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: none; background: transparent;
  color: var(--text-muted);
  cursor: pointer; font-size: 14px; text-align: left;
  transition: all 0.15s;
  width: 100%;
}
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--primary)/15; color: var(--primary); background-color: rgba(79,110,247,0.12); }
.nav-icon { font-size: 16px; }

.content {
  flex: 1;
  padding: 28px 32px;
  overflow-y: auto;
  max-width: 900px;
}

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

/* ── CARDS ── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
}
.card-title {
  font-size: 15px; font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.card-desc { color: var(--text-muted); font-size: 13px; margin-bottom: 16px; }

.form-grid { display: flex; flex-direction: column; }

/* ── FIELDS ── */
.field-group {
  display: flex; flex-direction: column; gap: 6px;
  margin-bottom: 16px;
}
.field-group:last-child { margin-bottom: 0; }
.field-group label { font-size: 13px; font-weight: 500; color: var(--text); }
.field-group small { font-size: 12px; color: var(--text-muted); }

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

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 12px;
  font-size: 14px;
  width: 100%;
  transition: border-color 0.15s;
  outline: none;
}
input:focus, select:focus { border-color: var(--primary); }
input::placeholder { color: var(--text-muted); }

.input-copy {
  display: flex; gap: 6px;
}
.input-copy input { flex: 1; }
.btn-copy {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  padding: 0 10px;
  cursor: pointer; font-size: 16px;
  transition: all 0.15s;
}
.btn-copy:hover { border-color: var(--primary); color: var(--primary); }

.checkbox-label {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; font-size: 14px;
}
input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--primary);
}

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  border: none; cursor: pointer;
  font-size: 14px; font-weight: 500;
  transition: all 0.15s;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid transparent; }
.btn-ghost:hover { background: var(--bg3); color: var(--text); }
.btn-danger { background: rgba(239,68,68,0.12); color: var(--error); border: 1px solid rgba(239,68,68,0.3); }
.btn-danger:hover { background: rgba(239,68,68,0.2); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-full { width: 100%; }

/* ── GENERATE BAR ── */
.generate-bar {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 20px;
  padding: 12px 16px;
  background: rgba(79,110,247,0.06);
  border: 1px solid rgba(79,110,247,0.2);
  border-radius: var(--radius-sm);
}
.generate-hint { font-size: 13px; color: var(--text-muted); }

/* ── USERS ── */
.user-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 10px;
  padding: 14px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.user-row .field-group { margin-bottom: 0; }

/* ── ACTIONS CARD ── */
.actions-card { background: transparent; border: none; padding: 8px 0; }
.actions-row { display: flex; gap: 12px; align-items: center; }

/* ── OUTPUT ── */
#output-section { margin-top: 24px; }

.output-tabs {
  display: flex; gap: 4px;
  margin-bottom: -1px;
}
.output-tab {
  padding: 8px 16px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  color: var(--text-muted);
  cursor: pointer; font-size: 13px;
  transition: all 0.15s;
}
.output-tab.active { background: var(--bg2); color: var(--text); border-bottom: 1px solid var(--bg2); }

.output-block {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 0 var(--radius-sm) var(--radius-sm) var(--radius-sm);
}
.output-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px; font-weight: 500;
}
.output-actions { display: flex; gap: 8px; }

.code-block {
  padding: 16px;
  font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.6;
  color: #a8d8a8;
  overflow-x: auto;
  white-space: pre;
  max-height: 420px;
  overflow-y: auto;
}

.save-bar {
  display: flex; gap: 12px; align-items: center;
  padding: 16px;
  border-top: 1px solid var(--border);
}
.save-bar input { flex: 1; }

/* ── SAVED CONFIGS ── */
.config-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 12px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
}
.config-card-info { flex: 1; }
.config-card-name { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.config-card-meta { font-size: 12px; color: var(--text-muted); }
.config-card-actions { display: flex; gap: 8px; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 15px;
}

/* ── MODAL ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%; max-width: 800px;
  max-height: 90vh;
  display: flex; flex-direction: column;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 18px; padding: 4px;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }

/* ── TOAST ── */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 14px;
  z-index: 200;
  animation: slideIn 0.2s ease;
  max-width: 320px;
}
.toast.success { border-color: var(--success); color: var(--success); }
.toast.error { border-color: var(--error); color: var(--error); }
@keyframes slideIn {
  from { transform: translateY(10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ── ERROR MSG ── */
.error-msg {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  color: var(--error);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 12px;
}
.success-msg {
  background: rgba(34,197,94,0.1);
  border: 1px solid rgba(34,197,94,0.3);
  color: var(--success);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 12px;
}

/* ── TAB CONTENT ── */
.tab-content { display: none !important; }
.tab-content.active { display: block !important; }
