:root {
    --bg: #f1efe8;
    --surface: #fffcf6;
    --ink: #1c1917;
    --muted: #78716c;
    --accent: #1a5f4a;
    --accent-soft: #d8ebe3;
    --danger: #9f1239;
    --border: #e4ddd2;
    --breakout: #166534;
    --breakdown: #9f1239;
    --font: "IBM Plex Sans", "Segoe UI", sans-serif;
    --display: "IBM Plex Serif", Georgia, serif;
    --sidebar-w: 240px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    color: var(--ink);
    background:
        radial-gradient(ellipse at top left, #e4efe8 0%, transparent 42%),
        radial-gradient(ellipse at bottom right, #ebe4d8 0%, transparent 38%),
        var(--bg);
    min-height: 100vh;
}

/* —— App shell + left sidebar —— */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: rgba(255, 252, 246, 0.96);
    border-right: 1px solid var(--border);
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 40;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 1.1rem 1.15rem;
    border-bottom: 1px solid var(--border);
}
.sidebar-brand a {
    font-family: var(--display);
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--ink);
    text-decoration: none;
    line-height: 1.2;
}
.sidebar-close {
    display: none;
    border: none;
    background: transparent;
    font-size: 1.6rem;
    line-height: 1;
    color: var(--muted);
    cursor: pointer;
    padding: 0.15rem 0.35rem;
}

.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0.65rem 1rem;
}

.nav-section {
    margin: 0.85rem 0.55rem 0.35rem;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.55rem 0.7rem;
    border-radius: 8px;
    color: var(--ink);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 500;
}
.nav-link:hover { background: var(--accent-soft); color: var(--accent); }
.nav-link.active {
    background: var(--accent-soft);
    color: var(--accent);
}
.nav-link.disabled {
    opacity: 0.45;
    cursor: default;
    pointer-events: none;
}
.nav-link.logout { color: var(--danger); }
.nav-link.logout:hover { background: #ffe4e6; color: var(--danger); }
.nav-ico {
    width: 1.1rem;
    text-align: center;
    font-size: 0.85rem;
    opacity: 0.85;
}

.sidebar-footer {
    padding: 0.85rem 1rem 1.15rem;
    border-top: 1px solid var(--border);
}
.sidebar-footer .muted {
    margin: 0 0 0.35rem;
    font-size: 0.8rem;
}
.sidebar-footer b { color: var(--ink); font-weight: 600; }

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.mobile-topbar {
    display: none;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 252, 246, 0.94);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 30;
}
.mobile-topbar .brand {
    font-family: var(--display);
    font-weight: 600;
    font-size: 1.05rem;
    color: var(--ink);
    text-decoration: none;
    flex: 1;
}
.mobile-user {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-soft);
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.85rem;
}

.menu-toggle {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0.4rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
}
.menu-toggle span {
    display: block;
    height: 2px;
    background: var(--ink);
    border-radius: 1px;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(28, 25, 23, 0.4);
    z-index: 35;
}

.auth-main, .auth-shell { min-height: 100vh; }

#btst-desk,
#morning-watch,
#pattern-set {
    scroll-margin-top: 4.5rem;
}

.container {
    max-width: 1240px;
    margin: 0 auto;
    padding: 1.5rem;
    width: 100%;
}
.auth-container { max-width: 480px; }

.page-header a {
    color: var(--accent);
    text-decoration: none;
}
.page-header h1 {
    font-family: var(--display);
    margin: 0.25rem 0;
    font-size: 2rem;
}

.muted { color: var(--muted); }

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.25rem 1.35rem;
    margin: 1.1rem 0;
}

.stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
    margin: 1rem 0 1.25rem;
}

.stat-tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem 1.1rem;
}
.stat-tile .label {
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin-bottom: 0.35rem;
}
.stat-tile strong {
    font-family: var(--display);
    font-size: 1.75rem;
}
.stat-tile.buy strong { color: var(--breakout); }
.stat-tile.sell strong { color: var(--breakdown); }

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

.pattern-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.85rem;
    background: #fff;
}
.pattern-card.buy { border-left: 3px solid var(--breakout); }
.pattern-card.sell { border-left: 3px solid var(--breakdown); }
.pattern-card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
}
.pattern-card p {
    margin: 0;
    font-size: 0.88rem;
    line-height: 1.45;
    color: var(--ink);
}
.pattern-card .tier {
    display: inline-block;
    margin-top: 0.5rem;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}

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

/* —— Watchlist redesign —— */
.wl-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
}
.wl-header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}
.wl-header-actions .secondary-btn {
    margin-top: 0;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
}

.wl-session-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.muted.tight, .fno-hint.tight { margin: 0.35rem 0 0; font-size: 0.85rem; }

