/* ==========================================================================
   Journaler — main stylesheet (no build step).
   Tokens first; light theme by default, dark via prefers-color-scheme or
   <html data-theme="dark">. Print rules live in print.css.
   ========================================================================== */

:root {
    --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-text: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
    --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, "Liberation Mono", monospace;

    --bg: #f6f4ef;
    --surface: #ffffff;
    --surface-2: #f0ede6;
    --text: #1f2328;
    --muted: #5f6670;
    --border: #dcd7cc;
    --accent: #2f5d8a;
    --accent-hover: #244a6f;
    --accent-contrast: #ffffff;
    --accent-soft: #e3ecf5;
    --ok: #1d7a46;
    --ok-soft: #e1f3e8;
    --warn: #8a5a00;
    --warn-soft: #fbf0d9;
    --danger: #b3261e;
    --danger-soft: #fbe5e3;
    --focus: #1a73e8;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 4px 16px rgb(0 0 0 / 0.06);

    --radius: 10px;
    --radius-small: 6px;
    --header-h: 52px;
    --sidebar-w: 272px;
    --content-w: 760px;

    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #15171a;
    --surface: #1d2024;
    --surface-2: #25292e;
    --text: #e6e8eb;
    --muted: #a0a7b0;
    --border: #353a41;
    --accent: #8ab4f8;
    --accent-hover: #a8c7fa;
    --accent-contrast: #0d1b2a;
    --accent-soft: #1f2d3d;
    --ok: #6fcf97;
    --ok-soft: #173326;
    --warn: #f2c14e;
    --warn-soft: #3a2f12;
    --danger: #f28b82;
    --danger-soft: #3d1d1b;
    --focus: #8ab4f8;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 4px 16px rgb(0 0 0 / 0.3);
    color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
    :root[data-theme="system"] {
        --bg: #15171a;
        --surface: #1d2024;
        --surface-2: #25292e;
        --text: #e6e8eb;
        --muted: #a0a7b0;
        --border: #353a41;
        --accent: #8ab4f8;
        --accent-hover: #a8c7fa;
        --accent-contrast: #0d1b2a;
        --accent-soft: #1f2d3d;
        --ok: #6fcf97;
        --ok-soft: #173326;
        --warn: #f2c14e;
        --warn-soft: #3a2f12;
        --danger: #f28b82;
        --danger-soft: #3d1d1b;
        --focus: #8ab4f8;
        --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 4px 16px rgb(0 0 0 / 0.3);
        color-scheme: dark;
    }
}

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

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

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

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 var(--font-ui);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
a:hover { color: var(--accent-hover); }

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
p { margin: 0 0 .75em; }
code { font-family: var(--font-mono); font-size: .9em; background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.icon { flex: none; vertical-align: middle; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.optional { color: var(--muted); font-weight: 400; }

.visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
}

.skip-link {
    position: absolute;
    left: 8px; top: -48px;
    z-index: 100;
    padding: 8px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
}
.skip-link:focus { top: 8px; }

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 38px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: background-color .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); color: var(--text); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-contrast); }
.btn-block { width: 100%; }
.btn-small { min-height: 30px; padding: 0 10px; font-size: .85rem; }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px; height: 38px;
    border: 0;
    border-radius: var(--radius-small);
    background: transparent;
    color: var(--text);
    cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

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

.form-stack { display: grid; gap: 14px; margin-top: 16px; }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

.field { display: grid; gap: 4px; }
.field-label { font-weight: 600; font-size: .9rem; }
.field-hint { color: var(--muted); font-size: .8rem; }

input[type="text"], input[type="email"], input[type="password"], input[type="search"],
input[type="time"], input[type="number"], select, textarea {
    width: 100%;
    min-height: 40px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    background: var(--surface);
    color: var(--text);
    font: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--focus); outline: 2px solid color-mix(in srgb, var(--focus) 35%, transparent); outline-offset: 0; }

.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }

/* ---------- Alerts, badges, panels, cards ---------- */

.alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 12px 0;
    padding: 10px 12px;
    border-radius: var(--radius-small);
    border: 1px solid transparent;
}
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.alert-ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.alert span { color: var(--text); }

.badge {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
    vertical-align: middle;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-fail { background: var(--danger-soft); color: var(--danger); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 20px;
}
.card-title { font-size: 1.1rem; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card-subtitle { font-size: 1rem; margin-top: 20px; }

.panel {
    margin: 16px 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    background: var(--surface);
}
.panel > :not(summary) { margin: 0 14px 14px; }
.panel-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 14px;
    font-weight: 600;
    cursor: pointer;
}

/* ---------- Self-check list ---------- */

.checks { list-style: none; margin: 0; padding: 0; }
.check-row {
    display: grid;
    grid-template-columns: 24px 1fr;
    column-gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
}
.check-row:last-child { border-bottom: 0; }
.check-status { grid-row: span 2; padding-top: 1px; }
.check-detail { grid-column: 2; color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.check-row.is-ok .check-status { color: var(--ok); }
.check-row.is-warn .check-status { color: var(--warn); }
.check-row.is-fail .check-status { color: var(--danger); }
.check-row.is-fail .check-label { font-weight: 600; }
.check-row.is-pending { color: var(--muted); }

/* ---------- Sign-in / setup pages ---------- */

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px 16px;
}
.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
}
.auth-card-wide { max-width: 640px; }
.auth-title { font-family: var(--font-text); font-size: 1.8rem; margin-bottom: 4px; }
.auth-subtitle { color: var(--muted); margin-bottom: 8px; }
.auth-card .btn-block + .btn-block { margin-top: 10px; }
.error-detail { white-space: pre-wrap; font-size: .8rem; background: var(--surface-2); padding: 10px; border-radius: var(--radius-small); overflow-x: auto; }

/* ---------- App header ---------- */

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 8px;
    height: var(--header-h);
    padding: 0 12px;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}
.brand { font-family: var(--font-text); font-size: 1.2rem; font-weight: 600; color: var(--text); text-decoration: none; }
.brand:hover { color: var(--text); }
.header-spacer { flex: 1; }
.header-actions { display: flex; align-items: center; gap: 4px; }

/* User menu built on <details>, so it works without JavaScript. */
.menu { position: relative; }
.menu-trigger {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 38px;
    padding: 0 10px;
    border-radius: var(--radius-small);
    cursor: pointer;
    list-style: none;
}
.menu-trigger::-webkit-details-marker { display: none; }
.menu-trigger:hover { background: var(--surface-2); }
.menu-name { max-width: 14ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 220px;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.menu-meta { padding: 6px 10px 8px; color: var(--muted); font-size: .85rem; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu-panel a, .menu-panel button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    border: 0;
    border-radius: var(--radius-small);
    background: none;
    color: var(--text);
    font: inherit;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}
.menu-panel a:hover, .menu-panel button:hover { background: var(--surface-2); }
.menu-panel form { margin: 0; }

/* ---------- Journal shell: sidebar + workspace ---------- */

.shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: calc(100vh - var(--header-h));
}
.sidebar {
    position: sticky;
    top: var(--header-h);
    height: calc(100vh - var(--header-h));
    overflow-y: auto;
    padding: 16px;
    border-right: 1px solid var(--border);
    background: var(--bg);
}
.sidebar-heading { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.sidebar-section + .sidebar-section { margin-top: 20px; }
.sidebar-section[hidden] { display: none; }

body.sidebar-collapsed .shell { grid-template-columns: 0 1fr; }
body.sidebar-collapsed .sidebar { visibility: hidden; padding: 0; border: 0; }

/* ---------- The page is the paper: no boxes, just the day and your writing ---------- */

body.is-journal { background: var(--surface); }
body.is-journal .app-header { border-bottom-color: color-mix(in srgb, var(--border) 50%, transparent); }

.workspace {
    position: relative;
    min-width: 0;
    background: var(--surface);
    cursor: text;                 /* clicking the blank paper starts writing at the end */
}
.paper {
    width: 100%;
    max-width: calc(var(--content-w) + 96px);
    margin: 0 auto;
    padding: 28px 48px 72px;
}
.paper .attachments, .paper .day-banner, .paper .day-header { cursor: auto; }

.day-header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "prev heading next" ". status .";
    align-items: center;
    column-gap: 4px;
    margin: 0 -46px 2px;          /* arrows sit in the margin; the title lines up with the text */
}
.day-header #prev-day { grid-area: prev; }
.day-header #next-day { grid-area: next; }
.day-heading { grid-area: heading; min-width: 0; }
.day-nav { opacity: .4; transition: opacity .2s; }
.day-nav:hover, .day-nav:focus-visible { opacity: 1; }
.day-kicker { margin: 0; color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 600; }
.day-title { font-family: var(--font-text); font-size: clamp(1.6rem, 3vw, 2.3rem); font-weight: 600; margin: 2px 0 0; }

