/* ============================================================
   Design System - CSS Variables
   ============================================================ */

:root {
    /* === Colors - Light Mode === */
    --bg-body: #F5F5F7;
    --bg-card: #FFFFFF;
    --bg-input: #F5F5F7;
    --bg-hover: #E8E8ED;
    --navbar-bg: rgba(255, 255, 255, 0.85);

    --text-primary: #1D1D1F;
    --text-secondary: #86868B;
    --text-tertiary: #A1A1A6;
    --text-inverse: #FFFFFF;

    --accent: #0071E3;
    --accent-hover: #0077ED;
    --accent-light: rgba(0, 113, 227, 0.1);

    --danger: #FF3B30;
    --danger-light: rgba(255, 59, 48, 0.1);
    --success: #34C759;
    --success-light: rgba(52, 199, 89, 0.1);
    --warning: #FF9500;
    --warning-light: rgba(255, 149, 0, 0.1);

    --border: #E5E5EA;
    --border-light: #F2F2F7;

    --modal-overlay: rgba(0, 0, 0, 0.3);

    /* === Spacing & Radius === */
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-full: 999px;

    /* === Shadows === */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 8px 16px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.08);

    /* === Motion === */
    --ease-apple: cubic-bezier(0.25, 0.1, 0.25, 1);
    --spring: cubic-bezier(0.175, 0.885, 0.32, 1.275);

    /* === Typography === */
    --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ============================================================
   Dark Mode - Variable Overrides
   ============================================================ */

[data-theme="dark"] {
    --bg-body: #000000;
    --bg-card: #1C1C1E;
    --bg-input: #2C2C2E;
    --bg-hover: #3A3A3C;
    --navbar-bg: rgba(0, 0, 0, 0.9);

    --text-primary: #F5F5F7;
    --text-secondary: #A1A1A6;
    --text-tertiary: #8E8E93;
    --text-inverse: #000000;

    --accent: #0A84FF;
    --accent-hover: #409CFF;
    --accent-light: rgba(10, 132, 255, 0.2);

    --danger: #FF453A;
    --danger-light: rgba(255, 69, 58, 0.2);
    --success: #30D158;
    --success-light: rgba(48, 209, 88, 0.2);
    --warning: #FF9F0A;
    --warning-light: rgba(255, 159, 10, 0.2);

    --border: #38383A;
    --border-light: #2C2C2E;

    --modal-overlay: rgba(0, 0, 0, 0.6);

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 8px 16px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.7);
}

/* System preference auto-switch */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg-body: #000000;
        --bg-card: #1C1C1E;
        --bg-input: #2C2C2E;
        --bg-hover: #3A3A3C;
        --navbar-bg: rgba(0, 0, 0, 0.9);

        --text-primary: #F5F5F7;
        --text-secondary: #A1A1A6;
        --text-tertiary: #8E8E93;
        --text-inverse: #000000;

        --accent: #0A84FF;
        --accent-hover: #409CFF;
        --accent-light: rgba(10, 132, 255, 0.2);

        --danger: #FF453A;
        --danger-light: rgba(255, 69, 58, 0.2);
        --success: #30D158;
        --success-light: rgba(48, 209, 88, 0.2);
        --warning: #FF9F0A;
        --warning-light: rgba(255, 159, 10, 0.2);

        --border: #38383A;
        --border-light: #2C2C2E;

        --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.5);
        --shadow-md: 0 8px 16px rgba(0, 0, 0, 0.6);
        --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.7);
    }
}

/* ============================================================
   Theme Toggle Button
   ============================================================ */

.theme-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.theme-toggle:hover {
    background: var(--bg-input);
    color: var(--text-primary);
}

.theme-toggle svg {
    width: 20px;
    height: 20px;
}

.icon-sun { display: none; }
.icon-moon { display: block; }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .icon-sun { display: block; }
    :root:not([data-theme="light"]) .icon-moon { display: none; }
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

/* --- Components --- */

/* 1. Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    font-weight: 500;
    font-size: 14px;
    line-height: 1.5;
    border-radius: var(--radius-full);
    /* Pill shape */
    border: none;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
    gap: 6px;
    white-space: nowrap;
}

.btn:active {
    transform: scale(0.96);
}

/* Button Sizes */
.btn-sm {
    padding: 4px 12px;
    font-size: 12px;
    gap: 4px;
}

.btn-lg {
    padding: 12px 24px;
    font-size: 16px;
    gap: 8px;
}

.btn-icon {
    padding: 8px;
    width: 32px;
    height: 32px;
}

