:root {
  --bg-base: #090d16;
  --bg-surface: #0f172a;
  --bg-elevated: #1e293b;
  --border: #263349;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --cyan: #06b6d4;
  --emerald: #10b981;
  --amber: #f59e0b;
  --rose: #f43f5e;
  --purple: #a855f7;
  --radius: 14px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  background: var(--bg-base);
  color: var(--text-main);
  font-family: var(--font-sans);
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* Layout */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 265px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 0.75rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border); }
.brand-logo { width: 38px; height: 38px; border-radius: 10px; }
.brand-title { font-weight: 800; font-size: 1.05rem; letter-spacing: 0.04em; color: var(--cyan); }
.brand-sub { font-size: 0.72rem; color: var(--text-muted); }

.nav-list { display: flex; flex-direction: column; gap: 0.35rem; flex: 1; }
.nav-btn {
  display: flex; align-items: center; justify-content: space-between;
  background: transparent; border: 1px solid transparent; color: var(--text-muted);
  padding: 0.65rem 0.85rem; border-radius: 10px; cursor: pointer;
  font-size: 0.88rem; font-weight: 500; text-align: left; transition: all 0.18s;
}
.nav-btn:hover { background: rgba(255,255,255,0.04); color: var(--text-main); }
.nav-btn.active { background: rgba(6, 182, 212, 0.14); border-color: rgba(6, 182, 212, 0.35); color: var(--cyan); font-weight: 600; }

.status-box {
  background: var(--bg-base); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.75rem; font-size: 0.78rem;
}
.status-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.35rem; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.dot.online { background: var(--emerald); box-shadow: 0 0 8px var(--emerald); }
.dot.offline { background: var(--amber); box-shadow: 0 0 8px var(--amber); }

.main-content { flex: 1; padding: 1.5rem 2rem; max-width: 1280px; width: 100%; margin: 0 auto; }
.topbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.page-title { font-size: 1.45rem; font-weight: 700; }
.page-desc { font-size: 0.86rem; color: var(--text-muted); }

/* Cards & Grids */
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1.25rem; margin-bottom: 1.5rem; }
.card {
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem;
}
.kpi-label { font-size: 0.78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-val { font-size: 1.75rem; font-weight: 800; margin: 0.25rem 0; font-family: var(--font-mono); }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.73rem; font-weight: 600;
}
.badge-high { background: rgba(16,185,129,0.15); color: #34d399; border: 1px solid rgba(16,185,129,0.35); }
.badge-mixed { background: rgba(245,158,11,0.15); color: #fbbf24; border: 1px solid rgba(245,158,11,0.35); }
.badge-low { background: rgba(244,63,94,0.15); color: #fb7185; border: 1px solid rgba(244,63,94,0.35); }
.badge-code { background: rgba(6,182,212,0.15); color: var(--cyan); font-family: var(--font-mono); }

/* Controls */
.btn {
  background: var(--cyan); color: #04131a; border: none; padding: 0.55rem 1rem;
  border-radius: 9px; font-weight: 700; font-size: 0.85rem; cursor: pointer; transition: 0.15s;
}
.btn:hover { filter: brightness(1.08); }
.btn-outline {
  background: transparent; color: var(--text-main); border: 1px solid var(--border);
  padding: 0.5rem 0.9rem; border-radius: 9px; font-size: 0.84rem; cursor: pointer;
}
.btn-outline:hover { border-color: var(--cyan); color: var(--cyan); }
.btn-danger { background: rgba(244,63,94,0.16); color: #fb7185; border: 1px solid rgba(244,63,94,0.35); }

input, select, textarea {
  width: 100%; background: var(--bg-base); border: 1px solid var(--border); color: var(--text-main);
  padding: 0.6rem 0.8rem; border-radius: 9px; font-size: 0.88rem; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--cyan); }

/* Concept Cards */
.concept-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem; }
.concept-card {
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.1rem; display: flex; flex-direction: column; gap: 0.65rem; cursor: pointer; transition: 0.18s;
}
.concept-card:hover { border-color: var(--cyan); transform: translateY(-2px); }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(3, 7, 18, 0.82); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center; padding: 1rem; z-index: 50;
}
.modal-backdrop.open { display: flex; }
.modal-panel {
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: 16px;
  max-width: 820px; width: 100%; max-height: 88vh; overflow-y: auto; padding: 1.5rem;
}
.field-block { margin-bottom: 0.9rem; padding-bottom: 0.8rem; border-bottom: 1px solid rgba(255,255,255,0.06); }
.field-label { font-size: 0.76rem; color: var(--cyan); text-transform: uppercase; font-weight: 700; margin-bottom: 0.25rem; }

/* Flashcard 3D */
.fc-box {
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 1.75rem; max-width: 720px; margin: 0 auto;
}
.fc-answer { margin-top: 1.25rem; padding-top: 1.25rem; border-top: 1px dashed var(--border); }

/* Diagnostic Table */
table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
th, td { text-align: left; padding: 0.65rem 0.75rem; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; }

/* Mobile */
@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .nav-list { flex-direction: row; flex-wrap: wrap; }
  .main-content { padding: 1rem; }
}
