/**************************************************************************/
/* ABOUT */
/**************************************************************************/
/* Styles for the browser client. Theme values are custom properties on
 * :root; the rules cover base elements and forms, the note list and
 * editor, recovery codes, the status line and banner, the delayed
 * notice that the app could not load, the key management screen, and
 * the rescue sheet. The rescue sheet shows only in print, and when it
 * is on the page it is all that prints, in black on white whatever the
 * screen theme. */

:root {
    --bg: #0a0a0a;
    --fg: #e0e0e0;
    --accent: #4a9eff;
    --muted: #666;
    --surface: #1a1a1a;
    --border: #333;
    --danger: #ff6b6b;
    --gap: 0.75rem;
    --load-failed-delay: 3s;

    --print-paper: #fff;
    --print-ink: #000;
    --sheet-font-size: 10pt;
    --sheet-heading-size: 16pt;
    --sheet-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    --sheet-gap: 3mm;
    --sheet-pad: 2mm;
    --sheet-rule: 0.3mm;
    --sheet-qr-size: 28mm;
    --sheet-box-size: 4mm;
}

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

body {
    font-family: system-ui, sans-serif;
    background: var(--bg);
    color: var(--fg);
    max-width: 640px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

h1 { margin-bottom: 1rem; }
p { margin-bottom: 1rem; line-height: 1.5; }

button {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    margin-right: 0.5rem;
    margin-bottom: 0.5rem;
}
button:hover { opacity: 0.9; }
button:disabled { opacity: 0.5; cursor: default; }

input {
    display: block;
    width: 100%;
    padding: 0.5rem;
    margin-bottom: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--fg);
    font-size: 1rem;
}

label {
    display: block;
    margin-bottom: 0.25rem;
    color: var(--muted);
    font-size: 0.9rem;
}

.recovery-key {
    background: var(--surface);
    border: 1px solid var(--accent);
    padding: 1rem;
    border-radius: 4px;
    font-size: 1.1rem;
    letter-spacing: 0.1em;
    word-break: break-all;
    margin-bottom: 1rem;
}

.note-list { list-style: none; margin: 1rem 0; }
.note-list li {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.note-list a { color: var(--accent); text-decoration: none; }
.note-list a:hover { text-decoration: underline; }
.note-date { color: var(--muted); font-size: 0.8rem; }

.note-content {
    background: var(--surface);
    padding: 1rem;
    border-radius: 4px;
    white-space: pre-wrap;
    line-height: 1.5;
    margin-bottom: 1rem;
}

.actions { margin: 1rem 0; }

.recovery-codes {
    background: var(--surface);
    border: 1px solid var(--accent);
    border-radius: 4px;
    padding: 1rem 1rem 1rem 2.5rem;
    margin-bottom: 1rem;
    font-size: 0.95rem;
    line-height: 2;
}

.form-links {
    margin-top: 1rem;
    display: flex;
    gap: 1.5rem;
}
.form-links a {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.9rem;
}
.form-links a:hover { text-decoration: underline; }

.notes-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.btn-muted {
    background: transparent;
    color: var(--muted);
    font-size: 0.85rem;
    padding: 0.25rem 0.5rem;
}
.btn-muted:hover { color: var(--fg); }

.editor-wrap {
    border: 1px solid var(--border);
    border-radius: 4px;
    margin-bottom: 1rem;
    overflow: hidden;
}

.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0.35rem 0.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.editor-toolbar button {
    background: transparent;
    color: var(--fg);
    border: none;
    border-radius: 3px;
    padding: 0.2rem 0.45rem;
    margin: 0;
    font-size: 0.85rem;
    min-width: 1.7rem;
    text-align: center;
    cursor: pointer;
    line-height: 1.4;
}
.editor-toolbar button:hover { background: var(--border); }
.editor-toolbar button.is-active {
    background: var(--accent);
    color: #fff;
}

.toolbar-sep {
    width: 1px;
    height: 1.2rem;
    background: var(--border);
    margin: 0 0.25rem;
}

.editor-content {
    min-height: 200px;
    color: var(--fg);
}

.editor-content .ProseMirror {
    min-height: 200px;
    padding: 0.75rem;
    outline: none;
    line-height: 1.6;
}

.editor-content .ProseMirror h1 { font-size: 1.5rem; margin: 0.5em 0; }
.editor-content .ProseMirror h2 { font-size: 1.25rem; margin: 0.5em 0; }
.editor-content .ProseMirror h3 { font-size: 1.1rem; margin: 0.5em 0; }
.editor-content .ProseMirror p { margin-bottom: 0.5em; }
.editor-content .ProseMirror ul,
.editor-content .ProseMirror ol { padding-left: 1.5rem; margin-bottom: 0.5em; }
.editor-content .ProseMirror blockquote {
    border-left: 3px solid var(--border);
    padding-left: 0.75rem;
    color: var(--muted);
    margin: 0.5em 0;
}
.editor-content .ProseMirror hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1em 0;
}
/* ProseMirror base rules (the editor is created with injectCSS: false). */
.editor-content .ProseMirror {
    position: relative;
    word-wrap: break-word;
    white-space: pre-wrap;
    white-space: break-spaces;
    font-variant-ligatures: none;
    font-feature-settings: "liga" 0;
}
.editor-content .ProseMirror [contenteditable="false"] { white-space: normal; }
.editor-content .ProseMirror [contenteditable="false"] [contenteditable="true"] {
    white-space: pre-wrap;
}
.editor-content img.ProseMirror-separator {
    display: inline !important;
    border: none !important;
    margin: 0 !important;
    width: 0 !important;
    height: 0 !important;
}
.editor-content .ProseMirror-gapcursor {
    display: none;
    pointer-events: none;
    position: absolute;
    margin: 0;
}
.editor-content .ProseMirror-gapcursor::after {
    content: "";
    display: block;
    position: absolute;
    top: -2px;
    width: 20px;
    border-top: 1px solid var(--fg);
    animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite;
}
@keyframes ProseMirror-cursor-blink {
    to { visibility: hidden; }
}
.editor-content .ProseMirror-hideselection *::selection { background: transparent; }
.editor-content .ProseMirror-hideselection * { caret-color: transparent; }
.editor-content .ProseMirror-focused .ProseMirror-gapcursor { display: block; }

