/* =========================================================================
   NiftyOptionTrader — dark trading-terminal design system (Phase 0)
   Layered on top of Bootstrap 5.3's built-in dark mode (data-bs-theme="dark"
   set in App.razor). We deepen the palette and add brand/status tokens here
   rather than fighting Bootstrap — every existing page already uses plain
   Bootstrap classes (card/table/badge/btn/alert/form-control), so retuning
   the underlying CSS variables reskins the whole app without rewriting
   every .razor file. Later phases restyle individual pages on top of this.
   ========================================================================= */

:root {
    /* Backgrounds, darkest to most elevated */
    --bg-app: #0a0d13;
    --bg-surface: #10141c;
    --bg-surface-2: #161b26;
    --bg-sidebar: #0b0e15;
    --bg-topbar: #0d1119;

    /* Borders */
    --border-subtle: #212739;
    --border-strong: #2c3348;

    /* Text */
    --text-primary: #e8ebf1;
    --text-secondary: #98a2b8;
    --text-muted: #626d85;

    /* Brand */
    --accent-gold: #d9a840;
    --accent-gold-soft: rgba(217, 168, 64, 0.14);
    --accent-blue: #4c8dff;

    /* Trading semantics */
    --pnl-positive: #23c67a;
    --pnl-negative: #f24b4b;
    --status-live: #f24b4b;
    --status-paper: #4c8dff;
    --status-warning: #eab138;

    /* Misc */
    --radius-md: 8px;
    --radius-sm: 6px;
    --font-mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, monospace;
}

html, body {
    height: 100%;
}

body {
    background-color: var(--bg-app) !important;
    color: var(--text-primary);
    font-feature-settings: "tnum" 1;
}

/* -------------------------------------------------------------------------
   Bootstrap variable overrides (dark theme scope) — deepen the default
   Bootstrap dark palette into a proper near-black terminal background and
   align card/table/border colors with our tokens.
   ------------------------------------------------------------------------- */
[data-bs-theme="dark"] {
    --bs-body-bg: var(--bg-app);
    --bs-body-color: var(--text-primary);
    --bs-secondary-color: var(--text-secondary);
    --bs-tertiary-color: var(--text-muted);
    --bs-border-color: var(--border-subtle);
    --bs-border-color-translucent: var(--border-subtle);

    --bs-card-bg: var(--bg-surface);
    --bs-card-border-color: var(--border-subtle);
    --bs-card-cap-bg: var(--bg-surface-2);

    --bs-table-bg: transparent;
    --bs-table-color: var(--text-primary);
    --bs-table-striped-bg: var(--bg-surface-2);
    --bs-table-hover-bg: rgba(76, 141, 255, 0.06);
    --bs-table-border-color: var(--border-subtle);

    --bs-tertiary-bg: var(--bg-surface-2);
    --bs-secondary-bg: var(--bg-surface-2);

    --bs-emphasis-color: var(--text-primary);
    --bs-link-color: var(--accent-blue);
    --bs-link-hover-color: #74a7ff;
}

/* Cards: subtle elevation instead of Bootstrap's flat dark fill */
.card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
}

.card.shadow-sm {
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px -12px rgba(0, 0, 0, 0.5) !important;
}

.card-header.bg-dark {
    background-color: var(--bg-surface-2) !important;
    border-bottom: 1px solid var(--border-subtle);
}

.card-header.bg-light,
.table-light,
.bg-light {
    background-color: var(--bg-surface-2) !important;
    color: var(--text-primary) !important;
}

/* Tables: quieter grid, sticky headers read clearly on dark */
.table > :not(caption) > * > * {
    border-bottom-color: var(--border-subtle);
}

thead.sticky-top,
.table-dark {
    background-color: var(--bg-surface-2) !important;
}

.table-warning,
tr.table-warning {
    --bs-table-bg: var(--accent-gold-soft) !important;
    color: var(--text-primary) !important;
}

/* Numeric emphasis — use tabular figures for anything price/qty/pnl */
.fw-bold, .fs-2, .fs-3, code, pre {
    font-feature-settings: "tnum" 1;
}

/* PnL coloring: prefer explicit tokens over Bootstrap's default green/red
   so positive/negative reads consistently against the dark background */
.text-success { color: var(--pnl-positive) !important; }
.text-danger  { color: var(--pnl-negative) !important; }

/* Buttons: keep Bootstrap's semantics but round corners to match the rest
   of the system */
.btn {
    border-radius: var(--radius-sm);
}

/* Forms */
.form-control, .form-select {
    background-color: var(--bg-surface-2);
    border-color: var(--border-strong);
    color: var(--text-primary);
}

.form-control:focus, .form-select:focus {
    background-color: var(--bg-surface-2);
    color: var(--text-primary);
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 0.2rem rgba(76, 141, 255, 0.15);
}

.form-text {
    color: var(--text-muted);
}

/* Alerts: darker fills, colored left rail for quick scanning */
.alert {
    border: 1px solid var(--border-subtle);
    border-left-width: 3px;
    background-color: var(--bg-surface-2);
}