.day-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
    padding: 6px 8px 6px 12px;
    border-radius: var(--radius-small);
    background: var(--warn-soft);
    font-size: .88rem;
}
.day-banner[data-relation="future"] { background: var(--accent-soft); }
.day-banner[hidden] { display: none; }

.save-status { grid-area: status; min-height: 20px; font-size: .78rem; color: var(--muted); transition: opacity .3s; }
.save-status[data-state="saving"]::before,
.save-status[data-state="dirty"]::before { content: "● "; color: var(--warn); }
.save-status[data-state="saved"]::before { content: "✓ "; color: var(--ok); }
.save-status[data-state="offline"],
.save-status[data-state="signed-out"],
.save-status[data-state="conflict"],
.save-status[data-state="error"] { color: var(--danger); font-weight: 600; }

/* ---------- Editor (Quill 2, re-skinned: borderless, toolbar fades while you type) ---------- */

.editor-wrap { margin-top: 6px; }
.workspace .ql-toolbar.ql-snow {
    position: sticky;
    top: var(--header-h);
    z-index: 10;
    margin: 0 -8px 6px;
    padding: 6px 0;
    border: 0;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(6px);
    font-family: var(--font-ui);
    opacity: .5;
    transition: opacity .25s;
}
.workspace .ql-toolbar.ql-snow:hover,
.workspace .ql-toolbar.ql-snow:focus-within,
.editor-wrap:focus-within .ql-toolbar.ql-snow { opacity: 1; }
body.is-typing .workspace .ql-toolbar.ql-snow { opacity: 0; pointer-events: none; }
body.is-typing .day-nav { opacity: 0; }

.workspace .ql-container.ql-snow {
    border: 0;
    background: transparent;
    font-family: var(--font-text);
    font-size: var(--editor-font-size, 17px);
}
.ql-editor {
    min-height: calc(100vh - var(--header-h) - 230px);
    padding: 4px 0 48px;
    line-height: 1.7;
    color: var(--text);
    cursor: text;
}
.ql-editor:focus { outline: none; }
.ql-editor.ql-blank::before { color: var(--muted); font-style: italic; left: 0; right: 0; }
.ql-editor h1, .ql-editor h2, .ql-editor h3 { font-family: var(--font-text); margin: .8em 0 .3em; }
.ql-editor a { color: var(--accent); }
.ql-editor blockquote { border-left: 3px solid var(--border); padding-left: 14px; color: var(--muted); }
.ql-editor code, .ql-editor .ql-code-block-container {
    background: var(--surface-2);
    color: var(--text);
    font-family: var(--font-mono);
    border-radius: 4px;
}
.ql-editor .ql-code-block-container { padding: 10px 12px; font-size: .88em; }
.ql-editor img { max-width: 100%; height: auto; border-radius: 6px; margin: 4px 0; }
.ql-editor li[data-list="checked"] { color: var(--muted); text-decoration: line-through; }
.ql-container.ql-disabled .ql-editor { opacity: .65; }

/* ---------- Focus mode: only the page (browser full screen when allowed) ---------- */

