/*
 * Maildrop 全站设计基础。
 * 统一令牌和交互状态，避免各页面继续复制主题变量并产生视觉漂移。
 */
:root {
    color-scheme: light;
    --bg-start: #eef3f1;
    --bg-end: #e5edea;
    --surface: #edf2f0;
    --surface-strong: #f7faf8;
    --surface-muted: #e2ebe7;
    --surface-flat: #ffffff;
    --primary: #2f746d;
    --primary-strong: #245e58;
    --primary-soft: #d7e6e2;
    --text: #18312f;
    --text-muted: #5d706d;
    --text-faint: #5d706d;
    --success: #276b56;
    --success-soft: #d8ebe3;
    --warning: #8a5a16;
    --warning-soft: #f5e8cf;
    --danger: #a63b3b;
    --danger-soft: #f2dede;
    --info: #244f87;
    --info-soft: #dbe6f4;
    --border: rgba(47, 90, 82, 0.18);
    --border-strong: rgba(47, 90, 82, 0.32);
    --highlight: rgba(255, 255, 255, 0.78);
    --shadow-dark: rgba(42, 75, 69, 0.16);
    --shadow-raised: 12px 12px 24px var(--shadow-dark), -12px -12px 24px var(--highlight);
    --shadow-large: var(--shadow-raised);
    --shadow-soft: 8px 8px 18px rgba(42, 75, 69, 0.14), -8px -8px 18px rgba(255, 255, 255, 0.7);
    --shadow-small: 5px 5px 12px rgba(42, 75, 69, 0.13), -5px -5px 12px rgba(255, 255, 255, 0.65);
    --shadow-inset: inset 4px 4px 10px rgba(42, 75, 69, 0.15), inset -4px -4px 10px rgba(255, 255, 255, 0.72);
    --focus: rgba(47, 116, 109, 0.34);
    --radius-xl: 28px;
    --radius-lg: 20px;
    --radius-md: 16px;
    --radius-sm: 12px;
    --radius-pill: 999px;
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;
    --ease: 180ms cubic-bezier(0.22, 0.61, 0.36, 1);
    --font-sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    --z-nav: 20;
    --z-toast: 40;
    --z-dialog: 50;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg-start: #1e2927;
    --bg-end: #18221f;
    --surface: #202d2a;
    --surface-strong: #293834;
    --surface-muted: #1b2825;
    --surface-flat: #25322f;
    --primary: #83c4bb;
    --primary-strong: #a0d7d0;
    --primary-soft: #29433e;
    --text: #eef6f3;
    --text-muted: #b3c3bf;
    --text-faint: #b3c3bf;
    --success: #88c9ad;
    --success-soft: #28463b;
    --warning: #f1c578;
    --warning-soft: #493b24;
    --danger: #f0a0a5;
    --danger-soft: #4d3034;
    --info: #a8c7ee;
    --info-soft: #293b53;
    --border: rgba(143, 176, 168, 0.2);
    --border-strong: rgba(158, 194, 185, 0.36);
    --highlight: rgba(83, 111, 104, 0.18);
    --shadow-dark: rgba(4, 10, 8, 0.48);
    --shadow-raised: 12px 12px 24px var(--shadow-dark), -10px -10px 24px var(--highlight);
    --shadow-soft: 8px 8px 18px rgba(3, 9, 7, 0.43), -8px -8px 18px rgba(81, 108, 101, 0.16);
    --shadow-small: 5px 5px 12px rgba(3, 9, 7, 0.4), -5px -5px 12px rgba(81, 108, 101, 0.14);
    --shadow-inset: inset 4px 4px 10px rgba(2, 7, 6, 0.44), inset -4px -4px 10px rgba(84, 113, 105, 0.14);
    --focus: rgba(131, 196, 187, 0.42);
}

