/* ─────────────────────────────────────────────────────────────
 * webmail/assets/cowmail.css
 *
 * Cowmail Webmail — bright yellow-gradient / Gmail-style IA skin.
 * Authority: docs/WEBMAIL_UI_DESIGN.md (PRIMARY design slice,
 * dev1.0 render-only).
 *
 * ONE local stylesheet shared by login / inbox / read / compose /
 * sent. No external font, no framework, no CDN, no dark-theme
 * companion file: the previous per-page inline dark CSS blocks are
 * removed, so this file is the single webmail theme.
 *
 * Design tokens (verbatim from the design spec):
 *   背景 #fffdf4 · 漸層 #fff7cc→#ffe078→#ffd34e · 強調 #f4bd24
 *   文字 #302a1b · 次文字 #746b55 · 邊線 #eee6cf · active #ffe9a0
 *
 * Reading / form panels stay white or cream; dark warm-grey text is
 * used everywhere (never white-on-yellow). Density: 220px desktop
 * sidebar, 48–56px list rows, 14px body / 15px reading body /
 * 12–13px secondary / 18–20px page title.
 * ───────────────────────────────────────────────────────────── */

:root {
    --cw-bg: #fffdf4;
    --cw-panel: #ffffff;
    --cw-cream: #fffaf0;
    --cw-grad-top: #fff7cc;
    --cw-grad-mid: #ffe078;
    --cw-grad-low: #ffd34e;
    --cw-accent: #f4bd24;
    --cw-text: #302a1b;
    --cw-muted: #746b55;
    --cw-border: #eee6cf;
    --cw-active: #ffe9a0;
    --cw-focus: #6b4a06;
    --cw-danger: #a8341f;
    --cw-danger-bg: #fdecea;
    --cw-row-min: 52px;
    --cw-side-w: 220px;
}

* {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    background: var(--cw-bg);
    color: var(--cw-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC",
        "PingFang TC", "Microsoft JhengHei", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    overflow-wrap: anywhere;
}

a {
    color: #7a5400;
}

:focus-visible {
    outline: 2px solid var(--cw-focus);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ── Top bar: brand / account / logout ───────────────────────── */

.cw-topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
    padding: 10px 18px;
    background: linear-gradient(180deg, var(--cw-grad-top) 0%, var(--cw-grad-mid) 58%, var(--cw-grad-low) 100%);
    border-bottom: 1px solid #efd98a;
}

.cw-brand {
    margin: 0;
    font-size: 19px;
    font-weight: 700;
    letter-spacing: 0.2px;
    color: var(--cw-text);
}

.cw-topbar-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    font-size: 13px;
    color: var(--cw-text);
}

.cw-account {
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
}

.cw-topbar-link {
    padding: 4px 10px;
    border: 1px solid #e3c55f;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.65);
    color: var(--cw-text);
    font-size: 13px;
    text-decoration: none;
}

.cw-topbar-link:hover {
    background: var(--cw-active);
}

/* Csrf::logoutForm() renders its own inline style (class/Csrf.php is
 * shared with the admin panel and is NOT owned by this slice), so the
 * light-theme override has to out-rank the inline declaration.
 * Author !important beats a non-important inline style.
 * The wrapper is a <div> (a form may not sit inside a <span>), so the
 * inline layout comes from the wrapper rather than from the form. */
.cw-logout {
    display: inline-block;
    margin: 0 !important;
}

.cw-logout form {
    display: inline;
    margin: 0;
}

.cw-logout button,
.cw-logout a {
    color: var(--cw-text) !important;
    font-size: 13px !important;
    font-family: inherit !important;
    font-weight: 600;
    cursor: pointer;
}

.cw-logout button {
    padding: 4px 10px !important;
    border: 1px solid #e3c55f !important;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.65) !important;
}

/* ── Shell: sidebar + content ────────────────────────────────── */

.cw-shell {
    display: flex;
    align-items: flex-start;
    min-height: calc(100vh - 49px);
}

.cw-sidebar {
    flex: 0 0 var(--cw-side-w);
    width: var(--cw-side-w);
    padding: 16px 12px;
    background: linear-gradient(180deg, var(--cw-grad-top) 0%, var(--cw-grad-mid) 100%);
    border-right: 1px solid #efd98a;
}

.cw-compose-link {
    display: block;
    margin-bottom: 14px;
    padding: 11px 14px;
    border-radius: 10px;
    background: var(--cw-accent);
    color: #3a2a00;
    font-weight: 700;
    font-size: 14px;
    text-align: center;
    text-decoration: none;
}