body.focus-mode .app-header,
body.focus-mode .sidebar { display: none; }
body.focus-mode .shell { grid-template-columns: 1fr; min-height: 100vh; }
body.focus-mode .workspace .ql-toolbar.ql-snow { top: 0; }
body.focus-mode .paper { padding-top: 56px; }
body.focus-mode .ql-editor { min-height: calc(100vh - 200px); }
.focus-exit {
    display: none;
    position: fixed;
    top: 12px;
    right: 16px;
    z-index: 30;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--muted);
    font: .8rem var(--font-ui);
    cursor: pointer;
    opacity: .6;
    transition: opacity .25s;
}
.focus-exit:hover, .focus-exit:focus-visible { opacity: 1; color: var(--text); }
body.focus-mode .focus-exit { display: inline-flex; }
body.focus-mode.is-typing .focus-exit { opacity: 0; }

/* ---------- Attachments ---------- */

.attachments { margin-top: 8px; padding-top: 14px; border-top: 1px solid var(--border); }
.attachments-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.attachments-title {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    font: 600 .75rem var(--font-ui);
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
}
.attachments-title .icon { width: 16px; height: 16px; }
.attachments label.btn .icon { width: 16px; height: 16px; }
.attachments.is-empty .attachment-list { display: none; }
.attachment-list {
    list-style: none;
    margin: 12px 0 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 10px;
}
.attachment {
    display: grid;
    grid-template-columns: 48px 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    background: var(--bg);
}
.attachment-open { display: block; padding: 0; border: 0; background: none; cursor: pointer; }
.attachment-thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 4px;
    object-fit: cover;
    background: var(--surface-2);
    color: var(--muted);
    font: 700 .68rem var(--font-ui);
}
.attachment-info { display: grid; min-width: 0; }
.attachment-name {
    overflow: hidden;
    padding: 0;
    border: 0;
    background: none;
    color: var(--text);
    font: inherit;
    font-weight: 500;
    text-align: left;
    text-decoration: none;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}
.attachment-name:hover { color: var(--accent); text-decoration: underline; }
.attachment-meta { font-size: .75rem; color: var(--muted); }
.attachment-actions { display: flex; }
.attachment-actions .icon-btn { width: 32px; height: 32px; color: var(--muted); }
.attachment-actions .icon-btn:hover { color: var(--text); }
.attachment progress { width: 100%; height: 6px; margin-top: 4px; accent-color: var(--accent); }
.attachments-hint { margin: 10px 0 0; }

