/*
 * Contadores de Histórias — "Editorial Blue Horizon" (design/stitch/DESIGN.md).
 * Light and editorial: white surfaces, hairline borders, sapphire blue, Plus Jakarta Sans throughout.
 * Plain CSS on purpose: no build step. Tokens first, then layers; existing class names keep their meaning.
 */

/* ---------- Fonts (self-hosted, OFL) ---------- */
@font-face { font-family: "Plus Jakarta Sans"; font-weight: 400; font-display: swap; src: url("../fonts/plus-jakarta-sans-latin-400.woff2?v=84c5d793") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Plus Jakarta Sans"; font-weight: 400; font-display: swap; src: url("../fonts/plus-jakarta-sans-latin-ext-400.woff2?v=ce45a7b6") format("woff2"); unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Plus Jakarta Sans"; font-weight: 500; font-display: swap; src: url("../fonts/plus-jakarta-sans-latin-500.woff2?v=76c8ec67") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Plus Jakarta Sans"; font-weight: 500; font-display: swap; src: url("../fonts/plus-jakarta-sans-latin-ext-500.woff2?v=b7124eca") format("woff2"); unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Plus Jakarta Sans"; font-weight: 600; font-display: swap; src: url("../fonts/plus-jakarta-sans-latin-600.woff2?v=d012efbb") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Plus Jakarta Sans"; font-weight: 600; font-display: swap; src: url("../fonts/plus-jakarta-sans-latin-ext-600.woff2?v=b7d98be6") format("woff2"); unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Plus Jakarta Sans"; font-weight: 700; font-display: swap; src: url("../fonts/plus-jakarta-sans-latin-700.woff2?v=fc99a59b") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Plus Jakarta Sans"; font-weight: 700; font-display: swap; src: url("../fonts/plus-jakarta-sans-latin-ext-700.woff2?v=187a90b6") format("woff2"); unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Plus Jakarta Sans"; font-weight: 800; font-display: swap; src: url("../fonts/plus-jakarta-sans-latin-800.woff2?v=9b74d53a") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Plus Jakarta Sans"; font-weight: 800; font-display: swap; src: url("../fonts/plus-jakarta-sans-latin-ext-800.woff2?v=5c463023") format("woff2"); unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Material Symbols Outlined"; font-weight: 400; font-display: block; src: url("../fonts/material-symbols-subset.woff2?v=339e20c0") format("woff2"); }

/* ---------- Tokens (DESIGN.md; the screens decide radii, design D2) ---------- */
:root {
    --canvas: #f8fafc;
    --surface: #ffffff;
    --subdued: #f1f5f9;
    --tint: #eff4ff;           /* table headers, segmented tabs, icon tiles */
    --tint-strong: #dde9ff;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --navy: #0e2346;           /* headings, strong text */
    --ink: #061c34;            /* body text */
    --slate: #5e718d;          /* secondary text: 4.97:1 on white, 4.51:1 on --tint */
    --primary: #1d58d8;
    --primary-hover: #1648b5;
    --primary-soft: rgba(29, 88, 216, .12);
    --sky: #38bdf8;            /* focus ring */
    --ok: #047857;  --ok-bg: #ecfdf5;  --ok-line: #a7f3d0;
    --info: #0369a1; --info-bg: #e0f2fe; --info-line: #bae6fd;
    --neutral: #475569; --neutral-bg: #f1f5f9;
    --error: #b91c1c; --error-bg: #fef2f2; --error-line: #fecaca;

    --font-body: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-mono: ui-monospace, "SF Mono", Menlo, monospace;

    --r-sm: .25rem; --r: .5rem; --r-md: .5rem; --r-lg: .75rem; --r-xl: .75rem; --r-full: 9999px;
    --s-xs: .25rem; --s-sm: .5rem; --s-md: 1rem; --s-lg: 1.5rem; --s-xl: 2.5rem;
    --margin: 3rem;

    --shadow-1: 0 1px 3px rgba(15, 23, 42, .04), 0 1px 2px rgba(15, 23, 42, .02);
    --shadow-2: 0 10px 25px -5px rgba(14, 35, 70, .07), 0 8px 10px -6px rgba(14, 35, 70, .04);
    --shadow-3: 0 25px 50px -12px rgba(14, 35, 70, .15);
    --focus-ring: 0 0 0 3px rgba(29, 88, 216, .12);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: light; }
