/* ---------------------------------------------------------------------------
   Webmail base stylesheet. Mobile first, no framework, no build step.
   Phase 3 extends this with the folder/list/message shell.
   --------------------------------------------------------------------------- */

:root {
    --ink: #16212b;
    --ink-soft: #5b6b7a;
    --line: #dde3e9;
    --surface: #ffffff;
    --canvas: #f4f6f8;
    --brand: #14607a;
    --brand-dark: #0f4a5e;
    --ok: #1f7a45;
    --ok-bg: #eaf6ee;
    --warn: #8a5a00;
    --warn-bg: #fdf4e3;
    --bad: #a32020;
    --bad-bg: #fbecec;
    --radius: 8px;
    --shadow: 0 1px 2px rgba(22, 33, 43, .08), 0 4px 12px rgba(22, 33, 43, .05);
    --tap: 44px;
}

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

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

body {
    margin: 0;
    background: var(--canvas);
    color: var(--ink);
    font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    overflow-wrap: break-word;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
p { margin: 0 0 .75rem; }

a { color: var(--brand); }
a:hover { color: var(--brand-dark); }

/* Visible focus everywhere, never removed. */
:focus-visible {
    outline: 3px solid #2f9bd6;
    outline-offset: 2px;
    border-radius: 4px;
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    background: var(--surface);
    padding: .6rem 1rem;
    z-index: 20;
}
.skip-link:focus { left: .5rem; top: .5rem; }

.page {
    padding: 1rem;
    margin: 0 auto;
    max-width: 1200px;
}
.page--narrow { max-width: 780px; }
.page--centered { min-height: 80vh; display: flex; align-items: center; }
.page__header { margin-bottom: 1rem; }

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
    margin: 0 0 1rem;
    width: 100%;
}
.panel--ok { border-left: 4px solid var(--ok); background: var(--ok-bg); }
.panel--warn { border-left: 4px solid var(--warn); background: var(--warn-bg); }
.panel--error { border-left: 4px solid var(--bad); background: var(--bad-bg); }

.muted { color: var(--ink-soft); }
.small { font-size: .85rem; }

.badge {
    display: inline-block;
    font-size: .75rem;
    font-weight: 600;
    padding: .1rem .45rem;
    border-radius: 999px;
    white-space: nowrap;
}
.badge--ok { background: var(--ok-bg); color: var(--ok); }
.badge--bad { background: var(--bad-bg); color: var(--bad); }

.checks { list-style: none; margin: 0; padding: 0; }
.checks li {
    display: flex;
    justify-content: space-between;
    gap: .75rem;
    padding: .45rem 0;
    border-bottom: 1px solid var(--line);
}
.checks li:last-child { border-bottom: 0; }

.kv { display: grid; grid-template-columns: 1fr; gap: .15rem .75rem; margin: 0; }
.kv dt { font-weight: 600; }
.kv dd { margin: 0 0 .5rem; }

.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th, .table td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--line); }
.table th { color: var(--ink-soft); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--tap);
    padding: .55rem 1.1rem;
    border: 1px solid var(--brand);
    border-radius: var(--radius);
    background: var(--brand);
    color: #fff;
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}
.button:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.button--secondary { background: var(--surface); color: var(--brand); }
.button--secondary:hover { background: #eef4f7; color: var(--brand-dark); }

.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }

.debug {
    background: #1d2733;
    color: #e8eef5;
    padding: .75rem;
    border-radius: var(--radius);
    overflow-x: auto;
    font-size: .8rem;
}