.drop-overlay {
    position: fixed;
    inset: calc(var(--header-h) + 8px) 8px 8px 8px;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--accent);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--accent) 7%, transparent);
    pointer-events: none;          /* drops reach the text (inline images) or the page (attachments) */
}
body.focus-mode .drop-overlay { inset: 8px; }
.drop-overlay[hidden] { display: none; }
.drop-overlay-inner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 999px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.preview-dialog {
    width: min(1000px, calc(100vw - 32px));
    height: min(90vh, 900px);
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}
.preview-dialog[open] { display: grid; grid-template-rows: auto 1fr; }
.preview-dialog::backdrop { background: rgb(0 0 0 / .6); }
.preview-head { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--border); }
.preview-head form { margin: 0; }
.preview-title { flex: 1; margin: 0; overflow: hidden; font-size: 1rem; text-overflow: ellipsis; white-space: nowrap; }
.preview-body { display: flex; align-items: center; justify-content: center; min-height: 0; overflow: auto; background: var(--bg); }
.preview-body img { max-width: 100%; max-height: 100%; object-fit: contain; }
.preview-body iframe { width: 100%; height: 100%; border: 0; background: #fff; }

/* ---------- Dictation: floating mic button, status, interim words ---------- */

.dictation-dock {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 25;
    display: flex;
    align-items: center;
    gap: 10px;
}
.mic-fab {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border: 0;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-contrast);
    box-shadow: 0 4px 14px rgb(0 0 0 / .22);
    cursor: pointer;
    transition: transform .15s, background-color .2s, opacity .25s;
}
.mic-fab .icon { width: 24px; height: 24px; }
.mic-fab:hover { transform: scale(1.05); background: var(--accent-hover); }
.mic-fab:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.mic-fab[hidden] { display: none; }
.mic-fab[data-state="listening"], .mic-fab[data-state="starting"], .mic-fab[data-state="paused"] { background: var(--danger); color: #fff; }
.mic-fab[data-state="listening"]::after {
    content: "";
    position: absolute;
    inset: -6px;
    border: 3px solid var(--danger);
    border-radius: 50%;
    animation: mic-pulse 1.4s ease-out infinite;
}
.mic-fab[data-state="paused"] { opacity: .75; }
.mic-fab[data-state="error"] { background: var(--surface-2); color: var(--danger); box-shadow: inset 0 0 0 2px var(--danger), 0 4px 14px rgb(0 0 0 / .2); }
@keyframes mic-pulse { from { transform: scale(.9); opacity: .8; } to { transform: scale(1.35); opacity: 0; } }
body.is-typing:not(.is-dictating) .mic-fab { opacity: .25; }

.mic-status {
    max-width: min(360px, calc(100vw - 120px));
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    box-shadow: var(--shadow);
    color: var(--muted);
    font-size: .85rem;
}
.mic-status[hidden] { display: none; }
.mic-status[data-state="listening"] { color: var(--danger); font-weight: 600; }
.mic-status[data-state="error"] { border-radius: var(--radius-small); color: var(--danger); }

.dictation-interim {
    position: absolute;
    z-index: 2;
    padding: 4px 0 0;
    color: var(--muted);
    font-style: italic;
    line-height: 1.7;
    white-space: pre-wrap;
    pointer-events: none;
    opacity: .75;
}
.dictation-interim[hidden] { display: none; }

/* ---------- Small dialogs (dictation notice, print) ---------- */

.small-dialog {
    width: min(520px, calc(100vw - 32px));
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}
.small-dialog::backdrop { background: rgb(0 0 0 / .45); }
.dialog-form { display: grid; gap: 12px; padding: 20px; }
.dialog-form h2 { display: flex; align-items: center; gap: 8px; margin: 0; font-family: var(--font-text); }
.dialog-form p { margin: 0; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.print-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0; padding: 0; border: 0; }
.print-dates input:disabled { opacity: .55; }

/* ---------- Settings page ---------- */

.settings-page .card { scroll-margin-top: calc(var(--header-h) + 12px); }
.fieldset-plain { margin: 0; padding: 0; border: 0; }
.segmented { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--border); border-radius: var(--radius-small); overflow: hidden; }
.segmented label { position: relative; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 8px 14px; border-right: 1px solid var(--border); }
.segmented label:last-child span { border-right: 0; }
.segmented input:checked + span { background: var(--accent); color: var(--accent-contrast); }
.segmented input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: -2px; }
.range-row { display: flex; align-items: center; gap: 12px; }
.range-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.range-row output { min-width: 4.5ch; font-variant-numeric: tabular-nums; }
.font-preview { font-family: var(--font-text); color: var(--muted); line-height: 1.5; }
.inline-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.token-reveal {
    margin: 12px 0;
    padding: 12px 14px;
    border: 1px solid color-mix(in srgb, var(--ok) 40%, transparent);
    border-radius: var(--radius-small);
    background: var(--ok-soft);
}
.token-reveal p { margin: 0 0 8px; }
.token-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.token-row code { padding: 6px 8px; font-size: .9rem; overflow-wrap: anywhere; user-select: all; }

/* ---------- Header search + search page ---------- */

