/* =============================================================================
   LMS Platform - application styles
   Author: Tim Rice

   Layout and components consume the CSS custom properties that the shared header
   sets from the instance theme. Colors default to the shipped palette.
   ============================================================================= */

:root {
    --brand: #D71105;
    --brand-hover: #5E0C09;
    --header: #0E0E0E;
    --footer: #0E0E0E;
    --body-bg: #FFFFFF;
    --box: #F5F5F5;
    --muted: #686868;
    --success: #0D9700;
    --text: #0E0E0E;
    --radius: 10px;
    --nav-width: 260px;
    --border: #e2e2e2;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--body-bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
}

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

/* ---------------------------------------------------------------- app shell */
.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--header);
    color: #fff;
    padding: 0 20px;
    height: 56px;
    flex: 0 0 auto;
}
.topbar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    color: #fff;
    font-size: 1.05rem;
}
.topbar .brand img { height: 30px; }
.topbar .user-menu { display: flex; align-items: center; gap: 16px; }
.topbar .user-menu a { color: #fff; }
.topbar .user-menu a:hover { color: var(--brand); text-decoration: none; }

.layout { display: flex; flex: 1 1 auto; min-height: 0; }

/* ------------------------------------------------------------------ sidebar */
.sidebar {
    width: var(--nav-width);
    flex: 0 0 var(--nav-width);
    background-color: var(--box);
    border-right: 1px solid var(--border);
    padding: 8px 0 16px;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width 0.15s ease, flex-basis 0.15s ease;
}

/* Dedicated top row holding the icon-only rail toggle (no overlap with links). */
.sidebar .sidebar-head {
    display: flex;
    justify-content: flex-end;
    padding: 4px 12px;
}
.sidebar .rail-toggle {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 0;
    border-radius: var(--radius);
    color: var(--muted);
    cursor: pointer;
}
.sidebar .rail-toggle:hover { color: var(--brand); background-color: #ececec; }

/* Section heading: a button that collapses or expands its links. */
.sidebar .nav-section {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    background: transparent;
    border: 0;
    cursor: pointer;
    text-transform: uppercase;
    font-size: 0.72rem;
    letter-spacing: 0.05em;
    color: var(--muted);
    padding: 14px 20px 6px;
    text-align: left;
}
.sidebar .nav-section:hover { color: var(--text); }
.sidebar .nav-section-caret { transition: transform 0.15s ease; font-size: 0.7rem; }
.sidebar .nav-group.collapsed .nav-section-caret { transform: rotate(-90deg); }
.sidebar .nav-group.collapsed .nav-group-body { display: none; }

.sidebar a.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: var(--text);
    border-left: 3px solid transparent;
    white-space: nowrap;
}
.sidebar a.nav-link:hover { background-color: #ececec; text-decoration: none; }
.sidebar a.nav-link.active {
    border-left-color: var(--brand);
    color: var(--brand);
    background-color: #fff;
    font-weight: 600;
}
.sidebar a.nav-link i { width: 18px; text-align: center; flex: 0 0 auto; }

/* -------------------------------------------------------------- rail (icon) */
.sidebar.is-rail { width: 60px; flex-basis: 60px; }
.sidebar.is-rail .nav-label,
.sidebar.is-rail .nav-section { display: none; }
/* Thin divider between icon groups in place of the hidden headings. */
.sidebar.is-rail .nav-group + .nav-group { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 6px; }
/* In rail mode every section shows its icons regardless of collapsed state. */
.sidebar.is-rail .nav-group.collapsed .nav-group-body { display: block; }
.sidebar.is-rail a.nav-link { justify-content: center; padding: 10px 0; gap: 0; }
.sidebar.is-rail .sidebar-head { justify-content: center; }

/* --------------------------------------------------------------- main area */
.main {
    flex: 1 1 auto;
    padding: 28px 32px;
    overflow-y: auto;
}
.page-title { margin: 0 0 20px; font-size: 1.5rem; }

/* ------------------------------------------------------- sub navigation tabs */
.subnav {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 18px;
}
.subnav-link {
    padding: 8px 16px;
    color: var(--text);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.subnav-link:hover { text-decoration: none; color: var(--brand); }
.subnav-link.active {
    color: var(--brand);
    border-bottom-color: var(--brand);
    font-weight: 600;
}

/* ------------------------------------------------------------------- footer */
.footer {
    background-color: var(--footer);
    color: #cfcfcf;
    text-align: center;
    padding: 14px;
    font-size: 0.85rem;
    flex: 0 0 auto;
}
.footer img { height: 22px; vertical-align: middle; margin-right: 8px; }

/* -------------------------------------------------------------------- cards */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 18px;
}
.card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
}
.card h3 { margin: 0 0 8px; font-size: 1.05rem; }
.card .muted { color: var(--muted); font-size: 0.9rem; }

/* ------------------------------------------------------------------ buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background-color: var(--brand);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    padding: 10px 18px;
    font-size: 0.95rem;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { background-color: var(--brand-hover); color: #fff; text-decoration: none; }
.btn-secondary { background-color: #444; }
.btn-secondary:hover { background-color: #222; }
.btn-block { width: 100%; justify-content: center; }

/* -------------------------------------------------------------------- forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 600; }
.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
}
.form-control:focus { outline: 2px solid var(--brand); border-color: var(--brand); }

/* ------------------------------------------------------------------- alerts */
.alert { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; }
.alert-error { background: #fdeceb; color: #8b0500; border: 1px solid #f4c4c0; }
.alert-success { background: #eaf7ea; color: #0d5f00; border: 1px solid #bfe6bf; }
.alert-info { background: var(--box); color: var(--text); border: 1px solid var(--border); }

/* ------------------------------------------------------------- auth screens */
.auth-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(160deg, var(--header) 0%, #2a2a2a 100%);
    padding: 20px;
}
.auth-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 32px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.auth-card .auth-brand {
    text-align: center;
    font-size: 1.35rem;
    font-weight: 700;
    margin-bottom: 6px;
}
.auth-card .auth-sub { text-align: center; color: var(--muted); margin-bottom: 24px; }

/* --------------------------------------------------------------- responsive */
@media (max-width: 800px) {
    .sidebar { display: none; }
    .main { padding: 20px 16px; }
}
