:root {
    color-scheme: light;
    --bg: #eef2f4;
    --panel: #ffffff;
    --panel-soft: #f6f8f9;
    --ink: #17212b;
    --muted: #667582;
    --line: #d7e0e5;
    --accent: #0f766e;
    --accent-dark: #115e59;
    --accent-soft: #e5f4f1;
    --danger: #b42318;
    --shadow: 0 18px 42px rgba(23, 33, 43, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

.console-app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.console-topbar {
    height: 64px;
    padding: 0 22px;
    background: #111a22;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.console-brand {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.console-brand strong {
    font-size: 18px;
    letter-spacing: 0;
}

.console-brand span {
    color: #91a1ad;
    font-size: 12px;
}

.api-link {
    margin-left: auto;
    color: #dcfce7;
    border: 1px solid rgba(220, 252, 231, 0.32);
    text-decoration: none;
    padding: 8px 13px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 700;
}

.api-link:hover {
    background: rgba(220, 252, 231, 0.08);
}

.icon-button {
    display: none;
    width: 40px;
    height: 40px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 6px;
    background: transparent;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 4px;
}

.icon-button span {
    width: 18px;
    height: 2px;
    background: #fff;
    border-radius: 2px;
}

.console-layout {
    flex: 1;
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    gap: 18px;
    padding: 18px;
    min-height: 0;
}

.account-panel,
.mail-list-panel,
.reader-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}

.account-panel {
    min-height: calc(100vh - 100px);
    padding: 18px;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

.workspace-head,
.reader-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
}

.workspace-head > div,
.reader-head > div {
    min-width: 0;
}

.workspace-head h2,
.reader-head h2 {
    margin: 0;
    font-size: 19px;
    letter-spacing: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.workspace-head p,
.reader-head p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.close-drawer {
    display: none;
    align-self: flex-end;
    margin-bottom: 12px;
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    font-size: 22px;
    line-height: 1;
}

.field-label {
    display: block;
    margin: 0 0 5px;
    color: #344054;
    font-size: 13px;
    font-weight: 750;
}

.field-hint {
    margin: 0 0 8px;
    color: var(--muted);
    font-size: 12px;
}

textarea {
    width: 100%;
    min-height: 126px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 12px;
    resize: vertical;
    outline: none;
    color: var(--ink);
    background: #fff;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
}

textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.panel-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 12px;
}

.import-progress {
    margin-top: 12px;
    padding: 10px;
    border: 1px solid rgba(15, 118, 110, 0.22);
    border-radius: 6px;
    background: var(--accent-soft);
}

.import-progress-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    color: var(--accent-dark);
    font-size: 12px;
    font-weight: 800;
}

.import-progress-head span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.import-progress-track {
    height: 7px;
    margin-top: 8px;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(15, 118, 110, 0.16);
}

.import-progress-track span {
    display: block;
    width: 0%;
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
    transition: width 180ms ease;
}

.primary-button,
.ghost-button,
.back-button {
    border-radius: 6px;
    min-height: 40px;
    padding: 0 13px;
    font-weight: 750;
}

.primary-button {
    background: var(--accent);
    border: 1px solid var(--accent);
    color: #fff;
}

.primary-button:hover {
    background: var(--accent-dark);
}

.ghost-button,
.back-button {
    background: #fff;
    border: 1px solid var(--line);
    color: #344054;
}

.refresh-button {
    flex: 0 0 auto;
    min-width: 64px;
    white-space: nowrap;
}

.ghost-button:hover,
.back-button:hover {
    background: var(--panel-soft);
}

.section-title {
    margin: 18px 0 10px;
    color: #344054;
    font-size: 13px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.text-button {
    border: 0;
    background: transparent;
    color: var(--muted);
    padding: 0;
    font-size: 12px;
    font-weight: 750;
}

.text-button:hover {
    color: var(--danger);
}

.account-list {
    display: grid;
    gap: 8px;
    flex: 1;
    min-height: 0;
    align-content: start;
    grid-auto-rows: min-content;
    overflow: auto;
    padding-right: 2px;
}

.account-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 34px;
    gap: 6px;
    align-items: stretch;
}

.account-row.merged-row {
    grid-template-columns: minmax(0, 1fr);
}

.account-item,
.account-remove {
    width: 100%;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 6px;
    color: var(--ink);
}

.account-item {
    position: relative;
    text-align: left;
    padding: 24px 11px 11px;
}

.account-remove {
    min-height: 100%;
    padding: 0;
    color: var(--muted);
    font-size: 20px;
    line-height: 1;
}

.account-row.active .account-item {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.account-index {
    position: absolute;
    top: 7px;
    left: 9px;
    color: #80909e;
    font-size: 10px;
    font-weight: 850;
    letter-spacing: 0;
}

.merged-row .account-item {
    padding-top: 11px;
}

.merged-row .account-item {
    border-color: rgba(15, 118, 110, 0.28);
}

.account-remove:hover {
    border-color: #fecaca;
    background: #fff5f5;
    color: var(--danger);
}

.account-email {
    display: block;
    font-weight: 800;
    word-break: break-all;
}

.account-meta {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-top: 3px;
}

.empty-note,
.empty-state,
.reader-empty {
    color: var(--muted);
    font-size: 13px;
}

.mail-workspace {
    display: grid;
    grid-template-columns: minmax(360px, 0.8fr) minmax(420px, 1.2fr);
    gap: 18px;
    min-width: 0;
    min-height: 0;
}

.mail-list-panel,
.reader-panel {
    min-height: calc(100vh - 100px);
    min-width: 0;
}

.mail-list-panel {
    padding: 18px;
    display: flex;
    flex-direction: column;
}

.status-line {
    min-height: 22px;
    margin: 14px 0 12px;
    color: var(--muted);
    font-size: 13px;
}

.status-line.error {
    color: var(--danger);
}

.status-line.success {
    color: var(--accent);
}

.mail-list {
    display: grid;
    gap: 10px;
    overflow: auto;
    padding-right: 3px;
    min-height: 0;
}

.mail-item {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    text-align: left;
    padding: 14px;
    color: var(--ink);
}

.mail-item:hover,
.mail-item.active {
    border-color: var(--accent);
    background: #f7fbfa;
}

.mail-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 14px;
}