@media (prefers-color-scheme: dark) {
    :root[data-theme="auto"] {
        color-scheme: dark;
        --bg-start: #1e2927;
        --bg-end: #18221f;
        --surface: #202d2a;
        --surface-strong: #293834;
        --surface-muted: #1b2825;
        --surface-flat: #25322f;
        --primary: #83c4bb;
        --primary-strong: #a0d7d0;
        --primary-soft: #29433e;
        --text: #eef6f3;
        --text-muted: #b3c3bf;
        --text-faint: #b3c3bf;
        --success: #88c9ad;
        --success-soft: #28463b;
        --warning: #f1c578;
        --warning-soft: #493b24;
        --danger: #f0a0a5;
        --danger-soft: #4d3034;
        --info: #a8c7ee;
        --info-soft: #293b53;
        --border: rgba(143, 176, 168, 0.2);
        --border-strong: rgba(158, 194, 185, 0.36);
        --highlight: rgba(83, 111, 104, 0.18);
        --shadow-dark: rgba(4, 10, 8, 0.48);
        --shadow-raised: 12px 12px 24px var(--shadow-dark), -10px -10px 24px var(--highlight);
        --shadow-soft: 8px 8px 18px rgba(3, 9, 7, 0.43), -8px -8px 18px rgba(81, 108, 101, 0.16);
        --shadow-small: 5px 5px 12px rgba(3, 9, 7, 0.4), -5px -5px 12px rgba(81, 108, 101, 0.14);
        --shadow-inset: inset 4px 4px 10px rgba(2, 7, 6, 0.44), inset -4px -4px 10px rgba(84, 113, 105, 0.14);
        --focus: rgba(131, 196, 187, 0.42);
    }
}

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

html {
    min-width: 320px;
    min-height: 100%;
    background: var(--bg-end);
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background: linear-gradient(145deg, var(--bg-start), var(--bg-end));
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.55;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
}

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

button,
[role="button"] {
    touch-action: manipulation;
}

button:not(:disabled),
[role="button"]:not([aria-disabled="true"]) {
    cursor: pointer;
}

button:disabled,
[aria-disabled="true"] {
    cursor: not-allowed;
    opacity: 0.58;
}

a {
    color: var(--primary-strong);
    text-underline-offset: 0.18em;
}

img,
svg {
    max-width: 100%;
}

.icon {
    width: 1.15rem;
    height: 1.15rem;
    flex: 0 0 auto;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

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

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 3px;
}

.soft-card,
.ui-card {
    border: 1px solid rgba(255, 255, 255, 0.42);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-soft);
}

.ui-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--space-5);
}

.button,
.btn,
.primary-button,
.icon-button,
.ui-button {
    min-height: 44px;
    border-radius: var(--radius-md);
    transition: transform var(--ease), box-shadow var(--ease), border-color var(--ease), background-color var(--ease), color var(--ease), opacity var(--ease);
}

@media (hover: hover) and (pointer: fine) {
    .button:not(:disabled):hover,
    .btn:not(:disabled):hover,
    .primary-button:not(:disabled):hover,
    .icon-button:not(:disabled):hover,
    .ui-button:not(:disabled):hover,
    .soft-card.is-interactive:hover,
    .ui-card.is-interactive:hover {
        transform: translateY(-2px);
        box-shadow: var(--shadow-raised);
    }
}

.button:not(:disabled):active,
.btn:not(:disabled):active,
.primary-button:not(:disabled):active,
.icon-button:not(:disabled):active,
.ui-button:not(:disabled):active,
.soft-card.is-interactive:active,
.ui-card.is-interactive:active {
    transform: translateY(1px);
    box-shadow: var(--shadow-inset);
}

.ui-field {
    width: 100%;
    min-height: 44px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text);
    background: var(--surface);
    box-shadow: var(--shadow-inset);
    transition: border-color var(--ease), box-shadow var(--ease), background-color var(--ease);
}

.ui-field[aria-invalid="true"] {
    border-color: var(--danger);
}

.ui-field:focus {
    border-color: var(--primary);
}

