:root {
  --bg: #0b0f17;
  --surface: #111827;
  --surface-elevated: #161f30;
  --border: #1f2937;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --font-sans: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
}

a { color: #60a5fa; text-decoration: none; }
a:hover { text-decoration: underline; }
.mono { font-family: var(--font-mono); font-size: 12px; }
.tabular { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.inline-form { display: inline; margin: 0; }
.text-warn { color: #fbbf24; font-weight: 600; }

/* Topbar (3-zone contract) */
.topbar {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-brand {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  flex-shrink: 0;
}
.topbar-brand:hover { text-decoration: none; }
.topbar-nav {
  display: flex;
  align-items: center;
  gap: 20px;
}
.nav-link {
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}
.nav-link:hover { color: var(--text); text-decoration: none; }
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.topbar-user { color: var(--muted); font-size: 13px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.btn:hover { text-decoration: none; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-outline { border-color: var(--border); background: var(--surface-elevated); }
.btn-outline:hover { border-color: #374151; }
.btn-ghost { color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface-elevated); }
.btn-danger { background: rgba(220, 38, 38, 0.15); border-color: rgba(220, 38, 38, 0.4); color: #fca5a5; }
.btn-danger:hover { background: rgba(220, 38, 38, 0.28); }

/* Flashes */
.flash-stack { max-width: 1200px; margin: 12px auto 0; padding: 0 20px; display: grid; gap: 8px; }
.flash {
  padding: 10px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 13px;
}
.flash-success { background: rgba(22, 163, 74, 0.14); border-color: rgba(22, 163, 74, 0.4); color: #86efac; }
.flash-error { background: rgba(220, 38, 38, 0.14); border-color: rgba(220, 38, 38, 0.4); color: #fca5a5; }

/* Containers & Panels */
.page-container { max-width: 1220px; margin: 0 auto; padding: 28px 20px 60px; }
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.page-head h1 { margin: 0 0 4px; font-size: 24px; }
.page-head p { margin: 0; }
.head-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.section-gap { margin-top: 24px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.panel-head h2, .panel h3 { margin: 0; font-size: 16px; }
.panel-foot { display: flex; justify-content: space-between; margin-top: 10px; font-size: 12px; }

.two-col-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.stats-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.stat-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat-box strong { font-size: 20px; }

/* Progress Bars */
.progress-track { height: 8px; background: #1f2937; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; transition: width 0.2s ease; }
.mini-track { width: 120px; height: 6px; background: #1f2937; border-radius: 999px; overflow: hidden; }
.mini-fill { height: 100%; }
.bar-ok { background: var(--ok); }
.bar-warn { background: var(--warn); }
.bar-danger { background: var(--danger); }
.bar-accent { background: var(--accent); }

/* Tables */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
.data-table th { color: var(--muted); font-weight: 600; font-size: 12px; }
.data-table th.num, .data-table td.num { text-align: right; }
.row-actions { display: inline-flex; gap: 6px; align-items: center; justify-content: flex-end; }

/* Forms & Auth */
.auth-wrap { min-height: calc(100vh - 52px); display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 28px;
}
.auth-card h1 { margin: 0 0 6px; font-size: 20px; }
.auth-footer { margin: 18px 0 0; text-align: center; color: var(--muted); }
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.form-row-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea, .select-compact {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.check-field { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }

/* Admin Subnav & Split Edit */
.admin-subnav {
  display: flex;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
  margin-bottom: 20px;
}
.admin-subnav a { color: var(--muted); font-weight: 600; }
.admin-subnav a:hover { color: var(--text); text-decoration: none; }
.split-edit-layout { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(300px, 1fr); gap: 20px; align-items: start; }
.preview-sticky { position: sticky; top: 20px; }
.warn-banner {
  background: rgba(217, 119, 6, 0.12);
  border: 1px solid rgba(217, 119, 6, 0.4);
  color: #fcd34d;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 18px;
}
.test-output {
  margin-top: 14px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
}

/* Pricing & QRPh */
.pricing-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; }
.pricing-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.pricing-card-active { border-color: var(--accent); }
.pricing-card-head h2 { margin: 0 0 4px; font-size: 18px; }
.pricing-card-head p { margin: 0; font-size: 13px; }
.price-amount { font-size: 28px; font-weight: 700; }
.plan-specs { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 12px 0; }
.plan-specs dt { font-size: 11px; color: var(--muted); }
.plan-specs dd { margin: 2px 0 0; font-weight: 600; }
.feature-list { margin: 0; padding-left: 18px; display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.pricing-cta { margin-top: auto; }
.qr-card { max-width: 440px; width: 100%; text-align: center; }
.qr-box { margin: 18px auto; width: 240px; height: 240px; background: #fff; border-radius: 8px; display: flex; align-items: center; justify-content: center; padding: 12px; }
.qr-image { max-width: 100%; max-height: 100%; }

/* VS Code-like IDE Workbench */
.ide-shell { display: flex; flex-direction: column; height: calc(100vh - 52px); }
.ide-toolbar {
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 14px;
  background: var(--surface-elevated);
  border-bottom: 1px solid var(--border);
}
.ide-toolbar-left, .ide-toolbar-right { display: flex; align-items: center; gap: 10px; }
.inline-label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.quota-widget { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.quota-label { display: flex; align-items: center; gap: 4px; color: var(--muted); white-space: nowrap; }
.quota-label strong { color: var(--text); }
.upgrade-link { color: #fbbf24; font-weight: 700; font-size: 12px; }

.ide-workbench {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 320px;
}
.ide-explorer, .ide-ai-pane {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.ide-ai-pane { border-right: none; border-left: 1px solid var(--border); }
.pane-title {
  height: 36px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
}
.file-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.file-item { display: flex; align-items: center; justify-content: space-between; border-radius: 5px; }
.file-item.active { background: rgba(59, 130, 246, 0.16); }
.file-open-btn {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--text);
  text-align: left;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  font-size: 12px;
}
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { color: var(--muted); flex-shrink: 0; }
.file-del-btn { background: transparent; border: none; color: var(--muted); cursor: pointer; padding: 4px 6px; }
.file-del-btn:hover { color: #fca5a5; }
.file-empty { padding: 12px; font-size: 12px; }

.ide-editor-pane { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.editor-tabbar {
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.editor-tab { font-size: 12px; font-weight: 600; color: var(--text); }
.code-surface { flex: 1; min-height: 0; display: flex; overflow: hidden; }
.line-gutter {
  margin: 0;
  padding: 14px 10px;
  min-width: 44px;
  text-align: right;
  color: #4b5563;
  background: #0d121c;
  border-right: 1px solid var(--border);
  user-select: none;
  line-height: 1.6;
  overflow: hidden;
}
.code-textarea {
  flex: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 14px;
  border: none;
  resize: none;
  background: var(--bg);
  color: #e2e8f0;
  font-size: 13px;
  line-height: 1.6;
  outline: none;
}

.ai-locked-box { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.ai-locked-box h3 { margin: 0; font-size: 15px; }
.ai-messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.ai-msg { padding: 10px; border-radius: 6px; font-size: 12px; border: 1px solid var(--border); white-space: pre-wrap; }
.ai-msg-system { color: var(--muted); background: var(--bg); }
.ai-msg-user { background: rgba(59, 130, 246, 0.12); border-color: rgba(59, 130, 246, 0.3); }
.ai-msg-assistant { background: var(--surface-elevated); }
.ai-input-area { padding: 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.ai-input-area textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px;
  font-family: inherit;
  font-size: 12px;
  resize: vertical;
}
.ai-actions { display: flex; gap: 8px; }

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 22px;
}
.modal-card h3 { margin: 0 0 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

@media (max-width: 960px) {
  .ide-workbench { grid-template-columns: 1fr; grid-template-rows: 180px 1fr 240px; }
  .two-col-grid, .split-edit-layout, .stats-grid { grid-template-columns: 1fr; }
}
