/* ===== 公共基础样式 (common.css) ===== */

:root {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
    color-scheme: light dark;

    /* ── Base ── */
    --color-bg: #f5f7fb;
    --color-cmd: #1a1a1a;
    --color-surface: #ffffff;
    --color-surface-hover: #f3f4f6;
    --color-surface-subtle: #f8fafc;
    --color-surface-muted: #f9fafb;
    --color-surface-raised: #fafafa;

    /* ── Text ── */
    --color-text: #1f2937;
    --color-text-cmd: #ffffff;
    --color-text-dark: #111827;
    --color-text-secondary: #374151;
    --color-text-tertiary: #4b5563;
    --color-text-muted: #6b7280;
    --color-text-placeholder: #9ca3af;
    --color-text-disabled: #d1d5db;

    /* ── Borders ── */
    --color-border: #e5e7eb;
    --color-border-light: #f3f4f6;
    --color-border-lighter: #f1f5f9;
    --color-border-medium: #d1d5db;
    --color-border-input: #e2e8f0;
    --color-border-cmd: #3d3d3d;

    /* ── Primary (Blue) ── */
    --color-primary: #2563eb;
    --color-primary-text: #1d4ed8;
    --color-primary-dark: #1e3a8a;
    --color-primary-light: #60a5fa;
    --color-primary-bg: #eff6ff;

    /* ── Success (Green) ── */
    --color-success: #22c55e;
    --color-success-text: #059669;
    --color-success-bg: #ecfdf5;

    /* ── Danger (Red) ── */
    --color-danger: #dc2626;
    --color-danger-text: #b91c1c;
    --color-danger-bg: #fef2f2;
    --color-danger-dark: #991b1b;
    --color-danger-light: #ef4444;

    /* ── Warning (Amber) ── */
    --color-warning: #f59e0b;
    --color-warning-text: #b45309;
    --color-warning-bg: #fef3c7;

    /* ── Shadows ── */
    --shadow-sm: 0 2px 12px rgba(15, 23, 42, .08);
    --shadow-toast: 0 6px 24px rgba(2, 6, 23, .28);

    /* ── Login ── */
    --login-bg: linear-gradient(135deg, #f0f4ff 0%, #e8ecf4 100%);
    --login-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);

    /* ── Toast ── */
    --toast-bg: #111827;
    --toast-success-bg: #252525;
    --toast-border: rgba(255, 255, 255, .08);

    /* ── Select Arrow ── */
    --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
    :root {
        /* Base */
        --color-bg: #0f1117;
        --color-surface: #1a1d24;
        --color-surface-hover: #252830;
        --color-surface-subtle: #1e2028;
        --color-surface-muted: #1e2028;
        --color-surface-raised: #1e2028;

        /* Text */
        --color-text: #e5e7eb;
        --color-text-dark: #f9fafb;
        --color-text-secondary: #d1d5db;
        --color-text-tertiary: #9ca3af;
        --color-text-muted: #9ca3af;
        --color-text-placeholder: #6b7280;
        --color-text-disabled: #4b5563;

        /* Borders */
        --color-border: #2d3140;
        --color-border-light: #252830;
        --color-border-lighter: #252830;
        --color-border-medium: #3d4250;
        --color-border-input: #3d4250;

        /* Primary */
        --color-primary: #3b82f6;
        --color-primary-text: #60a5fa;
        --color-primary-dark: #1e40af;
        --color-primary-light: #3b82f6;
        --color-primary-bg: rgba(37, 99, 235, .12);

        /* Success */
        --color-success: #22c55e;
        --color-success-text: #34d399;
        --color-success-bg: rgba(34, 197, 94, .1);

        /* Danger */
        --color-danger: #f87171;
        --color-danger-text: #fca5a5;
        --color-danger-bg: rgba(220, 38, 38, .12);
        --color-danger-dark: #b91c1c;
        --color-danger-light: #f87171;

        /* Warning */
        --color-warning: #fbbf24;
        --color-warning-text: #fcd34d;
        --color-warning-bg: rgba(245, 158, 11, .12);

        /* Shadows */
        --shadow-sm: 0 2px 12px rgba(0, 0, 0, .35);
        --shadow-toast: 0 6px 24px rgba(0, 0, 0, .5);

        /* Login */
        --login-bg: linear-gradient(135deg, #0f1117 0%, #161922 100%);
        --login-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);

        /* Toast */
        --toast-bg: #e5e7eb;
        --toast-success-bg: #374151;
        --toast-border: rgba(0, 0, 0, .15);

        /* Select Arrow */
        --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    }
}