.table-shell,
.ui-table-shell {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface-flat);
    box-shadow: var(--shadow-small);
    overscroll-behavior-inline: contain;
}

.ui-table-shell table {
    width: 100%;
    border-collapse: collapse;
}

.ui-table-shell thead {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--surface-strong);
}

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

.ui-table-shell tbody tr:hover {
    background: var(--primary-soft);
}

.toast-region,
.ui-toast-region {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: var(--z-toast);
    display: grid;
    width: min(380px, calc(100vw - 32px));
    gap: 8px;
    pointer-events: none;
}

.toast,
.ui-toast {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    justify-self: end;
    width: fit-content;
    max-width: min(320px, 100%);
    gap: 8px;
    min-height: 40px;
    padding: 6px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    background: var(--surface-strong);
    box-shadow: var(--shadow-small);
    font-size: 0.875rem;
    line-height: 1.35;
    pointer-events: auto;
    animation: ui-toast-in var(--ease) both;
}

.ui-toast-icon {
    width: 18px;
    height: 18px;
}

.ui-toast-message {
    min-width: 0;
    overflow-wrap: anywhere;
}

.ui-toast[data-type="success"],
.toast.success {
    border-color: color-mix(in srgb, var(--success) 55%, transparent);
}

.ui-toast[data-type="error"],
.toast.error {
    border-color: color-mix(in srgb, var(--danger) 62%, transparent);
}

.ui-toast-close {
    display: grid;
    width: 32px;
    min-height: 32px;
    padding: 0;
    place-items: center;
    border: 0;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    background: transparent;
}

dialog.ui-dialog {
    /* 默认收敛为中等尺寸，避免只有少量内容时仍占据大半屏幕。 */
    width: min(560px, calc(100vw - 32px));
    max-height: min(84vh, 720px);
    max-height: min(84dvh, 720px);
    padding: 0;
    overflow: auto;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-xl);
    color: var(--text);
    background: var(--surface);
    box-shadow: var(--shadow-raised);
}

/* 按内容密度分档，而不是让所有功能弹窗共享同一个过大宽度。 */
dialog.ui-dialog.ui-dialog--compact {
    width: min(420px, calc(100vw - 32px));
    max-height: min(76vh, 560px);
    max-height: min(76dvh, 560px);
}

dialog.ui-dialog.ui-dialog--medium {
    width: min(560px, calc(100vw - 32px));
    max-height: min(84vh, 720px);
    max-height: min(84dvh, 720px);
}

dialog.ui-dialog.ui-dialog--wide {
    width: min(760px, calc(100vw - 32px));
    max-height: min(88vh, 800px);
    max-height: min(88dvh, 800px);
}

dialog.ui-dialog::backdrop {
    background: rgba(10, 22, 19, 0.42);
    backdrop-filter: blur(4px);
}

.ui-spinner {
    width: 22px;
    height: 22px;
    border: 3px solid var(--primary-soft);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: ui-spin 0.75s linear infinite;
}

.ui-skeleton {
    min-height: 1em;
    border-radius: var(--radius-sm);
    background: linear-gradient(90deg, var(--surface-muted), var(--surface-strong), var(--surface-muted));
    background-size: 200% 100%;
    animation: ui-skeleton 1.4s ease-in-out infinite;
}

[aria-busy="true"] {
    cursor: progress;
}

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

@keyframes ui-skeleton {
    to { background-position: -200% 0; }
}

@keyframes ui-toast-in {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 768px) {
    .ui-card-grid {
        grid-template-columns: 1fr;
        gap: var(--space-4);
    }

    .toast-region,
    .ui-toast-region {
        top: auto;
        right: 16px;
        bottom: max(16px, env(safe-area-inset-bottom));
        left: 16px;
        width: auto;
    }
}

@media (max-width: 480px) {
    :root {
        --radius-xl: 22px;
        --radius-lg: 18px;
    }

    body {
        font-size: 15px;
    }
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
