/* ============================================
   Global UI Enhancements — Apple-inspired
   Layered on top of base.css
   ============================================ */

/* ── Foundation ── */
html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    text-rendering: optimizeLegibility;
    font-feature-settings: 'kern' 1, 'liga' 1;
    -webkit-font-smoothing: antialiased;
}

/* ── Refined Design Tokens ── */
:root {
    --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --duration-fast: 0.15s;
    --duration-normal: 0.25s;
    --duration-slow: 0.4s;
}

/* ── Section Title Decoration ── */
.content-section h2::before,
.section h2::before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 1.2em;
    background: var(--primary-color);
    border-radius: 2px;
    margin-right: 10px;
    vertical-align: middle;
    flex-shrink: 0;
}

/* ── Section Entrance — fade-up reveal with spring easing ── */
.section.active {
    animation: sectionReveal var(--duration-layout, 400ms) var(--ease-spring);
    will-change: transform, opacity;
}

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

/* ── Contextual Transitions ── */
/* Spring easing micro-interactions (200–300ms) */
.micro-transition {
    transition: transform var(--duration-micro, 250ms) var(--ease-spring),
                opacity var(--duration-micro, 250ms) var(--ease-spring);
}

/* Layout shift animations (400ms) */
.layout-transition {
    transition: transform var(--duration-layout, 400ms) var(--ease-spring),
                opacity var(--duration-layout, 400ms) var(--ease-spring);
}

/* ── Button Success Morph ── */
@keyframes morphOut {
    0%   { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(0.8); }
}

@keyframes morphIn {
    0%   { opacity: 0; transform: scale(0.8); }
    100% { opacity: 1; transform: scale(1); }
}

.btn-morph-out {
    animation: morphOut 150ms var(--ease-spring) forwards;
    will-change: transform, opacity;
}

.btn-morph-in {
    animation: morphIn 150ms var(--ease-spring) forwards;
    will-change: transform, opacity;
}

/* ── Typography Hierarchy ── */

/* Body text: 14px, weight 400 */
body {
    font-family: var(--font-primary);
    font-size: 14px;
    font-weight: 400;
}

/* Hero metrics: 36px–48px, weight 800, letter-spacing -0.02em */
.stat-info h3 {
    font-size: clamp(36px, 5vw, 48px);
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.1;
}

/* Section headers: 18px–20px, weight 600 */
.section h2 {
    font-size: clamp(18px, 2vw, 20px);
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: 1.75rem;
    line-height: 1.3;
}

.section h2 i {
    font-size: 0.85em;
    opacity: 0.5;
}

/* Muted captions: 12px, weight 400, text-muted */
.text-muted,
.stat-info .stat-label,
.stat-info .stat-description,
.caption,
.muted {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-muted);
}

.section h3,
.proxy-pool-panel h3,
.config-panel h3,
.system-info-panel h3,
.guide-panel h3,
.tutorial-panel h3 {
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* ── Card & Panel Consistency ── */
.config-panel,
.system-info-panel,
.upload-config-panel,
.usage-panel,
.plugins-panel,
.providers-container,
.guide-panel,
.tutorial-panel,
.proxy-pool-panel,
.contact-card {
    background: #ffffff;
    border-radius: var(--radius-xl);
    border: 1px solid rgba(0, 0, 0, 0.07);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
    transition: transform 300ms var(--ease-spring),
                box-shadow 300ms var(--ease-spring);
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.config-panel:hover,
.system-info-panel:hover,
.upload-config-panel:hover,
.usage-panel:hover,
.plugins-panel:hover,
.providers-container:hover,
.guide-panel:hover,
.tutorial-panel:hover,
.proxy-pool-panel:hover,
.contact-card:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.10), 0 2px 8px rgba(0, 0, 0, 0.06);
}

/* Stat cards */
.stat-card {
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.07);
    border-left: 3px solid var(--primary-color);
    border-radius: var(--radius-xl);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
    transition: transform 300ms var(--ease-spring),
                box-shadow 300ms var(--ease-spring);
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.stat-card:hover {
    transform: scale(1.02);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.10), 0 2px 8px rgba(0, 0, 0, 0.06);
}

/* Stat value emphasis */
.stat-card .stat-info h3 {
    font-size: clamp(2rem, 5vw, 2.5rem);
    font-weight: 800;
    letter-spacing: -0.03em;
}

/* Sidebar — override enhancements to not conflict with new fixed icon rail */
/* sidebar.css handles all sidebar styling now */

/* Modal & Dropdown */
.modal-content,
.provider-modal-content {
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: var(--radius-xl);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.12), 0 4px 16px rgba(0, 0, 0, 0.08);
}

.language-dropdown {
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.10), 0 2px 8px rgba(0, 0, 0, 0.06);
}

