/* ---- Custom Properties -------------------------------------------------- */

:root {
    --brand: #61CE70;
    --bg-page: #222;
    --bg-nav: #1a1a2e;
    --bg-card: #1e1e26;
    --bg-input: #2a2a36;
    --bg-hover: #2e2e3e;
    --bg-plot: #1a1a2e;
    --bg-deep: #191920;
    --bg-selected: #3a3a4e;
    --bg-dropdown-hover: #3e3e52;
    --text-bright: #fff;
    --text-primary: #ddd;
    --text-secondary: #bbb;
    --text-label: #999;
    --text-muted: #888;
    --text-dim: #666;
    --text-faint: #444;
    --border-default: #333;
    --border-input: #444;
    --border-strong: #555;
    --status-error: #e74c3c;
    --status-star: #f1c40f;
    --status-info: #4a9eda;
    --status-focus: #4a9eda;
    --accent-filter: #ff00ff;
    --accent-alert: #ff4444;
}


/* ---- Base --------------------------------------------------------------- */

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

body {
    margin: 0;
    background-color: var(--bg-page);
    color: var(--text-primary);
    font-family: system-ui, -apple-system, sans-serif;
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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


/* ---- Nav Bar ------------------------------------------------------------ */

.nav-bar {
    background-color: var(--bg-nav);
    height: 48px;
    display: flex;
    align-items: center;
    padding: 0 1rem;
    justify-content: space-between;
    flex-shrink: 0;
}

.nav-logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
}

.nav-logo img {
    height: 28px;
}

.nav-logo-text {
    color: var(--brand);
    font-size: 1.25rem;
    font-weight: 700;
}

.nav-links {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    font-size: 0.9rem;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, background-color 0.15s;
}

.nav-link:hover {
    color: var(--text-bright);
}

.nav-link.active {
    color: var(--text-bright);
    background-color: var(--bg-selected);
    border-bottom-color: var(--brand);
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-user {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.nav-logout {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.8rem;
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border-default);
    border-radius: 4px;
    transition: color 0.15s, border-color 0.15s;
}

.nav-logout:hover {
    color: var(--text-bright);
    border-color: var(--border-strong);
}


/* ---- Tables ------------------------------------------------------------- */

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    text-align: left;
    padding: 6px 10px;
    color: var(--text-label);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
    border-bottom: 1px solid var(--border-default);
    white-space: nowrap;
}

tbody td {
    padding: 6px 10px;
    font-size: 13px;
    border-bottom: 1px solid var(--border-default);
    color: var(--text-primary);
}

tbody tr {
    transition: background-color 0.1s;
}

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

tbody tr.selected {
    background-color: var(--bg-selected);
}


/* ---- Cards -------------------------------------------------------------- */

.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-default);
    border-radius: 8px;
    padding: 1rem;
}

.card-header {
    color: var(--text-bright);
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 0.75rem;
}


/* ---- Buttons ------------------------------------------------------------ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 4px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s, border-color 0.15s;
    text-decoration: none;
    white-space: nowrap;
}

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

.btn-primary {
    background-color: var(--brand);
    color: #000;
    border-color: var(--brand);
}

.btn-primary:hover:not(:disabled) {
    background-color: #52b860;
}

.btn-outline {
    background-color: transparent;
    color: var(--text-bright);
    border-color: var(--border-default);
}

.btn-outline:hover:not(:disabled) {
    background-color: var(--bg-hover);
    border-color: var(--border-strong);
}

.btn-outline-brand {
    background-color: transparent;
    color: var(--brand);
    border-color: var(--brand);
}

.btn-outline-brand:hover:not(:disabled) {
    background-color: rgba(97, 206, 112, 0.12);
}

.btn-outline-danger {
    background-color: transparent;
    color: var(--status-error);
    border-color: var(--status-error);
}

.btn-outline-danger:hover:not(:disabled) {
    background-color: rgba(231, 76, 60, 0.12);
}

.btn-outline-warning {
    background-color: transparent;
    color: #ffc107;
    border-color: #ffc107;
}

.btn-outline-warning:hover:not(:disabled) {
    background-color: #ffc107;
    color: #000;
}

.btn-sm {
    padding: 3px 8px;
    font-size: 12px;
}

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

.spinner-sm {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--border-default);
    border-top-color: var(--text-muted);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.btn-icon:hover {
    color: var(--text-bright);
}


/* ---- Forms -------------------------------------------------------------- */

input[type="text"],
input[type="password"],
input[type="search"],
input[type="email"],
input[type="number"],
input[type="date"],
select,
textarea {
    background-color: var(--bg-input);
    color: var(--text-bright);
    border: 1px solid var(--border-input);
    border-radius: 4px;
    padding: 6px 10px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--status-focus);
    box-shadow: 0 0 0 2px rgba(74, 158, 218, 0.25);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-dim);
}