/* ===== CSS Reset ===== */
* {
    margin: 0;
    padding: 0;
    outline: none;
    list-style: none;
    text-decoration: none;
    box-sizing: border-box;
    border: none;
    transition: all 0.3s ease-in-out;
}

a {
    color: inherit;
    text-decoration: none;
}

img {
    -webkit-user-drag: none;
}

input,
button,
select,
textarea {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    background: transparent;
    border: none;
    outline: none;
}

input:hover,
select:hover,
textarea:hover {
    border-color: var(--color-primary);
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--color-primary);
}

input::placeholder,
textarea::placeholder {
    transition: all 0.3s ease-in-out;
}

input:focus::placeholder,
textarea:focus::placeholder {
    color: transparent;
}

/* ===== Toast 通知 ===== */
.toast-wrap {
    position: fixed;
    top: 2rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 99999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.toast {
    white-space: nowrap;
    pointer-events: auto;
    background: var(--toast-bg);
    color: #fff;
    border-radius: 100px;
    padding: 8px 14px;
    box-shadow: var(--shadow-toast);
    border: 1px solid var(--toast-border);
    opacity: 0;
    gap: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translateY(-14px);
    animation: toastIn .22s ease forwards;
    font-size: 13px;
}

.toast.success {
    background: var(--toast-success-bg);
}

.toast.error {
    background: var(--color-danger-dark);
}

.toast-title {
    font-weight: 700;
}

.toast.hide {
    animation: toastOut .18s ease forwards;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(-14px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }

    to {
        opacity: 0;
        transform: translateY(-8px);
    }
}

/* ===== Btn loader spinner ===== */
.btn-loader {
    display: inline-flex;
    width: 1em;
    height: 1em;
    vertical-align: -0.125em;
    flex-shrink: 0;
}

.btn-loader__svg {
    width: 100%;
    height: 100%;
    display: block;
    animation: spinRotate 1.5s linear infinite;
}

.btn-loader__track {
    stroke: transparent;
}

.btn-loader__ring {
    stroke: currentColor;
    stroke-linecap: round;
    stroke-dasharray: 1, 200;
    stroke-dashoffset: 0;
    animation: spinDash 1.5s ease-in-out infinite;
}

@keyframes spinRotate {
    100% {
        transform: rotate(360deg);
    }
}

@keyframes spinDash {
    0% {
        stroke-dasharray: 1, 200;
        stroke-dashoffset: 0;
    }

    50% {
        stroke-dasharray: 90, 200;
        stroke-dashoffset: -35;
    }

    100% {
        stroke-dasharray: 1, 200;
        stroke-dashoffset: -125;
    }
}

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

.spinner {
    width: 28px;
    height: 28px;
    border: 4px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin .6s linear infinite;
    display: inline-block;
}

/* ===== Dark mode toast text fix ===== */
@media (prefers-color-scheme: dark) {
    .toast {
        color: #111827;
    }

    .toast.error {
        color: #fff;
    }

    button {
        color: #fff;
    }

    input,
    select,
    textarea {
        background: var(--color-surface);
    }
}

/* ===== Body Base ===== */
body {
    margin: 0;
    background: var(--color-bg);
    color: var(--color-text);
}

/* ===== Form Elements ===== */
input,
button,
select,
textarea {
    padding: 9px 10px;
    border: 1px solid var(--color-border-medium);
    border-radius: 8px;
    font-size: 14px;
}

select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: var(--select-arrow);
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    padding-right: 28px;
}