/* ── Buttons ── */
.btn {
    font-weight: 600;
    letter-spacing: 0.005em;
    border-radius: var(--radius-lg);
    transition: transform var(--duration-fast) var(--ease-out-expo),
                box-shadow var(--duration-fast) var(--ease-out-expo),
                opacity var(--duration-fast) var(--ease-out-expo),
                background-color var(--duration-fast) var(--ease-out-expo),
                border-color var(--duration-fast) var(--ease-out-expo);
    position: relative;
    overflow: hidden;
}

.btn:active {
    transform: scale(0.97);
    transition-duration: 0.05s;
}

.btn-primary {
    box-shadow: 0 1px 3px rgba(0, 113, 227, 0.15),
                0 1px 2px rgba(0, 113, 227, 0.1);
}

.btn-primary:hover {
    box-shadow: 0 4px 14px rgba(0, 113, 227, 0.2),
                0 2px 6px rgba(0, 113, 227, 0.12);
    transform: translateY(-1px);
}

.btn-secondary:hover,
.btn-outline:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.btn-danger:hover {
    transform: translateY(-1px);
}

.btn-small {
    transition: transform var(--duration-fast) var(--ease-out-expo),
                box-shadow var(--duration-fast) var(--ease-out-expo),
                opacity var(--duration-fast) var(--ease-out-expo),
                background-color var(--duration-fast) var(--ease-out-expo);
}

.btn-small:hover {
    transform: translateY(-1px);
}

.btn-small:active {
    transform: scale(0.96);
}

/* ── Form Inputs ── */
input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
    transition: border-color 0.3s ease,
                box-shadow 0.3s ease,
                background-color 0.3s ease,
                opacity 0.3s ease;
}

input:not([type="checkbox"]):not([type="radio"]):focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-10);
    background: var(--bg-primary);
}

/* Custom select arrow */
select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%2394a3b8' d='M5 6L0 0h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

/* Checkbox accent */
input[type="checkbox"],
input[type="radio"] {
    accent-color: var(--primary-color);
    cursor: pointer;
    width: 16px;
    height: 16px;
}

/* ── Sidebar ── */
/* nav-item styles are handled by sidebar.css */

/* ── Header → now .topbar, handled by header.css ── */

.status-badge {
    transition: transform var(--duration-normal) var(--ease-out-expo),
                opacity var(--duration-normal) var(--ease-out-expo);
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.status-badge:hover {
    transform: scale(1.02);
}

/* ── Toast ── */
.toast {
    animation: toastIn var(--duration-slow) var(--ease-out-expo);
    border-radius: var(--radius-lg);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(20px) scale(0.96); }
    to   { opacity: 1; transform: translateX(0) scale(1); }
}

/* ── Modals ── */
.modal-overlay {
    transition: opacity var(--duration-normal) ease;
}

.modal-overlay.active .modal,
.modal-overlay.active .modal-content,
.modal-overlay.active .provider-modal-content {
    animation: modalReveal 0.35s var(--ease-out-expo);
}