.status:empty { display: none; }
.status-error { color: var(--danger); }
.status-info { color: var(--muted); }
/* The load-failed notice is in index.html until main.js removes it. It
 * stays hidden for --load-failed-delay, so it shows only when the app
 * has not started by then. */
.load-failed {
    color: var(--danger);
    visibility: hidden;
    animation: load-failed-reveal 0s var(--load-failed-delay) forwards;
}
@keyframes load-failed-reveal {
    to { visibility: visible; }
}

.banner {
    background: var(--surface);
    border-left: 3px solid var(--accent);
    border-radius: 4px;
    padding: var(--gap);
}


.key-list { list-style: none; margin: 1rem 0; }
.key {
    display: grid;
    grid-template-columns: 1.5rem 1fr auto auto;
    gap: var(--gap);
    align-items: center;
    padding: var(--gap) 0;
    border-bottom: 1px solid var(--border);
}
.key-main { display: flex; flex-direction: column; min-width: 0; }
.key-label { overflow-wrap: anywhere; }
.key-meta, .key-ability { color: var(--muted); font-size: 0.8rem; }
.key-actions { white-space: nowrap; }
.key-actions button { margin: 0; }
.key-panel { margin-bottom: 1rem; }
.key-panel h2 { font-size: 1rem; margin-bottom: 0.5rem; }

/**************************************************************************/
/* RESCUE SHEET */
/**************************************************************************/

.rescue-sheet { display: none; }

@media print {
    /* The printed page's margin. */
    @page { margin: 12mm; }

    :root {
        --bg: var(--print-paper);
        --fg: var(--print-ink);
        --muted: var(--print-ink);
        --border: var(--print-ink);
    }

    body:has(.rescue-sheet) {
        max-width: none;
        margin: 0;
        padding: 0;
    }

    /* Hide every element that neither holds the sheet nor is in it. */
    body:has(.rescue-sheet) :not(.rescue-sheet, .rescue-sheet *, :has(.rescue-sheet)) {
        display: none;
    }

    .rescue-sheet {
        display: block;
        font-size: var(--sheet-font-size);
        color: var(--print-ink);
        background: var(--print-paper);
    }
    .rescue-sheet h2 {
        font-size: var(--sheet-heading-size);
        margin-bottom: var(--sheet-gap);
    }
    .rescue-sheet p { margin-bottom: var(--sheet-gap); line-height: 1.35; }
    .rescue-warning { font-weight: bold; }
    .rescue-meta {
        display: flex;
        flex-wrap: wrap;
        column-gap: calc(2 * var(--sheet-gap));
    }

    .rescue-codes {
        list-style: none;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: var(--sheet-gap);
        margin-bottom: var(--sheet-gap);
    }
    .rescue-code {
        display: grid;
        grid-template-columns: auto var(--sheet-qr-size) 1fr;
        grid-template-rows: 1fr auto;
        column-gap: var(--sheet-pad);
        align-items: start;
        padding: var(--sheet-pad);
        border: var(--sheet-rule) solid var(--print-ink);
        break-inside: avoid;
    }
    .rescue-number { grid-row: 1 / 3; font-weight: bold; }
    .rescue-qr {
        grid-row: 1 / 3;
        width: var(--sheet-qr-size);
        height: var(--sheet-qr-size);
    }
    .rescue-qr path { fill: var(--print-ink); }
    .rescue-words {
        font-family: var(--sheet-mono);
        line-height: 1.4;
        overflow-wrap: anywhere;
    }
    .rescue-used {
        display: flex;
        align-items: center;
        gap: var(--sheet-pad);
    }
    .rescue-box {
        width: var(--sheet-box-size);
        height: var(--sheet-box-size);
        border: var(--sheet-rule) solid var(--print-ink);
    }
}