textarea {
    min-height: 84px;
}

/* ===== Buttons ===== */
button {
    white-space: nowrap;
    padding: 6px 12px;
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 15px;
}

button:hover {
    opacity: .9;
}

button:disabled {
    opacity: .6;
    cursor: not-allowed;
}

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

button.secondary {
    background: var(--color-surface);
    color: var(--color-primary);
    border: 1px solid var(--color-border-medium);
}

.btn-lg {
    padding: 8px 14px;
    font-size: 16px;
}

.icon-btn {
    border: none;
    background: transparent;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    color: var(--color-text-muted);
    padding: 4px 6px;
}

.icon-btn .material-icons {
    font-size: 22px;
}

/* ===== Field ===== */
.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    width: -webkit-fill-available;
}

.field label {
    font-size: 12px;
    color: var(--color-text-muted);
}

/* ===== Icon Input Wrap ===== */
.icon-input-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.icon-input-wrap .icon-input-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 18px;
    color: var(--color-text-placeholder);
    pointer-events: none;
    z-index: 1;
}

.icon-input-wrap input {
    padding-left: 34px;
    width: 100%;
}

/* ===== Input Relative ===== */
.input-relative {
    position: relative;
    width: 100%;
}

.input-relative input {
    width: 100%;
    padding-right: 80px;
}

.input-relative button {
    position: absolute;
    right: 4px;
    top: 50%;
    border: 1px solid var(--color-border-input);
    border-radius: 6px;
    transform: translateY(-50%);
    padding: 4px 8px;
    font-size: 12px;
    cursor: pointer;
    color: var(--color-primary);
}

/* ===== Input Group / Group ===== */
.input-group {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.input-group input,
.input-group select {
    width: 100%;
}

.group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.group input,
.group select,
.group button {
    height: 36px;
}

/* ===== Filter Input Wrap ===== */
.filter-input-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.filter-input-wrap input {
    width: 160px;
    padding-right: 28px;
    padding-left: 32px;
}

.filter-input-wrap > .icon-input-icon {
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 18px;
    color: var(--color-text-placeholder);
    pointer-events: none;
    z-index: 1;
}

.filter-input-clear {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--color-text-placeholder);
    padding: 2px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: color .15s;
}

.filter-input-clear:hover {
    color: var(--color-text);
}

.filter-input-clear .material-icons {
    font-size: 16px;
}

/* ===== Card / Row / Grid ===== */
.card {
    background: var(--color-surface);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 8px;
}

.row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.grid2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.grid3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

/* ===== Tag ===== */
.tag {
    display: inline-block;
    font-size: 12px;
    white-space: nowrap;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--color-primary-bg-alt, var(--color-primary-bg));
    color: var(--color-primary-text);
}

.tag.danger,
.danger {
    background: var(--color-danger-bg-alt, var(--color-danger-bg));
    color: var(--color-danger-text);
}

/* ===== Checkbox ===== */
.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: var(--color-text-tertiary);
    cursor: pointer;
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--color-primary);
    cursor: pointer;
}

/* ===== Login Components ===== */
.login-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--login-bg);
    padding: 16px;
}

.login-card {
    width: min(420px, 100%);
    background: var(--color-surface);
    border-radius: 16px;
    box-shadow: var(--login-shadow);
    padding: 36px 32px 28px;
    animation: loginFadeIn 0.4s ease;
}

@keyframes loginFadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

.login-logo {
    text-align: center;
    margin-bottom: 28px;
}

.login-logo-img {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    margin-bottom: 12px;
}

.login-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--color-text);
    margin: 0;
}

.login-link {
    color: var(--color-primary);
    font-size: 13px;
    cursor: pointer;
    text-decoration: none;
}

.login-link:hover {
    text-decoration: underline;
}

