/* ============================================================
 *  FIT EDIH Portal — self-contained stylesheet (no CDN, no framework)
 *  Layout: top header + left category sidebar + unified card grid.
 *  Works offline on an internal network. Light + dark (auto).
 * ========================================================== */

/* ---- Reset ---- */
.hide { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body { -webkit-font-smoothing: antialiased; }
img, svg { display: block; max-width: 100%; }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }

/* ---- Design tokens (light) ---- */
:root {
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "SF Mono", "Cascadia Code", "Consolas", monospace;

    --bg:        #f5f6f8;
    --bg-soft:   #eceef2;
    --surface:   #ffffff;
    --surface-2: #f8f9fb;
    --border:    #e4e7ec;
    --border-2:  #d3d8e0;
    --text:      #1a1d21;
    --muted:     #6b7280;
    --accent:    #4f46e5;
    --accent-2:  #6366f1;
    --accent-soft: #eef2ff;
    --danger:    #dc2626;
    --success:   #16a34a;

    --radius:    14px;
    --radius-sm: 9px;
    --shadow:    0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
    --shadow-lg: 0 12px 28px -12px rgba(79, 70, 229, .35);
    --header-h:  60px;
    --sidebar-w: 250px;
    --maxw:      1360px;
}

/* ---- Design tokens (dark, auto) ---- */
@media (prefers-color-scheme: dark) {
    :root {
        --bg:        #0e1116;
        --bg-soft:   #171c24;
        --surface:   #161b22;
        --surface-2: #1b2129;
        --border:    #262d38;
        --border-2:  #333c4a;
        --text:      #e6e9ee;
        --muted:     #9aa4b2;
        --accent:    #7c83ff;
        --accent-2:  #9297ff;
        --accent-soft: #1d2130;
        --shadow:    0 1px 2px rgba(0, 0, 0, .3);
        --shadow-lg: 0 12px 30px -12px rgba(124, 131, 255, .45);
    }
}

body {
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
    line-height: 1.55;
    min-height: 100vh;
}

/* ---- Header ---- */
.app-header {
    position: sticky;
    top: 0;
    z-index: 30;
    background: color-mix(in srgb, var(--surface) 85%, transparent);
    backdrop-filter: saturate(180%) blur(10px);
    -webkit-backdrop-filter: saturate(180%) blur(10px);
    border-bottom: 1px solid var(--border);
}
.app-header .header-inner {
    max-width: var(--maxw);
    margin-inline: auto;
    padding-inline: 1.5rem;
    min-height: var(--header-h);
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
}
.brand {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -.02em;
    display: inline-flex;
    align-items: center;
    gap: .45rem;
}
.brand-mark { color: var(--accent); }
.brand-sub { color: var(--muted); font-size: .82rem; }
.header-spacer { flex: 1 1 auto; }
.header-user { font-size: .84rem; color: var(--muted); display: inline-flex; align-items: center; gap: .75rem; }
.header-user strong { color: var(--text); font-weight: 600; }
.header-user a { color: var(--accent); text-decoration: none; font-weight: 600; }
.header-user a:hover { text-decoration: underline; }

/* ---- App shell: sidebar + content ---- */
.shell {
    max-width: var(--maxw);
    margin-inline: auto;
    padding: 1.75rem 1.5rem 4rem;
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    gap: 1.75rem;
    align-items: start;
}

/* ---- Sidebar ---- */
.sidebar {
    position: sticky;
    top: calc(var(--header-h) + 1.25rem);
    display: flex;
    flex-direction: column;
    gap: .25rem;
}
.sidebar-label {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .12em;
    color: var(--muted);
    padding: 0 .75rem;
    margin-bottom: .5rem;
}
.filter {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .55rem .75rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text);
    font-size: .9rem;
    font-weight: 500;
    text-align: left;
    width: 100%;
    cursor: pointer;
    transition: background .14s ease, color .14s ease;
}
.filter:hover { background: var(--bg-soft); }
.filter.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}
.filter .dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: currentColor; opacity: .55; flex: 0 0 auto;
}
.filter .fcount {
    margin-left: auto;
    font-size: .72rem;
    font-variant-numeric: tabular-nums;
    color: var(--muted);
    background: var(--bg-soft);
    border-radius: 999px;
    padding: .05rem .45rem;
}
.filter.active .fcount { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }

/* ---- Content ---- */
.content { min-width: 0; }
.toolbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.toolbar h1 { font-size: 1.3rem; font-weight: 700; letter-spacing: -.02em; }
.toolbar .count-note { color: var(--muted); font-size: .85rem; }
.search {
    margin-left: auto;
    position: relative;
    flex: 0 1 320px;
}
.search input {
    width: 100%;
    padding: .6rem .8rem .6rem 2.3rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-2);
    background: var(--surface);
    color: var(--text);
    transition: border-color .14s ease, box-shadow .14s ease;
}
.search input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}
.search svg {
    position: absolute;
    left: .75rem; top: 50%; transform: translateY(-50%);
    color: var(--muted); pointer-events: none;
}

/* ---- Card grid ---- */
.grid-cards {
    display: grid;
    gap: 1.15rem;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    align-items: start;
}
.card {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.3rem;
    box-shadow: var(--shadow);
    transition: border-color .16s ease, transform .16s ease, box-shadow .16s ease;
}
.card:hover {
    border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}
.card-head { display: flex; align-items: flex-start; gap: .75rem; margin-bottom: .55rem; }
.card-icon {
    flex: 0 0 auto;
    width: 42px; height: 42px;
    display: grid; place-items: center;
    border-radius: 11px;
    background: var(--surface-2);
    border: 1px solid var(--border);
}
.card-icon svg { width: 22px; height: 22px; }
.card-icon i { font-size: 20px; line-height: 1; color: var(--accent); }
.card-title { flex: 1 1 auto; min-width: 0; }
.card h3 {
    font-size: 1.04rem;
    font-weight: 650;
    letter-spacing: -.01em;
    line-height: 1.25;
}
.cat-badge {
    display: inline-block;
    margin-top: .25rem;
    font-size: .68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--accent);
    background: var(--accent-soft);
    border-radius: 999px;
    padding: .1rem .5rem;
}
.cat-badge.hidden-badge {
    color: var(--danger);
    background: color-mix(in srgb, var(--danger) 12%, transparent);
    margin-left: .3rem;
}
.muted { color: var(--muted); font-size: .89rem; line-height: 1.5; }
.card > .muted { margin-bottom: .25rem; }

/* ---- Download rows ---- */
.dl-list {
    list-style: none;
    padding: 0;
    margin-top: auto;
    padding-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: .45rem;
}
.dl { display: flex; align-items: center; gap: .5rem; }
.dl-link {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .55rem .65rem;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    border: 1px solid var(--border);
    text-decoration: none;
    color: var(--text);
    transition: background .14s ease, border-color .14s ease;
}
.dl-link:hover {
    background: color-mix(in srgb, var(--accent) 8%, var(--surface-2));
    border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}
.dl-name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: .9rem;
    font-weight: 500;
}
.ico { flex: 0 0 auto; }
i.ico { width: 18px; text-align: center; font-size: 15px; }
.dl-link.external i.ico { color: var(--accent); }
.dl-link.external:hover {
    background: color-mix(in srgb, var(--accent) 8%, var(--surface-2));
    border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}
.ext-tag {
    flex: 0 0 auto;
    font-size: .62rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: .08rem .4rem;
}
.ver {
    flex: 0 0 auto;
    font-size: .7rem;
    font-variant-numeric: tabular-nums;
    color: var(--muted);
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: .1rem .42rem;
}

/* Admin-only marker: which groups this app is limited to. */
.group-badge {
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    border-color: color-mix(in srgb, var(--accent) 35%, transparent);
}

/* ---- Channel heading inside a card's download list ---- */
.chan-head {
    list-style: none;
    font-size: .66rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--muted);
    margin-top: .3rem;
    display: flex;
    align-items: center;
    gap: .5rem;
}
.chan-head::after {
    content: "";
    flex: 1 1 auto;
    height: 1px;
    background: var(--border);
}
.chan-head:first-child { margin-top: 0; }
.chan-head[data-channel="stable"], .chan-head[data-channel="production"] { color: var(--success); }

/* ---- Version group: one release, several architectures ---- */
.dl-multi {
    flex-direction: column;
    align-items: stretch;
    gap: .35rem;
}
.ver-head {
    align-self: flex-start;
    font-size: .74rem;
    font-weight: 600;
    color: var(--text);
}
.dl-variants {
    display: flex;
    flex-direction: column;
    gap: .35rem;
    padding-left: .55rem;
    border-left: 2px solid var(--border);
}
.dl-variant {
    display: flex;
    align-items: center;
    gap: .4rem;
    min-width: 0;
    /* The checksum chip drops to its own line rather than spilling out of the
       card when the platform label is long and the column is narrow. */
    flex-wrap: wrap;
    row-gap: .3rem;
}
/* The link sizes to its content instead of eating the free space, so the
   checksum button has room beside it on the same line. */
