/* Top2030 — one document, built for an Android phone first.
   Layout: a fixed app bar, a scrolling middle that fills whatever is left, and a
   bottom bar within thumb reach. No framework; the whole file is the design system. */

:root {
    --paper: #fbfaf7;
    --bg: #f2f1ed;
    --card: #ffffff;
    --ink: #17201f;
    --muted: #5e6b69;
    --line: #dcdcd5;
    --accent: #1f6b64;
    --accent-soft: #e4efed;
    --warn: #8a5a1b;
    --warn-soft: #f6ecda;
    --danger: #9a2f2f;

    --ui: "Assistant", "Segoe UI", "Arial Hebrew", system-ui, sans-serif;
    --doc: "David", "Frank Ruhl Libre", "Times New Roman", serif;

    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-start: env(safe-area-inset-right, 0px); /* rtl: inline-start is the right edge */
    --safe-end: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--ui);
    font-size: 16px;
    line-height: 1.55;
    -webkit-text-size-adjust: 100%;
}

/* ---------- app bar ---------- */

.appbar {
    flex: none;
    display: flex;
    align-items: center;
    gap: .6rem;
    background: var(--card);
    border-bottom: 1px solid var(--line);
    padding: .6rem max(.85rem, var(--safe-end)) .6rem max(.85rem, var(--safe-start));
    padding-top: calc(.6rem + var(--safe-top));
}

.appbar-title {
    flex: 1;
    min-width: 0;
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status {
    flex: none;
    font-size: .75rem;
    color: var(--accent);
    white-space: nowrap;
}

.icon-btn {
    flex: none;
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: transparent;
    color: var(--ink);
    font-size: 1.15rem;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
}

/* ---------- the ⋮ menu ---------- */

.menu { position: relative; flex: none; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }

.menu-items {
    position: absolute;
    inset-inline-end: 0;
    top: calc(100% + .4rem);
    z-index: 20;
    min-width: 12rem;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 10px 30px -14px rgba(0, 0, 0, .4);
    padding: .3rem;
    display: flex;
    flex-direction: column;
}

.menu-form { margin: 0; display: flex; }

.menu-item {
    width: 100%;
    text-align: start;
    background: transparent;
    border: none;
    border-radius: 7px;
    color: var(--ink);
    font: inherit;
    font-size: .92rem;
    padding: .55rem .6rem;
    text-decoration: none;
    cursor: pointer;
}

.menu-item:hover, .menu-item:focus-visible { background: var(--accent-soft); color: var(--accent); }

/* ---------- editor ---------- */

.editor-wrap {
    flex: 1;
    min-height: 0;
    display: flex;
    background: var(--paper);
}

.editor-wrap > textarea { flex: 1; min-width: 0; border: none; }

/* TinyMCE draws its own chrome; strip the outer frame so it reads as the page itself. */
.editor-wrap .tox-tinymce {
    flex: 1;
    min-width: 0;
    border: none !important;
    border-radius: 0 !important;
}

/* ---------- bottom bar ---------- */

.bottombar {
    flex: none;
    display: flex;
    gap: .5rem;
    background: var(--card);
    border-top: 1px solid var(--line);
    padding: .55rem max(.85rem, var(--safe-end)) .55rem max(.85rem, var(--safe-start));
    padding-bottom: calc(.55rem + var(--safe-bottom));
}

.btn {
    flex: 1;
    border: 1px solid var(--accent);
    border-radius: 9px;
    background: var(--accent);
    color: var(--paper);
    font: inherit;
    font-size: .95rem;
    font-weight: 600;
    padding: .65rem .8rem;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}

.btn.ghost { background: transparent; color: var(--accent); }

.restore-form { flex: 1; display: flex; margin: 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- login ---------- */

.page-login { background: var(--paper); }

.login {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 1rem;
    width: 100%;
    max-width: 24rem;
    margin: 0 auto;
    padding: 1.5rem max(1.4rem, var(--safe-end)) 1.5rem max(1.4rem, var(--safe-start));
}

.brand {
    margin: 0;
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--accent);
    direction: ltr;
    text-align: start;
}

.login h1 { margin: 0; font-family: var(--doc); font-size: 1.5rem; }
.login .sub { margin: 0; color: var(--muted); font-size: .9rem; }
.login form { display: flex; flex-direction: column; gap: 1rem; margin: 0; }

.field { display: flex; flex-direction: column; gap: .3rem; }
.field label { font-size: .82rem; color: var(--muted); }

.field input {
    font: inherit;
    font-size: 1rem;
    padding: .7rem .75rem;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--card);
    color: var(--ink);
    min-width: 0;
}