.header-search { position: relative; display: flex; align-items: center; flex: 0 1 300px; margin-left: 12px; }
.header-search .icon { position: absolute; left: 10px; width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.header-search input[type="search"] {
    min-height: 34px;
    padding: 4px 12px 4px 32px;
    border-color: transparent;
    border-radius: 999px;
    background: var(--surface-2);
}
.header-search input[type="search"]:focus { background: var(--surface); }

.search-form { display: flex; gap: 8px; margin-bottom: 16px; }
.search-form input { flex: 1; }
.search-results { list-style: none; margin: 0 0 24px; padding: 0; display: grid; gap: 8px; }
.search-result-link {
    display: grid;
    gap: 4px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
}
.search-result-link:hover { border-color: var(--accent); color: var(--text); }
.search-result-date { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.search-result-snippet { color: var(--muted); font-family: var(--font-text); }
.search-subtitle { font-size: 1rem; margin-top: 16px; }
.search-result-file { display: flex; align-items: center; gap: 10px; padding: 6px 4px; }
.search-file-icon { color: var(--muted); }
mark { padding: 0 1px; border-radius: 2px; background: color-mix(in srgb, var(--warn) 32%, transparent); color: inherit; }


/* Toolbar icons and pickers follow the theme */
.ql-snow .ql-stroke { stroke: var(--text); }
.ql-snow .ql-fill, .ql-snow .ql-stroke.ql-fill { fill: var(--text); }
.ql-snow .ql-picker { color: var(--text); }
.ql-snow .ql-picker-options { background: var(--surface); border-color: var(--border) !important; box-shadow: var(--shadow); }
.ql-snow.ql-toolbar button:hover .ql-stroke, .ql-snow.ql-toolbar button.ql-active .ql-stroke,
.ql-snow.ql-toolbar .ql-picker-label:hover .ql-stroke, .ql-snow.ql-toolbar .ql-picker-label.ql-active .ql-stroke { stroke: var(--accent); }
.ql-snow.ql-toolbar button:hover .ql-fill, .ql-snow.ql-toolbar button.ql-active .ql-fill { fill: var(--accent); }
.ql-snow.ql-toolbar button:hover, .ql-snow.ql-toolbar button.ql-active,
.ql-snow.ql-toolbar .ql-picker-label:hover, .ql-snow.ql-toolbar .ql-picker-label.ql-active,
.ql-snow.ql-toolbar .ql-picker-item:hover, .ql-snow.ql-toolbar .ql-picker-item.ql-selected { color: var(--accent); }
.ql-snow.ql-toolbar button:focus-visible { outline: 2px solid var(--focus); border-radius: 4px; }
.ql-snow .ql-tooltip {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
    box-shadow: var(--shadow);
    border-radius: var(--radius-small);
    font-family: var(--font-ui);
}
.ql-snow .ql-tooltip input[type="text"] { background: var(--surface); color: var(--text); border-color: var(--border); }

/* ---------- Sidebar calendar + recent days ---------- */

.cal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.cal-title { margin: 0; font-size: .95rem; }
.cal-nav { width: 30px; height: 30px; font-size: 1.2rem; }
.cal-nav:disabled { opacity: .3; cursor: default; }
.cal-grid { width: 100%; border-collapse: collapse; table-layout: fixed; }
.cal-grid th { font-size: .7rem; color: var(--muted); font-weight: 600; padding: 4px 0; }
.cal-grid td { padding: 1px; text-align: center; }
.cal-day {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 30px;
    border-radius: var(--radius-small);
    color: var(--text);
    font-size: .85rem;
    text-decoration: none;
}
a.cal-day:hover { background: var(--surface-2); color: var(--text); }
.cal-day.is-future { color: var(--muted); }
.cal-day.is-future.has-entry::after { background: var(--warn); }   /* planned ahead */
.cal-today-link {
    display: block;
    margin: 6px auto 0;
    padding: 2px 8px;
    border: 0;
    background: none;
    color: var(--accent);
    font: .8rem var(--font-ui);
    cursor: pointer;
}
.cal-day.has-entry { font-weight: 700; }
.cal-day.has-entry::after {
    content: "";
    position: absolute;
    bottom: 3px;
    width: 4px; height: 4px;
    border-radius: 50%;
    background: var(--accent);
}
.cal-day.is-today { box-shadow: inset 0 0 0 1.5px var(--accent); }
.cal-day.is-selected { background: var(--accent); color: var(--accent-contrast); }
.cal-day.is-selected::after { background: var(--accent-contrast); }
a.cal-day.is-selected:hover { background: var(--accent-hover); color: var(--accent-contrast); }

.recent-days { list-style: none; margin: 0; padding: 0; }
.recent-link {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0 8px;
    padding: 8px;
    margin: 0 -8px;
    border-radius: var(--radius-small);
    color: var(--text);
    text-decoration: none;
}
.recent-link:hover { background: var(--surface-2); color: var(--text); }
.recent-date { font-weight: 600; font-size: .85rem; }
.recent-words { font-size: .75rem; color: var(--muted); }
.recent-snippet {
    grid-column: 1 / -1;
    font-size: .8rem;
    color: var(--muted);
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.shortcuts { margin: 0; font-size: .8rem; }
.shortcuts dt { white-space: nowrap; }
.shortcuts dd { margin: 2px 0 8px; color: var(--muted); }
kbd {
    display: inline-block;
    padding: 0 5px;
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: 4px;
    background: var(--surface-2);
    font: .75rem var(--font-mono);
}

/* ---------- Toasts ---------- */

.toasts {
    position: fixed;
    z-index: 50;
    right: 16px;
    bottom: 16px;
    display: grid;
    gap: 8px;
    max-width: min(420px, calc(100vw - 32px));
}
.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius-small);
    background: var(--surface);
    box-shadow: var(--shadow);
    font-size: .9rem;
    animation: toast-in .2s ease-out;
}
.toast > span { flex: 1; }
.toast-warn { border-left-color: var(--warn); }
.toast-error { border-left-color: var(--danger); }
.toast-action { font-weight: 600; background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; }
.toast-close { background: none; border: 0; color: var(--muted); font-size: 1.2rem; line-height: 1; cursor: pointer; padding: 0 2px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Conflict dialog ---------- */

.conflict-dialog {
    width: min(960px, calc(100vw - 32px));
    max-height: calc(100vh - 48px);
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}
.conflict-dialog::backdrop { background: rgb(0 0 0 / .45); }
.conflict-form { display: grid; gap: 12px; padding: 20px; }
.conflict-form h2 { margin: 0; font-family: var(--font-text); }
.conflict-panes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.conflict-pane h3 { font-size: .9rem; margin-bottom: 6px; }
.conflict-preview {
    height: 45vh;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    background: var(--bg);
    font-family: var(--font-text);
}
.conflict-preview .ql-editor { min-height: 0; padding: 12px 14px; font-size: .95rem; }
.conflict-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
@media (max-width: 700px) {
    .conflict-panes { grid-template-columns: 1fr; }
    .conflict-preview { height: 28vh; }
}

/* ---------- Generic page (admin, settings) ---------- */

.page { max-width: 980px; margin: 0 auto; padding: 24px 20px 64px; }
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-header h1 { margin: 0; font-family: var(--font-text); }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.table tr.is-disabled td { opacity: .6; }
.table .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.table .actions form { margin: 0; }

.inline-details { position: relative; }
.inline-details > summary { list-style: none; }
.inline-details > summary::-webkit-details-marker { display: none; }
.inline-form {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    z-index: 5;
    display: flex;
    gap: 6px;
    width: 300px;
    padding: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    box-shadow: var(--shadow);
}

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

@media (max-width: 900px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        z-index: 30;
        left: 0;
        top: var(--header-h);
        width: min(85vw, var(--sidebar-w));
        box-shadow: var(--shadow);
        transform: translateX(-100%);
        transition: transform .2s ease;
    }
    body.sidebar-open .sidebar { transform: none; }
    body.sidebar-collapsed .shell { grid-template-columns: 1fr; }
    .paper { padding: 16px 18px 48px; }
    .day-header { margin: 0 -6px 2px; }
    .menu-name { display: none; }
    .header-search { flex-basis: 180px; margin-left: 4px; }
}

@media (max-width: 560px) {
    .brand { display: none; }
    .header-search { flex: 1 1 auto; }
    .attachment-list { grid-template-columns: 1fr; }
}

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