.dl-variant .dl-link { flex: 0 1 auto; min-width: min-content; padding: .45rem .55rem; }
.dl-size {
    flex: 0 0 auto;
    font-size: .72rem;
    font-variant-numeric: tabular-nums;
    color: var(--muted);
    margin-left: .15rem;
}
.dl-variant .copy-cmd.sha { padding: .32rem .45rem; font-size: .68rem; }
/* An architecture label is a fixed, short token — never ellipsise it. */
.dl-name--arch {
    flex: 0 0 auto;
    overflow: visible;
    text-overflow: clip;
    font-variant-numeric: tabular-nums;
}

/* ---- Version status + release notes ---- */
.ver-line { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.status-badge {
    flex: 0 0 auto;
    font-size: .62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    border-radius: 6px;
    padding: .1rem .4rem;
    border: 1px solid currentColor;
    color: var(--muted);
}
.status-draft, .status-unpublished { color: var(--danger); }
.status-scheduled { color: var(--accent); }
.status-deprecated { color: #b45309; }

.rel-notes { margin-top: .1rem; font-size: .82rem; }
.rel-notes summary {
    cursor: pointer;
    color: var(--muted);
    font-size: .74rem;
    font-weight: 600;
    padding: .15rem 0;
    list-style: revert;
}
.rel-notes summary:hover { color: var(--accent); }
.rel-text { margin: .35rem 0 .3rem; color: var(--text); }
.changelog { list-style: none; padding: 0; margin: .2rem 0 0; display: flex; flex-direction: column; gap: .25rem; }
.changelog li { display: flex; align-items: baseline; gap: .4rem; line-height: 1.35; }
.chg {
    flex: 0 0 auto;
    font-size: .6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-radius: 5px;
    padding: .05rem .32rem;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    color: var(--muted);
}
.chg-added { color: var(--success); }
.chg-fixed { color: var(--accent); }
.chg-security { color: var(--danger); }
.chg-removed { color: #b45309; }
.chg-deprecated { color: #b45309; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    font-size: .9rem;
    font-weight: 600;
    line-height: 1;
    padding: .7rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    text-decoration: none;
    transition: background .14s ease, border-color .14s ease, color .14s ease;
}
.btn:hover { background: var(--accent-2); }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border-2); }
.btn-ghost:hover { background: var(--bg-soft); border-color: var(--accent); color: var(--accent); }
.copy-cmd {
    flex: 0 0 auto;
    font-size: .74rem;
    font-weight: 600;
    padding: .4rem .65rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-2);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
    transition: border-color .14s ease, color .14s ease, background .14s ease;
}
.copy-cmd:hover { border-color: var(--accent); color: var(--accent); }
.copy-cmd.ok { color: var(--success); border-color: var(--success); }
.copy-cmd.sha { font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; }
.copy-cmd.sha:hover { color: var(--accent); }

/* ---- Empty states ---- */
.empty {
    color: var(--muted);
    font-size: .88rem;
    font-style: italic;
    border: 1px dashed var(--border-2);
    border-radius: var(--radius-sm);
    padding: .9rem;
    text-align: center;
    margin-top: 1rem;
}
.empty-hero {
    grid-column: 1 / -1;
    text-align: center;
    padding: 4.5rem 1rem;
    color: var(--muted);
}
.empty-badge { font-size: 2.75rem; margin-bottom: .5rem; opacity: .7; }
.empty-hero h2 { color: var(--text); font-size: 1.2rem; margin-bottom: .4rem; }
.empty-hero code {
    font-family: var(--mono);
    font-size: .85em;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: .1rem .4rem;
}

/* ---- Admin: users management ---- */
.admin-wrap {
    max-width: 960px;
    margin-inline: auto;
    padding: 1.75rem 1.5rem 4rem;
}
.flash {
    border-radius: var(--radius-sm);
    padding: .7rem .9rem;
    font-size: .88rem;
    margin-bottom: 1.25rem;
    border: 1px solid transparent;
}
.flash.ok {
    background: color-mix(in srgb, var(--success) 12%, var(--surface));
    border-color: color-mix(in srgb, var(--success) 45%, transparent);
}
.flash.err {
    background: color-mix(in srgb, var(--danger) 12%, var(--surface));
    border-color: color-mix(in srgb, var(--danger) 45%, transparent);
}
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.35rem 1.4rem;
    margin-bottom: 1.35rem;
}
.panel-title { font-size: 1rem; font-weight: 650; margin-bottom: 1rem; }
.panel-title .muted { font-weight: 400; font-size: .82rem; }
.hint { color: var(--muted); font-size: .8rem; margin-top: .85rem; }
.add-form {
    display: flex;
    gap: .9rem;
    align-items: flex-end;
    flex-wrap: wrap;
}
.add-form .field { margin-bottom: 0; flex: 1 1 180px; }
.add-form select, .add-form input {
    width: 100%;
    padding: .6rem .7rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-2);
    background: var(--surface-2);
    color: var(--text);
}
.add-form .field:last-of-type { flex: 0 0 120px; }

