:root {
    --bg: #f6f2e9;
    --panel: #fffdf8;
    --line: rgba(117, 99, 73, 0.18);
    --line-strong: rgba(117, 99, 73, 0.28);
    --text: #1f1e1a;
    --muted: #6b655a;
    --accent: #0f766e;
    --accent-soft: rgba(15, 118, 110, 0.12);
    --accent-2: #b45309;
    --accent-2-soft: rgba(180, 83, 9, 0.12);
    --danger: #b91c1c;
    --danger-soft: rgba(185, 28, 28, 0.12);
    --good: #166534;
    --good-soft: rgba(22, 101, 52, 0.12);
    --shadow: 0 20px 60px rgba(67, 52, 31, 0.08);
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: "Segoe UI", "Inter", sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top right, rgba(180, 83, 9, 0.16), transparent 24%),
        radial-gradient(circle at top left, rgba(15, 118, 110, 0.08), transparent 24%),
        linear-gradient(180deg, #fbf7f0 0%, #efe7da 100%);
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto 1fr;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    justify-content: space-between;
    gap: 24px;
    align-items: end;
    padding: 24px 28px 20px;
    background: rgba(250, 246, 238, 0.9);
    backdrop-filter: blur(18px);
    border-bottom: 1px solid var(--line);
}

.brand-block h1,
.panel-header h2,
.page-header-card h2,
.dashboard-hero h2 {
    margin: 4px 0 8px;
    font-size: 1.55rem;
}

.brand-block p,
.muted {
    color: var(--muted);
}

.page-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: end;
}

.nav-tab {
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.65);
    color: var(--text);
    border-radius: 999px;
    padding: 11px 16px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}

.nav-tab:hover {
    transform: translateY(-1px);
}

.nav-tab.is-active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    box-shadow: 0 12px 28px rgba(15, 118, 110, 0.22);
}

.workspace {
    padding: 28px;
}

.page-section {
    display: none;
    gap: 22px;
}

.page-section.is-active {
    display: grid;
}

.dashboard-hero,
.page-header-card {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 16px;
}

.page-header-card,
.panel,
.metric-card,
.status-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 24px;
    box-shadow: var(--shadow);
}

.page-header-card {
    padding: 22px 24px;
}

.panel,
.status-card {
    padding: 20px;
}

.compact-panel {
    padding: 18px;
}

.eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.72rem;
    color: var(--accent-2);
    font-weight: 700;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin-top: 8px;
}

.compact-grid {
    margin-top: 0;
}

.form-grid label {
    display: grid;
    gap: 6px;
    font-size: 0.92rem;
}

.form-grid label span {
    color: var(--muted);
}

.full {
    grid-column: 1 / -1;
}

input,
select,
button {
    font: inherit;
}

input,
select {
    width: 100%;
    border: 1px solid var(--line-strong);
    background: #fff;
    color: var(--text);
    border-radius: 14px;
    padding: 11px 12px;
}

.instrument-search-input {
    background: linear-gradient(180deg, #fffdf9 0%, #fbf4e8 100%);
    border-color: rgba(15, 118, 110, 0.28);
}

.instrument-search-input:focus {
    outline: 2px solid rgba(15, 118, 110, 0.18);
    border-color: var(--accent);
}

textarea {
    width: 100%;
    border: 1px solid var(--line-strong);
    background: #fff;
    color: var(--text);
    border-radius: 14px;
    padding: 11px 12px;
    resize: vertical;
    min-height: 72px;
    font: inherit;
}

button {
    border: 0;
    border-radius: 14px;
    padding: 12px 16px;
    cursor: pointer;
    font-weight: 700;
}

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

#run-button,
#start-live-button,
#save-settings-button,
#zerodha-login-button {
    background: var(--accent);
    color: white;
}

.secondary {
    background: #efe5d6;
    color: var(--text);
}

.danger-button {
    background: var(--danger);
    color: #fff;
}

.actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.inline-actions {
    display: flex;
    gap: 10px;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 14px;
}

.metric-card {
    padding: 18px;
}

.metric-card .label {
    color: var(--muted);
    font-size: 0.85rem;
}

.metric-card .value {
    margin-top: 8px;
    font-size: 1.35rem;
    font-weight: 800;
}

.metric-card .subtext {
    margin-top: 10px;
    color: var(--muted);
    font-size: 0.86rem;
    line-height: 1.4;
}

.metric-card.good {
    border-color: rgba(22, 101, 52, 0.24);
}