body {
    margin: 0; min-height: 100vh;
    font: 400 15px/1.55 var(--font-body);
    color: var(--ink);
    background-color: var(--canvas);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
h1, h2, h3 { font-family: var(--font-body); color: var(--navy); }
h1 { font-size: 2rem; line-height: 1.2; font-weight: 800; letter-spacing: -.03em; margin: 0 0 var(--s-md); }
h2 { font-size: 1.25rem; line-height: 1.35; font-weight: 700; letter-spacing: -.015em; margin: var(--s-lg) 0 var(--s-md); }
h3 { font-size: 1.05rem; font-weight: 700; margin: 0 0 var(--s-sm); }
p { margin: 0 0 var(--s-md); }
code, kbd { font-family: var(--font-mono); font-size: .86em; color: var(--primary); }
::selection { background: rgba(29, 88, 216, .18); }
:focus-visible { outline: 2px solid var(--sky); outline-offset: 2px; border-radius: var(--r-sm); } /* an outline: no component's box-shadow can hide it */
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; } /* fields have their own blue border and halo */
.icon {
    font-family: "Material Symbols Outlined"; font-weight: normal; font-style: normal;
    font-size: 1.25em; line-height: 1; letter-spacing: normal; text-transform: none;
    display: inline-block; vertical-align: -.22em; white-space: nowrap; direction: ltr;
    -webkit-font-feature-settings: "liga"; font-feature-settings: "liga"; -webkit-font-smoothing: antialiased;
    user-select: none;
}
.icon[data-icon]::before { content: attr(data-icon); } /* the name lives in an attribute, so it never joins the text */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 256px; flex-shrink: 0; position: sticky; top: 0; height: 100vh; overflow-y: auto;
    display: flex; flex-direction: column; gap: 2px; padding: var(--s-lg) var(--s-md);
    background: var(--surface); border-right: 1px solid var(--border);
}
.sidebar .brand { display: flex; align-items: center; gap: .7rem; padding: 0 .5rem var(--s-lg); margin-bottom: var(--s-xs);
    color: var(--navy); text-decoration: none; }
.sidebar .brand:hover { text-decoration: none; }
.sidebar .brand .mark { display: grid; place-items: center; width: 40px; height: 40px; flex-shrink: 0; border-radius: var(--r-lg);
    background: var(--primary); box-shadow: var(--shadow-1); }
