:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --info: #0284c7;
  --sidebar-w: 256px;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
}
[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #293548;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 14px;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; }
.between { justify-content: space-between; }

/* Layout */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 40;
  overflow-y: auto;
  transition: transform .2s ease;
}
.brand {
  padding: 1.1rem 1.25rem;
  font-weight: 700;
  font-size: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .6rem;
}
.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #06b6d4);
}
.nav-group { padding: .75rem .75rem .25rem; }
.nav-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); padding: .25rem .6rem; font-weight: 600;
}
.nav-link {
  display: flex; align-items: center; justify-content: space-between;
  padding: .55rem .75rem; border-radius: 8px; color: var(--text);
  font-weight: 500; margin-bottom: 2px;
}
.nav-link:hover { background: var(--surface-2); text-decoration: none; }
.nav-link.active { background: var(--primary); color: #fff; }
.main-area {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky; top: 0; z-index: 30;
}
.content-wrap { padding: 1.5rem; max-width: 1440px; width: 100%; margin: 0 auto; }

/* Cards & Grids */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}
.card-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 1rem; margin-bottom: 1rem;
}
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  box-shadow: var(--shadow);
}
.kpi-title { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 26px; font-weight: 700; margin-top: .25rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 1.25rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .9rem; }

/* Forms & Buttons */
label { display: flex; flex-direction: column; gap: .35rem; font-weight: 500; font-size: 13px; }
input, select, textarea {
  width: 100%; padding: .55rem .75rem;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); color: var(--text); font: inherit;
}
textarea { min-height: 110px; resize: vertical; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .52rem .95rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none;
}
.btn:hover { filter: brightness(.96); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); border-color: var(--warning); color: #fff; }
.btn-sm { padding: .32rem .65rem; font-size: 12px; }
.btn-block { width: 100%; }

/* Badges & Alerts */
.badge {
  display: inline-block; padding: .18rem .55rem; border-radius: 999px;
  font-size: 11px; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border);
}
.badge-success { background: rgba(5,150,105,.12); color: var(--success); border-color: rgba(5,150,105,.25); }
.badge-danger { background: rgba(220,38,38,.12); color: var(--danger); border-color: rgba(220,38,38,.25); }
.badge-warning { background: rgba(217,119,6,.12); color: var(--warning); border-color: rgba(217,119,6,.25); }
.badge-info { background: rgba(2,132,199,.12); color: var(--info); border-color: rgba(2,132,199,.25); }
.alert {
  padding: .85rem 1rem; border-radius: 10px; margin-bottom: 1rem;
  border: 1px solid var(--border); background: var(--surface-2);
}
.alert-success { border-color: rgba(5,150,105,.35); background: rgba(5,150,105,.09); }
.alert-danger { border-color: rgba(220,38,38,.35); background: rgba(220,38,38,.09); }
.alert-warning { border-color: rgba(217,119,6,.35); background: rgba(217,119,6,.09); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: .65rem .75rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); }

/* Auth & Installer */
.auth-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.75rem; box-shadow: var(--shadow); }
.install-shell { width: 100%; max-width: 860px; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .6rem; margin-bottom: 1.25rem; }
.check-item { display: flex; justify-content: space-between; padding: .55rem .8rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); }
.check-item.ok strong { color: var(--success); }
.check-item.fail strong { color: var(--danger); }
.check-item.warn strong { color: var(--warning); }
.code-box { background: #0f172a; color: #e2e8f0; padding: .75rem 1rem; border-radius: 8px; overflow-x: auto; font-size: 12px; }

/* Editor & Calendar */
.editor-toolbar { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .5rem; }
.html-editor {
  min-height: 260px; padding: .85rem; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface); overflow-y: auto;
}
.calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(120px, 1fr)); gap: .5rem; }
.calendar-cell {
  min-height: 110px; border: 1px solid var(--border); border-radius: 8px;
  padding: .45rem; background: var(--surface-2); font-size: 12px;
}
.cal-item {
  background: var(--surface); border-left: 3px solid var(--primary);
  padding: .25rem .4rem; border-radius: 4px; margin-top: .3rem; font-size: 11px;
}

.mobile-menu-btn { display: none; }
@media (max-width: 960px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-area { margin-left: 0; }
  .mobile-menu-btn { display: inline-flex; }
  .grid-2 { grid-template-columns: 1fr; }
  .calendar-grid { grid-template-columns: repeat(2, 1fr); }
}
