:root {
    --bg: #f3f6f8;
    --bg-accent: #e8eef3;
    --panel: #ffffff;
    --ink: #1c2b36;
    --muted: #6b7c89;
    --line: #d7e0e7;
    --brand: #0f6e56;
    --brand-soft: #e6f4ef;
    --danger: #b42318;
    --warn: #b54708;
    --shadow: 0 10px 30px rgba(28, 43, 54, 0.06);
    --radius: 14px;
    --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font);
    color: var(--ink);
    background:
        radial-gradient(circle at top left, rgba(15, 110, 86, 0.08), transparent 32%),
        linear-gradient(180deg, #eef3f6 0%, var(--bg) 40%, #f7fafb 100%);
    min-height: 100vh;
}

.app {
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px 20px 60px;
}

.workspace {
    display: grid;
    grid-template-columns: 3fr 7fr;
    gap: 16px;
    align-items: start;
}

.workspace-left,
.workspace-right {
    min-width: 0;
}

.workspace-left {
    position: sticky;
    top: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.import-panel {
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 360px);
}

.import-panel .panel-head.stack {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
}

.import-panel textarea {
    flex: 1;
    min-height: 220px;
    margin-bottom: 12px;
}

.totp-panel {
    margin-bottom: 0;
}

.totp-input-row {
    display: grid;
    gap: 8px;
}

.totp-label {
    font-size: 14px;
    color: var(--ink);
    font-weight: 600;
}

.totp-input-group {
    display: flex;
    gap: 0;
    align-items: stretch;
}

.totp-input-group .input {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    border-right: 0;
}

.totp-input-group .btn {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    flex-shrink: 0;
}

.totp-result {
    margin-top: 16px;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 20px 16px 16px;
    text-align: center;
    background: #fbfcfd;
}

.totp-result-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--ink);
    margin-bottom: 12px;
}

.totp-code {
    display: block;
    width: 100%;
    border: 0;
    background: transparent;
    color: #1a73e8;
    font-size: 42px;
    font-weight: 700;
    letter-spacing: 0.12em;
    font-family: "Cascadia Mono", "Consolas", "Segoe UI", monospace;
    cursor: pointer;
    padding: 4px 0 8px;
    line-height: 1.1;
}

.totp-code:hover {
    filter: brightness(0.92);
}

.totp-tip {
    margin: 0 0 14px;
    color: var(--muted);
    font-size: 13px;
}

.totp-progress {
    height: 8px;
    border-radius: 999px;
    background: #e8eef3;
    overflow: hidden;
    margin-bottom: 12px;
}

.totp-progress-bar {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #22a06b, #4bce97);
    transform-origin: left center;
    transition: width 0.2s linear;
}

.totp-timer {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
}

.totp-timer-num {
    display: inline-grid;
    place-items: center;
    min-width: 28px;
    height: 28px;
    padding: 0 6px;
    border-radius: 6px;
    background: #0f766e;
    color: #fff;
    font-weight: 700;
    font-size: 14px;
}

.import-actions {
    display: grid;
    gap: 10px;
}

.import-actions .btn,
.import-actions .file-btn {
    width: 100%;
    justify-content: center;
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.brand {
    display: flex;
    gap: 14px;
    align-items: center;
}

.brand-mark {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    background: linear-gradient(145deg, #127a5f, #0b4f3d);
    color: #fff;
    font-size: 24px;
    font-weight: 700;
    box-shadow: 0 10px 24px rgba(15, 110, 86, 0.28);
}

.brand h1 {
    margin: 0;
    font-size: 28px;
    letter-spacing: 0.02em;
}

.brand p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(88px, 1fr));
    gap: 10px;
}

.stat {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 14px;
    text-align: center;
    box-shadow: var(--shadow);
}

.stat span {
    display: block;
    font-size: 22px;
    font-weight: 700;
    color: var(--brand);
}

.stat label {
    color: var(--muted);
    font-size: 12px;
}

