:root {
    --bg-base: #FAFAFA;
    --bg-surface: #FFFFFF;
    --bg-sidebar: #0F172A;
    --bg-elevated: #FFFFFF;
    --bg-muted: #F8FAFC;
    --border: #E5E7EB;
    --text-primary: #0F172A;
    --text-secondary: #64748B;
    --text-tertiary: #94A3B8;
    --brand: #2563EB;
    --brand-hover: #1D4ED8;
    --success: #10B981;
    --warning: #F59E0B;
    --danger: #EF4444;
    --bg: var(--bg-base);
    --surface: var(--bg-surface);
    --surface-soft: var(--bg-muted);
    --text: var(--text-primary);
    --muted: var(--text-secondary);
    --primary: var(--brand);
    --primary-dark: var(--brand-hover);
    --green: var(--success);
    --yellow: var(--warning);
    --red: var(--danger);
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

[data-theme="dark"] {
    --bg-base: #0B1120;
    --bg-surface: #111827;
    --bg-sidebar: #020617;
    --bg-elevated: #1E293B;
    --bg-muted: #0F172A;
    --border: #243244;
    --text-primary: #E5E7EB;
    --text-secondary: #94A3B8;
    --text-tertiary: #64748B;
    --brand: #60A5FA;
    --brand-hover: #93C5FD;
    --success: #34D399;
    --warning: #FBBF24;
    --danger: #F87171;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font-family: Inter, "SF Pro Text", "PingFang SC", "HarmonyOS Sans", "Source Han Sans SC", "Microsoft YaHei", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    letter-spacing: 0;
}

a {
    color: var(--primary);
    text-decoration: none;
}

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

button,
input,
select,
textarea {
    font: inherit;
}

input,
select,
textarea {
    width: 100%;
    min-height: 36px;
    padding: 7px 10px;
    color: var(--text);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    outline: none;
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(29, 111, 220, 0.13);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

th {
    color: #445066;
    background: var(--surface-soft);
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

td {
    min-height: 48px;
}

.app-shell {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 18px 14px;
    background: #10213a;
    color: #fff;
}

.brand,
.auth-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-weight: 700;
}

.brand:hover {
    color: #fff;
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    border-radius: 8px;
    color: #fff;
    background: var(--primary);
    font-size: 13px;
    font-weight: 800;
}

.nav {
    display: grid;
    gap: 4px;
    margin-top: 24px;
}

.nav a {
    display: block;
    padding: 10px 12px;
    color: #c8d4e8;
    border-radius: 6px;
}

.nav a:hover,
.nav a.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

.main-shell {
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    padding: 0 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar h1 {
    margin: 0;
    font-size: 18px;
    line-height: 1.2;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.topbar-actions form,
.row-actions form,
.toolbar form {
    display: inline-flex;
    margin: 0;
}

.content {
    padding: 24px;
}

.panel,
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.panel {
    margin-bottom: 18px;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
}

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

.narrow-panel {
    max-width: 760px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.stat-card {
    padding: 16px;
}

.stat-card span {
    display: block;
    color: var(--muted);
    font-size: 13px;
}

.stat-card strong {
    display: block;
    margin-top: 8px;
    font-size: 28px;
    line-height: 1.15;
}

.stat-card .stat-time {
    font-size: 15px;
    line-height: 1.4;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 6px 12px;
    color: #263247;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
}

.btn:hover {
    color: var(--primary-dark);
    border-color: #b8c9de;
}

.btn-primary {
    color: #fff;
    background: var(--primary);
    border-color: var(--primary);
}

.btn-primary:hover {
    color: #fff;
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

.btn-secondary {
    color: #fff;
    background: #34445e;
    border-color: #34445e;
}

.btn-light {
    background: var(--surface-soft);
}

.btn-danger {
    color: #fff;
    background: var(--red);
    border-color: var(--red);
}

.btn-small {
    min-height: 30px;
    padding: 4px 9px;
    font-size: 13px;
}

.btn-block {
    width: 100%;
}

.disabled {
    pointer-events: none;
    opacity: 0.45;
}

.filter-grid,
.form-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    padding: 18px;
}

.filter-grid label,
.form-grid label,
.stack-form label {
    display: grid;
    gap: 6px;
}

.filter-grid label span,
.form-grid label span,
.stack-form label span {
    color: #445066;
    font-size: 13px;
    font-weight: 600;
}

.filter-actions,
.form-actions {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.stack-form {
    display: grid;
    gap: 14px;
    padding: 18px;
}

.check-line {
    display: flex !important;
    align-items: center;
    gap: 8px;
}

.check-line input {
    width: 16px;
    min-height: 16px;
}

.table-wrap {
    overflow-x: auto;
}

.row-unread td {
    font-weight: 700;
}

.subject-cell {
    min-width: 260px;
}

.truncate {
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.row-actions,
.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.toolbar {
    margin-bottom: 16px;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 2px 8px;
    color: #526074;
    background: #eef2f6;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}

.badge-blue {
    color: #155bb6;
    background: #e8f1ff;
}

.badge-green {
    color: #11744c;
    background: #e8f8f1;
}

.badge-yellow {
    color: #8a5d00;
    background: #fff4d6;
}

.badge-red {
    color: #a72b2b;
    background: #fdeaea;
}

.dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 999px;
    background: var(--primary);
}

.star {
    color: #8c96a8;
    font-size: 18px;
    line-height: 1;
}

.star.on {
    color: #e0a20d;
}

.muted {
    color: var(--muted);
}

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

.pagination {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 18px;
}

.message-meta {
    padding-bottom: 4px;
}

.message-title-line {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 18px;
    border-bottom: 1px solid var(--border);
}

.message-title-line h2 {
    margin: 0;
    font-size: 20px;
}

.detail-grid {
    display: grid;
    grid-template-columns: 140px minmax(0, 1fr);
    gap: 0;
    margin: 0;
    padding: 8px 18px 18px;
}

.detail-grid dt,
.detail-grid dd {
    padding: 8px 0;
    border-bottom: 1px solid #edf1f5;
}

.detail-grid dt {
    color: var(--muted);
    font-weight: 700;
}

.detail-grid dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.message-body {
    max-height: 560px;
    margin: 0;
    padding: 18px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    background: #fbfcfd;
}

.flash {
    margin-bottom: 16px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
}

.flash-success {
    color: #11744c;
    border-color: #b8e4d0;
    background: #eefaf5;
}

.flash-error {
    color: #a72b2b;
    border-color: #f1bbbb;
    background: #fff0f0;
}

.auth-page {
    min-height: 100vh;
    background: #eef3f8;
}

.install-page {
    min-height: 100vh;
    background: #eef3f8;
}

.auth-shell {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 24px;
}

.install-shell {
    display: grid;
    place-items: start center;
    min-height: 100vh;
    padding: 32px 16px;
}

.auth-panel {
    width: min(420px, 100%);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.install-panel {
    width: min(920px, 100%);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.auth-brand {
    padding: 22px 22px 8px;
    color: var(--text);
}

.install-brand {
    padding-bottom: 18px;
    border-bottom: 1px solid var(--border);
}

.auth-brand h1,
.auth-brand p {
    margin: 0;
}

.auth-brand h1 {
    font-size: 20px;
}

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

.user-chip,
.setting-status {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    padding: 5px 10px;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.setting-status {
    justify-content: space-between;
    gap: 16px;
}

.ok {
    color: var(--green);
}

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

.install-steps {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    padding: 18px;
    border-bottom: 1px solid var(--border);
}

.install-steps span {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 6px 10px;
    color: #155bb6;
    background: #e8f1ff;
    border-radius: 6px;
    font-weight: 700;
}

.install-section {
    padding: 18px;
    border-bottom: 1px solid var(--border);
}

.install-section h2 {
    margin: 0 0 14px;
    font-size: 16px;
}

.check-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.check-item {
    display: grid;
    grid-template-columns: 56px minmax(0, 1fr);
    gap: 2px 10px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-soft);
}

.check-item strong {
    grid-row: span 2;
    color: var(--green);
}

.check-item.fail strong {
    color: var(--red);
}

.check-item span {
    font-weight: 700;
}

.check-item em {
    color: var(--muted);
    font-style: normal;
    overflow-wrap: anywhere;
}

.install-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 0;
}

.install-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px;
}

.install-success {
    padding: 24px;
}

.install-success h2 {
    margin: 0 0 8px;
    font-size: 20px;
}

.install-result {
    display: grid;
    grid-template-columns: 150px minmax(0, 1fr);
    margin: 18px 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.install-result dt,
.install-result dd {
    margin: 0;
    padding: 12px;
    border-bottom: 1px solid var(--border);
}

.install-result dt {
    color: var(--muted);
    background: var(--surface-soft);
    font-weight: 700;
}

.install-result dd {
    overflow-wrap: anywhere;
}

.install-result dt:last-of-type,
.install-result dd:last-of-type {
    border-bottom: 0;
}

.install-result code {
    color: #10213a;
}

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

@media (max-width: 1120px) {
    .stats-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .filter-grid,
    .form-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 760px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
    }

    .nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .topbar {
        height: auto;
        align-items: flex-start;
        flex-direction: column;
        padding: 14px;
        gap: 10px;
    }

    .topbar-actions {
        flex-wrap: wrap;
    }

    .content {
        padding: 14px;
    }

    .stats-grid,
    .filter-grid,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }

    .message-title-line {
        flex-direction: column;
    }

    .install-steps,
    .check-list,
    .install-grid,
    .install-result {
        grid-template-columns: 1fr;
    }

    .install-actions {
        align-items: flex-start;
        flex-direction: column;
    }
}

/* Modern admin UI refresh */
.icon {
    width: 16px;
    height: 16px;
    fill: currentColor;
    flex: 0 0 16px;
}

.app-shell {
    grid-template-columns: 240px minmax(0, 1fr);
}

.sidebar {
    width: 240px;
    padding: 0 12px 14px;
    background: var(--bg-sidebar);
}

.brand {
    height: 56px;
    gap: 12px;
    padding: 0 8px;
}

.brand-mark {
    width: 32px;
    height: 32px;
    flex-basis: 32px;
    border-radius: 8px;
    background: linear-gradient(135deg, #2563eb, #14b8a6);
}

.brand-copy {
    display: grid;
    gap: 1px;
    min-width: 0;
}

.brand-copy strong,
.brand-copy small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.brand-copy small {
    color: #94a3b8;
    font-size: 12px;
    font-weight: 500;
}

.nav {
    gap: 18px;
    margin-top: 12px;
}

.nav-section {
    display: grid;
    gap: 4px;
}

.nav-heading {
    padding: 0 10px 4px;
    color: #64748b;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.nav a {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 36px;
    padding: 8px 10px 8px 14px;
    color: #cbd5e1;
    border-radius: 8px;
    transition: background .16s ease, color .16s ease, transform .16s ease;
}

.nav a::before {
    position: absolute;
    left: 0;
    width: 3px;
    height: 18px;
    content: "";
    background: transparent;
    border-radius: 999px;
}

.nav a:hover {
    color: #fff;
    background: rgba(255, 255, 255, .08);
    transform: translateX(1px);
}

.nav a.active {
    color: #fff;
    background: rgba(37, 99, 235, .18);
}

.nav a.active::before {
    background: #60a5fa;
}

.sidebar-footer {
    position: absolute;
    right: 12px;
    bottom: 14px;
    left: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px;
    color: #94a3b8;
    border-top: 1px solid rgba(148, 163, 184, .16);
}

.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    color: #fff;
    background: #334155;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 800;
}

.topbar {
    height: 56px;
    padding: 0 20px;
    background: rgba(255, 255, 255, .86);
    backdrop-filter: blur(12px);
}

[data-theme="dark"] .topbar {
    background: rgba(17, 24, 39, .86);
}

.topbar-left,
.breadcrumb,
.global-search,
.user-menu summary {
    display: flex;
    align-items: center;
}

.topbar-left {
    min-width: 0;
    gap: 10px;
}

.breadcrumb {
    gap: 8px;
    min-width: 0;
    color: var(--text-secondary);
    font-size: 13px;
}

.breadcrumb strong {
    color: var(--text-primary);
    font-size: 14px;
}

.global-search {
    width: 260px;
    height: 34px;
    gap: 8px;
    padding: 0 10px;
    color: var(--text-tertiary);
    background: var(--bg-muted);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.global-search input {
    min-height: 30px;
    padding: 0;
    background: transparent;
    border: 0;
    box-shadow: none;
}

.global-search kbd {
    padding: 1px 6px;
    color: var(--text-tertiary);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 5px;
    font-size: 11px;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
}

.icon-btn:hover,
.icon-btn:focus-visible {
    color: var(--text-primary);
    background: var(--bg-muted);
    border-color: var(--border);
}

.icon-btn:active,
.btn:active {
    transform: translateY(1px);
}

.icon-danger {
    color: var(--danger);
}

.mobile-menu-btn {
    display: none;
}

.user-menu {
    position: relative;
}

.user-menu summary {
    gap: 8px;
    height: 34px;
    padding: 2px 8px 2px 3px;
    color: var(--text-primary);
    border-radius: 999px;
    cursor: pointer;
    list-style: none;
}

.user-menu summary::-webkit-details-marker,
.column-menu summary::-webkit-details-marker,
.filter-more summary::-webkit-details-marker {
    display: none;
}

.user-menu summary:hover {
    background: var(--bg-muted);
}

.user-menu-panel,
.column-menu-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 20;
    display: grid;
    min-width: 180px;
    padding: 6px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 14px 34px rgba(15, 23, 42, .14);
}

.user-menu-panel a,
.user-menu-panel button {
    display: flex;
    width: 100%;
    min-height: 34px;
    align-items: center;
    padding: 7px 9px;
    color: var(--text-primary);
    background: transparent;
    border: 0;
    border-radius: 6px;
    text-align: left;
    cursor: pointer;
}

.user-menu-panel a:hover,
.user-menu-panel button:hover {
    background: var(--bg-muted);
}

.btn {
    border-radius: 6px;
    transition: background .16s ease, border-color .16s ease, color .16s ease, opacity .16s ease;
}

.btn:disabled,
.btn.is-loading,
button:disabled {
    cursor: not-allowed;
    opacity: .55;
}

.btn-ghost {
    color: var(--text-secondary);
    background: transparent;
    border-color: transparent;
}

.btn-ghost:hover {
    background: var(--bg-muted);
    border-color: transparent;
}

.btn-danger-soft {
    color: var(--danger);
    background: rgba(239, 68, 68, .08);
    border-color: rgba(239, 68, 68, .16);
}

.filter-panel {
    overflow: visible;
}

.mail-filter {
    padding: 16px;
}

.filter-primary {
    display: grid;
    grid-template-columns: minmax(220px, 1.5fr) minmax(180px, 1fr) minmax(150px, .8fr) auto;
    gap: 12px;
    align-items: end;
}

.mail-filter label {
    display: grid;
    gap: 6px;
}

.mail-filter label span {
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 700;
}

.filter-command {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.filter-more {
    position: relative;
}

.filter-drawer {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 12;
    display: grid;
    width: min(620px, calc(100vw - 300px));
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    padding: 14px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 14px 34px rgba(15, 23, 42, .14);
}

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

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 26px;
    padding: 3px 8px 3px 10px;
    color: var(--text-secondary);
    background: var(--bg-muted);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 12px;
}

.filter-chip strong {
    color: var(--text-tertiary);
    font-size: 14px;
}

.mail-panel {
    overflow: hidden;
}

.mail-panel-head {
    min-height: 54px;
}

.mail-panel-head > div:first-child {
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.panel-tools {
    display: flex;
    align-items: center;
    gap: 6px;
}

.column-menu {
    position: relative;
}

.column-menu-panel label {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 32px;
    color: var(--text-primary);
    white-space: nowrap;
}

.column-menu-panel input {
    width: 14px;
    min-height: 14px;
}

.batch-bar {
    position: sticky;
    top: 56px;
    z-index: 10;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: color-mix(in srgb, var(--brand) 8%, var(--bg-surface));
    border-bottom: 1px solid var(--border);
}

.mail-table {
    table-layout: fixed;
    min-width: 1080px;
}

.mail-table th,
.mail-table td {
    height: 56px;
    padding: 8px 12px;
}

.mail-table th {
    position: relative;
    height: 40px;
    color: var(--text-secondary);
    background: var(--bg-muted);
}

.mail-row {
    position: relative;
    transition: background .16s ease;
}

.mail-row::before {
    position: absolute;
    top: 10px;
    bottom: 10px;
    left: 0;
    width: 3px;
    content: "";
    background: transparent;
    border-radius: 999px;
}

.mail-row.row-unread::before {
    background: var(--brand);
}

.mail-row:hover,
.mail-row.is-focused {
    background: var(--bg-muted);
}

.mail-row.is-focused {
    outline: 2px solid color-mix(in srgb, var(--brand) 28%, transparent);
    outline-offset: -2px;
}

.col-select {
    width: 44px;
}

.col-select input {
    width: 16px;
    min-height: 16px;
}

.col-star {
    width: 44px;
    text-align: center;
}

.col-sender {
    width: 230px;
}

.col-subject {
    width: auto;
}

.col-mailbox {
    width: 210px;
}

.col-size {
    width: 100px;
}

.col-time {
    width: 170px;
}

.col-actions {
    width: 180px;
}

.sender-cell {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 10px;
}

.sender-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    color: #0f172a;
    background: #e0f2fe;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 800;
}

[data-theme="dark"] .sender-avatar {
    color: #e5e7eb;
    background: #1e3a8a;
}

.sender-cell div,
.subject-cell {
    display: grid;
    min-width: 0;
    gap: 2px;
}

.sender-cell strong,
.sender-cell span,
.subject-cell a,
.subject-cell span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sender-cell strong {
    color: var(--text-primary);
    font-size: 13px;
}

.sender-cell span,
.subject-cell span {
    color: var(--text-tertiary);
    font-size: 12px;
    font-weight: 500;
}

.subject-cell a {
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 700;
}

.mailbox-chip {
    display: inline-flex;
    max-width: 100%;
    min-height: 24px;
    align-items: center;
    padding: 3px 8px;
    overflow: hidden;
    color: var(--text-secondary);
    background: var(--bg-muted);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.row-actions-icons {
    opacity: 0;
    justify-content: flex-end;
    transition: opacity .14s ease;
}

.mail-row:hover .row-actions-icons,
.mail-row.is-focused .row-actions-icons,
.row-actions-icons:focus-within {
    opacity: 1;
}

.star {
    color: var(--text-tertiary);
}

.star.on {
    color: var(--warning);
}

.resize-handle {
    position: absolute;
    top: 8px;
    right: 0;
    bottom: 8px;
    width: 6px;
    cursor: col-resize;
}

.resize-handle::after {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 2px;
    width: 1px;
    content: "";
    background: transparent;
}

.resize-handle:hover::after {
    background: var(--brand);
}

.is-col-hidden {
    display: none;
}

.compact-pagination {
    justify-content: flex-end;
    color: var(--text-secondary);
    font-size: 13px;
}

.compact-pagination .icon-btn {
    font-size: 20px;
}

.empty-state {
    display: grid;
    justify-items: center;
    gap: 8px;
    padding: 48px 24px;
    color: var(--text-secondary);
    text-align: center;
}

.empty-state h3 {
    margin: 0;
    color: var(--text-primary);
    font-size: 16px;
}

.empty-state p {
    max-width: 460px;
    margin: 0;
}

.empty-illustration {
    position: relative;
    width: 88px;
    height: 58px;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: var(--bg-muted);
}

.empty-illustration::before,
.empty-illustration::after {
    position: absolute;
    top: 12px;
    width: 44px;
    height: 2px;
    content: "";
    background: var(--border);
}

.empty-illustration::before {
    left: 8px;
    transform: rotate(28deg);
}

.empty-illustration::after {
    right: 8px;
    transform: rotate(-28deg);
}

.mobile-scrim {
    display: none;
}

@media (max-width: 980px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        z-index: 40;
        height: 100vh;
        transform: translateX(-100%);
        transition: transform .2s ease;
    }

    .sidebar-open .sidebar {
        transform: translateX(0);
    }

    .mobile-scrim {
        position: fixed;
        inset: 0;
        z-index: 35;
        display: none;
        background: rgba(15, 23, 42, .36);
    }

    .sidebar-open .mobile-scrim {
        display: block;
    }

    .mobile-menu-btn {
        display: inline-flex;
    }

    .global-search {
        width: 180px;
    }

    .filter-primary {
        grid-template-columns: 1fr 1fr;
    }

    .filter-command {
        justify-content: flex-start;
    }

    .filter-drawer {
        right: auto;
        left: 0;
        width: min(620px, calc(100vw - 32px));
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 768px) {
    .topbar {
        padding: 10px 14px;
    }

    .breadcrumb {
        display: none;
    }

    .global-search {
        width: min(48vw, 220px);
    }

    .filter-primary,
    .filter-drawer {
        grid-template-columns: 1fr;
    }

    .filter-command {
        flex-wrap: wrap;
    }

    .mail-table,
    .mail-table thead,
    .mail-table tbody,
    .mail-table tr,
    .mail-table td {
        display: block;
        min-width: 0;
        width: 100% !important;
    }

    .mail-table thead {
        display: none;
    }

    .mail-table tbody {
        display: grid;
        gap: 10px;
        padding: 12px;
    }

    .mail-row {
        display: grid !important;
        grid-template-columns: 28px 28px minmax(0, 1fr);
        gap: 8px;
        min-height: 0;
        padding: 12px;
        background: var(--bg-surface);
        border: 1px solid var(--border);
        border-radius: 8px;
    }

    .mail-table td {
        height: auto;
        padding: 0;
        border: 0;
    }

    .mail-row .col-subject,
    .mail-row .col-mailbox,
    .mail-row .col-size,
    .mail-row .col-time,
    .mail-row .col-actions {
        grid-column: 1 / -1;
    }

    .row-actions-icons {
        opacity: 1;
        justify-content: flex-start;
    }

    .batch-bar {
        top: 0;
    }
}