.sidebar .brand .mark .icon { font-size: 22px; color: #fff; }
.sidebar .brand .name { display: flex; flex-direction: column; font: 800 1.2rem/1.1 var(--font-body); letter-spacing: -.02em; }
.sidebar .brand .name small { font: 700 .66rem/1.3 var(--font-body); letter-spacing: .08em; text-transform: uppercase; color: var(--primary); margin-top: 2px; }
.sidebar .section { font: 700 .68rem/1 var(--font-body); letter-spacing: .06em; text-transform: uppercase; color: var(--slate); padding: var(--s-lg) .75rem var(--s-sm); }
.sidebar .section + a { margin-top: 2px; }
.sidebar a:not(.brand) { display: flex; align-items: center; gap: .75rem; padding: .6rem .75rem; border-radius: var(--r-md);
    color: var(--ink); font-weight: 500; text-decoration: none; transition: background .15s, color .15s; }
.sidebar a:not(.brand) .icon { color: var(--slate); transition: color .15s; }
.sidebar a:not(.brand):hover { background: var(--subdued); }
.sidebar a:not(.brand):hover .icon { color: var(--primary); }
.sidebar a.active { background: var(--primary); color: #fff; font-weight: 600; box-shadow: 0 4px 12px -4px rgba(29, 88, 216, .45); }
.sidebar a.active .icon, .sidebar a.active:hover .icon { color: #fff; }
.sidebar a.active:hover { background: var(--primary-hover); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: flex-end; gap: var(--s-lg);
    padding: .7rem var(--margin); background: rgba(255, 255, 255, .92); border-bottom: 1px solid var(--border); backdrop-filter: saturate(1.2) blur(6px); }
.topbar .menu-toggle { display: none; margin-right: auto; }
.topbar .who { display: flex; align-items: center; gap: .6rem; color: var(--navy); font-weight: 600; text-decoration: none; }
.topbar .who:hover { text-decoration: none; }
.topbar .who .avatar { display: grid; place-items: center; width: 34px; height: 34px; border-radius: var(--r-lg); color: #fff; font: 700 .8rem var(--font-body);
    background: var(--primary); }
.topbar form { margin: 0; }
.topbar button.link { color: var(--slate); font-weight: 600; }
.topbar button.link:hover { color: var(--navy); }
.topbar button.link .icon { font-size: 1.15rem; }
.content { width: 100%; max-width: 1280px; padding: var(--s-lg) var(--margin) 4rem; }

/* Drawer (below 768px): a CSS checkbox toggle, no JavaScript needed. Out of the tab order on wide screens. */
.drawer-toggle { display: none; }
.drawer-backdrop { display: none; }

/* ---------- Page header: a white card with a faint photograph on the right (design D5) ---------- */
.page-head { position: relative; overflow: hidden; margin: 0 0 var(--s-lg); padding: var(--s-xl) var(--s-xl) var(--s-lg);
    border-radius: var(--r-lg); border: 1px solid var(--border); box-shadow: var(--shadow-1); background: var(--surface); }
.page-head::before { content: ""; position: absolute; inset: 0 0 0 40%; pointer-events: none;
    background: var(--photo, none) center / cover no-repeat; opacity: .38; mix-blend-mode: multiply; }
.page-head::after { content: ""; position: absolute; inset: 0; pointer-events: none;
    background: linear-gradient(90deg, #fff 0%, #fff 38%, rgba(255, 255, 255, .55) 70%, rgba(255, 255, 255, .15) 100%); }
.page-head.scene-reading { --photo: url("../images/reading.webp?v=9f790c74"); }
.page-head.scene-book { --photo: url("../images/book.webp?v=ebbb7181"); }
.page-head.scene-desk { --photo: url("../images/desk.webp?v=340dded3"); }
.page-head .head-row { position: relative; z-index: 1; display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-lg); flex-wrap: wrap; }
.page-head h1 { font-size: 2.5rem; line-height: 1.1; margin: .4rem 0 .5rem; }
.page-head h1 .title-icon { display: inline-grid; place-items: center; width: 2.6rem; height: 2.6rem; margin-right: .75rem; vertical-align: .15rem; border-radius: var(--r-lg);
    background: var(--primary); box-shadow: var(--shadow-1); }
.page-head h1 .title-icon .icon { font-size: 1.45rem; color: #fff; }
.page-head p { max-width: 640px; color: var(--slate); margin: 0; font-size: 1rem; }
.page-head .actions { display: flex; gap: var(--s-sm); flex-wrap: wrap; }
.eyebrow { display: inline-flex; align-items: center; gap: .45rem; font: 700 .7rem/1 var(--font-body); letter-spacing: .06em; text-transform: uppercase; color: var(--primary); }
.eyebrow::before { content: ""; width: 4px; height: 14px; border-radius: 2px; background: var(--primary); }
.eyebrow .icon { font-size: 1.05rem; }
.back-link { display: inline-flex; align-items: center; gap: .35rem; margin-bottom: var(--s-md); color: var(--slate); font-weight: 600; }
.back-link:hover { color: var(--primary); text-decoration: none; }

/* ---------- Panels ---------- */
.card { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
    padding: var(--s-lg); margin-bottom: var(--s-lg); box-shadow: var(--shadow-1); }
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.card .card-head { display: flex; align-items: center; gap: .75rem; margin-bottom: var(--s-md); }
.card .card-head .icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: var(--r-md); font-size: 1.2rem;
    color: var(--primary); background: var(--tint); }
.card .card-head h2 { margin: 0; font-size: 1.2rem; }
.card .card-head p { margin: 0; font-size: .85rem; color: var(--slate); }
.card.accent { background: linear-gradient(180deg, #f5f8ff, #fff 60%); border-color: #d6e2fb; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: var(--s-lg); align-items: start; }
.divider { height: 1px; margin: var(--s-lg) 0; border: 0; background: var(--border); }

/* Stat tiles (real numbers only) */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--s-md); margin-bottom: var(--s-lg); }
.tile { padding: var(--s-md); border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-1); }
.tile .label { display: block; font: 700 .68rem/1.3 var(--font-body); letter-spacing: .05em; text-transform: uppercase; color: var(--slate); margin-bottom: .4rem; }
.tile .value { font: 800 1.35rem/1.25 var(--font-body); letter-spacing: -.02em; color: var(--navy); overflow-wrap: anywhere; }
.tile .value .icon { color: var(--primary); font-size: 1.1rem; margin-right: .3rem; }
.tile .value.danger { color: var(--error); }
.tiles:last-child { margin-bottom: 0; }

/* ---------- Forms ---------- */
label { display: block; font: 600 .8rem/1.3 var(--font-body); color: var(--navy); margin-bottom: .4rem; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=time], input[type=search], input[type=number], input[type=url], select, textarea {
    width: 100%; padding: .62rem .8rem; font: inherit; font-size: .95rem; color: var(--ink);
    background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-md);
    transition: border-color .15s, box-shadow .15s; }
input::placeholder, textarea::placeholder { color: #64748b; } /* 4.76:1 on white */
input:hover, select:hover, textarea:hover { border-color: #b4c1d4; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus-ring); }
select { appearance: none; padding-right: 2.2rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%235e718d' stroke-width='1.6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right .8rem center; background-size: 12px 8px; }
textarea { min-height: 120px; resize: vertical; }
textarea.code { min-height: 320px; font-family: var(--font-mono); font-size: 13px; }
input[type=file] { width: 100%; padding: .55rem; color: var(--slate); background: var(--canvas); border: 1px dashed var(--border-strong); border-radius: var(--r-md); }
input[type=file]::file-selector-button { margin-right: .8rem; padding: .45rem .9rem; font: 600 .82rem var(--font-body); color: var(--navy);
    background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-md); cursor: pointer; }
input[type=file]::file-selector-button:hover { border-color: var(--primary); color: var(--primary); }
input[type=checkbox], input[type=radio] { accent-color: var(--primary); width: 1rem; height: 1rem; vertical-align: -.15em; }
.field { margin-bottom: var(--s-md); }
.field .hint, .hint { font-size: .8rem; color: var(--slate); margin-top: .35rem; }
.hint .icon { font-size: 1rem; color: var(--primary); }
.row { display: flex; gap: var(--s-md); flex-wrap: wrap; align-items: flex-start; } /* an error under one field never shifts the others */
.row > .field { flex: 1; min-width: 170px; }
.row > .field.action { flex: 0 0 auto; min-width: 0; padding-top: calc(.8rem * 1.3 + .4rem); } /* lines the button up with the inputs, below the labels */
.error { display: flex; align-items: flex-start; gap: .4rem; margin-top: .45rem; padding: .45rem .7rem; border-radius: var(--r-md);
    font-size: .82rem; line-height: 1.4; color: var(--error); background: var(--error-bg); border: 1px solid var(--error-line); }
.error::before { content: "error"; font-family: "Material Symbols Outlined"; font-size: 1.05rem; line-height: 1.25; } /* the same red as an error notice */
.error[hidden], .error:empty { display: none; } /* no box without a message */
td .error, .attachments .error { display: flex; }
.form-actions { display: flex; align-items: center; gap: var(--s-md); flex-wrap: wrap; margin-top: var(--s-sm); }
.with-icon { position: relative; }
.with-icon > .icon { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--slate); pointer-events: none;
    width: 1.25rem; overflow: hidden; } /* clipped to an icon's size: a missing glyph can never cover the field */
.with-icon > input, .with-icon > select { padding-left: 2.5rem; }
.with-icon:focus-within > .icon { color: var(--primary); }
label.check { display: inline-flex; align-items: center; gap: .45rem; margin: 0 1.1rem .4rem 0; color: var(--ink); font-weight: 500; cursor: pointer; }

/* ---------- Buttons ---------- */
button, .button { display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
    padding: .62rem 1.15rem; font: 600 .9rem/1.2 var(--font-body); text-decoration: none; cursor: pointer;
    color: #fff; background: var(--primary); border: 1px solid var(--primary); border-radius: var(--r-md);
    box-shadow: 0 1px 2px rgba(14, 35, 70, .08); transition: background .15s, border-color .15s, color .15s, box-shadow .15s; }
button:hover, .button:hover { text-decoration: none; background: var(--primary-hover); border-color: var(--primary-hover); }
button:active, .button:active { transform: translateY(1px); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.secondary, .button.secondary { color: var(--navy); background: var(--surface); border-color: var(--border-strong); }
button.secondary:hover, .button.secondary:hover { background: var(--canvas); border-color: var(--primary); color: var(--primary); }
button.link { padding: 0; color: var(--primary); background: none; border: 0; box-shadow: none; font-weight: 600; border-radius: var(--r-sm); }
button.link:hover { background: none; text-decoration: underline; text-underline-offset: 3px; }
button.danger { padding: 0; color: var(--error); background: none; border: 0; box-shadow: none; font-weight: 600; border-radius: var(--r-sm); }
button.danger:hover { background: none; text-decoration: underline; text-underline-offset: 3px; }
button.danger-button, .button.danger-button { color: #fff; background: #c62828; border-color: #c62828; } /* white text 5.6:1 */
button.danger-button:hover, .button.danger-button:hover { background: #a91f1f; border-color: #a91f1f; }
.danger { color: var(--error); }
.icon-link { display: inline-flex; align-items: center; gap: .3rem; font-weight: 600; white-space: nowrap; }
.icon-link .icon { font-size: 1.05rem; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--r-lg); border: 1px solid var(--border); background: var(--surface); margin-bottom: var(--s-lg); box-shadow: var(--shadow-1); }
table { width: 100%; border-collapse: collapse; }
.table-wrap table { margin: 0; }
:not(.table-wrap) > table { border-radius: var(--r-lg); overflow: hidden; background: var(--surface); border: 1px solid var(--border); margin-bottom: var(--s-lg); }
th { text-align: left; padding: .8rem 1rem; font: 700 .68rem/1.3 var(--font-body); letter-spacing: .05em; text-transform: uppercase; color: var(--slate);
    background: var(--tint); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: .85rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--canvas); }
tbody tr:last-child td { border-bottom: 0; }
td.title, .title-cell { font: 700 .98rem/1.35 var(--font-body); color: var(--navy); }
td.title a { color: inherit; }
td.title a:hover { color: var(--primary); }
td.num, th.num { font-variant-numeric: tabular-nums; text-align: center; }
td.actions { text-align: right; line-height: 1.9; }
td.actions .icon-link + .icon-link { margin-left: .9rem; }
td.actions button.link { display: inline-flex; white-space: nowrap; }
td.email, td .email { overflow-wrap: anywhere; min-width: 12rem; }
td:has(> .id-tag) { width: 1%; }
td .icon.muted { font-size: 1rem; }
th button.sort { all: unset; cursor: pointer; display: inline-flex; gap: .3rem; font: inherit; letter-spacing: inherit; text-transform: inherit; color: inherit; }
th button.sort:hover, th button.sort.on { color: var(--primary); }
th button.sort:focus-visible { outline: 2px solid var(--sky); outline-offset: 2px; }
.id-tag { font: 600 .78rem var(--font-mono); color: var(--slate); white-space: nowrap; }
.id-tag::before { content: "#"; }
.mail { display: inline-flex; align-items: center; gap: .4rem; padding: .22rem .65rem; border-radius: var(--r-md); font-size: .85rem;
    color: var(--ink); background: var(--subdued); }
.mail .icon { font-size: 1rem; color: var(--primary); }
.mono { font-family: var(--font-mono); font-size: .85rem; }
.avatar-sm { display: inline-grid; place-items: center; width: 30px; height: 30px; margin-right: .6rem; vertical-align: middle; border-radius: var(--r-md);
    font: 700 .75rem var(--font-body); color: #fff; background: var(--primary); }
.card > .toolbar .card-head { margin-bottom: 0; }
.card .table-wrap { margin-bottom: var(--s-md); box-shadow: none; }
.table-foot { display: flex; justify-content: space-between; align-items: center; gap: var(--s-md); flex-wrap: wrap; padding: .8rem 1rem; font-size: .82rem; color: var(--slate); border-top: 1px solid var(--border); }

/* ---------- Badges, pills, chips ---------- */
.badge { display: inline-flex; align-items: center; gap: .35rem; padding: .18rem .6rem; border-radius: var(--r-full);
    font: 700 .72rem/1.4 var(--font-body); color: var(--neutral); background: var(--neutral-bg); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--ok); background: var(--ok-bg); }
.badge.danger { color: var(--error); background: var(--error-bg); }
.badge.info, .badge.gold { color: var(--info); background: var(--info-bg); }
.pill { display: inline-grid; place-items: center; min-width: 2rem; padding: .1rem .55rem; border-radius: var(--r-full); font-weight: 700; font-size: .82rem;
    color: var(--primary); background: var(--tint); font-variant-numeric: tabular-nums; }
.pill.zero { color: var(--slate); background: var(--subdued); }
.chip { white-space: nowrap; display: inline-flex; align-items: center; gap: .35rem; padding: .22rem .6rem; border-radius: var(--r-md); font-size: .82rem; font-weight: 600;
    color: var(--navy); background: var(--subdued); }

/* ---------- Tabs, toolbar, search, flash ---------- */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: var(--s-md); flex-wrap: wrap; margin-bottom: var(--s-md); }
.toolbar input[type=search] { max-width: 380px; }
.search { position: relative; flex: 1; max-width: 420px; }
.search .icon { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--slate); pointer-events: none; }
.search input { padding-left: 2.4rem; }
.search.wide { max-width: none; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; padding: 4px; margin-bottom: var(--s-lg); border-radius: var(--r-lg);
    background: var(--tint); width: fit-content; max-width: 100%; }
.tabs a { padding: .5rem 1rem; border-radius: var(--r-md); color: var(--slate); font-weight: 600; font-size: .88rem; text-decoration: none; white-space: nowrap; }
.tabs a:hover { color: var(--navy); text-decoration: none; }
.tabs a.active { color: var(--primary); background: var(--surface); box-shadow: var(--shadow-1), 0 0 0 1px var(--border); }
.flash { display: flex; align-items: flex-start; gap: .6rem; padding: .8rem 1rem; margin-bottom: var(--s-lg); border-radius: var(--r-md);
    color: var(--ok); background: var(--ok-bg); border: 1px solid var(--ok-line); }
.flash::before { content: "check_circle"; font-family: "Material Symbols Outlined"; font-size: 1.2rem; line-height: 1.2; }
.flash.warn { color: var(--error); background: var(--error-bg); border-color: var(--error-line); }
.flash.warn::before { content: "error"; }
.flash > :last-child { margin-bottom: 0; }
.flash.stack-flash { flex-wrap: wrap; align-items: center; }
.muted { color: var(--slate); }
.small { font-size: .82rem; }
.nowrap { white-space: nowrap; }
.stack > * + * { margin-top: var(--s-sm); }
.section-title { display: flex; align-items: center; gap: .55rem; margin: var(--s-xl) 0 var(--s-md); }
.section-title .icon { display: grid; place-items: center; width: 32px; height: 32px; border-radius: var(--r-md); color: var(--primary); background: var(--tint); font-size: 1.15rem; }
.card.narrow { max-width: 760px; }
.grid-2.even { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.card.secret input { color: var(--primary); font-family: var(--font-mono); }
.membership { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem .6rem; margin-bottom: .45rem; }

/* Notices: white cards with a coloured edge, bottom-right; at the top on phones. */
.toasts { position: fixed; z-index: 60; right: var(--s-lg); bottom: var(--s-lg); display: flex; flex-direction: column; gap: var(--s-sm);
    width: min(440px, calc(100vw - 2rem)); pointer-events: none; }
.toast { pointer-events: auto; position: relative; display: flex; align-items: flex-start; gap: .6rem; padding: .85rem 2.6rem .85rem 1rem;
    border-radius: var(--r-md); font-size: .92rem; line-height: 1.45; color: var(--ink); background: var(--surface);
    border: 1px solid var(--border); border-left: 4px solid var(--ok); box-shadow: var(--shadow-2); animation: toast-in .2s ease-out both; }
.toast::before { content: "check_circle"; font-family: "Material Symbols Outlined"; font-size: 1.25rem; line-height: 1.15; color: var(--ok); }
.toast.error { border-left-color: var(--error); }
.toast.error::before { content: "error"; color: var(--error); }
.toast.leaving { animation: toast-out .2s ease-in both; }
.toast-close { position: absolute; top: .45rem; right: .45rem; padding: .25rem; color: var(--slate); background: none; border: 0; box-shadow: none; border-radius: var(--r-sm); }
.toast-close:hover { color: var(--navy); background: var(--subdued); }
.toast-close .icon { font-size: 1.1rem; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }
@media (max-width: 767px) { .toasts { top: 4.2rem; bottom: auto; right: 1rem; } }

/* Empty state */
.empty { padding: var(--s-xl) var(--s-md); text-align: center; color: var(--slate); }
.empty::before { content: "auto_stories"; display: block; font-family: "Material Symbols Outlined"; font-size: 2.2rem; line-height: 1; color: var(--border-strong); margin-bottom: .6rem; }
td.empty, td.muted[colspan] { padding: var(--s-xl) var(--s-md); text-align: center; }
td.muted[colspan]::before { content: "auto_stories"; display: block; font-family: "Material Symbols Outlined"; font-size: 2rem; line-height: 1; color: var(--border-strong); margin-bottom: .5rem; }

/* ---------- Pagination ---------- */
.pager { display: flex; justify-content: space-between; align-items: center; gap: var(--s-md); flex-wrap: wrap; margin: 0 0 var(--s-lg); font-size: .85rem; color: var(--slate); }
.pager .pages { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.pager .pages a, .pager .pages span, .pager .pages button { display: inline-grid; place-items: center; min-width: 2.1rem; height: 2.1rem; padding: 0 .55rem;
    border-radius: var(--r-md); font: 600 .85rem var(--font-body); color: var(--navy); background: var(--surface);
    border: 1px solid var(--border); box-shadow: none; text-decoration: none; }
.pager .pages a:hover, .pager .pages button:hover { color: var(--primary); border-color: var(--primary); background: var(--surface); }
.pager .pages .current { color: #fff; background: var(--primary); border-color: var(--primary); }
.pager .pages .disabled { opacity: .45; }
.pager strong { color: var(--navy); }
.pager p { margin: 0; }
.pager .per-page { display: inline-flex; align-items: center; gap: .5rem; margin: 0 auto 0 0; font: 600 .78rem var(--font-body); color: var(--slate); }
.pager .per-page select { width: auto; padding: .32rem 2rem .32rem .65rem; font-size: .85rem; }

/* ---------- Confirmation dialog ---------- */
dialog.confirm { width: min(440px, calc(100vw - 2rem)); padding: 0; color: var(--ink); border: 1px solid var(--border); border-radius: var(--r-xl);
    background: var(--surface); box-shadow: var(--shadow-3); }
dialog.confirm::backdrop { background: rgba(14, 35, 70, .35); backdrop-filter: blur(4px); }
dialog.confirm[open] { animation: fade-up .18s ease-out; }
@keyframes fade-up { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
dialog.confirm .inner { position: relative; padding: var(--s-xl) var(--s-lg) var(--s-lg); text-align: center; }
dialog.confirm .seal { display: grid; place-items: center; width: 52px; height: 52px; margin: 0 auto var(--s-md); border-radius: 50%;
    color: var(--primary); background: var(--tint); }
dialog.confirm.danger .seal { color: var(--error); background: var(--error-bg); }
dialog.confirm .seal .icon { font-size: 26px; }
dialog.confirm h2 { margin: 0 0 .5rem; font-size: 1.25rem; }
dialog.confirm p { color: var(--slate); margin: 0 0 var(--s-lg); }
dialog.confirm .buttons { display: flex; justify-content: center; gap: var(--s-sm); flex-wrap: wrap; }

/* ---------- Login and public pages: a light card on a plain page (design D7) ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: var(--s-xl) var(--s-md);
    /* the open-book photograph, softened under a light veil so the card stays crisp (owner review) */
    background: linear-gradient(180deg, rgba(248, 250, 252, .55), rgba(248, 250, 252, .80)), url("../images/book.webp?v=ebbb7181") center / cover no-repeat, var(--canvas); }
.auth-card { position: relative; width: min(420px, 100%); padding: var(--s-xl) var(--s-lg) var(--s-lg); border-radius: var(--r-xl);
    background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-2); }
.auth .brand-tile { display: grid; place-items: center; width: 56px; height: 56px; margin: 0 auto var(--s-md); border-radius: var(--r-lg);
    color: #fff; background: var(--primary); box-shadow: 0 6px 16px -6px rgba(29, 88, 216, .5); }
.auth .brand-tile .icon { font-size: 28px; }
.auth h1 { text-align: center; font-size: 1.6rem; margin: 0 0 var(--s-lg); }
.auth .site { text-align: center; font: 700 .7rem/1.4 var(--font-body); letter-spacing: .08em; text-transform: uppercase; color: var(--primary); margin-bottom: .35rem; }
.auth .auth-card > div > p:not(.alt), .auth .auth-card.public p { color: var(--slate); }
.auth form { margin-top: var(--s-sm); }
.auth .label-row { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s-sm); margin-bottom: .4rem; }
.auth .label-row label { margin: 0; }
.auth .forgot { display: block; margin-top: .45rem; text-align: right; font-size: .82rem; font-weight: 600; }
.auth h1.sr-only ~ form { margin-top: var(--s-lg); } /* the login has no visible title: room under the brand name */
.auth .label-row a { font-size: .78rem; font-weight: 600; }
.auth button[type=submit] { width: 100%; padding: .75rem 1.15rem; font-size: .95rem; }
.auth .alt { text-align: center; margin: var(--s-md) 0 0; font-size: .88rem; }
.auth-card.public { text-align: center; }
.auth-card.public form { margin-top: var(--s-lg); }

/* ---------- Stories: list marks, the editor (TinyMCE light UI), attachments ---------- */
.story-mark { display: inline-grid; place-items: center; width: 34px; height: 34px; margin-right: .75rem; vertical-align: middle; border-radius: var(--r-md);
    background: var(--tint); }
.story-mark .icon { font-size: 1.1rem; color: var(--primary); }
.title-input { font: 700 1.2rem/1.3 var(--font-body) !important; color: var(--navy) !important; letter-spacing: -.01em; }
.story-form .tox-tinymce { border-radius: var(--r-md) !important; border: 1px solid var(--border-strong) !important; }
.story-form .tox-tinymce:focus-within { outline: 2px solid var(--sky) !important; outline-offset: 2px; } /* toolbar focus */
/* Focus in the writing area (an iframe, so :focus-within doesn't fire): TinyMCE marks the frame .tox-edit-focus and draws its border. */
.story-form .tox .tox-edit-area::before { border: 2px solid var(--sky) !important; border-radius: 0 !important; }
/* Editor fullscreen: TinyMCE fixes the editor to the window; no ancestor may hold it (transform, filter, backdrop-filter). */
html.tox-fullscreen .shell, html.tox-fullscreen .main, html.tox-fullscreen .content, html.tox-fullscreen .card {
    backdrop-filter: none !important; -webkit-backdrop-filter: none !important; transform: none !important; animation: none !important; filter: none !important; }
html.tox-fullscreen .story-form .tox-tinymce { border-radius: 0 !important; outline: none; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 > .story-form { grid-row: span 2; }
.grid-2:has(> .adhoc-link) { grid-template-rows: auto 1fr; } /* the button sits right under the attachments */
.grid-2 > .adhoc-link { grid-column: 2; justify-self: stretch; align-self: start; }
@media (max-width: 1199px) { .grid-2 > .adhoc-link { grid-column: 1; } .grid-2 > .story-form { grid-row: auto; } }
.attachments table.files { display: table; width: 100%; background: none; border: 0; margin: 0 0 var(--s-md); box-shadow: none; }
.attachments table.files td { padding: .6rem .25rem; }
.attachments table.files tr:hover { background: none; }
.attachments table.files td a { display: inline-flex; align-items: center; gap: .4rem; overflow-wrap: anywhere; }
.attachments table.files td a .icon { color: var(--primary); }
.attachments table.files .muted.small { display: block; margin-left: 1.65rem; }
.attachments .upload { margin-top: var(--s-md); padding-top: var(--s-md); border-top: 1px solid var(--border); }

/* ---------- Responsive ---------- */
@media (max-width: 1199px) {
    :root { --margin: 2rem; }
    .sidebar { width: 228px; }
    .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 767px) {
    :root { --margin: 1rem; }
    body { font-size: 14.5px; }
    .sidebar { position: fixed; z-index: 50; left: 0; top: 0; bottom: 0; width: 280px; transform: translateX(-102%); transition: transform .2s ease-out, visibility 0s .2s;
        box-shadow: var(--shadow-3); visibility: hidden; /* a closed drawer's links leave the tab order */ }
    .drawer-toggle:checked ~ .shell .sidebar { visibility: visible; transform: none; transition: transform .2s ease-out; }
    .drawer-toggle { display: block; position: absolute; top: 0; left: 0; width: 1px; height: 1px; opacity: 0; }
    .drawer-toggle:focus-visible ~ .shell .menu-toggle { outline: 2px solid var(--sky); outline-offset: 2px; border-radius: var(--r-sm); }
    .drawer-toggle:checked ~ .shell .drawer-backdrop { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(14, 35, 70, .35); }
    .topbar { padding: .6rem var(--margin); }
    .topbar .menu-toggle { display: inline-flex; align-items: center; gap: .4rem; cursor: pointer; color: var(--navy); font-weight: 700; }
    .topbar .who .name { display: none; }
    .page-head { padding: var(--s-lg) var(--s-md) var(--s-md); }
    .page-head::before { inset: 0 0 0 30%; opacity: .25; }
    .page-head h1 { font-size: 1.75rem; }
    h1 { font-size: 1.6rem; }
    .card { padding: var(--s-md); }
    th, td { padding: .7rem .75rem; }
    :not(.table-wrap) > table { display: block; overflow-x: auto; } /* a wide table scrolls in its box, not the page */
    html, body { overflow-x: hidden; }
    .auth-card { padding: var(--s-lg) var(--s-md); }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
