:root {
  --bg: #0f1117;
  --surface: #181b24;
  --surface-2: #1f2330;
  --surface-3: #272c3d;
  --border: #2d3344;
  --text: #e4e7ef;
  --text-muted: #8b92a8;
  --text-dim: #5a6178;
  --primary: #6366f1;
  --primary-hover: #5558e3;
  --primary-light: rgba(99,102,241,.12);
  --success: #22c55e;
  --success-light: rgba(34,197,94,.12);
  --warning: #f59e0b;
  --warning-light: rgba(245,158,11,.12);
  --danger: #ef4444;
  --danger-light: rgba(239,68,68,.12);
  --info: #3b82f6;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.3);
  --topbar-h: 56px;
  --sidebar-w: 240px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.6;
  min-height: 100vh; overflow-x: hidden;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
h1,h2,h3,h4,h5 { font-weight: 700; line-height: 1.3; margin-bottom: .5em; }
h1{font-size:1.6rem}h2{font-size:1.3rem}h3{font-size:1.1rem}
small { color: var(--text-muted); }
code,pre { font-family: 'SF Mono', Monaco, Consolas, monospace; font-size: .875em; }
pre { background: var(--surface-2); padding: 12px; border-radius: var(--radius-sm); overflow-x: auto; border: 1px solid var(--border); }
code { background: var(--surface-2); padding: 2px 6px; border-radius: 4px; }
pre code { background: none; padding: 0; }

/* ===== LAYOUT ===== */
.app-layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border);
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 100; padding: 16px 0;
  overflow-y: auto; transition: transform .25s ease;
  display: flex; flex-direction: column;
}
.sidebar-brand { padding: 0 20px 20px; font-size: 1.15rem; font-weight: 800; color: var(--text); display:flex; align-items:center; gap:8px; }
.sidebar-brand span { color: var(--primary); }
.nav-section { padding: 8px 0; }
.nav-section-title { padding: 8px 20px; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-dim); font-weight: 700; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 10px 20px; color: var(--text-muted);
  font-weight: 500; font-size: .9rem; border-left: 3px solid transparent; transition: all .15s;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.active { color: var(--primary); background: var(--primary-light); border-left-color: var(--primary); }
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; }

.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  height: var(--topbar-h); background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 12px; gap: 8px; position: sticky; top: 0; z-index: 50;
  overflow: hidden;
}
.topbar .menu-toggle { display: none; background: none; border: none; color: var(--text); cursor: pointer; padding: 6px; flex-shrink: 0; }
.topbar .page-title { font-size: 1.05rem; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-user { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85rem; flex-shrink: 0;
}
.content { padding: 24px; flex: 1; max-width: 1200px; width: 100%; }

/* ===== CARDS ===== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 8px; }
.card-title { font-size: 1.05rem; font-weight: 700; }

/* ===== GRID ===== */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

/* ===== STATS ===== */
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; display:flex; flex-direction:column; gap:4px; }
.stat-card .stat-icon { font-size: 1.5rem; margin-bottom: 4px; }
.stat-card .stat-value { font-size: 1.8rem; font-weight: 800; }
.stat-card .stat-label { color: var(--text-muted); font-size: .85rem; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-size: .875rem; font-weight: 600;
  cursor: pointer; transition: all .15s; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.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: #000; }
.btn-sm { padding: 5px 10px; font-size: .8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-outline { background: transparent; border-color: var(--border); }

/* ===== BADGES ===== */
.badge {
  display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 6px;
  font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
}
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--primary-light); color: var(--primary); }
.badge-muted { background: var(--surface-3); color: var(--text-muted); }

/* ===== ALERTS ===== */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: .9rem; border: 1px solid; }
.alert-success { background: var(--success-light); border-color: var(--success); color: var(--success); }
.alert-error { background: var(--danger-light); border-color: var(--danger); color: var(--danger); }
.alert-info { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); }
.form-label .opt { color: var(--text-dim); font-weight: 400; font-size: .8rem; }
.form-control, .form-select, textarea.form-control {
  width: 100%; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-size: .9rem; font-family: inherit; transition: border-color .15s;
}
.form-control:focus, .form-select:focus, textarea.form-control:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light);
}
textarea.form-control { resize: vertical; min-height: 80px; }
.form-hint { font-size: .78rem; color: var(--text-dim); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ===== TABLES ===== */
.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table th { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); color: var(--text-muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
.table td { padding: 12px; border-bottom: 1px solid var(--border); }
.table tr:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }

/* ===== PROGRESS BAR ===== */
.progress-bar { height: 8px; background: var(--surface-3); border-radius: 4px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--primary); border-radius: 4px; transition: width .3s; }
.progress-bar-fill.success { background: var(--success); }
.progress-bar-fill.warning { background: var(--warning); }