.compact-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.compact-list li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.45rem;
    padding: 0.45rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
.compact-list li:last-child { border-bottom: none; }
.compact-list a {
    font-weight: 600;
    color: var(--ink);
    text-decoration: none;
}
.compact-list a:hover { color: var(--accent); }

.signal-table .sym-link {
    font-weight: 600;
    color: var(--ink);
    text-decoration: none;
}
.signal-table .sym-link:hover { color: var(--accent); }
.signal-table tr.row-buy td { background: rgba(22, 101, 52, 0.04); }
.signal-table tr.row-sell td { background: rgba(159, 18, 57, 0.04); }
.signal-table tr.reason-row td {
    padding-top: 0;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}
.signal-table tr.reason-row .why-reason {
    margin: 0;
    max-width: none;
    font-size: 0.82rem;
    color: var(--muted);
}

.family-list {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}
.family-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    overflow: hidden;
}
.family-card.has-signal { border-color: #cfc8bc; }
.family-card.bias-buy { border-left: 3px solid var(--breakout); }
.family-card.bias-sell { border-left: 3px solid var(--breakdown); }

.family-head {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) auto minmax(0, 1fr) auto;
    gap: 0.75rem 1rem;
    align-items: center;
    padding: 0.85rem 1rem;
}
.family-id .sym {
    font-family: var(--display);
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--ink);
    text-decoration: none;
}
.family-id .sym:hover { color: var(--accent); }
.meta-line { display: block; margin-top: 0.15rem; font-size: 0.8rem; }
.family-ltp { text-align: right; }
.family-ltp .label {
    display: block;
    font-size: 0.68rem;
    text-transform: uppercase;
    color: var(--muted);
}
.family-ltp strong {
    font-family: var(--display);
    font-size: 1.25rem;
}
.family-signal {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
}
.family-actions {
    display: flex;
    gap: 0.55rem;
    align-items: center;
}
.family-actions a {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.88rem;
}

.family-plan {
    padding: 0 1rem 0.85rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem 0.85rem;
    align-items: baseline;
    font-size: 0.85rem;
    color: var(--muted);
    border-top: 1px solid var(--border);
    padding-top: 0.65rem;
    margin: 0 0.25rem;
}
.family-plan b { color: var(--ink); }
.family-plan .why-reason {
    flex: 1 1 100%;
    margin: 0.25rem 0 0;
    max-width: none;
}

.options-wrap {
    border-top: 1px solid var(--border);
    background: #faf8f4;
}
.options-table { background: transparent; }
.options-table th { background: transparent; }
.options-table tr.row-buy td { background: rgba(22, 101, 52, 0.05); }
.options-table tr.row-sell td { background: rgba(159, 18, 57, 0.05); }

.patterns-drawer {
    padding: 0;
}
.patterns-drawer summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.35rem;
    font-family: var(--display);
    font-weight: 600;
    font-size: 1.1rem;
}
.patterns-drawer summary::-webkit-details-marker { display: none; }
.patterns-drawer[open] summary { border-bottom: 1px solid var(--border); }
.patterns-drawer .pattern-grid {
    padding: 1rem 1.35rem 1.25rem;
}

@media (max-width: 900px) {
    .wl-session-grid { grid-template-columns: 1fr; }
    .family-head {
        grid-template-columns: 1fr auto;
        gap: 0.5rem;
    }
    .family-signal, .family-actions {
        grid-column: 1 / -1;
    }
    .family-ltp { text-align: left; }
}

.instrument-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.1rem 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}
.instrument-card header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}
.instrument-card .sym {
    font-family: var(--display);
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--ink);
    text-decoration: none;
}
.instrument-card .sym:hover { color: var(--accent); }
.ltp-block { text-align: right; }
.ltp-block .label {
    display: block;
    font-size: 0.72rem;
    text-transform: uppercase;
    color: var(--muted);
}
.ltp-block strong {
    font-family: var(--display);
    font-size: 1.35rem;
}

.signal-block {
    border-top: 1px solid var(--border);
    padding-top: 0.75rem;
}
.signal-top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.45rem;
    margin-bottom: 0.4rem;
}
.mini-plan {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    font-size: 0.85rem;
    color: var(--muted);
}
.mini-plan b { color: var(--ink); }

.instrument-card footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: auto;
    padding-top: 0.35rem;
}
.instrument-card footer a {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.9rem;
}

.side-tag {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.score-mini {
    font-family: var(--display);
    font-weight: 600;
    font-size: 0.95rem;
}

.score-panel .score {
    font-family: var(--display);
    font-size: 2.5rem;
    margin: 0.25rem 0;
}
.score.bullish, .bullish, .score-mini.bullish { color: var(--breakout); }
.score.bearish, .bearish, .score-mini.bearish { color: var(--breakdown); }

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

.detail-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 1.25rem;
    align-items: start;
}
.detail-side .sticky-panel {
    position: sticky;
    top: 1rem;
}

