:root {
    color-scheme: dark;
    --bg-dark: #0f172a;
    --bg-card: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent: #3b82f6;
    --success: #22c55e;
    --success-action: #15803d;
    --warning: #eab308;
    --danger: #ef4444;
    --purple: #8b5cf6;
    --pink: #ec4899;
    --teal: #14b8a6;
    --orange: #f97316;
    --interactive-primary: #2563eb;
    --interactive-secondary: #7c3aed;
    --interactive-primary-hover: #1d4ed8;
    --destructive: #dc2626;
    --destructive-hover: #b91c1c;
    --focus-inner: #0f172a;
    --focus-outer: #f8fafc;
    --border-subtle: rgba(255, 255, 255, 0.1);
    --border-medium: rgba(255, 255, 255, 0.15);
    --border-strong: rgba(255, 255, 255, 0.2);
    --hover-bg: rgba(255, 255, 255, 0.1);
    --surface-elevated: rgba(255, 255, 255, 0.05);
    --surface-overlay: rgba(15, 23, 42, 0.88);
}

[data-theme="light"] {
    color-scheme: light;
    --bg-dark: #f1f5f9;
    --bg-card: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --focus-inner: #0f172a;
    --focus-outer: #ffffff;
    --border-subtle: rgba(0, 0, 0, 0.08);
    --border-medium: rgba(0, 0, 0, 0.12);
    --border-strong: rgba(0, 0, 0, 0.15);
    --hover-bg: rgba(0, 0, 0, 0.05);
    --surface-elevated: rgba(0, 0, 0, 0.03);
    --surface-overlay: rgba(255, 255, 255, 0.92);
}

:where(a[href], button, input, select, textarea, [tabindex]):focus-visible {
    outline: 3px solid var(--focus-inner);
    outline-offset: 3px;
    box-shadow: 0 0 0 6px var(--focus-outer);
}

:where(
    .header-icon,
    .modal-close,
    .view-toggle-btn,
    .nav-btn,
    .icon-button,
    .folder-toggle-btn,
    .action-btn,
    .account-btn,
    .back-btn,
    .rule-delete,
    .attachment-tag
) {
    min-width: 44px;
    min-height: 44px;
}

.action-groups {
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    gap: 8px;
}

.action-groups .action-row {
    min-width: 0;
}

.preview-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 6px 0 4px;
}

.preview-segment {
    display: inline-flex;
    align-items: stretch;
    border: 1px solid var(--border-strong);
    border-radius: 9px;
    overflow: hidden;
}

.preview-segment .view-toggle-btn {
    margin: 0;
    border: 0;
    border-right: 1px solid var(--border-strong);
    border-radius: 0;
}

.preview-segment .view-toggle-btn:last-child {
    border-right: 0;
}

.attachment-list {
    display: grid;
    gap: 8px;
    margin: 8px 0 20px;
    list-style: none;
}

.attachment-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px;
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    background: var(--surface-elevated);
}

.attachment-name {
    min-width: 0;
    overflow-wrap: anywhere;
}

.attachment-size {
    flex: 0 0 auto;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

@media (max-width: 640px) {
    .action-groups {
        grid-template-columns: 1fr;
    }

    .page-container .settings-item {
        align-items: stretch;
        flex-direction: column;
        gap: 10px;
    }

    .page-container .settings-value {
        overflow-wrap: anywhere;
    }

    .settings-item .theme-toggle {
        width: 100%;
        flex-wrap: wrap;
        border-radius: 12px;
    }

    .settings-item .theme-toggle .theme-btn {
        flex: 1 1 auto;
        min-height: 44px;
    }

    .preview-controls {
        align-items: stretch;
        flex-wrap: wrap;
    }

    .preview-segment {
        flex: 1 1 100%;
    }

    .preview-segment .view-toggle-btn {
        flex: 1 1 0;
    }

    .preview-controls > .read-btn {
        margin-left: 0;
    }
}

.sift-icon {
    width: 1.15em;
    height: 1.15em;
    display: inline-block;
    flex: 0 0 auto;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
    vertical-align: -0.2em;
}

.ai-confidence {
    font-variant-numeric: tabular-nums;
    font-size: 0.85em;
    color: var(--text-secondary);
    white-space: nowrap;
}

.pwa-status {
    position: fixed;
    z-index: 2000;
    top: max(8px, env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    max-width: min(92vw, 560px);
    padding: 10px 12px;
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    background: var(--surface-overlay);
    color: var(--text-primary);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    backdrop-filter: blur(12px);
}

.pwa-status[hidden] {
    display: none;
}

.pwa-status button {
    min-height: 36px;
    border: 0;
    border-radius: 8px;
    padding: 8px 12px;
    background: var(--interactive-primary);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
}

.completion-mark {
    width: 56px;
    height: 56px;
    margin: 0 auto 14px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: rgba(34, 197, 94, 0.14);
    color: var(--success);
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
