/* ===========================================================================
   LMS design system  -  "Studied"
   Warm paper surface, deep navy ink, one disciplined accent that shifts per
   portal (admin / partner / student) so the three portals read as one family.
   =========================================================================== */

:root {
    /* Surfaces */
    --paper:        #FBFAF7;   /* warm off-white page */
    --surface:      #FFFFFF;   /* cards */
    --surface-sunk: #F3F1EB;   /* inset / table header */
    --line:         #E4E0D6;   /* hairline rules */

    /* Ink */
    --ink:          #1A1F2E;   /* near-black blue */
    --ink-2:        #4A4F5E;   /* secondary text */
    --ink-3:        #868A95;   /* muted / captions */

    /* Brand + per-portal accent (overridden by body class) */
    --brand:        #2D4A7C;   /* scholarly blue, the constant */
    --accent:       #15706B;   /* default; portals override */
    --accent-soft:  #E6F0EF;

    /* State */
    --ok:    #15803D;  --ok-soft:   #E7F3EB;
    --warn:  #B45309;  --warn-soft: #FBEEE0;
    --err:   #B42318;  --err-soft:  #FBEAE8;

    --radius:   10px;
    --radius-sm: 6px;
    --shadow:   0 1px 2px rgba(26,31,46,.06), 0 8px 24px -12px rgba(26,31,46,.18);

    --font-display: "Source Serif 4", Georgia, "Times New Roman", serif;
    --font-body:    "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono:    ui-monospace, "SF Mono", "Cascadia Code", Menlo, monospace;
}

