:root {
    --bg-dark: #0b1020;
    --bg-darker: #060914;
    --sidebar-bg: #0f172a;
    --panel: rgba(15, 23, 42, 0.78);
    --panel-strong: rgba(15, 23, 42, 0.92);
    --card-border: rgba(148, 163, 184, 0.18);
    --text-primary: #f8fafc;
    --text-secondary: #9fb1c7;
    --accent: #14b8a6;
    --accent-strong: #0f766e;
    --accent-warm: #f97316;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --font-heading: 'Sora', sans-serif;
    --font-body: 'Manrope', sans-serif;
    --shadow-md: 0 12px 24px -12px rgba(15, 23, 42, 0.6);
    --shadow-lg: 0 24px 50px -28px rgba(15, 23, 42, 0.8);
    --radius-lg: 1rem;
    --radius-md: 0.75rem;
    --radius-sm: 0.5rem;
}

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

html,
body {
    height: 100%;
}

body {
    background-color: var(--bg-darker);
    background-image:
        radial-gradient(1200px 520px at 5% -20%, rgba(20, 184, 166, 0.28) 0%, transparent 60%),
        radial-gradient(900px 520px at 90% 0%, rgba(249, 115, 22, 0.2) 0%, transparent 55%),
        linear-gradient(180deg, rgba(6, 9, 20, 0.95) 0%, rgba(8, 13, 24, 0.98) 100%);
    color: var(--text-primary);
    font-family: var(--font-body);
    min-height: 100svh;
    overflow: hidden;
}

body.sidebar-open {
    overflow: hidden;
}

a {
    color: inherit;
}

.app-container {
    display: flex;
    height: 100svh;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--card-border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    gap: 1.25rem;
    position: sticky;
    top: 0;
    height: 100svh;
    overflow-y: auto;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.brand {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.brand i {
    color: var(--accent);
}

.nav-menu {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.nav-item {
    padding: 0.85rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border: 1px solid transparent;
}

.nav-item:hover,
.nav-item.active {
    background: rgba(20, 184, 166, 0.12);
    color: var(--text-primary);
    border-color: rgba(20, 184, 166, 0.3);
}

.status-card {
    background: rgba(8, 12, 24, 0.6);
    border-radius: var(--radius-md);
    padding: 1rem;
    border: 1px solid var(--card-border);
    box-shadow: var(--shadow-md);
}

.status-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-secondary);
    box-shadow: 0 0 10px currentColor;
    transition: all 0.3s ease;
}

.indicator.running {
    background: var(--success);
    color: var(--success);
}

.indicator.stopped {
    background: var(--danger);
    color: var(--danger);
}

.status-text {
    font-weight: 600;
    margin-bottom: 0.85rem;
    font-size: 1rem;
}

/* Buttons */
.btn {
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    transition: transform 0.2s ease, filter 0.2s ease;
    font-family: var(--font-body);
}

.btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.05);
}

.btn:focus-visible,
.icon-btn:focus-visible,
.profile-toggle:focus-visible {
    outline: 2px solid rgba(20, 184, 166, 0.6);
    outline-offset: 2px;
}

.btn-primary {
    background: var(--accent);
    color: #07121a;
}

.btn-danger {
    background: var(--danger);
    color: #0b0f1a;
}

.btn-sm {
    padding: 0.55rem 1rem;
    font-size: 0.85rem;
    width: 100%;
}

.btn-outline {
    border: 1px solid rgba(20, 184, 166, 0.6);
    background: transparent;
    color: var(--accent);
}

.btn-outline:hover {
    background: rgba(20, 184, 166, 0.15);
    color: var(--text-primary);
}

.btn-outline-danger {
    border: 1px solid rgba(239, 68, 68, 0.6);
    background: transparent;
    color: var(--danger);
}

.btn-outline-danger:hover {
    background: rgba(239, 68, 68, 0.15);
    color: var(--text-primary);
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid var(--card-border);
    background: rgba(8, 12, 24, 0.65);
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: border-color 0.2s ease, transform 0.2s ease;
}

.icon-btn:hover {
    border-color: rgba(20, 184, 166, 0.6);
    transform: translateY(-1px);
}

.sidebar-close {
    display: none;
}

/* Main Content */
.main-content {
    flex: 1;
    overflow-y: auto;
    height: 100svh;
    padding: clamp(1.5rem, 2vw, 2.5rem);
    position: relative;
}

.content-area {
    min-height: calc(100svh - 6rem);
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.nav-toggle {
    display: none;
}

.page-title h1 {
    font-family: var(--font-heading);
    font-size: clamp(1.5rem, 2vw, 2rem);
    font-weight: 700;
}

.refresh-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.7rem;
    color: var(--accent);
    background: rgba(20, 184, 166, 0.12);
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    margin-left: 0.5rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.user-profile {
    position: relative;
}

.profile-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.35rem 0.6rem;
    border-radius: 999px;
    border: 1px solid var(--card-border);
    background: rgba(8, 12, 24, 0.55);
    color: var(--text-primary);
    cursor: pointer;
}

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