.login-error {
    color: var(--color-danger);
    font-size: 13px;
    margin-top: 10px;
    text-align: center;
    min-height: 18px;
}

/* ===== Spacing Utilities ===== */
.m-0 { margin: 0; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.ml-1 { margin-left: 4px; }
.ml-2 { margin-left: 8px; }
.mr-1 { margin-right: 4px; }
.mr-2 { margin-right: 8px; }
.mx-auto { margin-left: auto; margin-right: auto; }

.p-0 { padding: 0; }
.p-1 { padding: 4px; }
.p-2 { padding: 8px; }
.p-3 { padding: 12px; }
.p-4 { padding: 16px; }
.px-1 { padding-left: 4px; padding-right: 4px; }
.px-2 { padding-left: 8px; padding-right: 8px; }
.px-3 { padding-left: 12px; padding-right: 12px; }
.py-1 { padding-top: 4px; padding-bottom: 4px; }
.py-2 { padding-top: 8px; padding-bottom: 8px; }
.py-3 { padding-top: 12px; padding-bottom: 12px; }

/* ===== Border Radius Utilities ===== */
.rounded-sm { border-radius: 4px; }
.rounded { border-radius: 8px; }
.rounded-md { border-radius: 10px; }
.rounded-lg { border-radius: 12px; }
.rounded-xl { border-radius: 16px; }
.rounded-full { border-radius: 999px; }
.rounded-circle { border-radius: 50%; }

/* ===== Text Utilities ===== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: 12px; }
.text-base { font-size: 14px; }
.text-lg { font-size: 16px; }
.text-muted { color: var(--color-text-muted); }
.text-primary { color: var(--color-primary); }
.text-danger { color: var(--color-danger); }
.text-success { color: var(--color-success); }
.font-bold { font-weight: 700; }
.mono { font-family: var(--font-mono, "SF Mono", "Cascadia Code", "Fira Code", Consolas, monospace); }
.nowrap { white-space: nowrap; }

/* ===== Display / Flex Utilities ===== */
.d-none { display: none; }
.d-block { display: block; }
.d-inline { display: inline; }
.d-inline-flex { display: inline-flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }
.flex-shrink-0 { flex-shrink: 0; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.w-full { width: 100%; }
.d-flex { display: flex; }
.align-center { align-items: center; }

.justify-center {
    justify-content: center;
}

.justify-between {
    justify-content: space-between;
}

.justify-around {
    justify-content: space-around;
}

.justify-evenly {
    justify-content: space-evenly;
}

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

.justify-end {
    justify-content: flex-end;
}

/* ===== 分页控件 ===== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 12px 0 4px;
    flex-wrap: wrap;
    user-select: none;
}

.pagination-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 13px;
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
}

.pagination-btn:hover:not(:disabled):not(.active) {
    background: var(--color-bg-hover);
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.pagination-btn.active {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
    font-weight: 600;
    pointer-events: none;
}

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

.pagination-btn .material-icons {
    font-size: 18px;
}

.pagination-info {
    font-size: 12px;
    color: var(--color-text-muted);
    margin: 0 6px;
    white-space: nowrap;
}

.pagination-size {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
    font-size: 12px;
    color: var(--color-text-muted);
}

.pagination-size select {
    height: 32px;
    padding: 0 8px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 13px;
    text-align: center;
}

/* ===== 回到顶部 ===== */
.back-to-top {
    position: fixed;
    right: 20px;
    bottom: 30px;
    z-index: 900;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .12);
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px);
    transition: opacity .25s, visibility .25s, transform .25s, background .15s;
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.back-to-top:hover {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

.back-to-top .material-icons {
    font-size: 22px;
}

/* ===== 统一页脚 ===== */
.app-footer {
    text-align: center;
    font-size: 13px;
    color: var(--color-text-muted);
    padding: 16px 12px;
    margin-top: auto;
    line-height: 1.6;
    letter-spacing: 0.2px;
}