/* Shared styles for every page. Page <style> blocks only hold what is
   specific to that page; colors always come from the tokens below. */

:root {
    --bg: #fafafa;
    --surface: #ffffff;
    --raised: #f4f4f5;
    --sidebar: #f4f4f5;
    --line: rgba(23, 23, 23, 0.08);
    --line-strong: rgba(23, 23, 23, 0.16);
    --text: #171717;
    --text-2: #525252;
    --muted: #737373;

    /* Ink blue: primary action, selection, links. Nothing else. */
    --accent: #1f4fa3;
    --accent-hover: #1a428a;
    --accent-soft: #edf1f9;

    /* Semantic only. Risk levels map onto these: faible / standard / élevé. */
    --pos: #15803d;
    --pos-bg: #edf7f0;
    --warn: #a16207;
    --warn-bg: #fbf5e6;
    --neg: #b91c1c;
    --neg-bg: #fcefef;

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
    --sidebar-w: 240px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font);
    font-size: 14px;
    line-height: 20px;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}
body:has(.sidebar) { padding-left: var(--sidebar-w); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
strong, b { font-weight: 600; }
small { font-size: 12px; color: var(--muted); }
code, kbd { font-family: var(--mono); font-size: 12px; background: var(--raised); padding: 1px 6px; border-radius: 4px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.container { max-width: 1440px; margin: 0 auto; padding: 32px; }

/* Page header: title, one line of context, page actions. Not a card. */
header { margin-bottom: 24px; }
.top-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
h1 { font-size: 24px; line-height: 32px; font-weight: 500; color: var(--text); }
h2 { font-size: 16px; line-height: 24px; font-weight: 500; color: var(--text); }
h3 { font-size: 14px; line-height: 20px; font-weight: 600; color: var(--text); }
.subtitle, header p { color: var(--text-2); margin-top: 4px; }
.section-title { font-size: 16px; line-height: 24px; font-weight: 500; color: var(--text); margin-bottom: 16px; }

/* Surfaces */
.card, .section, .upload-section, .settings-section {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
}
.info-box { background: var(--raised); border: 1px solid var(--line); border-radius: 8px; padding: 12px 16px; color: var(--text-2); }
.empty-state { text-align: center; padding: 64px 24px; color: var(--muted); }
.empty-state h2 { color: var(--text-2); margin-bottom: 8px; }
.help-text { margin-top: 8px; font-size: 13px; color: var(--muted); }

/* Banners: one left rule in the semantic color, text stays readable. */
.alert, .error, .banner { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; border-left: 3px solid; }
.error, .banner-neg { background: var(--neg-bg); color: var(--neg); border-color: var(--neg); }
.alert-warning, .banner-warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.alert-success, .banner-pos { background: var(--pos-bg); color: var(--pos); border-color: var(--pos); }
.banner a { color: inherit; text-decoration: underline; margin-left: 8px; }

/* Stats: label, figure. The figure carries no color unless it means something. */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 20px; }
.stat-label { color: var(--text-2); font-size: 13px; margin-bottom: 8px; }
.stat-value { font-size: 28px; line-height: 32px; font-weight: 500; color: var(--text); font-variant-numeric: tabular-nums; }

/* Tables */
table { width: 100%; border-collapse: collapse; background: var(--surface); font-variant-numeric: tabular-nums; }
th {
    text-align: left; font-size: 12px; line-height: 16px; font-weight: 500; color: var(--muted);
    padding: 8px 12px; border-bottom: 1px solid var(--line-strong); background: none;
    text-transform: none; letter-spacing: 0;
}
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:hover > td { background: var(--raised); }
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: auto; }
.mono, .num { font-family: var(--mono); font-size: 13px; font-variant-numeric: tabular-nums; }

/* Forms */
label { font-size: 13px; color: var(--text-2); }
.form-group { margin-bottom: 16px; }
.form-group label, .form-grid label { display: block; font-weight: 500; margin-bottom: 4px; }
input[type="text"], input[type="email"], input[type="password"], input[type="date"],
input[type="number"], input[type="search"], input[type="tel"], input[type="url"],
input:not([type]), select, textarea {
    font: inherit; font-size: 14px; color: var(--text);
    background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px;
    padding: 6px 10px; min-height: 32px; max-width: 100%;
    transition: border-color 150ms var(--ease), box-shadow 150ms var(--ease);
}
textarea { line-height: 20px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="file"] { font: inherit; font-size: 13px; color: var(--text-2); }
input[type="file"]::file-selector-button {
    font: inherit; font-weight: 500; color: var(--text); background: var(--surface);
    border: 1px solid var(--line-strong); border-radius: 8px; padding: 6px 12px; margin-right: 12px; cursor: pointer;
}
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
legend { padding: 0 4px; color: var(--muted); font-size: 12px; }
details > summary { cursor: pointer; }

