:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --border: #475569;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --warning: #eab308;
  --danger: #dc2626;
  --radius: 8px;
  --font: 'Inter', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; }
a { color: #93c5fd; text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem;
  padding: 0.5rem 0.85rem; border: none; border-radius: var(--radius);
  font: inherit; font-size: 0.85rem; font-weight: 600; cursor: pointer;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 0.35rem 0.6rem; font-size: 0.78rem; }
.btn-block { width: 100%; }

.badge {
  display: inline-block; padding: 0.15rem 0.45rem; border-radius: 999px;
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
}
.badge-draft { background: #334155; color: #cbd5e1; }
.badge-pending { background: #854d0e; color: #fef3c7; }
.badge-approved { background: #14532d; color: #bbf7d0; }
.badge-rejected { background: #7f1d1d; color: #fecaca; }

/* Login */
.login-page { display: flex; align-items: center; justify-content: center; padding: 2rem; }
.login-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 2rem; }
.login-brand h1 { font-size: 1.35rem; margin-bottom: 0.35rem; }
.login-brand p { color: var(--muted); font-size: 0.88rem; margin-bottom: 1.5rem; }
.login-form label { display: block; margin-bottom: 1rem; }
.login-form label span { display: block; font-size: 0.78rem; color: var(--muted); margin-bottom: 0.35rem; }
.login-form input {
  width: 100%; padding: 0.6rem 0.75rem; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--bg); color: var(--text); font: inherit;
}
.login-error { margin-top: 0.75rem; color: #fecaca; font-size: 0.85rem; }
.login-hint { margin-top: 1.25rem; font-size: 0.78rem; color: var(--muted); }
.login-hint ul { margin-top: 0.5rem; padding-left: 1.1rem; line-height: 1.5; }

/* CMS shell */
.cms-app { display: flex; flex-direction: column; height: 100vh; }
.cms-topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.65rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.cms-topbar h1 { font-size: 1rem; font-weight: 700; }
.cms-topbar-meta { display: flex; align-items: center; gap: 0.75rem; font-size: 0.82rem; color: var(--muted); }
.cms-body { flex: 1; display: grid; grid-template-columns: 280px 1fr; min-height: 0; }

.cms-sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar-head { padding: 0.75rem; border-bottom: 1px solid var(--border); display: flex; gap: 0.4rem; flex-wrap: wrap; }
.sidebar-tree { flex: 1; overflow: auto; padding: 0.5rem; }

.tree-folder, .tree-file {
  display: flex; align-items: center; gap: 0.35rem; width: 100%; text-align: left;
  padding: 0.4rem 0.5rem; border: none; border-radius: 6px; background: none;
  color: var(--text); font: inherit; font-size: 0.82rem; cursor: pointer;
}
.tree-folder:hover, .tree-file:hover { background: var(--surface-2); }
.tree-file.active { background: var(--primary); color: #fff; }
.tree-folder .icon { opacity: 0.7; }
.tree-children { padding-left: 0.85rem; }
.tree-file .badge { margin-left: auto; }

.cms-main { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.cms-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.65rem 1rem; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.cms-toolbar h2 { font-size: 0.95rem; font-weight: 600; }
.cms-toolbar-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

.cms-editor { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 0.75rem 1rem 1rem; }
.cms-editor textarea {
  flex: 1; min-height: 200px; width: 100%; padding: 0.85rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: #0b1220; color: #e2e8f0; font-family: Consolas, monospace; font-size: 0.8rem;
  resize: none; outline: none;
}
.cms-editor textarea:focus { border-color: var(--primary); }
.cms-meta { display: flex; gap: 1rem; flex-wrap: wrap; font-size: 0.78rem; color: var(--muted); margin-bottom: 0.65rem; }
.cms-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 0.9rem; }

.cms-dashboard { padding: 1rem; overflow: auto; }
.sidebar-dashboard {
  padding: 0.75rem; border-bottom: 1px solid var(--border); max-height: 240px; overflow: auto;
}
.sidebar-section-title { margin-bottom: 0.5rem; font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.45rem; margin-bottom: 0.75rem; }
.stat-card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.55rem; }
.stat-card strong { display: block; font-size: 1.1rem; }
.stat-card span { font-size: 0.65rem; color: var(--muted); text-transform: uppercase; }
.pending-list { list-style: none; }
.pending-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.65rem 0.75rem; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 0.4rem; font-size: 0.85rem;
}
.pending-actions { display: flex; gap: 0.35rem; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.65); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 1.25rem; width: min(420px, 100%);
}
.modal h3 { margin-bottom: 0.75rem; font-size: 1rem; }
.modal label { display: block; margin-bottom: 0.75rem; font-size: 0.82rem; }
.modal input, .modal select, .modal textarea {
  width: 100%; margin-top: 0.3rem; padding: 0.5rem; border: 1px solid var(--border);
  border-radius: 6px; background: var(--bg); color: var(--text); font: inherit;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }
.modal-wide { width: min(520px, 100%); }
.modal-subtitle { margin: 0.75rem 0 0.5rem; font-size: 0.85rem; color: var(--muted); }
.users-list-wrap { max-height: 180px; overflow: auto; margin-bottom: 0.5rem; }
.users-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
.users-table th, .users-table td { text-align: left; padding: 0.35rem 0.4rem; border-bottom: 1px solid var(--border); }
.users-table th { color: var(--muted); font-weight: 600; }

@media (max-width: 900px) {
  .cms-body { grid-template-columns: 1fr; }
  .cms-sidebar { max-height: 220px; }
}