.stat.danger span { color: var(--danger); }

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.panel-head {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.panel-head.between,
.row.between {
    justify-content: space-between;
    width: 100%;
}

.panel-head h2 {
    margin: 0;
    font-size: 18px;
}

.hint {
    color: var(--muted);
    font-size: 13px;
    margin: 4px 0 0;
}

.row {
    display: flex;
    align-items: center;
}

.gap { gap: 10px; }
.wrap { flex-wrap: wrap; }
.end { justify-content: flex-end; }

textarea,
.input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    font: inherit;
    color: var(--ink);
    background: #fbfcfd;
}

textarea {
    min-height: 110px;
    resize: vertical;
    margin-bottom: 10px;
}

.input.narrow { width: 160px; }

.btn {
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 9px 14px;
    font: inherit;
    cursor: pointer;
    background: #eef3f6;
    color: var(--ink);
    white-space: nowrap;
}

.btn:hover { filter: brightness(0.98); }
.btn.primary {
    background: var(--brand);
    color: #fff;
}
.btn.ghost {
    background: #fff;
    border-color: var(--line);
}
.btn.danger-outline {
    background: #fff;
    border-color: #f2c7c3;
    color: var(--danger);
}
.file-btn { display: inline-flex; align-items: center; }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

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

.table-wrap {
    overflow: auto;
    margin-top: 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 980px;
}

th, td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    font-size: 13px;
    vertical-align: middle;
}

th {
    background: #f7fafb;
    color: var(--muted);
    font-weight: 600;
}

tr.active { background: var(--brand-soft); }
tr:hover { background: #f5faf8; }

.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--brand-soft);
    color: var(--brand);
    font-size: 12px;
}

.badge.error {
    background: #fdeceb;
    color: var(--danger);
}

.badge.warn {
    background: #fff4e5;
    color: var(--warn);
}

.empty {
    color: var(--muted);
    text-align: center;
    padding: 28px 12px;
}

.linkish {
    color: var(--brand);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0 6px;
    font: inherit;
}

.mail-layout {
    display: grid;
    grid-template-columns: 1.1fr 1.2fr;
    gap: 12px;
    min-height: 360px;
}

.mail-list, .mail-detail {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fbfcfd;
    overflow: auto;
    max-height: 520px;
}

.mail-item {
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    cursor: pointer;
}

.mail-item:hover, .mail-item.active {
    background: var(--brand-soft);
}

.mail-item .subject {
    font-weight: 600;
    margin-bottom: 4px;
}

.mail-item .meta {
    color: var(--muted);
    font-size: 12px;
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.mail-detail {
    padding: 16px;
}

.mail-detail h3 {
    margin: 0 0 8px;
}

.mail-detail .meta {
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 14px;
    line-height: 1.6;
}

.mail-body {
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.7;
    font-size: 14px;
}

.tabs {
    display: inline-flex;
    background: #eef3f6;
    border-radius: 10px;
    padding: 3px;
}

.tab {
    border: none;
    background: transparent;
    padding: 7px 12px;
    border-radius: 8px;
    cursor: pointer;
    font: inherit;
}

.tab.active {
    background: #fff;
    color: var(--brand);
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

#edit-dialog {
    border: none;
    border-radius: 16px;
    padding: 0;
    width: min(520px, 92vw);
    box-shadow: 0 20px 60px rgba(0,0,0,.18);
}

#edit-dialog::backdrop {
    background: rgba(16, 24, 32, .45);
}

#edit-form {
    padding: 20px;
    display: grid;
    gap: 10px;
}

#edit-form h3 { margin: 0 0 4px; }
#edit-form label {
    display: grid;
    gap: 6px;
    font-size: 13px;
    color: var(--muted);
}

.toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    background: #123047;
    color: #fff;
    padding: 12px 16px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    z-index: 50;
    max-width: 360px;
}

@media (max-width: 1100px) {
    .workspace {
        grid-template-columns: 1fr;
    }

    .workspace-left {
        position: static;
        gap: 16px;
    }

    .import-panel {
        min-height: auto;
    }

    .import-panel textarea {
        min-height: 160px;
    }

    .totp-code {
        font-size: 34px;
    }
}

@media (max-width: 900px) {
    .mail-layout { grid-template-columns: 1fr; }
    .stats { width: 100%; }
}
