/* ========================================
   Polymarket Trade Crawler - Styles
   ======================================== */

:root {
    /* Base Colors & Shared Tokens */
    --primary: #10b981;
    --primary-dark: #059669;
    --primary-light: #34d399;
    --primary-glow: rgba(16, 185, 129, 0.3);

    --accent: #8b5cf6;
    --accent-dark: #7c3aed;

    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
    --info: #3b82f6;

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-2xl: 3rem;

    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms ease;
}

/* Dark Theme (Default) */
[data-theme="dark"],
:root:not([data-theme="light"]) {
    --bg-primary: #0f0f13;
    --bg-secondary: #16161d;
    --bg-card: #1a1a24;
    --bg-card-hover: #1f1f2a;

    --text-primary: #f5f5f7;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;

    --border-color: rgba(255, 255, 255, 0.08);
    --border-bright: rgba(255, 255, 255, 0.12);

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 40px var(--primary-glow);

    --orb-opacity: 0.4;
    --hover-color: rgba(255, 255, 255, 0.03);
}

/* Light Theme */
[data-theme="light"] {
    --bg-primary: #f8fafc;
    --bg-secondary: #f1f5f9;
    --bg-card: #ffffff;
    --bg-card-hover: #f8fafc;

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;

    --border-color: rgba(0, 0, 0, 0.08);
    --border-bright: rgba(0, 0, 0, 0.12);

    --success: #16a34a;
    /* More contrast */
    --warning: #d97706;
    /* More contrast */
    --error: #dc2626;
    /* More contrast */
    --info: #2563eb;
    /* More contrast */

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.15);
    --shadow-glow: 0 0 40px rgba(16, 185, 129, 0.1);

    --orb-opacity: 0.15;
    --hover-color: rgba(0, 0, 0, 0.03);
}

/* ========================================
   Reset & Base
   ======================================== */

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ========================================
   Background Effects
   ======================================== */

.background-effects {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
    overflow: hidden;
}

.gradient-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: var(--orb-opacity);
    animation: float 20s ease-in-out infinite;
}

.orb-1 {
    width: 600px;
    height: 600px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    top: -200px;
    right: -100px;
}

.orb-2 {
    width: 400px;
    height: 400px;
    background: linear-gradient(135deg, var(--accent) 0%, #ec4899 100%);
    bottom: -100px;
    left: -100px;
    animation-delay: -7s;
}

.orb-3 {
    width: 300px;
    height: 300px;
    background: linear-gradient(135deg, #3b82f6 0%, var(--primary) 100%);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation-delay: -14s;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0) rotate(0deg);
    }

    33% {
        transform: translateY(-30px) rotate(5deg);
    }

    66% {
        transform: translateY(20px) rotate(-5deg);
    }
}

/* ========================================
   Container
   ======================================== */

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: var(--spacing-xl);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ========================================
   Header
   ======================================== */

.header {
    text-align: center;
    margin-bottom: var(--spacing-2xl);
    padding-top: var(--spacing-xl);
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-md);
}

.logo-icon {
    width: 48px;
    height: 48px;
    color: var(--primary);
    filter: drop-shadow(0 0 20px var(--primary-glow));
}

.header h1 {
    font-size: 2.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--text-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header h1 .highlight {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 1.1rem;
    color: var(--text-secondary);
}

/* ========================================
   Cards
   ======================================== */

.top-row {
    display: flex;
    gap: var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
}

.top-row .card {
    flex: 1;
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
    backdrop-filter: blur(20px);
    transition: border-color var(--transition-normal), box-shadow var(--transition-normal);
}

.card:hover {
    border-color: var(--border-bright);
}

/* ========================================
   Input Card
   ======================================== */

.input-group {
    margin-bottom: var(--spacing-lg);
}

.input-group label {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: var(--spacing-sm);
}

.label-icon {
    font-size: 1.1rem;
}

.input-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    transition: all var(--transition-normal);
}

.input-group input::placeholder {
    color: var(--text-muted);
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.input-hint {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: var(--spacing-xs);
}

.action-row {
    display: flex;
    align-items: flex-end;
    gap: var(--spacing-md);
}

.input-group.shrink {
    flex: 0 0 140px;
    margin-bottom: 0;
}

.action-row .btn-primary {
    flex: 1;
    height: 46px;
    /* Match input height roughly */
}

/* ========================================
   Buttons
   ======================================== */

.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    width: 100%;
    padding: var(--spacing-md) var(--spacing-xl);
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 1.05rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-normal);
    box-shadow: var(--shadow-md), 0 0 20px var(--primary-glow);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg), 0 0 30px var(--primary-glow);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.btn-icon {
    font-size: 1.2rem;
}