.mail-subject {
    display: block;
    font-weight: 800;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mail-date {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
    text-align: right;
    white-space: nowrap;
}

.mail-from {
    display: block;
    margin-top: 7px;
    color: var(--muted);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mail-recipient {
    display: block;
    margin-top: 5px;
    color: var(--accent);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mail-snippet {
    display: block;
    margin-top: 9px;
    color: #475467;
    font-size: 13px;
    line-height: 1.35;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.empty-state,
.reader-empty {
    min-height: 220px;
    border: 1px dashed var(--line);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 6px;
    background: var(--panel-soft);
}

.empty-state strong,
.reader-empty strong {
    color: #344054;
}

.empty-action {
    min-width: 112px;
    margin-top: 10px;
}

.reader-panel {
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.reader-head {
    padding: 18px;
    border-bottom: 1px solid var(--line);
}

.back-button {
    display: none;
}

#readerFrame {
    flex: 1;
    width: 100%;
    border: 0;
    background: #fff;
}

.reader-empty {
    position: absolute;
    inset: 74px 18px 18px;
}

.reader-panel.has-mail .reader-empty {
    display: none;
}

.drawer-backdrop {
    display: none;
}

body.drawer-open {
    overflow: hidden;
}

@media (min-width: 901px) {
    body {
        height: 100vh;
        overflow: hidden;
    }

    .console-app {
        height: 100vh;
        min-height: 0;
    }

    .console-layout {
        height: calc(100vh - 64px);
    }

    .account-panel,
    .mail-list-panel,
    .reader-panel,
    .mail-workspace {
        height: 100%;
        min-height: 0;
    }
}

@media (max-width: 1180px) {
    .console-layout {
        grid-template-columns: 310px minmax(0, 1fr);
    }

    .mail-workspace {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(260px, 0.9fr) minmax(340px, 1.1fr);
        height: 100%;
        min-height: 0;
    }

    .mail-list-panel,
    .reader-panel {
        min-height: 0;
    }
}

@media (max-width: 900px) {
    .console-topbar {
        height: 58px;
        padding: 0 12px;
    }

    .icon-button {
        display: inline-flex;
    }

    .console-layout {
        display: block;
        padding: 12px;
    }

    .account-panel {
        position: fixed;
        z-index: 30;
        top: 0;
        left: 0;
        width: min(86vw, 360px);
        height: var(--console-vh, 100dvh);
        max-height: var(--console-vh, 100dvh);
        min-height: 0;
        padding-bottom: max(120px, calc(env(safe-area-inset-bottom) + 120px));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        transform: translateX(-105%);
        transition: transform 180ms ease;
        border-radius: 0;
        box-shadow: 28px 0 50px rgba(17, 26, 34, 0.22);
    }

    textarea {
        min-height: 112px;
        font-size: 16px;
        line-height: 1.35;
    }

    .field-label {
        font-size: 14px;
    }

    .field-hint {
        font-size: 13px;
    }

    .account-list {
        flex: 0 0 auto;
        overflow: visible;
        padding-bottom: max(120px, calc(env(safe-area-inset-bottom) + 120px));
    }

    .account-list::after {
        content: "";
        display: block;
        height: max(120px, calc(env(safe-area-inset-bottom) + 120px));
    }

    body.drawer-open .account-panel {
        transform: translateX(0);
    }

    .close-drawer {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .drawer-backdrop {
        position: fixed;
        inset: 0;
        z-index: 20;
        background: rgba(17, 26, 34, 0.42);
    }

    body.drawer-open .drawer-backdrop {
        display: block;
    }

    .mail-workspace,
    .mail-list-panel {
        display: block;
    }

    .mail-workspace {
        height: auto;
        min-height: 0;
    }

    .mail-list-panel {
        min-height: calc(100vh - 82px);
    }

    .reader-panel {
        position: fixed;
        inset: 0;
        z-index: 40;
        min-height: 100vh;
        transform: translateX(105%);
        transition: transform 180ms ease;
        border: 0;
        box-shadow: none;
    }

    .reader-panel.mobile-open {
        transform: translateX(0);
    }

    .reader-head {
        min-height: 66px;
        align-items: center;
        justify-content: flex-start;
    }

    .back-button {
        display: inline-block;
        flex: 0 0 auto;
    }
}

@media (max-width: 560px) {
    .console-brand strong {
        font-size: 16px;
    }

    .console-brand span {
        display: none;
    }

    .api-link {
        padding: 7px 10px;
    }

    .mail-list-panel {
        padding: 14px;
    }

    .workspace-head {
        align-items: center;
    }

    .workspace-head h2 {
        font-size: 17px;
    }

    .mail-row {
        grid-template-columns: 1fr;
        gap: 5px;
    }

    .mail-date {
        text-align: left;
    }

    .refresh-button {
        min-height: 36px;
        padding: 0 10px;
    }
}