.btn-icon.btn-sm {
    padding: 6px;
    width: 28px;
    height: 28px;
}

/* Button Variants */
.btn-primary {
    background-color: var(--text-primary);
    color: var(--text-inverse);
}

.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-accent {
    background-color: var(--accent);
    color: var(--text-inverse);
}

.btn-accent:hover {
    background-color: var(--accent-hover);
}

.btn-danger {
    background-color: var(--danger);
    color: var(--text-inverse);
}

.btn-danger:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* 2. Inputs */
.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

/* Base input/textarea/select styles */
input, textarea, select {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

input::placeholder, textarea::placeholder {
    color: var(--text-tertiary);
}

.form-input,.form-select {
    width: 100%;
    padding: 0.5rem 1rem;
    background: var(--bg-input);
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    font-size: 1rem;
    color: var(--text-primary);
    outline: none;
    transition: all 0.2s var(--ease-apple);
}

.form-input:focus {
    background: var(--bg-card);
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-light);
}

/* 3. Cards */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 24px;
    border: 1px solid var(--border-light);
}

/* 4. Navbar (Dashboard) */
.navbar {
    height: 64px;
    background: var(--navbar-bg, rgba(255, 255, 255, 0.85));
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
    justify-content: space-between;
}

.nav-brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-primary);
    text-decoration: none;
}

.nav-links {
    display: flex;
    gap: 24px;
    align-items: center;
}

.nav-link {
    display: inline-block;
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.95rem;
    transition: color 0.2s;
    cursor: pointer;
    padding: 4px 0;
}

.nav-link:hover,
.nav-link.active {
    color: var(--text-primary);
}

/* Drodown Menu */
.nav-item-dropdown {
    position: relative;
    display: flex;
    align-items: center;
    padding-bottom: 8px;
    /* Extend hit area downwards */
    margin-bottom: -8px;
    /* Compensate layout */
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--bg-card);
    min-width: 160px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    padding: 8px;
    display: none;
    z-index: 100;
    margin-top: 0;
    animation: scaleIn 0.2s var(--ease-apple);
}

.nav-item-dropdown:hover .dropdown-menu {
    display: block;
}

.dropdown-menu a {
    display: block;
    padding: 10px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.dropdown-menu a:hover {
    background: var(--bg-input);
    color: var(--text-primary);
}

.dropdown-divider {
    height: 1px;
    background: var(--border-light);
    margin: 4px 0;
}

/* 5. Misc */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.text-sm {
    font-size: 0.875rem;
}

.text-secondary {
    color: var(--text-secondary);
}

/* Animation Utility */
.animate-in {
    animation: fadeUp 0.6s var(--ease-apple) forwards;
    opacity: 0;
    transform: translateY(15px);
}

/* --- Keyframes (CRITICAL for Opacity Animations) --- */
@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes slideIn {
    from {
        transform: translateY(100%);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* 6. Layout Utilities (Global) */
.container {
    max-width: 1100px;
    margin: 40px auto;
    padding: 0 24px;
}

.header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 32px;
}

.page-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
}


/* 7. Data Tables */
.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.data-table th {
    text-align: left;
    padding: 16px 24px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    background: var(--bg-input);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.data-table td {
    padding: 16px 24px;
    font-size: 0.95rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr:hover td {
    background: var(--bg-hover);
}

/* 8. Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 99px;
    font-size: 0.8rem;
    font-weight: 600;
    background: var(--border-light);
    color: var(--text-primary);
}

.badge-success {
    background: var(--success-light);
    color: var(--success);
}

.badge-warning {
    background: var(--warning-light);
    color: var(--warning);
}

.badge-danger {
    background: var(--danger-light);
    color: var(--danger);
}

.badge-info {
    background: var(--accent-light);
    color: var(--accent);
}

.badge-neutral {
    background: var(--bg-input);
    color: var(--text-secondary);
}

/* ========== Pagination ========== */
.pagination {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 12px;
    padding: 16px;
    margin-top: 16px;
}

.pagination-info {
    font-size: 13px;
    color: var(--text-secondary);
}

.pagination button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ===== Modal Styles ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease-out;
}

.modal-overlay.hidden {
    display: none !important;
}

.modal {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 28px;
    width: 90%;
    max-width: 480px;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s var(--ease-apple);
}

.modal h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 20px 0;
}

.modal p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.6;
    margin: 0 0 24px 0;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ============================================================
   Utility Classes - 通用工具类
   ============================================================ */

/* 空状态提示 */
.empty-state {
    padding: 40px;
    text-align: center;
    color: var(--text-tertiary);
}

/* 加载状态 */
.loading-state {
    padding: 32px;
    text-align: center;
    color: var(--text-tertiary);
}

/* 列表项 */
.list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--bg-card);
    border-radius: 8px;
    margin-bottom: 8px;
    border: 1px solid var(--border-light);
}