/* Per-portal accents: same system, three tints. */
body.portal-admin   { --accent: #3B4D8F; --accent-soft: #EAECF6; }
body.portal-partner { --accent: #15706B; --accent-soft: #E4F0EF; }
body.portal-student { --accent: #B45309; --accent-soft: #FaeFE2; }

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    font-family: var(--font-body);
    background: var(--paper);
    color: var(--ink);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; color: var(--ink); line-height: 1.2; }
h1 { font-size: 1.7rem; margin: 0 0 .25rem; }
h2 { font-size: 1.25rem; margin: 0 0 .75rem; }
h3 { font-size: 1.05rem; margin: 0 0 .5rem; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---- App shell ----------------------------------------------------------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }

.sidebar {
    background: var(--ink);
    color: #C7CBD6;
    padding: 1.25rem 0;
    display: flex; flex-direction: column;
}
.brand {
    padding: 0 1.25rem 1.1rem;
    margin-bottom: .5rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand .wordmark { font-family: var(--font-display); font-size: 1.4rem; color: #fff; font-weight: 600; }
.brand .portal-tag {
    display: inline-block; margin-top: .15rem;
    font-size: .7rem; letter-spacing: .12em; text-transform: uppercase;
    color: var(--accent); font-weight: 600;
}
.nav { list-style: none; margin: 0; padding: .5rem .75rem; flex: 1; }
.nav li { margin: 1px 0; }
.nav a {
    display: flex; align-items: center; gap: .6rem;
    padding: .55rem .75rem; border-radius: var(--radius-sm);
    color: #C7CBD6; font-size: .92rem; font-weight: 500;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav a.active { background: var(--accent); color: #fff; }
.nav .nav-section {
    padding: 1rem .75rem .35rem; font-size: .68rem; letter-spacing: .1em;
    text-transform: uppercase; color: #6B7080;
}

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: .85rem 1.75rem; background: var(--surface);
    border-bottom: 1px solid var(--line);
}
.topbar .page-title { font-family: var(--font-display); font-size: 1.15rem; font-weight: 600; }
.usermenu { display: flex; align-items: center; gap: .85rem; font-size: .9rem; }
.usermenu .who { text-align: right; line-height: 1.25; }
.usermenu .who .name { font-weight: 600; }
.usermenu .who .role { color: var(--ink-3); font-size: .8rem; }
.usermenu .avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--accent-soft); color: var(--accent);
    display: grid; place-items: center; font-weight: 700; font-family: var(--font-display);
}

.content { padding: 1.75rem; max-width: 1100px; width: 100%; }

/* ---- Flash + validation -------------------------------------------------- */
.alert {
    padding: .7rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1.1rem;
    font-size: .92rem; border: 1px solid transparent;
}
.alert-ok  { background: var(--ok-soft);  color: var(--ok);  border-color: #BFE3C9; }
.alert-err { background: var(--err-soft); color: var(--err); border-color: #F2C9C4; }
.alert ul { margin: .25rem 0 0; padding-left: 1.1rem; }

/* ---- Cards --------------------------------------------------------------- */
.card {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 1.25rem 1.4rem; margin-bottom: 1.25rem;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }

/* Stat tiles: a thin accent rule on top is the recurring signature. */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat {
    background: var(--surface); border: 1px solid var(--line);
    border-top: 3px solid var(--accent); border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
}
.stat .num { font-family: var(--font-display); font-size: 2rem; font-weight: 600; line-height: 1; }
.stat .label { color: var(--ink-3); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; margin-top: .35rem; }

/* ---- Tables -------------------------------------------------------------- */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
thead th {
    background: var(--surface-sunk); text-align: left; font-weight: 600;
    padding: .7rem 1rem; color: var(--ink-2); border-bottom: 1px solid var(--line);
    font-size: .8rem; text-transform: uppercase; letter-spacing: .04em;
}
tbody td { padding: .75rem 1rem; border-bottom: 1px solid var(--line); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--paper); }

/* ---- Badges -------------------------------------------------------------- */
.badge {
    display: inline-block; padding: .15rem .55rem; border-radius: 999px;
    font-size: .73rem; font-weight: 600; letter-spacing: .02em;
    background: var(--surface-sunk); color: var(--ink-2);
}
.badge-ok    { background: var(--ok-soft);   color: var(--ok); }
.badge-warn  { background: var(--warn-soft); color: var(--warn); }
.badge-muted { background: var(--surface-sunk); color: var(--ink-3); }

/* ---- Forms --------------------------------------------------------------- */
.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: .35rem; }
.field .hint { color: var(--ink-3); font-size: .8rem; margin-top: .25rem; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=datetime-local], input[type=date], select, textarea {
    width: 100%; padding: .6rem .7rem; font: inherit; color: var(--ink);
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius-sm); transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { min-height: 110px; resize: vertical; }
.field-error { color: var(--err); font-size: .82rem; margin-top: .3rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.checkbox { display: flex; align-items: center; gap: .5rem; }
.checkbox input { width: auto; }

/* ---- Buttons ------------------------------------------------------------- */
.btn {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .55rem 1.1rem; border-radius: var(--radius-sm);
    font: inherit; font-weight: 600; font-size: .92rem; cursor: pointer;
    border: 1px solid transparent; transition: filter .12s, background .12s;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: var(--surface-sunk); }
.btn-danger { background: var(--err-soft); color: var(--err); border-color: #F2C9C4; }
.btn-danger:hover { background: #F7DCD9; }
.btn-sm { padding: .35rem .7rem; font-size: .82rem; }

.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.4rem; gap: 1rem; }
.page-head .sub { color: var(--ink-3); font-size: .92rem; }
.toolbar { display: flex; gap: .6rem; align-items: center; }

.empty {
    text-align: center; padding: 2.5rem 1rem; color: var(--ink-3);
    border: 1px dashed var(--line); border-radius: var(--radius); background: var(--surface);
}

/* ---- Auth pages ---------------------------------------------------------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.auth-card {
    width: 100%; max-width: 400px; background: var(--surface);
    border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 2rem 1.9rem; position: relative; overflow: hidden;
}
.auth-card::before {
    content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--accent);
}
.auth-card .wordmark { font-family: var(--font-display); font-size: 1.6rem; font-weight: 600; }
.auth-card .portal-tag {
    font-size: .7rem; letter-spacing: .12em; text-transform: uppercase;
    color: var(--accent); font-weight: 700; display: block; margin-bottom: 1.4rem;
}
.auth-card h1 { font-size: 1.3rem; margin-bottom: 1.1rem; }
.mono { font-family: var(--font-mono); }

/* ---- Responsive ---------------------------------------------------------- */
@media (max-width: 820px) {
    .app { grid-template-columns: 1fr; }
    .sidebar {
        flex-direction: row; align-items: center; overflow-x: auto;
        padding: .6rem .75rem; gap: .5rem;
    }
    .brand { border: none; padding: 0 .75rem 0 .25rem; margin: 0; white-space: nowrap; }
    .brand .portal-tag { display: none; }
    .nav { display: flex; padding: 0; gap: .25rem; }
    .nav .nav-section { display: none; }
    .nav a { padding: .45rem .7rem; white-space: nowrap; }
    .form-row { grid-template-columns: 1fr; }
    .content { padding: 1.1rem; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}
