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

:root {
    --blue: #0078D4;
    --blue-dark: #005A9E;
    --blue-light: #EFF6FC;
    --bg: #F3F2F1;
    --surface: #FFFFFF;
    --border: #E1DFDD;
    --text: #201F1E;
    --muted: #605E5C;
    --error: #D13438;
    --success: #107C10;
    --warning: #F59E0B;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.10);
}

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

header {
    background: var(--blue);
    color: #fff;
    padding: 0 20px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

header h1 {
    font-size: 1.15rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-right {
    display: flex;
    gap: 8px;
    align-items: center;
}

.header-account-info {
    font-size: 0.8rem;
    opacity: 0.85;
}

.auto-status-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: 1.5px solid rgba(255, 255, 255, 0.4);
}

.auto-status-pill.active {
    background: rgba(16, 124, 16, 0.7);
    border-color: #4ade80;
}

.pulse {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    animation: pulse 1.5s infinite;
}

.pulse.off {
    background: #9BA1A6;
    animation: none;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1)
    }

    50% {
        opacity: 0.5;
        transform: scale(1.3)
    }
}

.tabs {
    display: flex;
    background: var(--surface);
    border-bottom: 2px solid var(--border);
}

.tab-btn {
    flex: 1;
    padding: 11px 8px;
    font-size: 0.82rem;
    font-weight: 600;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--muted);
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: color 0.15s, border-color 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.tab-btn.active {
    color: var(--blue);
    border-bottom-color: var(--blue);
}

.tab-btn:hover:not(.active) {
    color: var(--text);
    background: var(--bg);
}

.main-layout {
    display: flex;
    flex: 1;
    height: calc(100vh - 56px);
    overflow: hidden;
}

#sidebar {
    width: 270px;
    min-width: 270px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.section-header {
    padding: 12px 16px 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

.section-header h3 {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--muted);
    letter-spacing: 0.06em;
}

.badge {
    font-size: 0.68rem;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 10px;
}

.badge-blue {
    background: var(--blue);
    color: #fff;
}

.badge-green {
    background: var(--success);
    color: #fff;
}

.badge-orange {
    background: var(--warning);
    color: #fff;
}

.add-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 16px;
    background: var(--blue-light);
    color: var(--blue);
    border: none;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    font-size: 0.84rem;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.15s;
}

.add-btn:hover {
    background: #dbeeff;
}

#account-list {
    list-style: none;
    padding: 6px 0;
}

.account-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    border-bottom: 1px solid var(--border);
}

.account-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--blue);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.82rem;
    font-weight: 700;
    flex-shrink: 0;
}

.account-info {
    flex: 1;
    min-width: 0;
}

.account-name {
    font-size: 0.81rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.account-email {
    font-size: 0.71rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--muted);
    padding: 5px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    transition: color 0.15s, background 0.15s;
    flex-shrink: 0;
}

.btn-icon:hover {
    color: var(--error);
    background: #fde7e9;
}

.no-accounts-hint {
    padding: 12px 16px;
    background: #fff8e1;
    border-bottom: 1px solid #ffe082;
    font-size: 0.78rem;
    color: #7a5c00;
    line-height: 1.4;
}

#content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.tab-panel {
    display: none;
    flex: 1;
    flex-direction: column;
    overflow: hidden;
}

.tab-panel.active {
    display: flex;
}

.content-header {
    padding: 12px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.content-header h2 {
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

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

#search-input {
    padding: 6px 14px;
    border: 1.5px solid var(--border);
    border-radius: 20px;
    font-size: 0.82rem;
    outline: none;
    width: 220px;
    transition: border-color 0.15s;
}

#search-input:focus {
    border-color: var(--blue);
}

.email-list {
    list-style: none;
}

.email-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.12s;
    background: var(--surface);
}

.email-item:hover {
    background: var(--blue-light);
}

.email-item.unread {
    background: #fff;
    border-left: 3px solid var(--blue);
}

.email-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.88rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.email-main {
    flex: 1;
    min-width: 0;
}

.email-row1 {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 2px;
}

.email-from {
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}

.email-date {
    font-size: 0.72rem;
    color: var(--muted);
    flex-shrink: 0;
}

.email-subject {
    font-size: 0.83rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.email-subject.bold {
    font-weight: 700;
}

.email-to-row {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
}

.email-to {
    font-size: 0.72rem;
    color: var(--muted);
}

.account-tag {
    font-size: 0.67rem;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 10px;
    background: var(--blue-light);
    color: var(--blue);
    flex-shrink: 0;
}

.badge-unread {
    background: var(--blue);
    color: #fff;
    font-size: 0.67rem;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 10px;
}

.panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

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

.panel-section h3 {
    font-size: 0.9rem;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text);
}

.panel-section p {
    font-size: 0.82rem;
    color: var(--muted);
    margin-bottom: 14px;
    line-height: 1.5;
}

.tag-input-row {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.tag-input-row input {
    flex: 1;
    padding: 8px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.83rem;
    outline: none;
    transition: border-color 0.15s;
}

.tag-input-row input:focus {
    border-color: var(--blue);
}

.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
    min-height: 32px;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: default;
}