.cw-compose-link:hover {
    background: var(--cw-grad-low);
}

.cw-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.cw-nav a {
    display: block;
    padding: 8px 12px;
    border-radius: 8px;
    color: var(--cw-text);
    font-size: 14px;
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cw-nav a:hover {
    background: rgba(255, 255, 255, 0.72);
}

.cw-nav a[aria-current="page"] {
    background: var(--cw-active);
    font-weight: 700;
}

.cw-content {
    flex: 1 1 auto;
    min-width: 0;
    padding: 18px;
}

/* ── Toolbar (list header / pager chrome) ────────────────────── */

.cw-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    margin-bottom: 12px;
    padding: 10px 14px;
    background: var(--cw-panel);
    border: 1px solid var(--cw-border);
    border-radius: 10px;
}

.cw-meta {
    font-size: 13px;
    color: var(--cw-muted);
}

.cw-btn {
    display: inline-block;
    padding: 7px 14px;
    border: 1px solid #e3c55f;
    border-radius: 8px;
    background: var(--cw-active);
    color: var(--cw-text);
    font-family: inherit;
    font-size: 13px;
    line-height: 1.4;
    text-decoration: none;
    cursor: pointer;
}

.cw-btn:hover {
    background: var(--cw-grad-low);
}

.cw-btn-secondary {
    background: var(--cw-cream);
}

.cw-spacer {
    flex: 1 1 auto;
}

/* ── Message list ───────────────────────────────────────────── */

.email-list {
    background: var(--cw-panel);
    border: 1px solid var(--cw-border);
    border-radius: 10px;
    overflow: hidden;
}

.email-item {
    display: grid;
    grid-template-columns: 10px minmax(0, 190px) minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    min-height: var(--cw-row-min);
    padding: 10px 14px;
    border-bottom: 1px solid var(--cw-border);
}

.email-item:last-child {
    border-bottom: 0;
}

.email-item:hover {
    background: var(--cw-cream);
}

.email-item.unread {
    background: #fffae4;
    font-weight: 600;
}

.email-item.unread .subject {
    font-weight: 700;
}

.email-item .from,
.email-item .subject {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.email-item .from {
    color: var(--cw-text);
    font-size: 13px;
}

.email-item .subject {
    color: var(--cw-muted);
    font-size: 14px;
}

.email-item.unread .subject {
    color: var(--cw-text);
}

.email-item .date {
    color: var(--cw-muted);
    font-size: 12px;
    white-space: nowrap;
    text-align: right;
}

.email-item a {
    color: inherit;
    text-decoration: none;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: transparent;
}

.status-dot.unread {
    background: var(--cw-accent);
    box-shadow: 0 0 0 2px #fdeeb8;
}

.malformed-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--cw-danger);
}

.empty {
    padding: 56px 20px;
    color: var(--cw-muted);
    text-align: center;
}

/* ── Reading panel ───────────────────────────────────────────── */

.cw-page-title {
    margin: 0 0 12px;
    font-size: 20px;
    font-weight: 700;
}

.cw-panel {
    margin-bottom: 14px;
    padding: 18px;
    background: var(--cw-panel);
    border: 1px solid var(--cw-border);
    border-radius: 10px;
}

.email-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.email-meta {
    margin-top: 6px;
    color: var(--cw-muted);
    font-size: 13px;
    line-height: 1.8;
}

.email-body {
    background: var(--cw-panel);
    border: 1px solid var(--cw-border);
    border-radius: 10px;
    padding: 18px;
    color: var(--cw-text);
    font-size: 15px;
    line-height: 1.75;
    overflow-wrap: anywhere;
}

.email-body p {
    margin: 0 0 12px;
}

.attachments {
    margin-top: 14px;
    padding: 16px;
    background: var(--cw-panel);
    border: 1px solid var(--cw-border);
    border-radius: 10px;
}

.attachments h3 {
    margin: 0 0 8px;
    font-size: 14px;
}

.attachments ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.attachments li {
    padding: 7px 0;
    border-bottom: 1px solid var(--cw-border);
    font-size: 13px;
}

.attachments li:last-child {
    border-bottom: 0;
}