.checklist {
    list-style: none;
    padding: 0;
    margin: 0.75rem 0 0;
}
.checklist li {
    display: flex;
    gap: 0.65rem;
    padding: 0.65rem 0;
    border-bottom: 1px solid var(--border);
}
.checklist li:last-child { border-bottom: none; }
.checklist .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-top: 0.35rem;
    background: #d6d3d1;
    flex-shrink: 0;
}
.checklist li.fired .dot { background: var(--breakout); box-shadow: 0 0 0 3px rgba(22, 101, 52, 0.15); }
.checklist strong { display: inline; margin-right: 0.35rem; }
.checklist p {
    margin: 0.25rem 0 0;
    font-size: 0.82rem;
    color: var(--muted);
    line-height: 1.4;
}

.live-signal-list { display: flex; flex-direction: column; gap: 0.75rem; }
.live-signal-item {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem;
    background: #fff;
}
.live-signal-item p {
    margin: 0.4rem 0 0;
    font-size: 0.9rem;
    line-height: 1.45;
}

.table-wrap { overflow-x: auto; }
.reason-cell {
    max-width: 280px;
    font-size: 0.85rem;
    line-height: 1.4;
}

.login-box {
    max-width: 380px;
    margin: 4rem auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 2rem;
}
.login-box h1 {
    font-family: var(--display);
    margin-top: 0;
}

label {
    display: block;
    margin: 0.75rem 0 0.35rem;
    font-size: 0.9rem;
}
input, select, button { font: inherit; }
input[type="text"],
input[type="password"],
select {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
}

button, .btn-danger, .secondary-btn {
    margin-top: 1rem;
    padding: 0.65rem 1rem;
    border: none;
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
}
.secondary-btn {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent);
    margin-top: 0.75rem;
}
.btn-danger {
    margin-top: 0;
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
    font-size: 0.85rem;
    padding: 0.35rem 0.6rem;
}

.inline-form {
    display: grid;
    grid-template-columns: 1.4fr 1.6fr 1fr auto;
    gap: 0.5rem;
    align-items: end;
}
.inline-form button { margin-top: 0; }

.search-results {
    list-style: none;
    padding: 0;
    margin: 0.75rem 0 0;
}
.search-results li {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 0.35rem;
    cursor: pointer;
    background: #fff;
}
.search-results li:hover { background: var(--accent-soft); }

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
}
.data-table th,
.data-table td {
    text-align: left;
    padding: 0.7rem 0.8rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.data-table th {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    background: #faf7f1;
}

.badge {
    display: inline-block;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    margin-right: 0.2rem;
    background: #f5f5f4;
    color: #44403c;
}
.badge.breakout, .badge.orb_buy, .badge.pullback_buy, .badge.vwap_buy, .badge.btst_buy {
    background: #dcfce7;
    color: var(--breakout);
}
.badge.breakdown, .badge.orb_sell, .badge.pullback_sell, .badge.vwap_sell, .badge.btst_sell {
    background: #ffe4e6;
    color: var(--breakdown);
}

.session-panel .session-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}
.session-panel h2 { margin: 0; }
.live-pill {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 600;
}
.btst-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 0.75rem;
}
.btst-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.9rem;
    background: #fff;
}
.btst-card.buy { border-left: 3px solid var(--breakout); }
.btst-card.sell { border-left: 3px solid var(--breakdown); }
.btst-card header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.4rem;
}
.btst-card header a {
    font-family: var(--display);
    font-weight: 600;
    color: var(--ink);
    text-decoration: none;
}

.alert-error {
    background: #ffe4e6;
    color: var(--danger);
    padding: 0.75rem;
    border-radius: 6px;
    margin-bottom: 1rem;
}

.trade-plan-panel .trade-plan-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 0.9rem;
    margin: 0.75rem 0;
}
.trade-plan-panel .label {
    display: block;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin-bottom: 0.2rem;
}

.why-reason {
    line-height: 1.55;
    max-width: 52rem;
    margin: 0.5rem 0 0.75rem;
}
.flash-ok {
    background: var(--accent-soft);
    color: var(--accent);
    padding: 0.65rem 0.9rem;
    border-radius: 6px;
    margin: 0.75rem 0;
}
.verdict-panel .why-reason { max-width: none; }
.paper-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    align-items: end;
}
.paper-form label {
    margin: 0;
    font-size: 0.8rem;
    color: var(--muted);
}
.paper-form button { margin-top: 0; }
.inline-close {
    display: flex;
    gap: 0.35rem;
    align-items: center;
}
.inline-close button { margin-top: 0; }
.data-table.compact th,
.data-table.compact td {
    padding: 0.45rem 0.5rem;
    font-size: 0.82rem;
}
.badge.manual {
    background: #e7e5e4;
    color: #44403c;
}

