:root {
    --indigo: #4f46e5;
    --indigo-dark: #3730a3;
    --emerald: #059669;
    --violet: #7c3aed;
    --slate: #64748b;
    --ink: #1e293b;
    --muted: #64748b;
    --line: #e2e8f0;
    --bg: #f0f4f8;
    --card: #ffffff;
    --danger: #dc2626;
    --warning: #d97706;
    --ok: #059669;
    --radius: 12px;
    --shadow: 0 4px 15px rgba(0, 0, 0, .05);
    --shadow-lg: 0 18px 45px -12px rgba(15, 23, 42, .18);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', 'Poppins', system-ui, -apple-system, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--indigo); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }

/* ── Layout ─────────────────────────────────────────────────────────────── */
.app-shell { display: flex; width: 100%; max-width: 1700px; margin: 0 auto; }

.sidebar {
    width: 262px;
    background: #fff;
    border-right: 1px solid var(--line);
    padding: 18px 14px;
    position: sticky;
    top: 0;
    align-self: flex-start;
    max-height: 100vh;
    overflow-y: auto;
    flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; }
.brand-logo {
    width: 40px; height: 40px; border-radius: 12px;
    background: linear-gradient(135deg, var(--indigo), #ec4899);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-size: 20px;
}
.brand-name { font-weight: 800; font-size: 17px; letter-spacing: -.4px; }
.brand-tag { font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-weight: 700; }

.nav-group { margin-bottom: 18px; }
.nav-group h4 {
    font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px;
    color: var(--muted); margin: 0 8px 8px; font-weight: 800;
}
.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 10px; border-radius: 10px; color: var(--ink);
    font-weight: 600; font-size: 14px; margin-bottom: 2px;
}
.nav-link:hover { background: #f1f5f9; text-decoration: none; color: var(--indigo); }
.nav-link.active { background: #eef2ff; color: var(--indigo); }
.nav-link .ico { width: 20px; text-align: center; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    background: rgba(255, 255, 255, .9);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
    padding: 12px 26px;
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 30;
}
.topbar .crumb { font-weight: 700; color: var(--ink); }
.topbar .user { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: linear-gradient(135deg, var(--indigo), var(--violet));
    color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700;
}

.content { padding: 24px 26px 60px; max-width: 1440px; width: 100%; margin: 0 auto; }

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
    background: var(--card); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 20px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-title { font-size: 15px; font-weight: 800; color: var(--indigo); display: flex; align-items: center; gap: 8px; }
.card-title.emerald { color: var(--emerald); }
.card-title.violet { color: var(--violet); }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat .n { font-size: 26px; font-weight: 800; }
.stat .l { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; font-weight: 700; }

/* ── Forms ──────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
label { display: block; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--indigo); margin-bottom: 5px; }
label.plain { text-transform: none; letter-spacing: normal; color: var(--ink); font-size: 13px; }
input, select, textarea {
    width: 100%; padding: 9px 12px; background: #f8fafc; border: 1px solid #cbd5e1;
    border-radius: 8px; font: inherit; font-size: 14px; color: var(--ink);
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--indigo); background: #fff;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}
textarea { resize: vertical; min-height: 80px; }
.readonly-field { background: #f1f5f9; border-style: dashed; color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 160px; }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 16px; border: none; border-radius: 9px; font: inherit; font-weight: 700;
    font-size: 14px; cursor: pointer; text-decoration: none; transition: transform .15s, box-shadow .15s;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn-primary { background: linear-gradient(135deg, var(--indigo), var(--indigo-dark)); color: #fff; box-shadow: 0 4px 12px rgba(79, 70, 229, .3); }
.btn-violet { background: linear-gradient(135deg, var(--violet), #5b21b6); color: #fff; }
.btn-emerald { background: linear-gradient(135deg, var(--emerald), #047857); color: #fff; }
.btn-ghost { background: #f1f5f9; color: #334155; border: 1px solid var(--line); }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn[disabled], .btn.disabled { opacity: .55; pointer-events: none; }

/* ── Badges ─────────────────────────────────────────────────────────────── */
.badge {
    display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px;
    border-radius: 999px; font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px;
}
.badge-official { background: #e0e7ff; color: #3730a3; }
.badge-ai { background: #ede9fe; color: #5b21b6; }
.badge-teacher { background: #d1fae5; color: #065f46; }
.badge-calc { background: #e2e8f0; color: #475569; }
.badge-critical { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-ok { background: #d1fae5; color: #065f46; }
.badge-line { background: #f1f5f9; color: #475569; }

/* ── Steps / progress ───────────────────────────────────────────────────── */
.steps { display: flex; gap: 8px; margin-bottom: 22px; flex-wrap: wrap; }
.step-item {
    flex: 1; min-width: 140px; padding: 10px 12px; border-radius: 10px;
    background: #fff; border: 1px solid var(--line); font-size: 12.5px; font-weight: 700; color: var(--muted);
}
.step-item.done { border-color: #a7f3d0; color: var(--emerald); background: #f0fdf7; }
.step-item.current { border-color: var(--indigo); color: var(--indigo); background: #eef2ff; }
.step-item .num { display: inline-flex; width: 20px; height: 20px; border-radius: 50%; background: #e2e8f0; color: #475569; align-items: center; justify-content: center; margin-right: 6px; font-size: 11px; }
.step-item.current .num { background: var(--indigo); color: #fff; }
.step-item.done .num { background: var(--emerald); color: #fff; }

.progress { height: 8px; background: #e2e8f0; border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--indigo), var(--violet)); }

/* ── Semantic tags (text + color, never color alone) ────────────────────── */
.tag {
    display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px;
    border-radius: 999px; font-size: 11px; font-weight: 800; letter-spacing: .2px;
    border: 1px solid transparent; white-space: nowrap;
}
.tag-official { background: #e0e7ff; color: #3730a3; border-color: #c7d2fe; }
.tag-teacher { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.tag-ai { background: #ede9fe; color: #5b21b6; border-color: #ddd6fe; }
.tag-calc { background: #e2e8f0; color: #475569; border-color: #cbd5e1; }
.tag-error { background: #fee2e2; color: #991b1b; border-color: #fecaca; }

/* ── Contextual help ────────────────────────────────────────────────────── */
.help-box {
    background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 12px;
    padding: 12px 16px; margin-bottom: 18px;
}
.help-box summary { cursor: pointer; font-weight: 700; color: #1e40af; }
.help-box .help-body { margin-top: 8px; color: #334155; font-size: 14px; }

/* ── Primary action card ────────────────────────────────────────────────── */
.action-hero {
    background: linear-gradient(135deg, #eef2ff, #faf5ff);
    border: 1px solid #ddd6fe; border-radius: 16px; padding: 26px;
    display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap;
}
.action-hero h2 { margin: 0 0 6px; font-size: 20px; }

/* ── Tables ─────────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
tr:hover td { background: #f8fafc; }

/* ── Misc ───────────────────────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-size: 14px; font-weight: 600; }
.alert-ok { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-info { background: #eef2ff; color: #3730a3; border: 1px solid #c7d2fe; }

.empty { text-align: center; padding: 34px 16px; color: var(--muted); }
.empty .big { font-size: 38px; margin-bottom: 8px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.list li:last-child { border-bottom: none; }

.chip { display: inline-block; background: #f1f5f9; border-radius: 8px; padding: 5px 9px; font-size: 12px; color: #334155; margin: 0 5px 5px 0; }
.phase { border-left: 4px solid var(--line); padding-left: 12px; margin-bottom: 14px; }
.phase.opening { border-color: var(--emerald); }
.phase.development { border-color: var(--indigo); }
.phase.closing { border-color: var(--violet); }

.kv { display: grid; grid-template-columns: 180px 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; }

.timerow { display: flex; gap: 10px; align-items: center; }
.bar { flex: 1; height: 10px; background: #e2e8f0; border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Auth ───────────────────────────────────────────────────────────────── */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(135deg, #eef2ff, #f0f4f8 60%, #faf5ff); }
.auth-card { width: 100%; max-width: 420px; background: #fff; border-radius: 18px; padding: 34px; box-shadow: var(--shadow-lg); }
.auth-title { text-align: center; margin-bottom: 4px; font-weight: 800; font-size: 22px; }
.auth-sub { text-align: center; color: var(--muted); margin-bottom: 22px; font-size: 13.5px; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
    .app-shell { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: static; }
    .grid-2, .grid-4 { grid-template-columns: 1fr; }
    .content { padding: 16px; }
    .kv { grid-template-columns: 1fr; }
}

/* ── Print ──────────────────────────────────────────────────────────────── */
@media print {
    .sidebar, .topbar, .actions, .no-print { display: none !important; }
    .content { padding: 0; max-width: none; }
    .card { box-shadow: none; border-color: #cbd5e1; page-break-inside: avoid; }
    body { background: #fff; }
}