.metric-card.danger {
    border-color: rgba(185, 28, 28, 0.24);
}

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

.status-card {
    display: grid;
    gap: 10px;
}

.status-line {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 6px 0;
}

.status-line.compact {
    margin: 0;
    font-size: 0.98rem;
}

.progress-track {
    height: 10px;
    background: #ede7dc;
    border-radius: 999px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), #38bdf8);
}

.broker-card,
.strategy-config-card {
    display: grid;
    gap: 12px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255, 253, 248, 0.9);
}

.broker-actions {
    grid-template-columns: 1fr 1fr;
}

.field-note,
.tiny-note {
    color: var(--muted);
    font-size: 0.78rem;
    line-height: 1.45;
}

.live-running-list {
    display: grid;
    gap: 10px;
}

.live-running-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255, 253, 248, 0.9);
}

.live-running-meta {
    min-width: 0;
    display: grid;
    gap: 4px;
}

.live-running-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.live-running-title {
    font-weight: 700;
    color: var(--ink);
}

.stream-detail-section {
    display: none;
}

.stream-detail-section.is-active {
    display: grid;
    gap: 18px;
}

.embedded-split {
    padding: 0;
    border: 0;
    box-shadow: none;
    background: transparent;
}

.tall-table-wrap {
    max-height: 560px;
}

.settings-flags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tiny-note code {
    font-family: Consolas, monospace;
    background: #f2eadc;
    padding: 2px 6px;
    border-radius: 8px;
}

.split-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.sub-panel {
    min-width: 0;
}

.table-wrap {
    overflow: auto;
    max-height: 360px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #fff;
}

.journal-wrap {
    max-height: 440px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

th,
td {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(107, 101, 90, 0.12);
    text-align: left;
    white-space: nowrap;
}

th {
    position: sticky;
    top: 0;
    background: #faf7f1;
    z-index: 1;
}

td:last-child,
th:last-child {
    white-space: normal;
}

.chart-panel canvas,
#live-candle-chart {
    width: 100%;
    height: auto;
    border-radius: 16px;
}

.chart-panel canvas {
    background:
        linear-gradient(180deg, rgba(15, 118, 110, 0.08), transparent 60%),
        #fff;
    border: 1px solid rgba(15, 118, 110, 0.12);
}

#live-candle-chart {
    margin-top: 12px;
    background:
        linear-gradient(180deg, rgba(180, 83, 9, 0.08), transparent 60%),
        #fff;
    border: 1px solid rgba(180, 83, 9, 0.12);
}

.pos {
    color: var(--good);
}

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

.pill {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
}

.pill.good {
    background: var(--good-soft);
    color: var(--good);
}

.pill.warn {
    background: var(--accent-2-soft);
    color: var(--accent-2);
}

.pill.danger {
    background: var(--danger-soft);
    color: var(--danger);
}

.pill.neutral {
    background: rgba(107, 101, 90, 0.1);
    color: var(--muted);
}

.auth-overlay {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(circle at top, rgba(180, 83, 9, 0.18), transparent 38%),
        rgba(27, 24, 19, 0.72);
    backdrop-filter: blur(10px);
}

.auth-overlay.is-visible {
    display: flex;
}

.auth-card {
    width: min(460px, 100%);
    display: grid;
    gap: 16px;
    padding: 28px;
    border-radius: 28px;
    background: #fffdf8;
    border: 1px solid rgba(107, 101, 90, 0.18);
    box-shadow: 0 24px 60px rgba(27, 24, 19, 0.24);
}

.auth-form {
    display: none;
    gap: 14px;
}

.auth-form.is-visible {
    display: grid;
}

.auth-form h3 {
    margin: 0;
    color: var(--ink);
}

.auth-form label {
    display: grid;
    gap: 6px;
}

.auth-form input {
    width: 100%;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
}

.topbar-auth {
    display: flex;
    align-items: center;
    gap: 10px;
}

@media (max-width: 1180px) {
    .topbar,
    .dashboard-hero,
    .page-header-card {
        align-items: start;
        flex-direction: column;
    }

    .split-panel {
        grid-template-columns: 1fr;
    }

    .live-running-card {
        align-items: start;
        flex-direction: column;
    }
}

@media (max-width: 760px) {
    .workspace,
    .topbar {
        padding: 18px;
    }

    .form-grid,
    .actions {
        grid-template-columns: 1fr;
    }

    .page-nav {
        width: 100%;
        justify-content: start;
    }

    .nav-tab {
        flex: 1 1 calc(50% - 10px);
        text-align: center;
    }
}
