:root {
    --bg: #08111f;
    --card: #111827;
    --line: #24334a;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --up: #ef4444;
    --down: #3b82f6;
}

* { box-sizing: border-box; }

.login-gate {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: grid;
    align-content: center;
    justify-items: center;
    gap: 10px;
    padding: 32px 28px;
    background: #08111f;
}

.login-gate[hidden] { display: none !important; }

.login-gate label,
.login-gate button,
.login-gate p {
    width: 100%;
}

@media (min-width: 901px) {
    .login-gate label,
    .login-gate button,
    .login-gate p {
        width: 280px;
    }
}

.login-gate label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.login-gate input,
.login-gate button {
    box-sizing: border-box;
    border-radius: 8px;
}

.login-gate input {
    width: 100%;
    height: 36px;
    font-size: 14px;
}

.login-gate button {
    height: 32px;
    font-size: 13px;
}

.login-gate input {
    border: 1px solid #334155;
    background: #0b1526;
    color: var(--text);
    padding: 0 12px;
}

.login-gate button {
    border: 0;
    background: #1e3a5f;
    color: #e5e7eb;
    font-weight: 800;
    cursor: pointer;
}

.login-gate p { min-height: 18px; margin: 0; color: #fca5a5; font-size: 12px; }

html, body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: Pretendard, "Noto Sans KR", sans-serif;
    overflow-x: hidden;
}

button, input { font-family: inherit; }

.shell {
    min-height: 100%;
    display: flex;
    flex-direction: column;
    gap: 22px;
    padding: 12px 0 20px;
    padding-top: calc(env(safe-area-inset-top) + 12px);
}

.section-title {
    margin: 0 0 12px;
    font-size: 13px;
    font-weight: 750;
}

.mode-dock .section-title,
.symbol-dock .section-title { margin-bottom: 0; }

.symbol-line {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.symbol-line span { color: var(--muted); }

.hold-title {
    margin: 0 0 12px;
    font-size: 13px;
}

.account-stack {
    display: grid;
    gap: 18px;
}

#accountPanel[hidden],
#logPanel[hidden] {
    display: none !important;
}

.order-target {
    margin: -4px 0 12px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.app-nav {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    min-height: 48px;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
    border-bottom: 1px solid var(--line);
    background: #061018;
}

.app-nav strong {
    font-size: 13px;
    letter-spacing: 0.04em;
}

.symbol-dock,
.account-summary,
.quote-order,
.chart-pane,
.side-pane {
    margin: 0 12px;
}

.symbol-dock {
    display: grid;
    gap: 12px;
    padding: 16px;
    border-radius: 16px;
}

.env-bar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin: 0 12px -6px;
}