.alert-success { border-left-color: var(--pnl-positive); color: var(--text-primary); }
.alert-danger  { border-left-color: var(--pnl-negative); color: var(--text-primary); }
.alert-warning { border-left-color: var(--status-warning); color: var(--text-primary); }
.alert-info    { border-left-color: var(--accent-blue); color: var(--text-primary); }

/* Scrollbars — thin, dark, consistent with the terminal feel */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background-color: var(--border-strong);
    border-radius: 8px;
    border: 2px solid var(--bg-app);
}

/* =========================================================================
   App shell — top status bar + grouped sidebar (Phase 0)
   ========================================================================= */

.app-shell {
    min-height: 100vh;
    background: var(--bg-app);
}

.app-topbar {
    height: 48px;
    background: var(--bg-topbar);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    gap: 1.5rem;
    position: sticky;
    top: 0;
    z-index: 1030;
}

.app-topbar .brand {
    color: var(--accent-gold);
    font-weight: 700;
    letter-spacing: 0.02em;
    font-size: 0.95rem;
    white-space: nowrap;
}

.app-topbar .status-group {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    flex-wrap: wrap;
}

.app-topbar .status-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
}

.app-topbar .status-label {
    color: var(--text-muted);
}

.app-topbar .status-value {
    color: var(--text-primary);
    font-weight: 600;
    font-family: var(--font-mono);
}

.app-topbar .pnl-value.positive { color: var(--pnl-positive); }
.app-topbar .pnl-value.negative { color: var(--pnl-negative); }

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.status-dot.on { background: var(--pnl-positive); box-shadow: 0 0 6px var(--pnl-positive); }
.status-dot.off { background: var(--text-muted); }
.status-dot.live { background: var(--status-live); box-shadow: 0 0 6px var(--status-live); }
.status-dot.paper { background: var(--status-paper); }

.app-body {
    display: flex;
    align-items: stretch;
}

.app-sidebar {
    width: 216px;
    flex-shrink: 0;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-subtle);
    padding: 1rem 0.75rem;
    min-height: calc(100vh - 48px);
}

.app-sidebar .nav-section-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    padding: 0.9rem 0.6rem 0.3rem;
}

.app-sidebar .nav-section-label:first-child {
    padding-top: 0.3rem;
}

.app-sidebar .nav-link {
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    padding: 0.45rem 0.6rem;
    font-size: 0.87rem;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    transition: background-color 0.12s ease, color 0.12s ease;
}

.app-sidebar .nav-link i {
    font-size: 0.95rem;
    width: 1.1rem;
    text-align: center;
    color: var(--text-muted);
}

.app-sidebar .nav-link:hover {
    background: var(--bg-surface-2);
    color: var(--text-primary);
}

.app-sidebar .nav-link.active {
    background: var(--accent-gold-soft);
    color: var(--accent-gold);
}

.app-sidebar .nav-link.active i {
    color: var(--accent-gold);
}

.app-main {
    flex-grow: 1;
    padding: 1.5rem;
    background: var(--bg-app);
    min-width: 0;
}

/* Charts workstation (Charts.razor) — full-bleed, maximum space for the actual chart canvas,
   matching a dedicated trading terminal's layout (e.g. Angel One's own chart view: the toolbar is
   the only chrome, the chart fills everything else). .app-main's own 1.5rem padding is cancelled
   with an equal negative margin so this reaches the sidebar's edge and the window's right/bottom
   edges instead of sitting in an inset box; the height calc accounts for the 48px topbar (see
   .app-topbar) since .app-main has no explicit height of its own to measure percentages against.
   #cw-panels (workstation.js) then gets the rest of the vertical space via flex, and its grid rows
   are sized in fr units rather than a fixed pixel height so N panels always split whatever room is
   actually available instead of being capped at a fixed 420px regardless of viewport size. */
#chart-workstation {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 48px);
    margin: -1.5rem;
}

#chart-workstation .cw-panels {
    flex: 1 1 auto;
    min-height: 0;
}

@media (max-width: 900px) {
    .app-topbar .status-group { display: none; }
    .app-sidebar { width: 64px; }
    .app-sidebar .nav-section-label,
    .app-sidebar .nav-link span { display: none; }
    .app-sidebar .nav-link { justify-content: center; }
}

/* =========================================================================
   Existing Blazor template chrome (error UI / reconnect modal) — unchanged
   ========================================================================= */

#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

    #blazor-error-ui .reload {
        color: #0d6efd;
        cursor: pointer;
    }

    #blazor-error-ui .dismiss {
        cursor: pointer;
        position: absolute;
        right: 0.75rem;
        top: 0.5rem;
    }

#components-reconnect-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1050;
    background: rgba(0, 0, 0, 0.4);
}

    #components-reconnect-modal > div {
        background: var(--bg-surface);
        color: var(--text-primary);
        border: 1px solid var(--border-strong);
        border-radius: 6px;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
        left: 50%;
        max-width: 90vw;
        padding: 1.25rem 1.5rem;
        position: fixed;
        top: 40%;
        transform: translate(-50%, -50%);
    }

.components-reconnect-show,
.components-reconnect-failed,
.components-reconnect-rejected {
    display: block;
}

.components-reconnect-hide {
    display: none;
}