@keyframes modalReveal {
    from { opacity: 0; transform: scale(0.94) translateY(10px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── Scrollbar — see base.css for canonical rules ── */

/* ── Table & Data List Styling ── */
table th,
table td {
    border-bottom: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
}

table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--bg-secondary);
}

table tr:hover td {
    background: var(--bg-secondary);
}

/* Alternating row backgrounds for readability */
table tbody tr:nth-child(even) td {
    background: var(--bg-secondary);
}

table tbody tr:nth-child(even):hover td {
    background: var(--bg-tertiary);
}

[data-theme="dark"] table tr:hover td {
    background: var(--bg-tertiary);
}

[data-theme="dark"] table tbody tr:nth-child(even) td {
    background: rgba(30, 41, 59, 0.4);
}

[data-theme="dark"] table tbody tr:nth-child(even):hover td {
    background: var(--bg-tertiary);
}

/* ── List & Table Rows ── */
.provider-item,
.provider-item-detail,
.plugin-card,
.config-file-item,
.proxy-item {
    transition: transform var(--duration-normal) var(--ease-out-expo),
                box-shadow var(--duration-normal) var(--ease-out-expo),
                border-color var(--duration-normal) var(--ease-out-expo),
                opacity var(--duration-normal) var(--ease-out-expo);
}

.provider-item:hover,
.plugin-card:hover,
.config-file-item:hover,
.proxy-item:hover {
    border-color: var(--border-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

/* ── Provider Tags ── */
.provider-tag {
    transition: transform var(--duration-fast) var(--ease-out-expo),
                opacity var(--duration-fast) var(--ease-out-expo);
}

.provider-tag:hover {
    transform: translateY(-1px);
}

.provider-tag:active {
    transform: scale(0.97);
}

/* ── Flow Steps (Guide/Tutorial) ── */
.flow-step {
    transition: transform var(--duration-normal) var(--ease-out-expo),
                box-shadow var(--duration-normal) var(--ease-out-expo),
                opacity var(--duration-normal) var(--ease-out-expo);
}

.flow-step:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

/* ── Feature Cards ── */
.feature-card {
    transition: transform var(--duration-normal) var(--ease-out-expo),
                box-shadow var(--duration-normal) var(--ease-out-expo),
                opacity var(--duration-normal) var(--ease-out-expo);
}

.feature-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* ── Logs ── */
.logs-container {
    border-radius: var(--radius-xl);
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Courier New', monospace;
}

.log-entry {
    transition: background-color var(--duration-fast) ease;
    padding: 0.3rem 0;
    border-radius: 2px;
}

.log-entry:hover {
    background: rgba(255, 255, 255, 0.04);
}

/* ── Progress Bars ── */
.progress-fill,
.progress-bar .fill {
    transform-origin: left;
    transition: transform 0.6s var(--ease-out-expo);
}

/* ── Highlight Note ── */
.highlight-note {
    border-radius: var(--radius-lg);
    transition: background-color var(--duration-normal) ease,
                border-color var(--duration-normal) ease,
                opacity var(--duration-normal) ease;
}

/* ── Loading Spinner ── */
.fa-spinner.fa-spin {
    animation: smoothSpin 0.8s linear infinite;
}

@keyframes smoothSpin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* ── Status Dots ── */
.proxy-item .proxy-status.running {
    box-shadow: 0 0 6px rgba(34, 197, 94, 0.4);
}

.proxy-item .proxy-status.pending {
    box-shadow: 0 0 6px rgba(245, 158, 11, 0.4);
    animation: statusPulse 1.5s ease-in-out infinite;
}

@keyframes statusPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ── Responsive Polish ── */
@media (max-width: 768px) {
    .section h2 {
        font-size: 18px;
        margin-bottom: 1.25rem;
    }

    .stat-info h3 {
        font-size: 36px;
    }
    
    .config-panel,
    .system-info-panel,
    .upload-config-panel,
    .usage-panel,
    .plugins-panel,
    .proxy-pool-panel {
        padding: 1.25rem;
    }
}

@media (max-width: 480px) {
    .section h2 {
        font-size: 18px;
    }

    .stat-info h3 {
        font-size: 36px;
    }
}

/* ── Skeleton Screen Shimmer ── */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-secondary, #f1f5f9) 25%,
        var(--bg-primary, #F8FAFC) 50%,
        var(--bg-secondary, #f1f5f9) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-lg, 12px);
    will-change: background-position;
}

[data-theme="dark"] .skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-secondary, #1e293b) 25%,
        var(--bg-tertiary, #334155) 50%,
        var(--bg-secondary, #1e293b) 75%
    );
    background-size: 200% 100%;
}

@keyframes shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Skeleton placeholder sizes */
.skeleton-text {
    height: 14px;
    margin-bottom: 8px;
    width: 80%;
}

.skeleton-title {
    height: 24px;
    margin-bottom: 12px;
    width: 60%;
}

.skeleton-card {
    height: 120px;
    width: 100%;
}

/* ── Selection Highlight ── */
::selection {
    background: var(--primary-20);
    color: var(--text-primary);
}

/* ── Focus Visible (keyboard nav) ── */
/* Generic catch-all — base.css defines element-specific rules for
   a, button, input, select, textarea, [role="button"], [tabindex].
   This rule covers any other focusable element. */
:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* ── Reduced Motion ── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
    }
    html { scroll-behavior: auto; }

    .skeleton {
        animation: none !important;
        background: var(--bg-secondary) !important;
    }

    .status-badge i {
        animation: none !important;
        opacity: 1 !important;
    }

    .section.active {
        animation: none !important;
        opacity: 1;
        transform: none;
    }

    .btn-morph-out,
    .btn-morph-in {
        animation: none !important;
    }
}

/* ── Dark Theme Surface_Card Refinement ── */
[data-theme="dark"] .config-panel,
[data-theme="dark"] .system-info-panel,
[data-theme="dark"] .upload-config-panel,
[data-theme="dark"] .usage-panel,
[data-theme="dark"] .plugins-panel,
[data-theme="dark"] .providers-container,
[data-theme="dark"] .guide-panel,
[data-theme="dark"] .tutorial-panel,
[data-theme="dark"] .proxy-pool-panel,
[data-theme="dark"] .stat-card,
[data-theme="dark"] .contact-card,
[data-theme="dark"] .plugin-card,
[data-theme="dark"] .key-card,
[data-theme="dark"] .login-container,
[data-theme="dark"] .login-box,
[data-theme="dark"] .modal,
[data-theme="dark"] .modal-content,
[data-theme="dark"] .provider-modal-content,
[data-theme="dark"] .language-dropdown {
    background: var(--bg-secondary, #0e1525);
    border: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

/* [data-theme="dark"] .header — removed, now handled by header.css .topbar */

[data-theme="dark"] .sidebar {
    /* sidebar.css handles dark mode sidebar */
}

[data-theme="dark"] .navbar {
    background: rgba(28, 28, 30, 0.78);
    border-bottom: none;
    box-shadow: var(--shadow-sm);
}
