/* ============================================================
   PaperFilter — shared design-system foundation (global only)
   v2: Linear/Vercel-style refined light theme. Self-hosted Inter (latin;
   CJK falls back to system) — no external font/CSS/JS (China-safe).
   Page-specific rules live in index.css / job.css / history.css /
   protocol.css, loaded per-page via the {% block head %} in base.html.
   ============================================================ */

@font-face {
    font-family: "InterVar";
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url("fonts/inter-var-latin.woff2") format("woff2");
}

:root {
    /* surfaces & ink */
    --bg:#fbfcfd; --surface:#ffffff; --surface-2:#f5f6f8; --surface-3:#eef0f3;
    --ink:#0b1220; --ink-2:#3b4453; --muted:#6b7480;
    /* hairline borders (low-contrast) */
    --border:#e9ebef; --border-strong:#d8dbe1;
    /* accent */
    --accent:#4f46e5; --accent-dark:#4338ca; --accent-soft:#eef0ff; --accent-ink:#3730a3;
    --ring:0 0 0 3px rgba(79,70,229,.30);
    /* semantic */
    --good:#15803d; --good-soft:#dcfce7; --warn:#b45309; --warn-soft:#fef3c7;
    --bad:#b91c1c; --bad-soft:#fee2e2; --code-bg:#f4f5f7;
    /* type */
    --font-sans: "InterVar", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "PingFang SC", "Microsoft YaHei", sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --tracking-tight:-0.02em; --tracking-tighter:-0.03em;
    /* radii */
    --radius:12px; --radius-sm:8px; --radius-lg:18px; --radius-pill:999px;
    /* layered soft shadows (the Linear/Vercel depth) */
    --shadow-sm:0 1px 2px rgba(11,18,32,.05), 0 1px 1px rgba(11,18,32,.04);
    --shadow:0 1px 2px rgba(11,18,32,.04), 0 4px 12px rgba(11,18,32,.06), 0 12px 24px rgba(11,18,32,.05);
    --shadow-lg:0 8px 24px rgba(11,18,32,.10), 0 24px 56px rgba(11,18,32,.12);
    /* motion */
    --dur:.16s; --dur-2:.28s; --ease:cubic-bezier(.4,0,.2,1);
    --maxw:1040px;

    /* type scale */
    --fs-xs:0.78rem; --fs-sm:0.875rem; --fs-base:1rem; --fs-lg:1.125rem;
    --fs-h4:1rem; --fs-h3:1.2rem; --fs-h2:1.5rem; --fs-h1:2.1rem;

    /* spacing */
    --space-1:0.25rem; --space-2:0.5rem; --space-3:0.75rem; --space-4:1rem;
    --space-5:1.5rem; --space-6:2rem; --space-7:3rem;
}

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

* { box-sizing: border-box; }
/* the `hidden` attribute must always win over component display rules */
[hidden] { display: none !important; }

/* invalid form field highlight + inline form error message */
.field-error input, .field-error textarea, .field-error select {
    border-color: var(--bad) !important;
    box-shadow: 0 0 0 3px var(--bad-soft);
}
.field-error .field-label { color: var(--bad); }
.form-error {
    color: var(--bad); background: var(--bad-soft);
    border-radius: var(--radius-sm); padding: 0.6rem 0.85rem;
    font-size: var(--fs-sm); margin: 0 0 var(--space-3);
}

/* ---------- Base elements ---------- */

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--ink);
    line-height: 1.6;
    font-size: var(--fs-base);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-feature-settings: "kern" 1, "liga" 1, "calt" 1;
}

h1, h2, h3, h4 {
    color: var(--ink);
    line-height: 1.25;
    font-weight: 700;
    margin: 0 0 0.6rem;
    /* normal tracking: negative letter-spacing crams CJK and looks awkward */
    letter-spacing: normal;
}
h1 { font-size: var(--fs-h1); margin-top: 0; line-height: 1.15; }
h2 { font-size: var(--fs-h2); margin-top: 0; }
h3 { font-size: var(--fs-h3); }
h4 { font-size: var(--fs-h4); }

p { margin: 0 0 0.85rem; }
p:last-child { margin-bottom: 0; }

a {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.15s ease;
}
a:hover { color: var(--accent-dark); text-decoration: underline; }

code {
    font-family: var(--font-mono);
    background: var(--code-bg);
    color: var(--ink-2);
    padding: 0.08rem 0.36rem;
    border-radius: 4px;
    font-size: 0.9em;
}

hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: var(--space-5) 0;
}

::selection {
    background: var(--accent-soft);
    color: var(--accent-dark);
}

.lead {
    color: var(--muted);
    font-size: var(--fs-lg);
    line-height: 1.55;
    margin-top: 0;
}