.table-scroll { overflow-x: auto; }
.users-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.users-table th {
    text-align: left;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
    font-weight: 600;
    padding: .5rem .6rem;
    border-bottom: 1px solid var(--border);
}
.users-table td {
    padding: .6rem .6rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.users-table tr:last-child td { border-bottom: none; }
.u-name { font-weight: 600; }
.you {
    font-size: .66rem;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-soft);
    border-radius: 999px;
    padding: .05rem .4rem;
    margin-left: .4rem;
    vertical-align: middle;
}
.role-badge {
    display: inline-block;
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-radius: 999px;
    padding: .1rem .5rem;
    background: var(--bg-soft);
    color: var(--muted);
}
.role-badge.role-admin { background: var(--accent-soft); color: var(--accent); }
.inline { display: flex; align-items: center; gap: .4rem; margin: 0; }
.inline select, .pw-input {
    padding: .4rem .55rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-2);
    background: var(--surface-2);
    color: var(--text);
    font-size: .85rem;
}
.pw-input { width: 130px; }
.btn-sm { padding: .45rem .7rem; font-size: .8rem; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 85%, #000); }
.row-actions { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
a.btn { text-decoration: none; }

/* JSON editor */
.json-editor {
    width: 100%;
    font-family: var(--mono);
    font-size: .85rem;
    line-height: 1.5;
    padding: .8rem .9rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-2);
    background: var(--surface-2);
    color: var(--text);
    resize: vertical;
    tab-size: 2;
}
.json-editor:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}
.editor-bar { display: flex; align-items: center; gap: .75rem; margin-top: .8rem; }
.json-status { font-size: .8rem; font-variant-numeric: tabular-nums; }

/* Upload */
.upload-form {
    display: flex;
    align-items: center;
    gap: .8rem;
    flex-wrap: wrap;
    margin-top: 1.1rem;
    padding-top: 1.1rem;
    border-top: 1px dashed var(--border);
}
.file-input {
    flex: 1 1 auto;
    font-size: .88rem;
    padding: .5rem;
    border: 1px solid var(--border-2);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}
.file-input::file-selector-button {
    font: inherit;
    margin-right: .7rem;
    padding: .4rem .7rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-2);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}

/* ---- Login ---- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login-card {
    width: 100%;
    max-width: 24rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 2.25rem 2rem;
}
.login-brand { display: inline-flex; align-items: center; gap: .45rem; font-size: 1.35rem; font-weight: 700; letter-spacing: -.02em; }
.login-card .brand-sub { display: block; margin: .35rem 0 1.5rem; }
.field { display: block; margin-bottom: 1rem; }
.field span { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: .35rem; }
.field input {
    width: 100%;
    padding: .7rem .8rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-2);
    background: var(--surface-2);
    color: var(--text);
    transition: border-color .14s ease, box-shadow .14s ease;
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.login-alert {
    display: flex; gap: .5rem;
    background: color-mix(in srgb, var(--danger) 10%, var(--surface));
    border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: .65rem .8rem;
    font-size: .85rem;
    margin-bottom: 1.15rem;
}
.sso-divider { display: flex; align-items: center; gap: .7rem; color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .12em; margin: 1.35rem 0; }
.sso-divider::before, .sso-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.login-foot { margin-top: 1.5rem; font-size: .78rem; color: var(--muted); text-align: center; }

/* ---- Responsive ---- */
@media (max-width: 900px) {
    .shell { grid-template-columns: 1fr; gap: 1.25rem; }
    .sidebar {
        position: static;
        flex-direction: row;
        flex-wrap: wrap;
        gap: .5rem;
        overflow-x: auto;
    }
    .sidebar-label { width: 100%; padding: 0; }
    .filter { width: auto; }
    .filter .fcount { margin-left: .4rem; }
}
@media (max-width: 560px) {
    .app-header .header-inner, .shell { padding-inline: 1rem; }
    .grid-cards { grid-template-columns: 1fr; }
    .brand-sub { display: none; }
    .search { flex-basis: 100%; margin-left: 0; }
}