/* 提示框 */
.tip-box {
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 0.9rem;
    margin-bottom: 16px;
}

.tip-box-info {
    background: var(--accent-light);
    color: var(--accent);
}

.tip-box-warning {
    background: var(--warning-light);
    color: var(--warning);
}

.tip-box-danger {
    background: var(--danger-light);
    color: var(--danger);
}

.tip-box-success {
    background: var(--success-light);
    color: var(--success);
}

/* 取消按钮样式 */
.btn-cancel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
}

.btn-cancel:hover {
    background: var(--bg-hover);
}

/* 页面容器 */
.page-container {
    background: var(--bg-body);
    min-height: 100vh;
}

/* 内容卡片 */
.content-card {
    background: var(--bg-card);
    border-radius: 20px;
    padding: 32px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-light);
}

/* 分组标题行（用于表格等） */
.group-header {
    background: var(--bg-input);
}

/* 禁用标签 */
.badge-disabled {
    font-size: 0.75rem;
    background: var(--bg-input);
    color: var(--text-tertiary);
    padding: 2px 8px;
    border-radius: 4px;
}

/* 二维码容器 */
.qr-container {
    display: inline-block;
    padding: 10px;
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border);
}

/* ============================================================
   Social Login Buttons - 社交登录按钮
   ============================================================ */

.social-divider {
    display: flex;
    align-items: center;
    margin: 24px 0 16px;
    color: var(--text-tertiary);
    font-size: 0.85rem;
}

.social-divider::before,
.social-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}

.social-divider span {
    padding: 0 16px;
}

/* 社交登录图标容器 */
.social-icons {
    display: flex;
    justify-content: center;
    gap: 16px;
}

/* 社交登录图标按钮 */
.social-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s var(--ease-apple);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
    text-decoration: none;
}

.social-icon-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.social-icon-btn:active {
    transform: scale(0.95);
}

.social-icon-btn svg {
    width: 24px;
    height: 24px;
}

/* GitHub 图标 */
.social-icon-github {
    background: var(--bg-card);
    color: var(--text-primary);
}

.social-icon-github:hover {
    background: var(--bg-hover);
}

/* Apple 图标 */
.social-icon-apple {
    background: var(--bg-card);
    color: var(--text-primary);
}

.social-icon-apple:hover {
    background: var(--bg-hover);
}

/* 保留旧的按钮样式用于其他地方 */
.social-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.btn-social {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s var(--ease-apple);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
    text-decoration: none;
}

.btn-social:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-social:active {
    transform: scale(0.98);
}

.btn-social svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* Google Button */
.btn-google {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
}

.btn-google:hover {
    background: var(--bg-hover);
}

/* GitHub Button */
.btn-github {
    background: #24292f;
    border-color: #24292f;
    color: #ffffff;
}

.btn-github:hover {
    background: #1b1f23;
}

[data-theme="dark"] .btn-github {
    background: #f0f0f0;
    border-color: #f0f0f0;
    color: #24292f;
}

[data-theme="dark"] .btn-github:hover {
    background: #ffffff;
}

/* Apple Button */
.btn-apple {
    background: #000000;
    border-color: #000000;
    color: #ffffff;
}

.btn-apple:hover {
    background: #1a1a1a;
}

[data-theme="dark"] .btn-apple {
    background: #ffffff;
    border-color: #ffffff;
    color: #000000;
}

[data-theme="dark"] .btn-apple:hover {
    background: #f0f0f0;
}

/* OAuth Binding Card in Settings */
.oauth-bindings {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.oauth-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background: var(--bg-input);
    border-radius: 12px;
}

.oauth-item-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.oauth-item-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border: 1px solid var(--border);
}

.oauth-item-icon svg {
    width: 24px;
    height: 24px;
}

.oauth-item-details {
    display: flex;
    flex-direction: column;
}

.oauth-item-name {
    font-weight: 600;
    color: var(--text-primary);
}

.oauth-item-status {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.oauth-item-status.bound {
    color: var(--success);
}

.btn-bind {
    padding: 8px 16px;
    font-size: 0.85rem;
}

.btn-unbind {
    padding: 8px 16px;
    font-size: 0.85rem;
    background: var(--danger-light);
    color: var(--danger);
    border: none;
}

.btn-unbind:hover {
    background: var(--danger);
    color: white;
}