.remember { display: flex; align-items: center; gap: .5rem; font-size: .88rem; color: var(--muted); }

.error {
    margin: 0;
    background: #fdecec;
    border: 1px solid #f0c4c4;
    color: var(--danger);
    border-radius: 9px;
    padding: .6rem .7rem;
    font-size: .88rem;
}

/* ---------- flash message ---------- */

.flash {
    flex: none;
    margin: 0;
    background: var(--accent-soft);
    color: var(--accent);
    border-bottom: 1px solid var(--line);
    padding: .5rem max(.85rem, var(--safe-end)) .5rem max(.85rem, var(--safe-start));
    font-size: .85rem;
}

/* ---------- version list ---------- */

.version-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    background: var(--paper);
}

.version-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: .8rem max(.95rem, var(--safe-end)) .8rem max(.95rem, var(--safe-start));
    border-bottom: 1px solid var(--line);
    color: var(--ink);
    text-decoration: none;
}

.version-item:hover { background: var(--accent-soft); }

.version-main { display: flex; flex-direction: column; min-width: 0; }
.version-main .when { font-weight: 600; font-size: .95rem; font-variant-numeric: tabular-nums; }
.version-main .who { color: var(--muted); font-size: .8rem; }

.pill {
    flex: none;
    font-size: .72rem;
    padding: .18rem .5rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    white-space: nowrap;
}

.pill.now { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.empty { color: var(--muted); padding: 1.5rem max(.95rem, var(--safe-end)); }

/* ---------- one version, read-only ---------- */

.banner {
    flex: none;
    margin: 0;
    background: var(--warn-soft);
    color: var(--warn);
    border-bottom: 1px solid var(--line);
    padding: .55rem max(.85rem, var(--safe-end)) .55rem max(.85rem, var(--safe-start));
    font-size: .82rem;
}

.readonly-doc {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    background: var(--paper);
    font-family: var(--doc);
    padding: 1.1rem max(1rem, var(--safe-end)) 2rem max(1rem, var(--safe-start));
}

.readonly-doc h1 { font-size: 1.5rem; margin: 0 0 .5rem; }
.readonly-doc h2 { font-size: 1.25rem; margin: 1.1rem 0 .4rem; }
.readonly-doc img { max-width: 100%; height: auto; }
.readonly-doc table { border-collapse: collapse; width: 100%; }
.readonly-doc th, .readonly-doc td { border: 1px solid #999; padding: 4px 6px; }

/* ---------- login management ---------- */

.manage {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    background: var(--paper);
    padding: 1rem max(1rem, var(--safe-end)) 2rem max(1rem, var(--safe-start));
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.manage-section {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 1rem 1.1rem;
}

.manage-section h2 { margin: 0 0 .25rem; font-size: 1.05rem; }
.manage-hint { margin: 0 0 .75rem; color: var(--muted); font-size: .82rem; }

.manage-form, .guest-row { display: flex; flex-direction: column; gap: .7rem; margin: 0; }

/* Each guest is one row of its own, separated so two of them never read as one form. */
.guest-row + .guest-row {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--line);
}

.guest-actions { display: flex; gap: .5rem; }
.guest-actions .btn { flex: 1; }

.btn.danger { border-color: var(--danger); background: transparent; color: var(--danger); }

.error-flash {
    background: #fdecec;
    color: var(--danger);
    border-bottom-color: #f0c4c4;
}

@media (min-width: 720px) {
    .manage { align-items: center; }
    .manage-section { width: 100%; max-width: 40rem; }

    /* Name, password and the allowed box sit on one line once there is room. */
    .guest-row {
        flex-direction: row;
        align-items: flex-end;
        flex-wrap: wrap;
    }
    .guest-row .field { flex: 1 1 10rem; min-width: 0; }
    .guest-row .remember { padding-bottom: .6rem; }
    .guest-actions { flex: 0 0 auto; }
    .guest-actions .btn { flex: 0 0 auto; min-width: 6rem; }
    .guest-row .manage-hint { flex: 1 0 100%; margin: 0; }
}

/* ---------- wider screens: the same page, with room around the document ---------- */

@media (min-width: 820px) {
    .editor-wrap, .readonly-doc, .version-list { background: var(--bg); }

    .readonly-doc > * { max-width: 42rem; margin-inline: auto; }

    .bottombar { justify-content: flex-start; }
    .bottombar .btn, .bottombar .restore-form { flex: 0 0 auto; min-width: 10rem; }
}