.user-profile .avatar {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--accent), var(--accent-warm));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
    color: #06131a;
    box-shadow: var(--shadow-md);
}

.profile-menu {
    display: none;
    position: absolute;
    top: calc(100% + 0.6rem);
    right: 0;
    background: var(--panel-strong);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    padding: 0.6rem;
    box-shadow: var(--shadow-lg);
    width: 200px;
    z-index: 100;
}

.profile-menu.open {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* Sections */
.hero-section {
    background: linear-gradient(120deg, rgba(20, 184, 166, 0.18), rgba(15, 23, 42, 0.92));
    border: 1px solid rgba(20, 184, 166, 0.25);
    border-radius: var(--radius-lg);
    padding: 2rem;
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    box-shadow: var(--shadow-lg);
    gap: 2rem;
}

.hero-content h2 {
    font-family: var(--font-heading);
    margin-bottom: 0.5rem;
}

.hero-content p {
    color: var(--text-secondary);
    max-width: 420px;
}

.hero-stats {
    display: flex;
    gap: 2rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.stat-item .label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.stat-item .value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--accent);
    font-family: var(--font-heading);
}

/* KPI Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.card {
    background: var(--panel);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    backdrop-filter: blur(12px);
    box-shadow: var(--shadow-md);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.card-header h3 {
    margin: 0;
}

.card-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.card-actions .form-control {
    width: 120px;
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
    margin-top: 0;
}

.kpi-card {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.kpi-icon.positive {
    background: rgba(34, 197, 94, 0.18);
    color: var(--success);
}

.kpi-icon.negative {
    background: rgba(239, 68, 68, 0.18);
    color: var(--danger);
}

.kpi-value {
    font-size: 1.5rem;
    font-weight: 700;
    font-family: var(--font-heading);
    display: block;
}

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

/* Charts */
.charts-row {
    margin-bottom: 2rem;
}

.chart-card {
    min-height: 360px;
    position: relative;
}

.chart-card h3 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

canvas {
    max-height: 320px;
}

.section-header h2 {
    font-family: var(--font-heading);
}

.filters {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.filters .form-control {
    width: 150px;
    margin-top: 0;
}

/* Tables */
.table-card {
    margin-bottom: 2rem;
}

.service-card {
    margin-bottom: 2rem;
}

.service-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.service-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.service-actions .btn {
    min-width: 140px;
}

.service-output {
    margin-top: 0.75rem;
    max-height: 320px;
}

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

.data-table th,
.data-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--card-border);
}

.data-table th {
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

.data-table td {
    font-size: 0.95rem;
}

.table-responsive {
    overflow-x: auto;
}

.badge {
    padding: 0.25rem 0.5rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border: 1px solid rgba(148, 163, 184, 0.25);
    color: var(--text-secondary);
}

.badge-bull {
    background: rgba(34, 197, 94, 0.16);
    color: var(--success);
    border-color: rgba(34, 197, 94, 0.3);
}

.badge-bear {
    background: rgba(239, 68, 68, 0.16);
    color: var(--danger);
    border-color: rgba(239, 68, 68, 0.3);
}

.badge-neutral {
    background: rgba(148, 163, 184, 0.2);
    color: var(--text-secondary);
    border-color: rgba(148, 163, 184, 0.35);
}

.badge-warn {
    background: rgba(245, 158, 11, 0.18);
    color: var(--warning);
    border-color: rgba(245, 158, 11, 0.4);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.18);
    color: var(--danger);
    border-color: rgba(239, 68, 68, 0.4);
}

.positive {
    color: var(--success);
}

.negative {
    color: var(--danger);
}

.live-price {
    font-variant-numeric: tabular-nums;
}

.live-price.live-pending {
    color: var(--text-secondary);
}

/* Forms */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.form-control {
    width: 100%;
    padding: 0.65rem 0.75rem;
    border-radius: var(--radius-sm);
    background: rgba(8, 12, 24, 0.6);
    border: 1px solid var(--card-border);
    color: var(--text-primary);
    margin-top: 6px;
    font-size: 0.95rem;
}

.form-control:focus {
    outline: 2px solid rgba(20, 184, 166, 0.5);
    border-color: rgba(20, 184, 166, 0.5);
}

.msg-box {
    margin-top: 1rem;
    padding: 0.6rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    text-align: center;
}

.msg-error {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

.msg-success {
    background: rgba(34, 197, 94, 0.2);
    color: var(--success);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(3, 6, 18, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(6px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--panel-strong);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    width: min(440px, 92vw);
    padding: 0;
    box-shadow: var(--shadow-lg);
}

.modal-content.chart-modal {
    width: min(980px, 95vw);
}

.chart-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.chart-meta span {
    padding: 0.35rem 0.65rem;
    border-radius: 999px;
    background: rgba(8, 12, 24, 0.6);
    border: 1px solid var(--card-border);
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.6rem;
}

.chart-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.chart-legend-line {
    width: 18px;
    height: 3px;
    border-radius: 3px;
    background: var(--text-secondary);
}

.chart-legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--text-secondary);
}