.hint { color: var(--muted); font-size: var(--fs-sm); }
.muted { color: var(--muted); }

/* focus-visible ring used across interactive elements */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ---------- Header / nav ---------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(255, 255, 255, 0.78);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    backdrop-filter: saturate(180%) blur(14px);
    color: var(--ink);
    padding: 0.8rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--border);
}

.brand {
    position: relative;
    color: var(--ink);
    text-decoration: none;
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: -0.01em;
    padding-left: 0.85rem;
}
.brand::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--accent);
}
.brand:hover { color: var(--accent-dark); text-decoration: none; }

.topbar-nav {
    display: flex;
    gap: 0.3rem;
    align-items: center;
}
.topbar-link {
    color: var(--ink-2);
    text-decoration: none;
    font-weight: 600;
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-sm);
    transition: background 0.15s ease, color 0.15s ease;
    font-size: 0.92rem;
}
.topbar-link:hover { color: var(--ink); background: var(--surface-2); text-decoration: none; }
.topbar-link.active {
    color: var(--accent-dark);
    background: var(--accent-soft);
}

.tagline {
    color: var(--muted);
    font-size: 0.82rem;
    margin-left: auto;
}

.topbar-user { display: flex; align-items: center; gap: 0.4rem; }
.topbar-whoami { font-size: 0.85rem; font-weight: 600; color: var(--ink-2); }
.topbar-logout { margin: 0; }
.topbar-logout button {
    font: inherit; border: 1px solid var(--border); background: var(--surface);
    color: var(--ink-2); cursor: pointer;
}
@media (max-width: 640px) { .tagline { display: none; } }
@media (max-width: 640px) {
    .tagline { display: none; }
}

/* ---------- Layout ---------- */

.container {
    max-width: var(--maxw);
    margin: 2rem auto;
    padding: 0 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.footer {
    text-align: center;
    color: var(--muted);
    padding: 2rem 1rem 3rem;
    border-top: 1px solid var(--border);
    margin-top: 1rem;
    font-size: var(--fs-sm);
}

.breadcrumb { margin: -0.5rem 0 0; }

/* ---------- Card ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}
.card.muted { background: var(--surface-2); }
/* interactive cards (rows, list items): subtle lift on hover */
.card-hover, a.card-hover {
    transition: box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.card-hover:hover {
    box-shadow: var(--shadow);
    transform: translateY(-2px);
    border-color: var(--border-strong);
}

/* alert / note block */
.card.alert,
.alert,
.note {
    border-left: 4px solid var(--warn);
    background: var(--warn-soft);
    color: var(--ink-2);
}
.card.alert h2, .alert h2 { color: var(--warn); }
.card.alert .secondary-link,
.alert .secondary-link {
    margin-left: 0.8rem;
    color: var(--accent-dark);
    text-decoration: underline;
    font-weight: 600;
}
.note {
    border-radius: var(--radius);
    padding: 0.85rem 1.1rem;
    font-size: var(--fs-sm);
}
.note.good { border-left-color: var(--good); background: var(--good-soft); }
.note.bad  { border-left-color: var(--bad);  background: var(--bad-soft); }

/* ---------- Buttons ---------- */

.btn,
button.primary,
.primary-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 0.55rem 1.1rem;
    font: inherit;
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
    user-select: none;
}
.btn:hover, button.primary:hover, .primary-link:hover { text-decoration: none; }
.btn:focus-visible,
button.primary:focus-visible,
.primary-link:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-soft), 0 0 0 1px var(--accent);
}
.btn:disabled,
button.primary:disabled,
.btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
}
.btn:active:not(:disabled),
button.primary:active,
.primary-link:active { transform: translateY(0.5px); }

.btn-primary,
button.primary,
.primary-link {
    background: var(--accent);
    color: #fff;
    font-size: 1rem;
}
.btn-primary:hover,
button.primary:hover,
.primary-link:hover { background: var(--accent-dark); color: #fff; }

.btn-secondary,
.btn-ghost {
    background: var(--surface);
    color: var(--ink-2);
    border-color: var(--border-strong);
}
.btn-secondary:hover,
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }

.btn-sm { padding: 0.35rem 0.7rem; font-size: var(--fs-sm); }

/* small icon button (history actions, etc.) */
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    width: 1.9em;
    height: 1.9em;
    cursor: pointer;
    text-decoration: none;
    font-size: 1rem;
    color: var(--ink-2);
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.icon-btn:hover {
    background: var(--surface-2);
    border-color: var(--border);
    color: var(--ink);
}

/* back / secondary navigation link */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    padding: 0.3rem 0.7rem;
    border-radius: var(--radius-sm);
    transition: background 0.15s ease, color 0.15s ease;
}
.back-link:hover {
    color: var(--accent-dark);
    background: var(--accent-soft);
    text-decoration: none;
}