/* ===== EXERCISE CONTENT ===== */
.exercise-content { line-height: 1.7; }
.exercise-content h1,.exercise-content h2,.exercise-content h3 { margin-top: 1.5em; margin-bottom: .5em; }
.exercise-content h2 { border-bottom: 1px solid var(--border); padding-bottom: .3em; }
.exercise-content p { margin-bottom: 1em; }
.exercise-content ul,.exercise-content ol { margin: 1em 0; padding-left: 1.5em; }
.exercise-content li { margin-bottom: .4em; }
.exercise-content strong { color: var(--text); }
.exercise-content blockquote { border-left: 3px solid var(--primary); padding-left: 16px; color: var(--text-muted); margin: 1em 0; }
.exercise-content hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }
.exercise-content a { color: var(--primary); }
.exercise-content table { width: 100%; border-collapse: collapse; margin: 1em 0; }
.exercise-content th,.exercise-content td { border: 1px solid var(--border); padding: 8px; }

/* ===== STEP LIST ===== */
.step-list { list-style: none; padding: 0; counter-reset: step; }
.step-list .step { display: flex; gap: 12px; margin-bottom: 16px; }
.step-list .step-num {
  width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .8rem; flex-shrink: 0;
}
.step-list .step-type { font-size: .7rem; text-transform: uppercase; color: var(--text-dim); font-weight: 700; }

/* ===== CHAT ===== */
.chat-messages { max-height: 400px; overflow-y: auto; padding: 8px; }
.chat-msg { margin-bottom: 12px; padding: 10px 14px; border-radius: var(--radius); max-width: 85%; }
.chat-msg.user { background: var(--primary); color: #fff; margin-left: auto; }
.chat-msg.ai { background: var(--surface-2); border: 1px solid var(--border); }
.chat-msg .role { font-size: .7rem; font-weight: 700; text-transform: uppercase; opacity: .7; margin-bottom: 4px; }

/* ===== MISC ===== */
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.items-center { align-items: center; }
.wrap { flex-wrap: wrap; }
.mt-8{margin-top:8px}.mt-16{margin-top:16px}.mt-24{margin-top:24px}
.mb-8{margin-bottom:8px}.mb-16{margin-bottom:16px}
.text-center{text-align:center}
.text-muted{color:var(--text-muted)}
.text-success{color:var(--success)}.text-danger{color:var(--danger)}.text-warning{color:var(--warning)}
.w-full{width:100%}
.hidden{display:none!important}
.loading { opacity: .5; pointer-events: none; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state .emoji { font-size: 3rem; margin-bottom: 12px; }
.points-pill { background: var(--warning-light); color: var(--warning); padding: 4px 10px; border-radius: 20px; font-weight: 700; font-size: .85rem; }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  :root { --sidebar-w: 260px; }
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .topbar .menu-toggle { display: block; }
  .topbar .points-pill { display: none; }
  .content { padding: 16px; }
  .grid-2, .grid-3, .grid-4, .form-row { grid-template-columns: 1fr; }
  .grid-auto { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .card-header { flex-direction: column; align-items: flex-start; }
  h1 { font-size: 1.3rem; }
  .topbar-user .user-name { display: none; }
  .btn-block-mobile { width: 100%; }
}
@media (max-width: 480px) {
  .content { padding: 12px; }
  .btn { padding: 8px 12px; font-size: .82rem; }
  .chat-msg { max-width: 95%; }
  .logout-text { display: none; }
}

/* Overlay for mobile sidebar */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 99; }
.sidebar-overlay.show { display: block; }

/* Landing page */
.landing-hero { text-align: center; padding: 80px 20px; max-width: 700px; margin: 0 auto; }
.landing-hero h1 { font-size: 2.5rem; margin-bottom: 16px; background: linear-gradient(135deg, var(--primary), #a855f7); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.landing-hero p { font-size: 1.15rem; color: var(--text-muted); margin-bottom: 32px; }
.landing-features { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; max-width: 1000px; margin: 0 auto; padding: 0 20px 60px; }
.feature-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; text-align: center; }
.feature-card .icon { font-size: 2.5rem; margin-bottom: 12px; }
.feature-card h3 { margin-bottom: 8px; }
.feature-card p { color: var(--text-muted); font-size: .9rem; }

@media (max-width: 768px) {
  .landing-hero { padding: 40px 20px; }
  .landing-hero h1 { font-size: 1.8rem; }
  .landing-hero p { font-size: 1rem; }
}