/* Buttons: one primary per view, the rest are quiet. */
.btn, button, input[type="submit"] {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 32px; padding: 0 12px; border-radius: 8px;
    font: inherit; font-size: 13px; font-weight: 500; line-height: 1;
    color: var(--text); background: var(--surface); border: 1px solid var(--line-strong);
    cursor: pointer; text-decoration: none; white-space: nowrap;
    transition: background-color 150ms var(--ease), border-color 150ms var(--ease), color 150ms var(--ease), transform 120ms var(--ease);
}
.btn:hover, button:hover { background: var(--raised); text-decoration: none; }
.btn:active, button:active { transform: scale(0.98); }
.btn-primary {
    background: var(--accent); color: #fff; border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--neg); }
.btn-danger:hover { background: var(--neg-bg); }
.btn-small { min-height: 28px; padding: 0 8px; font-size: 12px; }
.button-group { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.back-link { color: var(--text-2); font-size: 13px; }
button:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

/* Badges: quiet text on a tint. Color only when it carries a status. */
.badge, .status-badge, .doc-count {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 12px; line-height: 16px; font-weight: 500;
    padding: 2px 8px; border-radius: 6px;
    background: var(--raised); color: var(--text-2); white-space: nowrap;
}
.status-pending, .badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-info { background: var(--accent-soft); color: var(--accent); }
.status-reviewed, .badge-ok { background: var(--pos-bg); color: var(--pos); }
.badge-neg { background: var(--neg-bg); color: var(--neg); }

/* Signature: the square risk marker. Same everywhere a risk level shows. */
.risk { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.risk::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--line-strong); flex: none; }
.risk-faible::before { background: var(--pos); }
.risk-modere::before { background: var(--warn); }
.risk-eleve::before { background: var(--neg); }

/* Risk distribution: one bar, each segment is a level. */
.risk-bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--raised); gap: 2px; }
.risk-bar > span { display: block; }
.risk-bar .faible { background: var(--pos); }
.risk-bar .modere { background: var(--warn); }
.risk-bar .eleve { background: var(--neg); }
.risk-legend { display: flex; gap: 20px; flex-wrap: wrap; margin-top: 12px; font-size: 13px; color: var(--text-2); }
.risk-legend .num { color: var(--text); }

/* Sidebar */
.sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 10;
    display: flex; flex-direction: column; gap: 0;
    background: var(--sidebar); border-right: 1px solid var(--line);
    padding: 16px 12px; overflow-y: auto;
}
.sidebar-brand { display: flex; align-items: baseline; gap: 8px; padding: 4px 10px 0; }
.sidebar-brand b { font-size: 16px; font-weight: 600; color: var(--text); }
.sidebar-brand span { font-size: 13px; color: var(--muted); }
.sidebar-group { margin-top: 24px; }
.sidebar-label { display: block; font-size: 12px; color: var(--muted); padding: 0 10px; margin-bottom: 4px; }
.sidebar a.nav-link {
    display: flex; align-items: center; height: 32px; padding: 0 10px; margin-bottom: 2px;
    border-radius: 8px; border: 1px solid transparent;
    color: var(--text-2); font-size: 14px; text-decoration: none;
    transition: background-color 150ms var(--ease), color 150ms var(--ease);
}
.sidebar a.nav-link:hover { background: rgba(23, 23, 23, 0.04); color: var(--text); }
.sidebar a.nav-link[aria-current="page"] {
    background: var(--surface); border-color: var(--line); color: var(--text); font-weight: 500;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.sidebar-foot { margin-top: auto; padding: 16px 10px 0; border-top: 1px solid var(--line); }
.sidebar-user { font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot .sidebar-actions { display: flex; gap: 12px; margin-top: 8px; align-items: center; }
.sidebar-foot a, .sidebar-foot button {
    font-size: 13px; color: var(--text-2); background: none; border: 0; padding: 0; min-height: 0;
}
.sidebar-foot a:hover, .sidebar-foot button:hover { color: var(--text); background: none; text-decoration: underline; }

@media (max-width: 960px) {
    body:has(.sidebar) { padding-left: 0; padding-top: 48px; }
    .sidebar {
        inset: 0 0 auto 0; width: auto; height: 48px; flex-direction: row; align-items: center;
        padding: 0 12px; gap: 4px; overflow-x: auto; overflow-y: hidden;
        border-right: 0; border-bottom: 1px solid var(--line);
    }
    .sidebar-brand { padding: 0 8px 0 0; }
    .sidebar-brand span, .sidebar-label, .sidebar-user { display: none; }
    .sidebar-group { margin: 0; display: flex; gap: 2px; }
    .sidebar a.nav-link { margin: 0; white-space: nowrap; }
    .sidebar-foot { margin: 0 0 0 8px; padding: 0; border: 0; }
    .sidebar-foot .sidebar-actions { margin: 0; white-space: nowrap; }
    .container { padding: 16px; }
}

@media print {
    body:has(.sidebar) { padding: 0; }
    .sidebar { display: none; }
    .card, .section, .stat-card, .table-wrap { border-color: #ddd; break-inside: avoid; }
}
