:root {
    --bg: #f5f7fb;
    --panel: #ffffff;
    --text: #172033;
    --muted: #667085;
    --line: #d9e0ec;
    --brand: #223a5e;
    --accent: #315efb;
    --danger: #b42318;
    --danger-bg: #fee4e2;
    --sidebar: #111827;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: Arial, sans-serif; }
a { color: inherit; text-decoration: none; }
.shell { display: grid; grid-template-columns: 300px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: #fff; padding: 24px; }
.brand { display: flex; gap: 14px; align-items: center; margin-bottom: 28px; }
.brand-mark { width: 48px; height: 48px; border-radius: 14px; background: #fff; color: #111827; display: grid; place-items: center; font-weight: 800; }
.brand h1 { margin: 0; font-size: 20px; }
.brand p { margin: 4px 0 0; color: #cbd5e1; }
.nav-link { display: block; padding: 12px 14px; border-radius: 10px; background: rgba(255,255,255,.08); margin-bottom: 18px; }
.nav-link:hover { background: rgba(255,255,255,.16); }
.main { padding: 22px 28px 28px; min-width: 0; }

.app-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    margin-bottom: 18px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #ffffff;
    box-shadow: 0 8px 22px rgba(15, 23, 42, .04);
}
.app-topbar-left { display: flex; flex-direction: column; gap: 2px; }
.app-topbar-left strong { font-size: 15px; }
.app-topbar-left span { color: var(--muted); font-size: 12px; }
.app-topbar-right { font-size: 14px; color: #374151; }
.app-topbar-right a { color: var(--accent); font-weight: 700; }
.app-topbar-right a:hover { text-decoration: underline; }
.app-topbar .role { color: var(--muted); margin-left: 4px; }
.app-topbar .separator { color: var(--line); margin: 0 8px; }

.hero { background: linear-gradient(135deg, #1d3557, #315efb); color: #fff; padding: 28px; border-radius: 22px; margin-bottom: 22px; display: flex; justify-content: space-between; gap: 20px; }
.hero h1 { margin: 0 0 8px; font-size: 32px; }
.hero p { margin: 0; color: #e5edff; }
.hero-meta { min-width: 190px; align-self: flex-start; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.18); padding: 14px; border-radius: 16px; }
.hero-meta span { display: block; color: #dbeafe; font-size: 12px; margin-bottom: 4px; }
.hero-meta strong { word-break: break-word; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: 12px; }
.grid { display: grid; gap: 22px; margin-bottom: 22px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 20px; box-shadow: 0 12px 30px rgba(15, 23, 42, .06); }
.panel.compact { background: rgba(255,255,255,.06); border-color: rgba(255,255,255,.12); box-shadow: none; }
.panel h2 { margin: 0 0 16px; font-size: 20px; }
.muted { color: var(--muted); }
.sidebar .muted { color: #cbd5e1; }
.project-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.project-link { display: block; padding: 12px; border-radius: 12px; color: #fff; background: rgba(255,255,255,.06); }
.project-link.active, .project-link:hover { background: rgba(255,255,255,.16); }
.project-link span { display: block; color: #cbd5e1; font-size: 12px; margin-top: 4px; }
label { display: grid; gap: 7px; font-size: 13px; font-weight: 700; margin-bottom: 12px; }
input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font: inherit; background: #fff; color: var(--text); }
textarea { resize: vertical; }
button, .button { border: 0; border-radius: 10px; padding: 10px 14px; background: var(--accent); color: #fff; font-weight: 700; cursor: pointer; display: inline-block; }
button:hover, .button:hover { filter: brightness(.96); }
button.secondary, .button.secondary { background: #eef2ff; color: #1e3a8a; }
button.danger, .button.danger, .danger { background: var(--danger-bg); color: var(--danger); }
.small { padding: 7px 10px; font-size: 12px; }
.stats { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; margin-bottom: 22px; }
.stats div { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.stats strong { display: block; font-size: 28px; }
.stats span { color: var(--muted); font-size: 13px; }
.module-list, .question-list, .task-list, .document-list, .note-list, .timeline { display: grid; gap: 12px; }
.module-list div { border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.module-list span, .document-row span, .note span, .timeline-event small { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
.inline-form { display: grid; grid-template-columns: 1fr auto auto auto; gap: 10px; align-items: end; margin-bottom: 16px; }
.documents-form { grid-template-columns: 1fr 1fr auto; }
.task-row { display: grid; grid-template-columns: minmax(180px, 1fr) 135px 110px 150px auto; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 14px; }
.document-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.row-actions { display: flex; gap: 8px; align-items: center; }
.note { border-left: 4px solid var(--accent); background: #f8fafc; border-radius: 12px; padding: 12px; }
.note p { margin: 0; white-space: pre-wrap; }
.timeline-event { border-left: 4px solid #94a3b8; padding: 0 0 14px 14px; }
.timeline-event p { margin: 8px 0 0; white-space: pre-wrap; }
.event-type { display: inline-block; font-size: 11px; text-transform: uppercase; background: #eef2ff; color: #1e3a8a; border-radius: 999px; padding: 4px 8px; margin-bottom: 6px; }
code { display: block; background: #f1f5f9; padding: 9px; border-radius: 10px; white-space: normal; }
.section-heading { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 16px; }
.section-heading h2 { margin-bottom: 6px; }

.clear-chat-form { flex-shrink: 0; }
.chat-form { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; margin-bottom: 18px; }
.chat-history { display: grid; gap: 12px; }
.chat-message { border: 1px solid var(--line); border-radius: 16px; padding: 14px; background: #fff; }
.chat-message.user { background: #f8fafc; }
.chat-message.assistant { border-left: 4px solid var(--accent); }
.chat-meta { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.chat-meta strong { color: var(--text); font-size: 13px; }
.chat-content { white-space: pre-wrap; line-height: 1.45; }
.danger-panel { border-color: #fecaca; }
.danger-panel p { color: var(--danger); }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(135deg, #111827, #1d3557); }
.login-card { width: min(420px, 100%); background: #fff; border-radius: 24px; padding: 30px; box-shadow: 0 24px 60px rgba(0,0,0,.25); }
.login-brand-mark { width: 54px; height: 54px; border-radius: 16px; display: grid; place-items: center; background: var(--sidebar); color: #fff; font-weight: 800; margin-bottom: 14px; }
.login-card h1 { margin: 0 0 6px; }
.login-card p { margin: 0 0 20px; color: var(--muted); }
.login-card .button { width: 100%; margin-top: 6px; }
.error-box { background: var(--danger-bg); color: var(--danger); border-radius: 12px; padding: 10px 12px; margin-bottom: 16px; font-weight: 700; }

@media (max-width: 1200px) {
    .stats { grid-template-columns: repeat(3, 1fr); }
    .task-row { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 900px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar { position: static; }
    .grid.two, .stats { grid-template-columns: 1fr; }
    .inline-form, .documents-form, .task-row, .chat-form { grid-template-columns: 1fr; }
    .app-topbar, .hero, .section-heading, .document-row, .chat-meta { flex-direction: column; align-items: stretch; }
}

.priority-panel { margin-bottom: 18px; border-color: rgba(37, 99, 235, 0.28); box-shadow: 0 12px 34px rgba(15, 23, 42, 0.08); }
.chat-submit { display: grid; gap: 8px; align-content: end; }
.chat-status { min-height: 18px; color: var(--muted); font-size: 12px; }
.empty-chat-message { margin-top: 0; }
button:disabled { opacity: 0.65; cursor: wait; }