/* dashed "add" button (protocol) — base look kept global for consistency */
.add-criterion-btn {
    margin-top: 0.7rem;
    background: var(--surface);
    border: 1px dashed var(--border-strong);
    color: var(--accent-dark);
    border-radius: var(--radius-sm);
    padding: 0.5rem 1rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.add-criterion-btn:hover { background: var(--accent-soft); border-color: var(--accent); }

/* ---------- Forms ---------- */

.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field-label { font-weight: 600; color: var(--ink); }
.field-label em {
    color: var(--warn);
    font-style: normal;
    font-weight: 500;
    font-size: 0.85rem;
    margin-left: 0.4rem;
}
.field-hint { color: var(--muted); font-size: var(--fs-sm); }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
select,
textarea {
    font: inherit;
    color: var(--ink);
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; }

.upload-form { display: flex; flex-direction: column; gap: 1.1rem; }

/* styled file dropzone (replaces the native "choose file" control) */
.filedrop-input {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.filedrop {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: var(--space-2); text-align: center;
    padding: var(--space-5) var(--space-4); min-height: 92px;
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface-2);
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.filedrop:hover { border-color: var(--accent); background: var(--accent-soft); }
.filedrop:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.filedrop.is-dragover { border-style: solid; border-color: var(--accent); background: var(--accent-soft); }
.filedrop.has-file { border-style: solid; border-color: var(--good); background: var(--surface); }
.filedrop-icon { flex: none; width: 28px; height: 28px; color: var(--accent); }
.filedrop.has-file .filedrop-icon { color: var(--good); }
.filedrop-body { display: flex; flex-direction: column; align-items: center; gap: 2px; width: 100%; min-width: 0; }
.filedrop-title { color: var(--ink); font-weight: 600; }
.filedrop-title strong { color: var(--accent); font-weight: 700; }
.filedrop-meta {
    display: block; max-width: 100%;
    font-size: var(--fs-sm); color: var(--muted);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.filedrop.has-file .filedrop-meta { color: var(--ink-2); }
.field-error .filedrop {
    border-style: solid; border-color: var(--bad);
    box-shadow: 0 0 0 3px var(--bad-soft);
}

/* fieldset-style option group (index + protocol) */
.options {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    background: var(--surface);
}
.options legend { padding: 0 0.4rem; font-weight: 600; color: var(--ink); }
.options label { display: block; padding: 0.2rem 0; }

/* mode tabs (segmented control) — shared by index + protocol */
.mode-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.35rem;
}
.mode-tab {
    flex: 1 1 0;
    min-width: 110px;
    text-align: center;
    padding: 0.55rem 0.9rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.mode-tab input { display: none; }
.mode-tab:has(input:checked) {
    background: var(--surface);
    color: var(--accent-dark);
    box-shadow: var(--shadow-sm);
}
.mode-panel textarea {
    width: 100%;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    resize: vertical;
    min-height: 140px;
}

/* segmented scope toggle — shared by index + history */
.scope-toggle {
    display: inline-flex;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px;
}
.scope-toggle button {
    background: none;
    border: none;
    padding: 0.3rem 0.8rem;
    font: inherit;
    cursor: pointer;
    color: var(--muted);
    border-radius: 999px;
    font-weight: 600;
    font-size: var(--fs-sm);
    transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.scope-toggle button.active {
    background: var(--surface);
    color: var(--accent-dark);
    box-shadow: var(--shadow-sm);
}
.scope-toggle.small button { padding: 0.2rem 0.65rem; font-size: var(--fs-xs); }

/* ---------- Badges & pills ---------- */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.55rem;
    border-radius: 4px;
    font-size: var(--fs-xs);
    font-weight: 700;
    letter-spacing: 0.04em;
    background: var(--surface-2);
    color: var(--ink-2);
}
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad  { background: var(--bad-soft);  color: var(--bad); }

.pill {
    display: inline-flex;
    align-items: center;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    font-size: var(--fs-xs);
    font-weight: 700;
    background: var(--surface-2);
    color: var(--ink-2);
    font-feature-settings: 'tnum';
}
.pill + .pill { margin-left: 0.25rem; }
.pill.p-include { background: var(--good-soft); color: var(--good); }
.pill.p-maybe   { background: var(--warn-soft); color: var(--warn); }
.pill.p-exclude { background: var(--surface-2); color: var(--ink-2); }

/* ---------- Responsive ---------- */

@media (max-width: 480px) {
    .topbar {
        padding: 0.7rem 1rem;
        gap: 0.6rem 1rem;
    }
    .topbar-nav { flex-wrap: wrap; }
    .container { padding: 0 0.9rem; margin: 1.25rem auto; }
    .card { padding: 1.1rem; }
}
