* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #f5f7fa;
    --panel: #ffffff;
    --text: #333333;
    --muted: #666666;
    --subtle: #999999;
    --line: #e8eaf0;
    --soft-line: #f0f0f0;
    --primary: #667eea;
    --primary-dark: #764ba2;
    --danger: #ff4d4f;
    --danger-soft: #fff2f0;
    --success: #11998e;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(18, 27, 56, 0.05);
}

body {
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    font-size: 13px;
}

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

button {
    cursor: pointer;
}

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

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 320px;
    flex: 0 0 320px;
    padding: 24px;
    overflow-y: auto;
    background: var(--panel);
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.05);
}

.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    padding-bottom: 24px;
    margin-bottom: 32px;
    border-bottom: 1px solid var(--soft-line);
}

.brand-icon {
    display: grid;
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    place-items: center;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    font-size: 20px;
}

.brand h1 {
    margin-bottom: 2px;
    color: var(--text);
    font-size: 20px;
    line-height: 1.25;
}

.brand p {
    color: var(--subtle);
    font-size: 12px;
    line-height: 1.45;
}

.quick-links {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 10px;
    margin: -16px 0 24px;
    border: 1px solid #edf0f7;
    border-radius: 8px;
    background: #f8faff;
}

.quick-links a,
.quick-links span {
    display: inline-flex;
    min-height: 34px;
    align-items: center;
    justify-content: center;
    padding: 8px 10px;
    border-radius: 7px;
    background: #ffffff;
    color: #2f54eb;
    font-size: 13px;
    font-weight: 700;
    box-shadow: 0 1px 4px rgba(31, 45, 84, 0.06);
}

.quick-links a {
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.quick-links a:hover {
    background: #2f54eb;
    color: #ffffff;
    transform: translateY(-1px);
}

.quick-links a:first-child {
    grid-column: 1 / -1;
}

.quick-links a:last-child {
    grid-column: 1 / -1;
}

.quick-links span {
    grid-column: 1 / -1;
    color: #595f75;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.side-section {
    margin-bottom: 28px;
}

.side-section h2 {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 16px;
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
}

.field {
    display: block;
    margin-bottom: 16px;
}

.field span {
    display: block;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 13px;
}

.field input,
.field select,
.field textarea,
.search-row input,
.search-row select,
.pagination select,
.pagination input {
    width: 100%;
    min-height: 38px;
    padding: 10px 12px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    background: #ffffff;
    color: var(--text);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.search-row input:focus,
.search-row select:focus,
.pagination select:focus,
.pagination input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.11);
}

.field small {
    display: block;
    margin-top: 4px;
    color: var(--subtle);
    font-size: 11px;
    line-height: 1.45;
}