.chart-insights {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.chart-insight {
    padding: 0.35rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid var(--card-border);
    background: rgba(8, 12, 24, 0.6);
    color: var(--text-secondary);
}

.chart-insight strong {
    color: var(--text-primary);
    font-weight: 600;
}

#patternChartContainer {
    width: 100%;
    height: 100%;
}

#patternChart {
    width: 100%;
    height: 100%;
}

.report-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.report-meta .meta-item {
    background: rgba(8, 12, 24, 0.6);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    padding: 0.85rem;
}

.report-meta .meta-label {
    display: block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

.report-meta .meta-value {
    font-size: 0.95rem;
    font-weight: 600;
}

.report-json {
    background: rgba(8, 12, 24, 0.6);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    padding: 1rem;
    max-height: 260px;
    overflow: auto;
    font-size: 0.85rem;
    line-height: 1.4;
    color: var(--text-secondary);
    font-family: "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.2rem 1.5rem;
    border-bottom: 1px solid var(--card-border);
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: flex-end;
    border-top: 1px solid var(--card-border);
}

.close-modal {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
}

/* Config */
.config-category {
    margin-bottom: 2rem;
}

.config-category h3 {
    font-size: 1.05rem;
    font-family: var(--font-heading);
    margin-bottom: 0.8rem;
}

.config-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.5rem;
}

/* Alerts */
.alert-card {
    border-left: 4px solid var(--warning);
    padding: 1rem;
    margin-bottom: 2rem;
    background: rgba(245, 158, 11, 0.08);
    border-radius: var(--radius-sm);
}

.hidden {
    display: none;
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5, 7, 14, 0.65);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 900;
}

.sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* Auth */
.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100svh;
    padding: 2rem;
}

.auth-shell {
    width: min(980px, 95vw);
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 2rem;
    align-items: center;
}

.auth-intro {
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.auth-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 700;
}

.auth-brand i {
    color: var(--accent);
}

.auth-card {
    background: var(--panel-strong);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    box-shadow: var(--shadow-lg);
}

.auth-card h1 {
    font-family: var(--font-heading);
    margin-bottom: 0.4rem;
}

.auth-card p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.auth-metrics {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.auth-metric {
    background: rgba(8, 12, 24, 0.55);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    padding: 1rem;
}

.auth-metric span {
    display: block;
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.auth-metric strong {
    font-size: 1.15rem;
    font-family: var(--font-heading);
}

.auth-card button {
    width: 100%;
    padding: 0.8rem;
    background: var(--accent);
    color: #06131a;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s ease;
    margin-top: 1rem;
}

.auth-card button:hover {
    transform: translateY(-1px);
}

.auth-error {
    color: var(--danger);
    font-size: 0.85rem;
    margin-top: 1rem;
    text-align: center;
    display: none;
}

.log-output {
    background: rgba(8, 12, 24, 0.6);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    padding: 1rem;
    max-height: 420px;
    overflow: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.85rem;
    line-height: 1.5;
    white-space: pre-wrap;
}

/* Responsive */
@media (max-width: 1100px) {
    .hero-section {
        flex-direction: column;
        align-items: flex-start;
    }

    .hero-stats {
        width: 100%;
        justify-content: space-between;
    }

    .chart-card {
        min-height: 320px;
    }

    .config-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    body {
        overflow: auto;
    }

    .app-container {
        flex-direction: column;
        height: auto;
        min-height: 100svh;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        z-index: 999;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-close {
        display: inline-flex;
    }

    .nav-toggle {
        display: inline-flex;
    }

    .main-content {
        padding: 1.2rem;
        overflow: visible;
        height: auto;
    }

    .top-bar {
        align-items: flex-start;
    }

    .page-title {
        flex: 1;
        min-width: 180px;
    }

    .profile-label {
        display: none;
    }
}

@media (max-width: 800px) {
    .hero-stats {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .stat-item {
        align-items: flex-start;
    }

    .data-table thead {
        display: none;
    }

    .data-table,
    .data-table tbody,
    .data-table tr,
    .data-table td {
        display: block;
        width: 100%;
    }

    .data-table tr {
        margin-bottom: 1rem;
        border: 1px solid var(--card-border);
        border-radius: var(--radius-md);
        padding: 0.5rem;
        background: rgba(8, 12, 24, 0.55);
    }

    .data-table td {
        display: flex;
        justify-content: space-between;
        gap: 1rem;
        padding: 0.6rem 0.4rem;
        border-bottom: 1px dashed rgba(148, 163, 184, 0.2);
    }

    .data-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
    }

    .data-table td:last-child {
        border-bottom: none;
    }
}

@media (max-width: 720px) {
    .auth-shell {
        grid-template-columns: 1fr;
    }

    .auth-card {
        padding: 2rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}