label {
    color: var(--text-secondary);
    font-size: 13px;
    display: block;
    margin-bottom: 4px;
}

.form-group {
    margin-bottom: 12px;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

input[type="checkbox"] {
    accent-color: var(--brand);
}


/* ---- Filters Panel (offcanvas, slides from right) ----------------------- */

.filters-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 340px;
    height: 100vh;
    background-color: var(--bg-card);
    border-left: 1px solid var(--border-default);
    z-index: 1050;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.filters-panel.open {
    transform: translateX(0);
}

.filters-backdrop {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1040;
    display: none;
}

.filters-backdrop.open {
    display: block;
}

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

.filters-panel-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-bright);
}

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

.filters-panel-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border-default);
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}


/* ---- Filter Button Active State: neon magenta glow --------------------- */

.filter-btn-active {
    border-color: var(--accent-filter) !important;
    color: var(--accent-filter) !important;
    background-color: rgba(255, 0, 255, 0.12) !important;
    box-shadow:
        0 0 6px rgba(255, 0, 255, 0.5),
        0 0 14px rgba(255, 0, 255, 0.3),
        0 0 30px rgba(255, 0, 255, 0.15);
    animation: neon-pulse 1.8s ease-in-out infinite alternate;
    font-weight: 600 !important;
}

@keyframes neon-pulse {
    from {
        box-shadow:
            0 0 6px rgba(255, 0, 255, 0.5),
            0 0 14px rgba(255, 0, 255, 0.3),
            0 0 30px rgba(255, 0, 255, 0.15);
    }
    to {
        box-shadow:
            0 0 8px rgba(255, 0, 255, 0.7),
            0 0 20px rgba(255, 0, 255, 0.45),
            0 0 40px rgba(255, 0, 255, 0.25);
    }
}


/* ---- Classification Pills ----------------------------------------------- */

.pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.03em;
    line-height: 1.4;
    white-space: nowrap;
}

.pill-noise {
    background-color: rgba(136, 136, 136, 0.2);
    color: #888;
}

.pill-normal {
    background-color: rgba(74, 158, 218, 0.15);
    color: var(--status-info);
}

.pill-interesting {
    background-color: rgba(241, 196, 15, 0.15);
    color: var(--status-star);
}

.pill-unclassified {
    background-color: rgba(102, 102, 102, 0.15);
    color: var(--text-dim);
}


/* ---- Detail Panel (fixed right side, scrollable) ------------------------ */

.detail-panel {
    position: fixed;
    top: 48px;
    right: 0;
    width: 480px;
    bottom: 0;
    background-color: var(--bg-card);
    border-left: 1px solid var(--border-default);
    overflow-y: auto;
    z-index: 100;
    display: flex;
    flex-direction: column;
}

.detail-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-default);
    flex-shrink: 0;
}

.detail-panel-header h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-bright);
}

.detail-panel-body {
    padding: 12px 14px;
    flex: 1;
    overflow-y: auto;
}

.detail-field {
    display: flex;
    margin-bottom: 6px;
    font-size: 13px;
}

.detail-field-label {
    width: 120px;
    flex-shrink: 0;
    color: var(--text-label);
}

.detail-field-value {
    color: var(--text-primary);
    word-break: break-all;
}

.detail-section {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border-default);
}


/* ---- Pagination Controls ------------------------------------------------ */

.pagination {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
}

.pagination .btn {
    padding: 2px 8px;
    font-size: 12px;
    min-width: 28px;
}

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


/* ---- Charts / Plotly ---------------------------------------------------- */

.chart-container {
    width: 100%;
    min-height: 180px;
    position: relative;
}

.chart-container .js-plotly-plot {
    width: 100% !important;
}

.chart-label {
    font-size: 11px;
    color: var(--text-label);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 4px;
    font-weight: 600;
}


/* ---- Database Status Banner --------------------------------------------- */

.db-status-banner {
    background: #cc2222;
    color: #fff;
    text-align: center;
    padding: 8px 12px;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.3px;
    flex-shrink: 0;
    display: none;
}

.db-status-banner.visible {
    display: block;
}

.db-status-banner .btn-retry {
    margin-left: 16px;
    background: transparent;
    color: rgba(255, 255, 255, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    padding: 2px 10px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 400;
}

.db-status-banner .btn-retry:hover {
    color: #fff;
    border-color: #fff;
}


/* ---- Modal -------------------------------------------------------------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-default);
    border-radius: 8px;
    padding: 20px;
    min-width: 320px;
    max-width: 520px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-card h3 {
    margin: 0 0 16px;
    color: var(--text-bright);
    font-size: 16px;
    font-weight: 600;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
}


/* ---- Star Toggle -------------------------------------------------------- */

.star-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    padding: 0 4px;
    color: var(--text-faint);
    transition: color 0.15s;
}