.upload-area {
    display: flex;
    width: 100%;
    min-height: 142px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 28px 20px;
    margin-bottom: 12px;
    border: 2px dashed #e0e0e0;
    border-radius: var(--radius);
    background: #fafafa;
    color: var(--muted);
    text-align: center;
    transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.upload-area:hover,
.upload-area.dragging {
    border-color: var(--primary);
    background: #f5f7ff;
}

.upload-area.dragging {
    transform: translateY(-1px);
}

.upload-icon {
    margin-bottom: 8px;
    font-size: 32px;
}

.upload-area strong {
    font-weight: 500;
}

.upload-area small {
    margin-top: 6px;
    color: var(--subtle);
    font-size: 11px;
}

.btn {
    display: inline-flex;
    min-height: 38px;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 10px 14px;
    border: 0;
    border-radius: 8px;
    color: var(--text);
    line-height: 1.3;
    transition: transform 0.2s ease, opacity 0.2s ease, background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #ffffff;
}

.btn-primary:hover {
    opacity: 0.92;
}

.btn-secondary {
    background: #f0f0f0;
    color: var(--text);
}

.btn-secondary:hover {
    background: #e3e4ea;
}

.btn-danger {
    border: 1px solid #ffccc7;
    background: var(--danger-soft);
    color: var(--danger);
}

.btn-danger:hover {
    background: var(--danger);
    color: #ffffff;
}

.imap-options {
    display: none;
}

.imap-options.active {
    display: block;
}

.log-panel {
    max-height: 150px;
    padding: 12px;
    margin-top: 16px;
    overflow-y: auto;
    border-radius: 8px;
    background: #1e1e1e;
    color: #d4d4d4;
    font-family: Consolas, "Courier New", monospace;
    font-size: 11px;
    line-height: 1.6;
}

.log-panel span {
    color: #858585;
}

.main {
    flex: 1;
    min-width: 0;
    padding: 24px;
    overflow-y: auto;
}

.announcement {
    display: flex;
    gap: 12px;
    align-items: center;
    min-height: 72px;
    padding: 18px 24px;
    margin-bottom: 24px;
    overflow: hidden;
    border-radius: 12px;
    background: linear-gradient(135deg, #ff3d71 0%, #ffb000 100%);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.26);
}

.announcement.hidden {
    display: none;
}

.announcement-icon {
    flex: 0 0 auto;
    font-size: 28px;
}

.announcement-marquee {
    position: relative;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.announcement-marquee::before,
.announcement-marquee::after {
    position: absolute;
    top: 0;
    z-index: 1;
    width: 36px;
    height: 100%;
    pointer-events: none;
    content: "";
}

.announcement-marquee::before {
    left: 0;
    background: linear-gradient(90deg, rgba(255, 61, 113, 0.95), rgba(255, 61, 113, 0));
}

.announcement-marquee::after {
    right: 0;
    background: linear-gradient(270deg, rgba(255, 176, 0, 0.95), rgba(255, 176, 0, 0));
}

.announcement-text {
    display: inline-block;
    min-width: max-content;
    padding-left: 100%;
    color: #fffbe6;
    font-size: 20px;
    font-weight: 800;
    line-height: 1.35;
    white-space: nowrap;
    animation: announcement-scroll 16s linear infinite;
    will-change: transform;
}

.announcement:hover .announcement-text,
.announcement:focus-within .announcement-text {
    animation-play-state: paused;
}

@keyframes announcement-scroll {
    from {
        transform: translateX(0);
    }

    to {
        transform: translateX(-100%);
    }
}

.announcement-close {
    display: grid;
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    font-size: 18px;
    transition: background 0.2s ease;
}

.announcement-close:hover {
    background: rgba(255, 255, 255, 0.32);
}

@media (prefers-reduced-motion: reduce) {
    .announcement-text {
        padding-left: 0;
        animation: none;
        white-space: normal;
    }

    .announcement-marquee::before,
    .announcement-marquee::after {
        display: none;
    }
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    position: relative;
    min-height: 142px;
    padding: 24px;
    overflow: hidden;
    border-radius: 8px;
    color: #ffffff;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.stat-card:hover {
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.12);
    transform: translateY(-4px);
}

.stat-card::before {
    position: absolute;
    top: -30px;
    right: -30px;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: #ffffff;
    content: "";
    opacity: 0.1;
}

.stat-card-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.stat-card-success {
    background: linear-gradient(135deg, var(--success) 0%, #38ef7d 100%);
}

.stat-card-accent {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.stat-icon {
    margin-bottom: 8px;
    font-size: 32px;
    opacity: 0.9;
}

.stat-card span {
    display: block;
    margin-bottom: 4px;
    color: rgba(255, 255, 255, 0.86);
    font-weight: 500;
}

.stat-card strong {
    display: block;
    color: #ffffff;
    font-size: 32px;
    font-weight: 700;
    line-height: 1;
}

.toolbar {
    display: flex;
    gap: 16px;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    margin-bottom: 20px;
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
}

.search-row {
    display: flex;
    flex: 1;
    gap: 10px;
    max-width: 520px;
}

.search-row input {
    flex: 1;
    min-width: 200px;
}

.search-row select {
    width: 150px;
}

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

.actions .btn {
    width: auto;
    white-space: nowrap;
}

.select-all-data {
    display: inline-flex;
    min-height: 38px;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    background: #ffffff;
    color: var(--muted);
    white-space: nowrap;
}

.select-all-data input,
.checkbox-cell input {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.table-card {
    overflow: hidden;
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
}

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

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

thead {
    background: #fafafa;
}

th,
td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--soft-line);
    text-align: left;
    white-space: nowrap;
}

th {
    color: var(--text);
    font-weight: 600;
}

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

tbody tr:hover {
    background: #f8f9ff;
}

tbody tr:last-child td {
    border-bottom: 0;
}

.checkbox-cell {
    width: 42px;
    text-align: center;
}

.email-cell {
    max-width: 210px;
    overflow: hidden;
    color: var(--primary);
    font-weight: 500;
    text-overflow: ellipsis;
}

.secret-cell {
    max-width: 160px;
    overflow: hidden;
    font-family: Consolas, "Courier New", monospace;
    font-size: 11px;
    text-overflow: ellipsis;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 54px;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.status-valid {
    background: #d4edda;
    color: #155724;
}

.status-expired {
    background: #f8d7da;
    color: #721c24;
}

.status-unknown {
    background: #fff3cd;
    color: #856404;
}

.row-actions {
    display: flex;
    gap: 8px;
}

.mini-btn {
    min-height: 30px;
    padding: 6px 12px;
    border: 0;
    border-radius: 6px;
    font-size: 12px;
    transition: background 0.2s ease, color 0.2s ease;
}

.mini-btn-refresh {
    background: #f0f5ff;
    color: #2f54eb;
}

.mini-btn-refresh:hover {
    background: #2f54eb;
    color: #ffffff;
}

.mini-btn-view {
    background: #e6f7ff;
    color: #1890ff;
}

.mini-btn-view:hover {
    background: #1890ff;
    color: #ffffff;
}

.mini-btn-delete {
    background: var(--danger-soft);
    color: var(--danger);
}

.mini-btn-delete:hover {
    background: var(--danger);
    color: #ffffff;
}

.empty-state {
    padding: 60px 20px;
    color: var(--subtle);
    text-align: center;
}

.empty-state-icon {
    margin-bottom: 12px;
    font-size: 48px;
}

.pagination {
    display: none;
    gap: 12px;
    align-items: center;
    justify-content: flex-end;
    padding: 16px;
    border-top: 1px solid var(--soft-line);
    color: var(--muted);
}

.pagination.active {
    display: flex;
}

.pagination strong {
    color: var(--text);
}

.pagination select {
    width: 70px;
    min-height: 32px;
    padding: 6px 10px;
}

.pagination input {
    width: 54px;
    min-height: 32px;
    padding: 6px;
    text-align: center;
}

.page-numbers {
    display: flex;
    gap: 6px;
}

.page-btn {
    min-width: 34px;
    min-height: 32px;
    padding: 6px 10px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    background: #ffffff;
    color: var(--text);
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.page-btn:hover:not(:disabled),
.page-btn.active {
    border-color: var(--primary);
    background: var(--primary);
    color: #ffffff;
}

.page-btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.modal-overlay,
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.5);
}

.modal-overlay.active,
.loading-overlay.active {
    display: flex;
}

.modal {
    display: flex;
    width: min(1000px, 90vw);
    max-height: 86vh;
    flex-direction: column;
    overflow: hidden;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.22);
}

.modal-sm {
    width: min(620px, 92vw);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--soft-line);
}

.modal-header h2 {
    color: var(--text);
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    display: grid;
    width: 32px;
    height: 32px;
    place-items: center;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--subtle);
    font-size: 24px;
    line-height: 1;
    transition: background 0.2s ease, color 0.2s ease;
}

