:root {
    color-scheme: dark;
    --bg-primary: #040813;
    --bg-panel: #0e1628;
    --bg-card: #131c33;
    --text-primary: #f4f7ff;
    --text-muted: #a9b6dc;
    --accent: #5f7bff;
    --danger: #ff6f6f;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: radial-gradient(circle at top, #101935, #050913 45%);
    color: var(--text-primary);
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

.layout-root {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.layout-body {
    width: min(960px, 100%);
}

.welcome-card {
    background: rgba(14, 22, 40, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 24px;
    padding: clamp(32px, 5vw, 56px);
    box-shadow: 0 25px 80px rgba(4, 7, 18, 0.85);
    backdrop-filter: blur(14px);
}

.welcome-card h1 {
    margin: 0;
    font-size: clamp(2rem, 3vw, 2.6rem);
}

.welcome-card p {
    color: var(--text-muted);
    line-height: 1.6;
    margin-top: 12px;
    max-width: 640px;
}

.input-grid {
    margin-top: 28px;
    display: grid;
    gap: 18px;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

label {
    display: block;
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

input[type=\"text\"], input[type=\"password\"] {
    width: 100%;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(7, 12, 24, 0.85);
    color: var(--text-primary);
    padding: 14px;
    font-size: 1rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(95, 123, 255, 0.25);
}

.actions {
    margin-top: 32px;
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
}

.btn-primary {
    border: none;
    border-radius: 999px;
    padding: 14px 32px;
    font-weight: 600;
    background: linear-gradient(120deg, #5f7bff, #7b5bff);
    color: #fff;
    cursor: pointer;
    font-size: 1rem;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 30px rgba(95, 123, 255, 0.35);
}

.note {
    margin-top: 18px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.auth-badge {
    margin-top: 24px;
    padding: 14px 18px;
    border-radius: 16px;
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.4);
    color: #8ff2bb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.btn-secondary {
    border: none;
    border-radius: 999px;
    padding: 10px 20px;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    cursor: pointer;
}

@media (max-width: 600px) {
    .welcome-card {
        padding: 24px;
    }

    .actions {
        flex-direction: column;
    }
}

/* Phase 2 */
.panel {
    background: rgba(14, 22, 40, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 20px;
    padding: 28px;
    margin-top: 24px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
}

.panel-header h2 {
    margin: 0;
}

.pill {
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 0.85rem;
}

.pill.running {
    background: rgba(45, 212, 191, 0.15);
    border: 1px solid rgba(45, 212, 191, 0.4);
    color: #9efce7;
}

.pill.stopped {
    background: rgba(255, 111, 111, 0.15);
    border: 1px solid rgba(255, 111, 111, 0.45);
    color: #ffb0b0;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-top: 24px;
}

.form-grid input,
.form-grid select {
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(7, 12, 24, 0.75);
    color: var(--text-primary);
    padding: 12px;
}

.toggle-field {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-stop {
    border: none;
    border-radius: 12px;
    padding: 12px 18px;
    background: var(--danger);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}

.btn-secondary {
    border: none;
    border-radius: 999px;
    padding: 12px 18px;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    cursor: pointer;
}

.running-hint {
    margin-top: 18px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 14px;
    padding: 18px;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 320px 1fr 260px;
    gap: 24px;
    margin-top: 24px;
}

.quick-panel .quick-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.quick-panel .quick-actions button {
    border: none;
    border-radius: 10px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    cursor: pointer;
    font-weight: 600;
}

.logs {
    margin-top: 20px;
}

.logs h4 {
    margin-bottom: 10px;
    color: var(--text-muted);
}

.log-entry {
    border-radius: 10px;
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.2);
    margin-bottom: 10px;
    font-size: 0.9rem;
}

.log-entry span {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: block;
}

.workspace .focus-row {
    display: flex;
    gap: 12px;
    align-items: center;
    margin: 18px 0;
}

.workspace .focus-row input {
    flex: 1;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(7, 12, 24, 0.85);
    color: var(--text-primary);
    padding: 12px;
}

.chart-box {
    background: rgba(0, 0, 0, 0.25);
    border-radius: 16px;
    padding: 0;
    margin-bottom: 18px;
}

.focus-chart-container {
    position: relative;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    background: radial-gradient(circle at top, #0d1424, #050913 70%);
    overflow: hidden;
    min-height: 280px;
}

.focus-chart-canvas {
    width: 100%;
    height: clamp(240px, 38vh, 420px);
    position: relative;
}

.chart-fullscreen-button {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(5, 9, 19, 0.6);
    color: #f5f7fa;
    font-size: 0.85rem;
    line-height: 1;
    cursor: pointer;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.chart-fullscreen-button span {
    pointer-events: none;
}

.chart-fullscreen-button:hover {
    background: rgba(0, 194, 255, 0.25);
    border-color: rgba(0, 194, 255, 0.8);
    color: #aef;
}

.chart-fullscreen-button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

:fullscreen .chart-fullscreen-button::after {
    content: '✕';
}

:fullscreen .chart-fullscreen-button span {
    display: none;
}

:fullscreen .chart-fullscreen-button {
    background: rgba(5, 9, 19, 0.8);
}

.chart-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 32px;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.chart-placeholder ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.chart-placeholder li {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.9rem;
}

.focus-chart-shell {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 20px;
}

.focus-chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.focus-chart-symbol {
    display: flex;
    align-items: center;
    gap: 16px;
}

.focus-chart-symbol-name {
    font-size: 1.5rem;
    font-weight: 600;
}

.focus-chart-price-block {
    display: flex;
    gap: 10px;
    align-items: baseline;
}

.focus-chart-price {
    font-size: 1.25rem;
    font-weight: 500;
}

.focus-chart-change {
    font-size: 0.95rem;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
}

.focus-chart-change.positive {
    color: #4ade80;
    background: rgba(74, 222, 128, 0.15);
}

.focus-chart-change.negative {
    color: #f87171;
    background: rgba(248, 113, 113, 0.18);
}

.focus-chart-status {
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.focus-chart-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.6);
}

.focus-chart-status-dot.disconnected {
    background: #f87171;
    box-shadow: 0 0 8px rgba(248, 113, 113, 0.5);
}

.focus-chart-toolbar {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.focus-chart-controls {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.focus-chart-controls button {
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(14, 22, 40, 0.8);
    color: var(--text-primary);
    border-radius: 8px;
    padding: 6px 14px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.focus-chart-controls button:hover {
    background: rgba(95, 123, 255, 0.2);
    border-color: rgba(95, 123, 255, 0.4);
}

.focus-chart-controls button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.focus-chart-controls button.active {
    background: rgba(79, 70, 229, 0.4);
    border-color: rgba(129, 140, 248, 0.9);
    color: #fff;
}

.focus-chart-controls .extended-layout-button {
    margin-left: 4px;
    background: rgba(0, 194, 255, 0.15);
    border-color: rgba(0, 194, 255, 0.35);
    color: #a1f0ff;
    font-weight: 600;
}

.focus-chart-controls .extended-layout-button:hover:not(:disabled) {
    background: rgba(0, 194, 255, 0.25);
    border-color: rgba(0, 194, 255, 0.8);
}

.focus-chart-stats {
    display: flex;
    gap: 16px;
}

.focus-chart-stats div {
    display: flex;
    flex-direction: column;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.focus-chart-stats strong {
    color: var(--text-primary);
    font-size: 1rem;
}

.focus-chart-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(5, 9, 19, 0.7);
    z-index: 2;
}

.focus-chart-spinner {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.15);
    border-top-color: var(--accent);
    animation: spin 1s linear infinite;
}

.focus-chart-loading.hidden {
    display: none;
}

.focus-chart-debug {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 12px;
    max-height: 160px;
    overflow-y: auto;
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 0.8rem;
    display: none;
}

.focus-chart-debug.visible {
    display: block;
}

.focus-chart-debug h5 {
    margin: 0 0 8px 0;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.focus-chart-debug > div {
    max-height: 120px;
    overflow-y: auto;
}

/* Extended layout */
.extended-layout-page {
    padding: clamp(16px, 4vw, 40px);
}

.extended-layout-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 28px;
}

.extended-layout-header h1 {
    margin: 0;
    font-size: clamp(1.8rem, 3vw, 2.4rem);
    letter-spacing: 0.04em;
}

.extended-layout-subtitle {
    margin: 0 0 4px;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 0.2em;
}

.extended-layout-back {
    color: #8fb7ff;
    text-decoration: none;
    font-weight: 600;
    border: 1px solid rgba(143, 183, 255, 0.35);
    padding: 10px 18px;
    border-radius: 999px;
}

.extended-layout-back:hover {
    border-color: rgba(143, 183, 255, 0.8);
}

.extended-layout-empty {
    border: 1px dashed rgba(255, 255, 255, 0.15);
    border-radius: 16px;
    padding: 32px;
    background: rgba(8, 10, 18, 0.65);
    color: var(--text-muted);
}

.extended-layout-empty code {
    background: rgba(255, 255, 255, 0.08);
    padding: 2px 6px;
    border-radius: 6px;
}

.extended-layout-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.extended-panel {
    padding: 18px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    background: linear-gradient(145deg, rgba(9, 14, 25, 0.9), rgba(4, 7, 14, 0.9));
    display: flex;
    flex-direction: column;
    min-height: 320px;
}

.extended-panel header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 10px;
}

.extended-panel h2 {
    margin: 0;
    font-size: 1rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #8fb3ff;
}

.panel-position {
    margin: 0 0 4px;
    text-transform: uppercase;
    font-size: 0.7rem;
    color: var(--text-muted);
    letter-spacing: 0.2em;
}

.panel-meta {
    text-align: right;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.panel-symbol {
    font-weight: 600;
    letter-spacing: 0.2em;
}

.extended-chart {
    position: relative;
    flex: 1;
    min-height: 260px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(3, 6, 12, 0.7);
    overflow: hidden;
}

.extended-chart-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(3, 6, 12, 0.75);
    z-index: 3;
}

.extended-chart-loading.hidden {
    display: none;
}

.extended-chart-spinner {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.15);
    border-top-color: var(--accent);
    animation: spin 1s linear infinite;
}

@media (max-width: 1024px) {
    .extended-layout-grid {
        grid-template-columns: 1fr;
    }
}

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

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

.table-block th, .table-block td {
    text-align: left;
    padding: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.9rem;
}

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

.telemetry td, .telemetry th {
    padding: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.telemetry-card {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 18px;
}

.telemetry-card .value {
    font-size: 1.8rem;
    font-weight: 600;
}

.positive {
    color: #66ffa6;
}

.negative {
    color: #ff8787;
}

.status-banner {
    margin-bottom: 18px;
    padding: 12px 16px;
    border-radius: 12px;
    background: rgba(95, 123, 255, 0.15);
    border: 1px solid rgba(95, 123, 255, 0.4);
}

.focus-chip {
    background: rgba(255, 255, 255, 0.08);
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 0.85rem;
}

@media (max-width: 1200px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

.chart-lookup-panel .actions {
    margin-top: 18px;
}

.chart-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin: 18px 0;
    padding: 12px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.07);
}

.chart-meta span {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.chart-meta strong {
    display: block;
    font-size: 1.05rem;
    margin-top: 4px;
}

.chart-lookup-canvas {
    position: relative;
    min-height: 420px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: linear-gradient(145deg, rgba(5, 7, 15, 0.8), rgba(10, 13, 24, 0.85));
    overflow: hidden;
}

.chart-lookup-canvas .chart-placeholder {
    padding: 48px 24px;
}

.alert {
    margin-top: 14px;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.alert.info {
    background: rgba(95, 123, 255, 0.12);
    border-color: rgba(95, 123, 255, 0.5);
}

.alert.danger {
    background: rgba(255, 111, 111, 0.12);
    border-color: rgba(255, 111, 111, 0.6);
}