/* —— Settings page —— */
.settings-jump {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 0.85rem;
    margin: 0 0 1.25rem;
    padding-bottom: 0.85rem;
    border-bottom: 1px solid var(--border);
}
.settings-jump a {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
}
.settings-jump a:hover { text-decoration: underline; }

.settings-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}
.setting-row {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) auto;
    gap: 0.75rem 1rem;
    align-items: start;
    padding: 0.95rem 0;
    border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: none; }
.setting-row.is-overridden {
    background: linear-gradient(90deg, rgba(216, 235, 227, 0.35), transparent);
    margin: 0 -0.5rem;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    border-radius: 6px;
}
.setting-meta label {
    margin: 0;
    font-weight: 600;
    font-size: 0.95rem;
}
.setting-key {
    display: inline-block;
    margin: 0.2rem 0.4rem 0 0;
    font-size: 0.72rem;
    color: var(--muted);
    background: #f5f5f4;
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
}
.override-pill {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--accent);
    background: var(--accent-soft);
    padding: 0.12rem 0.4rem;
    border-radius: 4px;
}
.setting-meta .muted {
    margin: 0.35rem 0 0;
    font-size: 0.82rem;
    line-height: 1.4;
}
.setting-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    align-items: center;
}
.setting-controls input,
.setting-controls select {
    flex: 1;
    min-width: 8rem;
    margin: 0;
}
.setting-controls button,
.settings-actions button,
.add-setting-form button {
    margin-top: 0;
}
.setting-reset { margin: 0; }
.toggle-label {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    cursor: pointer;
    font-size: 0.9rem;
}
.toggle-label input[type="checkbox"] {
    width: 1.05rem;
    height: 1.05rem;
    accent-color: var(--accent);
}
.settings-actions {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}
.add-setting-form {
    margin-top: 0.5rem;
}

.range-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin: 0.5rem 0 0.85rem;
}
.preset-chip {
    display: inline-block;
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    text-decoration: none;
    color: var(--ink);
    font-size: 0.85rem;
    font-weight: 500;
    background: #fff;
}
.preset-chip:hover { border-color: var(--accent); color: var(--accent); }
.preset-chip.active {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}
.range-form {
    max-width: 36rem;
}
.range-form button { align-self: end; }

@media (max-width: 900px) {
    .setting-row {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
    .setting-controls { width: 100%; }
    .setting-controls input,
    .setting-controls select { min-width: 0; width: 100%; }
}

@media (max-width: 960px) {
    .detail-layout { grid-template-columns: 1fr; }
    .detail-side .sticky-panel { position: static; }
    .stats-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
    .app-shell { display: block; }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-105%);
        transition: transform 0.22s ease;
        box-shadow: none;
        height: 100dvh;
    }
    body.sidebar-open .sidebar {
        transform: translateX(0);
        box-shadow: 8px 0 24px rgba(28, 25, 23, 0.12);
    }
    .sidebar-close { display: inline-block; }
    .sidebar-backdrop { display: block; }
    body.sidebar-open .sidebar-backdrop { display: block; }
    .sidebar-backdrop[hidden] { display: none !important; }

    .mobile-topbar { display: flex; }

    .container {
        padding: 1rem;
        padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
    }

    .page-header h1 { font-size: 1.55rem; }
    .watchlist-cards {
        grid-template-columns: 1fr;
    }
    .btst-grid {
        grid-template-columns: 1fr;
    }
    .instrument-card header {
        flex-wrap: wrap;
    }
    .ltp-block { text-align: left; }
    .inline-form { grid-template-columns: 1fr; }
    .paper-form { grid-template-columns: 1fr 1fr; }
    .inline-close {
        flex-wrap: wrap;
        width: 100%;
    }
    .inline-close input { flex: 1; min-width: 0; }
    .data-table { font-size: 0.85rem; }
    .data-table th,
    .data-table td {
        padding: 0.55rem 0.5rem;
        white-space: nowrap;
    }
    .reason-cell {
        white-space: normal;
        max-width: 200px;
    }
    .login-box {
        margin: 2rem auto;
        padding: 1.5rem;
    }
}

@media (max-width: 800px) {
    .stats-row { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 520px) {
    .stats-row { grid-template-columns: 1fr; }
    .paper-form { grid-template-columns: 1fr; }
    .stat-tile strong { font-size: 1.45rem; }
    .score-panel .score { font-size: 2rem; }
    .session-panel .session-header {
        flex-direction: column;
        align-items: flex-start;
    }
}