.tag-blue {
    background: var(--blue-light);
    color: var(--blue);
    border: 1px solid #b3d6f0;
}

.tag-green {
    background: #dff6dd;
    color: var(--success);
    border: 1px solid #9fd89f;
}

.tag-remove {
    background: none;
    border: none;
    cursor: pointer;
    color: inherit;
    opacity: 0.6;
    padding: 0;
    font-size: 0.9rem;
    line-height: 1;
}

.tag-remove:hover {
    opacity: 1;
}

/* Auto-forward toggle */
.auto-toggle-card {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 20px;
}

.auto-toggle-card.active {
    border-color: var(--success);
    background: #f0fdf4;
}

.auto-toggle-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.auto-toggle-title {
    font-size: 0.95rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.toggle-switch {
    position: relative;
    width: 52px;
    height: 28px;
    cursor: pointer;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: #C8C6C4;
    border-radius: 28px;
    transition: background 0.2s;
}

.toggle-slider:before {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    left: 3px;
    top: 3px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked+.toggle-slider {
    background: var(--success);
}

.toggle-switch input:checked+.toggle-slider:before {
    transform: translateX(24px);
}

.auto-info {
    font-size: 0.78rem;
    color: var(--muted);
    line-height: 1.5;
}

.auto-info.active-info {
    color: var(--success);
    font-weight: 600;
}

.last-check {
    font-size: 0.72rem;
    color: var(--muted);
    margin-top: 6px;
}

.rule-card {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 14px;
}

.rule-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.rule-card-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text);
}

.rule-field {
    margin-bottom: 12px;
}

.rule-field label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
    display: block;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background 0.15s, opacity 0.15s;
}

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

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

.btn-primary:hover:not(:disabled) {
    background: var(--blue-dark);
}

.btn-danger {
    background: #fde7e9;
    color: var(--error);
    border: 1px solid #f4b8bb;
}

.btn-danger:hover:not(:disabled) {
    background: #fbd0d2;
}

.btn-success {
    background: #dff6dd;
    color: var(--success);
    border: 1px solid #9fd89f;
}

.btn-success:hover:not(:disabled) {
    background: #c8f0c6;
}

.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 1.5px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--border);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.78rem;
}

.alert {
    padding: 9px 12px;
    border-radius: var(--radius);
    font-size: 0.8rem;
    font-weight: 500;
    margin-top: 8px;
}

.alert-error {
    background: #fde7e9;
    color: var(--error);
    border: 1px solid #f4b8bb;
}

.alert-success {
    background: #dff6dd;
    color: var(--success);
    border: 1px solid #9fd89f;
}

.alert-info {
    background: var(--blue-light);
    color: var(--blue);
    border: 1px solid #b3d6f0;
}

.alert-warning {
    background: #fff8e1;
    color: #7a5c00;
    border: 1px solid #ffe082;
}

#detail-panel {
    position: fixed;
    right: 0;
    top: 56px;
    bottom: 0;
    width: 540px;
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    z-index: 50;
    transform: translateX(100%);
    transition: transform 0.25s ease;
}

#detail-panel.open {
    transform: translateX(0);
}

.detail-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.detail-subject {
    font-size: 1rem;
    font-weight: 700;
    flex: 1;
    line-height: 1.3;
}

.detail-meta {
    padding: 12px 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--bg);
}

.detail-meta-row {
    display: flex;
    gap: 8px;
    font-size: 0.82rem;
    align-items: flex-start;
}

.detail-meta-label {
    font-weight: 700;
    color: var(--muted);
    min-width: 75px;
    flex-shrink: 0;
}

.detail-meta-value {
    color: var(--text);
    flex: 1;
    word-break: break-word;
}

.detail-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    font-size: 0.875rem;
    line-height: 1.6;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 70px 24px;
    gap: 14px;
    text-align: center;
}

.empty-state svg {
    color: #C8C6C4;
}

.empty-state h3 {
    font-size: 1rem;
    color: var(--muted);
}

.empty-state p {
    font-size: 0.875rem;
    color: var(--muted);
    max-width: 320px;
    line-height: 1.5;
}

.spinner {
    width: 26px;
    height: 26px;
    border: 3px solid var(--border);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 70px;
    gap: 14px;
}

.loading-state p {
    color: var(--muted);
    font-size: 0.875rem;
}

#toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: #323130;
    color: #fff;
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    z-index: 300;
    transition: transform 0.3s ease;
    max-width: 420px;
    text-align: center;
    box-shadow: var(--shadow);
}

#toast.show {
    transform: translateX(-50%) translateY(0);
}

.divider {
    height: 1px;
    background: var(--border);
    margin: 18px 0;
}

.filter-active-banner {
    padding: 8px 20px;
    background: #fff8e1;
    border-bottom: 1px solid #ffe082;
    font-size: 0.78rem;
    color: #7a5c00;
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-active-banner button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--blue);
    font-size: 0.78rem;
    font-weight: 600;
    padding: 0;
    text-decoration: underline;
}

@media (max-width: 700px) {
    #sidebar {
        width: 220px;
        min-width: 220px;
    }

    #detail-panel {
        width: 100%;
    }
}