.modal-close:hover {
    background: #f5f5f5;
    color: var(--text);
}

.modal-body {
    flex: 1;
    overflow-y: auto;
}

.modal-body.padded {
    padding: 20px 24px;
}

.paste-textarea {
    min-height: 200px;
    resize: vertical;
    font-family: Consolas, "Courier New", monospace;
}

.tabs {
    display: flex;
    padding: 0 24px;
    border-bottom: 1px solid var(--soft-line);
    background: #fafafa;
}

.tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 14px 24px;
    border: 0;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--muted);
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.tab:hover,
.tab.active {
    color: var(--primary);
}

.tab.active {
    border-bottom-color: var(--primary);
    background: #ffffff;
}

.tab-badge {
    display: inline-flex;
    min-width: 20px;
    justify-content: center;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--primary);
    color: #ffffff;
    font-size: 11px;
}

.tab-content {
    display: none;
    padding: 20px 24px;
}

.tab-content.active {
    display: block;
}

.email-list {
    display: grid;
    gap: 12px;
}

.email-item {
    width: 100%;
    padding: 16px;
    border: 1px solid var(--soft-line);
    border-radius: var(--radius);
    background: #ffffff;
    color: inherit;
    cursor: pointer;
    text-align: left;
    transition: border-color 0.2s ease, background 0.2s ease;
}

.email-item:hover {
    border-color: var(--primary);
    background: #f8f9ff;
}