.brand {
    margin: 2px 0 0;
    color: #e5e7eb;
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.brand-block { display: grid; justify-items: start; gap: 6px; }

.logout-btn {
    height: 24px;
    padding: 0 8px;
    border: 1px solid #24334a;
    border-radius: 6px;
    background: #0b1220;
    color: #94a3b8;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
}

.top-controls {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
}

.top-toggle {
    display: grid;
    grid-template-columns: 64px 168px;
    align-items: center;
    column-gap: 8px;
}

.top-toggle > span {
    color: var(--muted);
    font-size: 11px;
    font-weight: 750;
    letter-spacing: 0.02em;
}

.symbol-dock { background: #101827; }

.env-dock-label,
.mode-dock-label,
.symbol-dock-label {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 10px;
}

.env-dock-label strong,
.mode-dock-label strong,
.symbol-dock-label strong {
    font-size: 13px;
}

.env-badge,
.mode-badge,
.symbol-badge,
.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 800;
}

.env-badge.mock { background: #14532d; color: #86efac; }
.env-badge.real { background: #3f3f46; color: #d4d4d8; }
.badge { background: #172554; color: #bfdbfe; }
.mode-badge.auto { background: #14532d; color: #86efac; }
.mode-badge.manual { background: #172554; color: #93c5fd; }
.symbol-badge { background: #1e3a5f; color: #dbeafe; }

.env-segments,
.mode-segments {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 168px;
    padding: 2px;
    border: 1px solid #24334a;
    border-radius: 8px;
    background: #0b1220;
}

.symbol-segments {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    width: 100%;
    padding: 5px;
    border-radius: 9px;
    background: #0b1526;
}

.env-segments button,
.mode-segments button {
    width: 100%;
    min-height: 26px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #94a3b8;
    font-size: 11px;
    font-weight: 750;
    cursor: pointer;
    touch-action: manipulation;
}

.symbol-segments button {
    min-height: 46px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
    touch-action: manipulation;
}

.env-segments button.active[data-env="MOCK"],
.mode-segments button.active[data-mode="MANUAL"] { background: #14532d; color: #bbf7d0; }
.env-segments button.active[data-env="REAL"],
.mode-segments button.active[data-mode="AUTO"] { background: #7f1d1d; color: #fecaca; }
.symbol-segments button.active { background: #1d4ed8; color: white; }

.lock-note {
    width: 100%;
    margin: 0;
    color: #fca5a5;
    font-size: 11px;
    font-weight: 700;
    text-align: right;
}

.quote-order {
    display: grid;
    gap: 16px;
    padding: 16px;
    border-radius: 16px;
    background: #0b1526;
}

.quote-block { display: grid; gap: 12px; }

.session-stats {
    display: grid;
    gap: 4px;
    max-width: 220px;
}

.session-stats div {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    font-size: 12px;
}

.session-stats span { color: var(--muted); }

.session-stats b { font-weight: 650; color: var(--text); }

#highPrice { color: var(--up); }

#lowPrice { color: var(--down); }

.order-card { width: 100%; }

.order-card .paper-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.order-card .paper-controls label {
    grid-column: 1 / -1;
}

.brand {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.brand-mark {
    background: var(--up);
    color: white;
    font-size: 11px;
    font-weight: 800;
    padding: 6px 8px;
    border-radius: 8px;
}

.brand small,
.quote-label,
.muted,
.note {
    color: var(--muted);
}

.brand small { display: block; font-size: 12px; }

.quote {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 4px 12px;
    align-items: end;
}

.quote-label { grid-column: 1 / -1; font-size: 12px; }

.price {
    font-size: 34px;
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1.05;
}

.change {
    font-size: 16px;
    font-weight: 800;
    padding-bottom: 4px;
}

.up { color: var(--up); }
.down { color: var(--down); }

.phase-badge {
    border-radius: 12px;
    padding: 12px 14px;
    border: 1px solid #263449;
    background: #131c2c;
    color: #cbd5e1;
}

.phase-badge strong { display: block; font-size: 14px; }
.phase-badge small { display: block; margin-top: 4px; font-size: 12px; color: var(--muted); }

.workspace { width: 100%; }

.chart-pane { padding: 4px 0 0; }

.chart-toolbar {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
}

.chart-heading strong { font-size: 14px; }

.interval-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    overflow-x: auto;
    scrollbar-width: none;
}

.interval-bar::-webkit-scrollbar { display: none; }

.interval-bar button {
    flex: 0 0 auto;
    min-height: 36px;
    padding: 8px 11px;
    border: 1px solid #2b3d57;
    border-radius: 8px;
    background: #16233a;
    color: #94a3b8;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

.interval-bar button.active {
    background: #1d4ed8;
    border-color: #3b82f6;
    color: #f8fafc;
}

.tv-frame {
    height: min(52svh, 480px);
    min-height: 320px;
    border-radius: 14px;
    overflow: hidden;
    background: #0b1422;
}

.tv-frame iframe { width: 100%; height: 100%; border: 0; }

.side-pane {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 0 0 calc(28px + env(safe-area-inset-bottom, 0px));
}

.tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #0b1526;
}

.tabs button {
    min-height: 44px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
}

.tabs button.active { background: #1d4ed8; color: white; }

.card {
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--card);
}

.account-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 12px;
}

.account-head h3 { margin: 0; font-size: 13px; }

.chip {
    border-radius: 999px;
    padding: 4px 8px;
    background: #3f1212;
    color: #f87171;
    font-size: 11px;
    font-weight: 800;
}

.chip.manual { background: #172554; color: #93c5fd; }

.account-grid,
.trail {
    display: grid;
    gap: 10px;
}

.account-grid div,
.trail div {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    border-bottom: 1px solid #1a2436;
    padding-bottom: 8px;
    font-size: 14px;
}

.account-grid span,
.trail span { color: var(--muted); }

.note { margin: 8px 0 0; font-size: 12px; line-height: 1.45; }

.trail { margin-top: 10px; }

.paper-controls {
    display: grid;
    gap: 10px;
}

.paper-controls label {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
}

.stepper {
    display: grid;
    grid-template-columns: 36px 1fr 36px;
    gap: 4px;
    margin-top: 4px;
}

.stepper button,
.stepper input {
    height: 44px;
    border: 1px solid #334155;
    border-radius: 7px;
    background: #0b1526;
    color: var(--text);
    font-size: 16px;
    font-weight: 800;
    text-align: center;
}

.order-btn {
    height: 44px;
    border: 0;
    border-radius: 7px;
    color: white;
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
}

.buy-btn { background: var(--up); }
.sell-btn { background: var(--down); }

.order-btn:disabled {
    background: #374151;
    color: #94a3b8;
    cursor: not-allowed;
}

.order-message { min-height: 16px; margin: 8px 0 0; color: var(--muted); font-size: 12px; }

.day-head {
    width: 100%;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border: 0;
    background: transparent;
    color: var(--text);
    text-align: left;
    cursor: pointer;
}

.day-head small,
.log-item small,
.empty { color: var(--muted); }

.log-item {
    display: grid;
    gap: 2px;
    padding: 10px 0;
    border-top: 1px solid #1a2436;
}

.log-item b { font-size: 15px; }

@media (min-width: 901px) {
    .shell {
        width: min(1100px, calc(100% - 32px));
        margin: 16px auto 32px;
        gap: 26px;
        padding: 0 0 24px;
        border: 1px solid var(--line);
        border-radius: 18px;
        overflow: hidden;
        background: #061018;
    }
    .app-nav { position: static; margin: 0; }
    .symbol-dock {
        grid-template-columns: minmax(160px, 220px) minmax(280px, 420px);
        align-items: center;
        justify-content: space-between;
    }
    .symbol-dock .section-title,
.order-card .section-title,
.account-summary .section-title { margin-bottom: 12px; }
    .env-bar { margin: 8px 12px -8px; }
    .quote-order {
        grid-template-columns: minmax(0, 1fr) 340px;
        align-items: start;
    }
    .quote-order .phase-badge { grid-column: 1 / -1; }
    .order-card { width: 340px; }
    .price { font-size: 40px; }
    .chart-toolbar {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
    .tv-frame { height: 520px; }
    .summary-grid { grid-template-columns: 1fr; }
    .side-pane { padding-bottom: 8px; }
}

@media (max-width: 900px) {
    .brand { font-size: 13px; }
    .brand-block { min-width: 0; }
    .workspace,
    .tv-frame {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        box-sizing: border-box;
    }
    .chart-pane {
        width: calc(100% - 24px);
        max-width: calc(100% - 24px);
        margin-left: auto;
        margin-right: auto;
        min-width: 0;
        box-sizing: border-box;
        overflow-x: hidden;
    }
    .tv-frame .js-plotly-plot,
    .tv-frame .plot-container,
    .tv-frame .svg-container,
    .tv-frame svg,
    .tv-frame canvas {
        max-width: 100%;
    }
    .order-card,
    .order-card .paper-controls,
    .order-card .paper-controls label,
    .stepper,
    .order-btn {
        box-sizing: border-box;
        max-width: 100%;
        min-width: 0;
    }
    .order-card .paper-controls {
        width: 100%;
        margin-inline: auto;
        padding: 0;
        justify-items: stretch;
    }
    .order-card .paper-controls label {
        width: 100%;
        margin: 0;
        padding: 0;
    }
    .stepper {
        display: grid;
        grid-template-columns: 40px minmax(0, 1fr) 40px;
        gap: 8px;
        width: 100%;
        margin: 4px 0 0;
        box-sizing: border-box;
    }
    .stepper button,
    .stepper input {
        width: 100%;
        min-width: 0;
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }
    .stepper input {
        -moz-appearance: textfield;
        appearance: textfield;
    }
    .stepper input::-webkit-outer-spin-button,
    .stepper input::-webkit-inner-spin-button {
        -webkit-appearance: none;
        margin: 0;
    }
    .order-btn {
        width: 100%;
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }
}

@media (max-width: 479px) {
    .price { font-size: 32px; }
    .symbol-segments button { font-size: 12px; padding: 0 6px; }
}