.cw-fine {
    color: var(--cw-muted);
    font-size: 12px;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.actions form {
    display: inline;
}

.back {
    display: inline-block;
    margin-bottom: 14px;
}

/* ── Forms (login / compose / retry) ─────────────────────────── */

.cw-form-panel {
    max-width: 760px;
    margin: 0 auto;
    padding: 20px;
    background: var(--cw-panel);
    border: 1px solid var(--cw-border);
    border-radius: 12px;
}

.cw-field {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    padding: 11px 0;
    border-bottom: 1px solid var(--cw-border);
}

.cw-field label {
    flex: 0 0 84px;
    color: var(--cw-muted);
    font-size: 13px;
}

.cw-field input[type="text"],
.cw-field input[type="email"],
.cw-field input[type="password"],
.cw-field textarea,
.cw-field input[type="file"] {
    flex: 1 1 220px;
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid var(--cw-border);
    border-radius: 8px;
    background: #fffdf8;
    color: var(--cw-text);
    font-family: inherit;
    font-size: 14px;
}

.cw-field textarea {
    min-height: 260px;
    resize: vertical;
    line-height: 1.7;
}

.cw-form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 16px;
}

.cw-btn-primary {
    background: var(--cw-accent);
    font-weight: 700;
}

.error,
.cw-error {
    margin-bottom: 14px;
    padding: 10px 12px;
    border: 1px solid #f0c2b8;
    border-radius: 8px;
    background: var(--cw-danger-bg);
    color: var(--cw-danger);
    font-size: 13px;
}

/* ── Sent / delivery status ──────────────────────────────────── */

.cw-record {
    margin-bottom: 14px;
    padding: 16px 18px;
    background: var(--cw-panel);
    border: 1px solid var(--cw-border);
    border-radius: 10px;
}

.cw-record h2 {
    margin: 0 0 10px;
    font-size: 16px;
    overflow-wrap: anywhere;
}

.cw-dl {
    display: grid;
    grid-template-columns: 116px minmax(0, 1fr);
    gap: 4px 12px;
    margin: 0;
    font-size: 13px;
}

.cw-dl dt {
    color: var(--cw-muted);
}

.cw-dl dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.cw-audit {
    margin: 6px 0 0;
    padding-left: 18px;
    font-size: 13px;
}

/* ── Login card ──────────────────────────────────────────────── */

.cw-login-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px 16px;
    background: linear-gradient(180deg, var(--cw-grad-top) 0%, var(--cw-grad-mid) 55%, var(--cw-grad-low) 100%);
}

.cw-login-card {
    width: 100%;
    max-width: 400px;
    padding: 26px;
    background: var(--cw-panel);
    border: 1px solid #efd98a;
    border-radius: 14px;
    box-shadow: 0 10px 28px rgba(120, 92, 20, 0.16);
}

.cw-login-card h1 {
    margin: 0 0 6px;
    font-size: 20px;
    text-align: center;
}

.cw-login-card .cw-lead {
    margin: 0 0 20px;
    color: var(--cw-muted);
    font-size: 13px;
    text-align: center;
}

.login-box .btn {
    width: 100%;
    margin-top: 4px;
    padding: 11px;
    border: 1px solid #dfb93f;
    border-radius: 8px;
    background: var(--cw-accent);
    color: #3a2a00;
    font-family: inherit;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
}

.login-box .btn:hover {
    background: var(--cw-grad-low);
}

/* ── Narrow / mobile: no page-level horizontal overflow ──────── */

@media (max-width: 860px) {
    .cw-shell {
        display: block;
    }

    .cw-sidebar {
        width: auto;
        padding: 12px;
        border-right: 0;
        border-bottom: 1px solid #efd98a;
    }

    /* Gmail-like horizontal strip; the strip scrolls, the page does
     * not gain a horizontal scrollbar. */
    .cw-nav {
        flex-direction: row;
        gap: 6px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
    }

    .cw-nav a {
        flex: 0 0 auto;
        max-width: 60vw;
    }

    .cw-compose-link {
        margin-bottom: 10px;
    }

    .cw-content {
        padding: 12px;
    }

    .email-item {
        grid-template-columns: 10px minmax(0, 1fr);
        gap: 4px 10px;
    }

    .email-item .from,
    .email-item .subject {
        white-space: normal;
    }

    .email-item .date {
        grid-column: 2;
        text-align: left;
    }

    .cw-field label {
        flex: 0 0 100%;
    }

    .cw-dl {
        grid-template-columns: minmax(0, 1fr);
    }

    .cw-dl dd {
        margin-bottom: 6px;
    }
}