/* ========================================
   CSV Explorer — Spreadsheet Dark Theme
   ======================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    --primary: #3B82F6;
    --primary-glow: rgba(59, 130, 246, 0.2);
    --accent: #10B981;
    --accent-glow: rgba(16, 185, 129, 0.2);
    --warning: #F59E0B;
    --danger: #EF4444;

    --bg-deep: #0B0F1A;
    --bg-base: #111828;
    --bg-surface: #1E293B;
    --bg-elevated: #334155;
    --bg-glass: rgba(17, 24, 40, 0.9);
    --bg-row-alt: rgba(30, 41, 59, 0.4);

    --text-primary: #F1F5F9;
    --text-secondary: #94A3B8;
    --text-muted: #64748B;

    --border: rgba(51, 65, 85, 0.5);
    --border-hover: rgba(71, 85, 105, 0.7);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;

    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-deep);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ── Header ── */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    gap: 12px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-center {
    flex: 1;
    max-width: 400px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 1rem;
    white-space: nowrap;
}

.logo-icon {
    width: 30px;
    height: 30px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 500;
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn:hover {
    background: var(--bg-elevated);
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: #2563EB;
}

.btn-icon {
    padding: 6px;
    width: 30px;
    height: 30px;
    justify-content: center;
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-muted);
}

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

/* ── Search ── */
.search-wrapper {
    position: relative;
}

.search-svg {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 6px 10px 6px 32px;
    font-family: var(--font-sans);
    font-size: 0.8rem;
    color: var(--text-primary);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    outline: none;
}

.search-input:focus {
    border-color: var(--primary);
}

/* ── Drop Zone ── */
.drop-zone {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    margin: 40px 20px;
    cursor: pointer;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.03), rgba(16, 185, 129, 0.03));
    transition: all var(--transition-base);
    text-align: center;
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--primary);
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.07), rgba(16, 185, 129, 0.07));
}

.drop-content {
    padding: 48px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.drop-icon {
    color: var(--text-muted);
    margin-bottom: 8px;
}

.drop-content strong {
    font-size: 1rem;
}

.drop-sub {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.drop-link {
    color: var(--primary);
    cursor: pointer;
    text-decoration: underline;
}

.drop-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ── Table ── */
.table-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.toolbar {
    padding: 8px 20px;
    background: var(--bg-base);
    border-bottom: 1px solid var(--border);
}

.info-bar {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    gap: 6px;
    align-items: center;
}

.info-sep {
    color: var(--border);
}

.table-container {
    flex: 1;
    overflow: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.data-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

.data-table th {
    padding: 8px 14px;
    text-align: left;
    background: var(--bg-base);
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border);
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
    transition: color var(--transition-fast);
}

.data-table th:hover {
    color: var(--primary);
}

.data-table th.sorted {
    color: var(--primary);
}

.data-table th .sort-arrow {
    margin-left: 4px;
    font-size: 0.65rem;
}

.data-table td {
    padding: 7px 14px;
    border-bottom: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text-primary);
    white-space: nowrap;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.data-table tbody tr:nth-child(even) {
    background: var(--bg-row-alt);
}

.data-table tbody tr:hover {
    background: rgba(59, 130, 246, 0.06);
}

.td-number {
    color: var(--accent);
    text-align: right;
}

.td-date {
    color: var(--warning);
}

.table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 20px;
    background: var(--bg-base);
    border-top: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--text-muted);
}

.page-controls {
    display: flex;
    gap: 4px;
}

/* ── Panel Overlay ── */
.panel-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-base);
}

.panel-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.panel {
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    transform: translateY(20px);
    transition: transform var(--transition-base);
}

.panel-overlay.open .panel {
    transform: translateY(0);
}

.panel-wide {
    max-width: 700px;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.panel-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

.panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

/* ── Stats ── */
.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
    margin-bottom: 10px;
}

.stat-card-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 8px;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 8px;
}

.stat-item-label {
    font-size: 0.68rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.stat-item-value {
    font-size: 0.85rem;
    font-weight: 600;
    font-family: var(--font-mono);
}

/* ── Chart ── */
.chart-controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: end;
    margin-bottom: 16px;
}

.chart-controls .control-group {
    flex: 1;
    min-width: 120px;
}

.control-label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
}

.control-select {
    width: 100%;
    padding: 6px 10px;
    font-family: var(--font-sans);
    font-size: 0.8rem;
    color: var(--text-primary);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
}

.chart-area {
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    padding: 16px;
    min-height: 300px;
}

/* ── Toast ── */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 10px 14px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.82rem;
    color: var(--text-primary);
    animation: toast-in 0.3s ease-out;
    max-width: 300px;
}

.toast.success {
    border-left: 3px solid var(--accent);
}

.toast.error {
    border-left: 3px solid var(--danger);
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateX(30px);
    }

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

@media (max-width: 700px) {
    .header {
        padding: 8px 10px;
    }

    .logo span {
        display: none;
    }

    .header-center {
        display: none !important;
    }

    .drop-zone {
        margin: 20px 10px;
    }
}