.email-item header {
    display: flex;
    gap: 12px;
    justify-content: space-between;
    margin-bottom: 8px;
}

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

.email-item time {
    flex: 0 0 auto;
    color: var(--subtle);
    font-size: 12px;
}

.email-from {
    margin-bottom: 8px;
    color: var(--primary);
    font-size: 12px;
}

.email-preview {
    display: -webkit-box;
    overflow: hidden;
    color: var(--muted);
    line-height: 1.5;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.detail-grid {
    display: grid;
    gap: 12px;
}

.detail-meta {
    margin-bottom: 16px;
}

.detail-row {
    display: grid;
    grid-template-columns: 86px minmax(0, 1fr);
    gap: 12px;
    line-height: 1.6;
}

.detail-row span {
    color: var(--subtle);
}

.detail-row strong,
.detail-row p {
    min-width: 0;
    color: var(--text);
    word-break: break-word;
}

.mail-frame {
    width: 100%;
    min-height: 420px;
    border: 1px solid var(--soft-line);
    border-radius: 8px;
    background: #ffffff;
}

.loading-overlay {
    z-index: 2000;
}

.loading-box {
    min-width: 260px;
    padding: 32px 48px;
    border-radius: 12px;
    background: #ffffff;
    color: var(--text);
    text-align: center;
}

.spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto 16px;
    border: 3px solid #f0f0f0;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.progress-wrap {
    display: none;
    margin-top: 16px;
}

.progress-wrap.active {
    display: block;
}

.progress-bar {
    height: 8px;
    overflow: hidden;
    border-radius: 4px;
    background: #e0e0e0;
}

.progress-bar div {
    width: 0%;
    height: 100%;
    border-radius: 4px;
    background: linear-gradient(90deg, var(--primary), var(--primary-dark));
    transition: width 0.25s ease;
}

.progress-wrap span {
    display: block;
    margin-top: 8px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 500;
}

.toast-stack {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 3000;
    display: grid;
    gap: 10px;
    width: min(340px, calc(100vw - 40px));
}

.toast {
    padding: 12px 14px;
    border: 1px solid #d7e2ff;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 8px 24px rgba(17, 24, 39, 0.13);
    color: var(--text);
    line-height: 1.5;
}

@media (max-width: 1100px) {
    .toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .search-row {
        max-width: none;
    }

    .actions {
        flex-wrap: wrap;
    }
}

@media (max-width: 768px) {
    .app-shell {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        flex-basis: auto;
        padding: 16px;
    }

    .brand {
        margin-bottom: 20px;
        padding-bottom: 16px;
    }

    .brand h1 {
        font-size: 18px;
    }

    .main {
        padding: 16px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .stat-card {
        min-height: 126px;
        padding: 20px;
    }

    .toolbar {
        padding: 16px;
    }

    .search-row,
    .actions {
        width: 100%;
    }

    .search-row {
        flex-wrap: wrap;
    }

    .search-row input,
    .search-row select,
    .actions .btn,
    .select-all-data {
        flex: 1 1 180px;
    }

    table {
        font-size: 12px;
    }

    th,
    td {
        padding: 10px 8px;
    }

    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
    }

    .modal {
        width: 95vw;
        max-height: 90vh;
    }

    .modal-header {
        padding: 16px;
    }

    .modal-header h2 {
        font-size: 16px;
    }

    .tabs {
        padding: 0 16px;
    }

    .tab {
        flex: 1;
        justify-content: center;
        padding: 12px 10px;
    }

    .tab-content,
    .modal-body.padded {
        padding: 16px;
    }
}

@media (max-width: 480px) {
    .sidebar,
    .main {
        padding: 12px;
    }

    .brand-icon {
        width: 36px;
        height: 36px;
        flex-basis: 36px;
        font-size: 18px;
    }

    .brand h1 {
        font-size: 16px;
    }

    .brand p,
    .field span,
    .field input,
    .field select,
    .btn {
        font-size: 12px;
    }

    .announcement {
        padding: 14px;
    }

    .announcement-text {
        font-size: 16px;
    }

    .stat-card strong {
        font-size: 28px;
    }

    .email-item header {
        flex-direction: column;
        gap: 4px;
    }

    .detail-row {
        grid-template-columns: 1fr;
        gap: 2px;
    }

    .toast-stack {
        right: 12px;
        bottom: 12px;
        width: calc(100vw - 24px);
    }
}