code { font-size: .9em; background: #eef1f4; padding: .1rem .3rem; border-radius: 4px; }

@media (min-width: 640px) {
    .page { padding: 1.5rem; }
    .kv { grid-template-columns: 220px 1fr; }
    .kv dd { margin-bottom: .15rem; }
}

/* --- Phase 2: authentication UI ------------------------------------------- */

.page--auth {
    max-width: 420px;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem 1.25rem;
    width: 100%;
}
.card--auth { border-top: 4px solid var(--brand); }
.card__title { margin-bottom: .35rem; }
.card__footnote { margin: 1rem 0 0; }

.field { margin: 0 0 1rem; }
.field label {
    display: block;
    font-weight: 600;
    font-size: .9rem;
    margin-bottom: .3rem;
}
.field input {
    display: block;
    width: 100%;
    min-height: var(--tap);
    padding: .55rem .7rem;
    font: inherit;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid #b9c4ce;
    border-radius: var(--radius);
}
.field input:focus { border-color: var(--brand); }
/* 16px minimum stops iOS Safari zooming the viewport on focus. */
@media (max-width: 480px) { .field input { font-size: 16px; } }

.button--block { width: 100%; }
.button--small { min-height: 36px; padding: .3rem .7rem; font-size: .85rem; }

.notice {
    margin: 0 0 1rem;
    padding: .6rem .75rem;
    border-radius: var(--radius);
    border-left: 4px solid;
    font-size: .92rem;
}
.notice--ok { background: var(--ok-bg); border-color: var(--ok); color: #14522f; }
.notice--warn { background: var(--warn-bg); border-color: var(--warn); color: #6b4600; }
.notice--error { background: var(--bad-bg); border-color: var(--bad); color: #7d1a1a; }

.topbar {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .6rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar__brand { font-weight: 700; color: var(--brand); }
.topbar__identity {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    margin-left: auto;
    text-align: right;
    min-width: 0;
}
.topbar__name { font-weight: 600; font-size: .9rem; }
.topbar__email {
    font-size: .78rem;
    color: var(--ink-soft);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.topbar__logout { margin: 0; }

.signature-preview {
    border: 1px dashed var(--line);
    border-radius: var(--radius);
    padding: .6rem;
    font-size: .9rem;
    white-space: pre-wrap;
}

@media (max-width: 420px) {
    .topbar { flex-wrap: wrap; }
    .topbar__identity { margin-left: 0; text-align: left; width: 100%; order: 3; }
}

/* --- Phase 3: mail shell, folder nav, message list, message view ---------- */

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.shell { padding: 0; max-width: 1400px; margin: 0 auto; }
.shell__main { padding: .75rem; min-width: 0; }

/* Folder navigation: a <details> element, so it collapses on mobile and needs
   no JavaScript. On wide screens it becomes a permanent sidebar. */
.folder-nav {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}
.folder-nav__toggle {
    display: flex;
    align-items: center;
    gap: .5rem;
    min-height: var(--tap);
    padding: .5rem 1rem;
    cursor: pointer;
    font-weight: 600;
    list-style: none;
}
.folder-nav__toggle::-webkit-details-marker { display: none; }
.folder-nav__toggle::before {
    content: "▸";
    color: var(--ink-soft);
    transition: transform .15s ease;
}
.folder-nav[open] > .folder-nav__toggle::before { transform: rotate(90deg); }
.folder-nav__current {
    margin-left: auto;
    font-weight: 400;
    font-size: .85rem;
    color: var(--ink-soft);
}
.folder-nav__list ul { list-style: none; margin: 0; padding: 0 0 .5rem; }

.folder a,
.folder--disabled .folder__name {
    display: flex;
    align-items: center;
    gap: .5rem;
    min-height: var(--tap);
    padding: .4rem 1rem .4rem calc(1rem + (var(--depth, 0) * 0.85rem));
    color: var(--ink);
    text-decoration: none;
    border-left: 3px solid transparent;
}
.folder a:hover { background: #eef4f7; }
.folder--active > a {
    background: #e7f1f5;
    border-left-color: var(--brand);
    font-weight: 600;
    color: var(--brand-dark);
}
.folder--disabled .folder__name { color: var(--ink-soft); cursor: default; }
.folder__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder__badge {
    margin-left: auto;
    background: var(--brand);
    color: #fff;
    font-size: .72rem;
    font-weight: 700;
    padding: .05rem .4rem;
    border-radius: 999px;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: .5rem;
    margin-bottom: .5rem;
}
.toolbar__title h1 { font-size: 1.2rem; margin: 0; }
.toolbar__title p { margin: 0; }
.toolbar__perpage { display: flex; align-items: center; gap: .35rem; margin: 0; }
.toolbar__perpage select {
    min-height: 36px;
    font: inherit;
    font-size: .9rem;
    padding: .2rem .4rem;
    border: 1px solid #b9c4ce;
    border-radius: 6px;
    background: var(--surface);
}

.messages {
    list-style: none;
    margin: 0 0 1rem;
    padding: 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}
.message-row + .message-row { border-top: 1px solid var(--line); }
.message-row__link {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: "sender meta" "subject subject";
    gap: .1rem .5rem;
    padding: .6rem .75rem;
    min-height: var(--tap);
    text-decoration: none;
    color: var(--ink);
}
.message-row__link:hover { background: #f7fafb; }
.message-row__sender {
    grid-area: sender;
    font-size: .92rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.message-row__subject {
    grid-area: subject;
    font-size: .95rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.message-row__preview { color: var(--ink-soft); font-weight: 400; }
.message-row__meta {
    grid-area: meta;
    display: flex;
    align-items: center;
    gap: .3rem;
    font-size: .78rem;
    color: var(--ink-soft);
    white-space: nowrap;
}
.message-row--unread { background: #fbfdfe; }
.message-row--unread .message-row__sender,
.message-row--unread .message-row__subject { font-weight: 700; }
.message-row--unread .message-row__link { border-left: 3px solid var(--brand); padding-left: calc(.75rem - 3px); }
.message-row--flagged .message-row__link { box-shadow: inset -3px 0 0 var(--warn); }

.tag {
    display: inline-block;
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .03em;
    padding: .05rem .3rem;
    border-radius: 4px;
    background: #eaf0f4;
    color: var(--ink-soft);
}
.tag--flag { background: var(--warn-bg); color: var(--warn); }

.pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .4rem;
    margin-bottom: 1rem;
}
.pager__status { font-size: .85rem; color: var(--ink-soft); margin: 0 .3rem; }

.breadcrumb { margin: 0 0 .5rem; font-size: .9rem; }

.message__subject { font-size: 1.25rem; margin-bottom: .6rem; }
.message__headers {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: .1rem .6rem;
    margin: 0 0 .8rem;
    padding-bottom: .8rem;
    border-bottom: 1px solid var(--line);
    font-size: .9rem;
}
.message__headers dt { font-weight: 600; color: var(--ink-soft); }
.message__headers dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.message__body-frame {
    display: block;
    width: 100%;
    height: 70vh;
    min-height: 320px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
}
.message__plain {
    padding: .75rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    font-size: .95rem;
    overflow-wrap: anywhere;
}
.message__alt { margin-top: .6rem; }
.message__alt summary { cursor: pointer; font-size: .9rem; min-height: var(--tap); display: flex; align-items: center; }

.attachments { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: .8rem; }
.attachments h2 { font-size: 1rem; }
.attachments ul { list-style: none; margin: 0; padding: 0; }
.attachments li {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: .4rem;
    padding: .35rem 0;
    min-height: var(--tap);
}

.message__footer { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: .6rem; }
.message__footer p { margin: 0 0 .2rem; }
.message__footer code { overflow-wrap: anywhere; }

/* Desktop: folder sidebar alongside the list, always expanded. */
@media (min-width: 860px) {
    .shell {
        display: grid;
        grid-template-columns: 250px minmax(0, 1fr);
        align-items: start;
    }
    .shell__main { padding: 1rem 1.25rem; }

    .folder-nav {
        border-bottom: 0;
        border-right: 1px solid var(--line);
        min-height: calc(100vh - 53px);
        position: sticky;
        top: 53px;
    }
    /* The disclosure control is a mobile affordance only. */
    .folder-nav > .folder-nav__toggle { display: none; }
    .folder-nav > .folder-nav__list { display: block !important; }
    /* ...but that alone stopped working. Chrome 128+ hides a CLOSED <details>'s
       contents through the UA pseudo-element ::details-content, which carries
       content-visibility: hidden. That is not overridable by display on the
       child, so the whole sidebar rendered blank while still occupying its
       min-height above — a full empty screen on every page. Browsers without
       ::details-content ignore this rule and keep using the line above. */
    .folder-nav::details-content {
        content-visibility: visible;
        display: block;
    }

    .message-row__link {
        grid-template-columns: 200px minmax(0, 1fr) auto;
        grid-template-areas: "sender subject meta";
        align-items: center;
    }

    .message__body-frame { height: 60vh; }
}

/* --- Phase 4: search ------------------------------------------------------ */

.search-form { margin-bottom: 1rem; }
.search-form__grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0 .8rem;
}
.field--wide { grid-column: 1 / -1; }
.field__hint {
    margin: .25rem 0 0;
    font-size: .8rem;
    color: var(--ink-soft);
}
.field select {
    display: block;
    width: 100%;
    min-height: var(--tap);
    padding: .5rem .6rem;
    font: inherit;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid #b9c4ce;
    border-radius: var(--radius);
}
@media (max-width: 480px) {
    .field select, .field input[type="date"] { font-size: 16px; }
}
.field--checks { display: flex; flex-direction: column; justify-content: flex-end; gap: .2rem; }
.check {
    display: flex;
    align-items: center;
    gap: .45rem;
    min-height: var(--tap);
    font-weight: 400;
    font-size: .92rem;
    cursor: pointer;
}
.check input { width: 18px; height: 18px; margin: 0; }

.search-results h2 { font-size: 1.05rem; margin-bottom: .2rem; }
.search-results > p.muted { margin-bottom: .6rem; }

@media (min-width: 700px) {
    .search-form__grid { grid-template-columns: 1fr 1fr; }
}
.topbar__search { flex-shrink: 0; }

/* --- Phase 5: compose ----------------------------------------------------- */

.compose__from {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: .5rem;
    padding: .5rem .6rem;
    margin-bottom: 1rem;
    background: #f3f7f9;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.compose__label { font-weight: 600; font-size: .9rem; color: var(--ink-soft); }
.compose__value { font-size: .92rem; overflow-wrap: anywhere; }

.compose__more { margin: 0 0 1rem; }
.compose__more summary {
    cursor: pointer;
    min-height: var(--tap);
    display: flex;
    align-items: center;
    font-size: .9rem;
    font-weight: 600;
    color: var(--brand);
}

.field textarea {
    display: block;
    width: 100%;
    padding: .6rem .7rem;
    font: inherit;
    line-height: 1.5;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid #b9c4ce;
    border-radius: var(--radius);
    resize: vertical;
    min-height: 12rem;
}
.field input[type="file"] {
    display: block;
    width: 100%;
    padding: .5rem 0;
    font: inherit;
    font-size: .9rem;
}
@media (max-width: 480px) {
    .field textarea { font-size: 16px; }
}

.button[disabled] { opacity: .6; cursor: default; }
.topbar__compose { flex-shrink: 0; }

/* --- Phase 6: reply / forward --------------------------------------------- */

.message__actions {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin-top: 1rem;
    padding-top: .8rem;
    border-top: 1px solid var(--line);
}

.forward-attachments {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: .6rem .7rem 0;
    margin: 0 0 1rem;
}
.forward-attachments legend {
    font-weight: 600;
    font-size: .9rem;
    padding: 0 .3rem;
}
.forward-attachments .check { flex-wrap: wrap; gap: .35rem; }

blockquote {
    margin: 0 0 0 .5rem;
    padding-left: .7rem;
    border-left: 3px solid var(--line);
    color: var(--ink-soft);
}