.star-btn:hover {
    color: var(--status-star);
}

.star-btn.starred {
    color: var(--status-star);
}


/* ---- Explorer Layout ---------------------------------------------------- */

.explorer-layout {
    display: flex;
    height: calc(100vh - 48px);
    overflow: hidden;
}

.explorer-list-pane {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    min-width: 0;
}

.explorer-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-default);
    flex-wrap: wrap;
}

.explorer-search {
    width: 220px;
}

.explorer-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-bright);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.explorer-page-counts {
    display: flex;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.event-row {
    padding: 10px 14px;
    border-bottom: 1px solid var(--bg-input);
    cursor: pointer;
    transition: background-color 0.1s;
}

.event-row:hover {
    background-color: var(--bg-hover);
}

.event-row.selected {
    background-color: var(--bg-selected);
    border-left: 3px solid var(--status-focus);
    padding-left: 11px;
}

.event-row.loading::after {
    content: "";
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--border-default);
    border-top-color: var(--text-muted);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    float: right;
    margin-top: 2px;
}


/* ---- Classification Pill Picker ----------------------------------------- */

.class-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 1px 6px;
    font-size: 12px;
    line-height: 1.1;
    min-width: 22px;
    font-weight: 500;
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    text-decoration: none;
    flex-shrink: 0;
    transition: background-color 0.1s, color 0.1s, border-color 0.1s;
}

.class-pill:hover {
    background-color: var(--bg-hover);
}

.class-pill.active-noise {
    color: var(--bg-page);
    background-color: var(--text-muted);
    border-color: var(--text-muted);
    font-weight: 700;
}

.class-pill.active-normal {
    color: var(--bg-page);
    background-color: var(--status-info);
    border-color: var(--status-info);
    font-weight: 700;
}

.class-pill.active-interesting {
    color: var(--bg-page);
    background-color: var(--status-star);
    border-color: var(--status-star);
    font-weight: 700;
}


/* ---- Type Badge --------------------------------------------------------- */

.type-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 400;
    padding: 1px 6px;
    border-radius: 4px;
    background-color: var(--bg-hover);
    border: 1px solid var(--border-input);
    color: var(--text-secondary);
    white-space: nowrap;
    flex-shrink: 0;
}


/* ---- Map Container ------------------------------------------------------ */

.map-container {
    width: 100%;
    height: 220px;
    border-radius: 4px;
    overflow: hidden;
}


/* ---- Scrollbar (Webkit) ------------------------------------------------- */

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

::-webkit-scrollbar-track {
    background: var(--bg-deep);
}

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

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

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) var(--bg-deep);
}


/* ---- Utility classes ---------------------------------------------------- */

.text-bright  { color: var(--text-bright); }
.text-primary { color: var(--text-primary); }
.text-muted   { color: var(--text-muted); }
.text-dim     { color: var(--text-dim); }
.text-brand   { color: var(--brand); }
.text-error   { color: var(--status-error); }
.text-star    { color: var(--status-star); }
.text-info    { color: var(--status-info); }

.text-right   { text-align: right; }
.text-center  { text-align: center; }

.mt-0  { margin-top: 0; }
.mt-1  { margin-top: 0.5rem; }
.mt-2  { margin-top: 1rem; }
.mb-0  { margin-bottom: 0; }
.mb-1  { margin-bottom: 0.5rem; }
.mb-2  { margin-bottom: 1rem; }

.flex       { display: flex; }
.flex-col   { flex-direction: column; }
.items-center { align-items: center; }
.gap-1      { gap: 0.5rem; }
.gap-2      { gap: 1rem; }

.hidden { display: none; }


/* ---- Responsive --------------------------------------------------------- */

@media (max-width: 1200px) {
    .detail-panel {
        width: 380px;
    }
}

@media (max-width: 900px) {
    .detail-panel {
        position: fixed;
        width: 100%;
        left: 0;
        top: 48px;
        bottom: 0;
    }

    .filters-panel {
        width: 100%;
    }

    .explorer-search {
        width: 100%;
    }

    .explorer-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
}

@media (max-width: 600px) {
    .nav-bar {
        padding: 0 0.5rem;
    }

    .nav-links {
        gap: 0.25rem;
    }

    .nav-link {
        padding: 0.25rem 0.5rem;
        font-size: 0.8rem;
    }

    thead th,
    tbody td {
        padding: 4px 6px;
        font-size: 12px;
    }

    .modal-card {
        width: 95%;
        padding: 14px;
    }
}