.btn-loading {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.btn-ghost {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    padding: var(--spacing-xs) var(--spacing-md);
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-ghost:hover {
    background: var(--bg-secondary);
    border-color: var(--border-bright);
    color: var(--text-primary);
}

.btn-download {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    flex: 1;
    padding: var(--spacing-md) var(--spacing-lg);
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-normal);
}

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

.btn-download.btn-secondary {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-download.btn-secondary:hover {
    border-color: var(--primary);
}

/* ========================================
   Theme Toggle
   ======================================== */

.theme-toggle-container {
    position: absolute;
    top: var(--spacing-xl);
    right: var(--spacing-xl);
    z-index: 100;
}

.theme-btn {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--spacing-sm);
    cursor: pointer;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-normal);
    box-shadow: var(--shadow-sm);
}

.theme-btn:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.theme-btn svg {
    width: 20px;
    height: 20px;
}

[data-theme="light"] .sun-icon {
    display: none;
}

[data-theme="dark"] .moon-icon {
    display: none;
}

:root:not([data-theme="light"]) .moon-icon {
    display: none;
}

/* ========================================
   Log Card
   ======================================== */

.log-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-md);
}

.log-header h3 {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 1rem;
    font-weight: 600;
}

.log-area {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    height: 180px;
    /* 固定高度 */
    overflow-y: auto;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.85rem;
    scroll-behavior: smooth;
}

/* 针对日志区域的细窄滚动条 */
.log-area::-webkit-scrollbar {
    width: 4px;
}

.log-area::-webkit-scrollbar-thumb {
    background: var(--border-bright);
    border-radius: 2px;
}

.log-area::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.log-entry {
    display: flex;
    gap: var(--spacing-sm);
    padding: var(--spacing-xs) 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.log-entry:last-child {
    border-bottom: none;
}

.log-time {
    color: var(--text-muted);
    flex-shrink: 0;
}

.log-message {
    word-break: break-word;
}

.log-info .log-message {
    color: var(--text-secondary);
}

.log-success .log-message {
    color: var(--success);
}

.log-warning .log-message {
    color: var(--warning);
}

.log-error .log-message {
    color: var(--error);
}

.log-fetch .log-message {
    color: var(--info);
}

/* ========================================
   Result Card
   ======================================== */

.result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-lg);
    flex-wrap: wrap;
    gap: var(--spacing-md);
}

.result-time-range {
    font-size: 0.9rem;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    flex: 1;
    margin: 0 var(--spacing-lg);
    text-align: center;
    min-width: 250px;
    max-width: 500px;
}

.result-header h3 {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--success);
}

.result-stats {
    display: flex;
    gap: var(--spacing-xl);
}

.stat {
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.download-actions {
    display: flex;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-xl);
}

.preview-section h4 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-md);
}

.table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

th,
td {
    padding: var(--spacing-sm) var(--spacing-md);
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

th {
    background: var(--bg-secondary);
    font-weight: 600;
    color: var(--text-secondary);
    position: sticky;
    top: 0;
}

tr:hover td {
    background: var(--hover-color);
}

.side-buy {
    color: var(--success);
    font-weight: 500;
}

.side-sell {
    color: var(--error);
    font-weight: 500;
}

.outcome-yes {
    color: var(--success);
}

.outcome-no {
    color: var(--error);
}

/* Market cell with link */
.market-cell {
    max-width: 280px;
    white-space: normal;
    word-break: break-word;
}

.market-cell a {
    color: var(--text-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.market-cell a:hover {
    color: var(--primary);
    text-decoration: underline;
}

/* ========================================
   Footer
   ======================================== */

.footer {
    margin-top: auto;
    padding-top: var(--spacing-xl);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ========================================
   Scrollbar
   ======================================== */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--border-bright);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ========================================
   Responsive
   ======================================== */

@media (max-width: 640px) {
    .container {
        padding: var(--spacing-md);
    }

    .header h1 {
        font-size: 1.75rem;
    }

    .logo {
        flex-direction: column;
        gap: var(--spacing-sm);
    }

    .logo-icon {
        width: 40px;
        height: 40px;
    }

    .card {
        padding: var(--spacing-lg);
    }

    .result-header {
        flex-direction: column;
        text-align: center;
    }

    .download-actions {
        flex-direction: column;
    }

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

    .top-row {
        flex-direction: column;
    }

    .action-row {
        flex-direction: column;
        align-items: stretch;
    }

    .input-group.shrink {
        flex: 1 0 auto;
        margin-bottom: var(--spacing-md);
    }
}