:root {
    color-scheme: dark;
    --bg: #080b13;
    --panel: rgba(20, 25, 39, 0.9);
    --panel-border: #2a3144;
    --text: #f4f6fb;
    --muted: #929bb0;
    --accent: #7667ff;
    --accent-strong: #8c80ff;
    --green: #48d597;
    --red: #ff667d;
    --amber: #f3be62;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background:
        radial-gradient(circle at 85% 0%, rgba(118, 103, 255, 0.2), transparent 32rem),
        linear-gradient(145deg, #090c14 0%, #0d101a 55%, #090b11 100%);
    font-family: Inter, Pretendard, "Noto Sans KR", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input { font: inherit; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2rem;
    padding: 1.1rem clamp(1rem, 4vw, 3.5rem);
    border-bottom: 1px solid var(--panel-border);
    background: rgba(8, 11, 19, 0.86);
    backdrop-filter: blur(18px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    color: inherit;
    text-decoration: none;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 2.7rem;
    height: 2.7rem;
    border-radius: 0.85rem;
    background: linear-gradient(145deg, var(--accent-strong), #5143dc);
    font-weight: 800;
    box-shadow: 0 0 2rem rgba(118, 103, 255, 0.28);
}

.brand strong, .brand small { display: block; }
.brand small { margin-top: 0.15rem; color: var(--muted); font-size: 0.72rem; }

.topbar-controls { display: flex; flex-direction: column; align-items: flex-end; gap: 0.3rem; }
.topbar-meta { display: flex; align-items: center; justify-content: flex-end; gap: 0.6rem; }
.topbar-link { color: var(--muted); font-size: 0.68rem; text-decoration: none; }
.topbar-link:hover { color: var(--text); }
.build-version { color: #697287; font: 0.64rem ui-monospace, SFMono-Regular, monospace; letter-spacing: 0.03em; }
.login-panel-toggle {
    padding: 0.15rem 0.35rem;
    color: var(--muted);
    border: 0;
    background: transparent;
    cursor: pointer;
    font-size: 0.68rem;
}
.login-panel-toggle:hover { color: var(--text); }
.topbar-controls.collapsed .key-control { display: none; }

.key-control {
    display: grid;
    grid-template-columns: auto minmax(20rem, 34rem) auto;
    align-items: center;
    gap: 0.6rem 0.8rem;
}

.key-control > label { color: var(--muted); font-size: 0.78rem; font-weight: 700; }
.key-field { min-width: 0; }
.key-input { display: flex; gap: 0.45rem; }
.key-input input { min-width: 0; flex: 1; }
.remember-key {
    display: inline-flex;
    align-items: center;
    gap: 0.42rem;
    margin-top: 0.45rem;
    color: var(--muted);
    cursor: pointer;
    font-size: 0.72rem;
}
.remember-key input { width: 0.9rem; min-height: 0.9rem; margin: 0; accent-color: var(--accent); }

input {
    width: 100%;
    min-height: 2.65rem;
    padding: 0.65rem 0.8rem;
    color: var(--text);
    border: 1px solid #343c51;
    border-radius: 0.65rem;
    outline: none;
    background: #0e1320;
}

input:focus {
    border-color: var(--accent-strong);
    box-shadow: 0 0 0 3px rgba(118, 103, 255, 0.14);
}

.button {
    min-height: 2.65rem;
    padding: 0.62rem 1rem;
    color: var(--text);
    border: 1px solid transparent;
    border-radius: 0.65rem;
    cursor: pointer;
    font-weight: 750;
}

.button:disabled { cursor: wait; opacity: 0.55; }
.button.primary { background: var(--accent); }
.button.primary:hover { background: var(--accent-strong); }
.button.quiet { border-color: #343c51; background: #161c2a; }
.button.danger { color: #ffd7dd; border-color: rgba(255, 102, 125, 0.35); background: rgba(255, 102, 125, 0.1); }
.button.activate { color: #c9ffe7; border-color: rgba(72, 213, 151, 0.35); background: rgba(72, 213, 151, 0.1); }

.status {
    padding: 0.38rem 0.65rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 800;
    white-space: nowrap;
}

.status.neutral { color: var(--muted); background: #171d2a; }
.status.ok { color: #b9f9d9; background: rgba(72, 213, 151, 0.13); }
.status.error { color: #ffd1d8; background: rgba(255, 102, 125, 0.13); }

main { width: min(1180px, calc(100% - 2rem)); margin: 0 auto; padding: 3rem 0 5rem; }

.hero {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 2rem;
    margin-bottom: 1.6rem;
}

.eyebrow { margin: 0 0 0.45rem; color: var(--accent-strong); font-size: 0.72rem; font-weight: 850; letter-spacing: 0.15em; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0.65rem; font-size: clamp(2.3rem, 6vw, 4.6rem); letter-spacing: -0.065em; }
h2 { margin-bottom: 0; font-size: 1.28rem; }
.subtext { max-width: 44rem; margin-bottom: 0; color: var(--muted); line-height: 1.65; }

.summary { display: flex; border: 1px solid var(--panel-border); border-radius: 1rem; overflow: hidden; background: rgba(12, 16, 26, 0.72); }
.summary div { min-width: 5.5rem; padding: 0.85rem 1rem; text-align: center; border-left: 1px solid var(--panel-border); }
.summary div:first-child { border-left: 0; }
.summary strong, .summary span { display: block; }
.summary strong { font-size: 1.45rem; }
.summary span { margin-top: 0.2rem; color: var(--muted); font-size: 0.73rem; }

.panel {
    margin-top: 1rem;
    padding: 1.35rem;
    border: 1px solid var(--panel-border);
    border-radius: 1rem;
    background: var(--panel);
    box-shadow: 0 1.4rem 4rem rgba(0, 0, 0, 0.18);
}

.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.2rem; }
.market-badge { padding: 0.35rem 0.58rem; color: #d4ceff; border: 1px solid rgba(140, 128, 255, 0.4); border-radius: 0.45rem; font: 750 0.72rem ui-monospace, monospace; }

#watch-form { display: grid; grid-template-columns: minmax(16rem, 1fr) 0.28fr auto; align-items: end; gap: 0.8rem; }
.field label { display: block; margin-bottom: 0.45rem; color: var(--muted); font-size: 0.76rem; font-weight: 750; }
.search-box { position: relative; }
.search-results {
    position: absolute;
    top: calc(100% + 0.4rem);
    left: 0;
    right: 0;
    z-index: 20;
    max-height: 19rem;
    overflow-y: auto;
    padding: 0.4rem;
    border: 1px solid #3b455d;
    border-radius: 0.75rem;
    background: #111725;
    box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.45);
}
.search-results button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.75rem;
    color: var(--text);
    border: 0;
    border-radius: 0.5rem;
    background: transparent;
    cursor: pointer;
    text-align: left;
}
.search-results button:hover, .search-results button:focus { background: #20283a; outline: none; }
.search-results strong { display: block; }
.search-results small { color: var(--muted); font-family: ui-monospace, SFMono-Regular, monospace; }
.search-results .exchange { color: #bdb5ff; font-size: 0.7rem; font-weight: 800; }
.search-result-message { padding: 0.9rem; color: var(--muted); font-size: 0.82rem; }
.selected-stock { margin-top: 0.65rem; color: var(--green); font-size: 0.78rem; }
.form-message { min-height: 1.3rem; margin: 0.7rem 0 0; color: var(--muted); font-size: 0.82rem; }
.form-message.error { color: var(--red); }
.form-message.ok { color: var(--green); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 780px; }
th, td { padding: 0.9rem 0.75rem; border-bottom: 1px solid #252c3c; text-align: left; }
th { color: var(--muted); font-size: 0.71rem; letter-spacing: 0.05em; text-transform: uppercase; }
td { font-size: 0.88rem; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.inactive { opacity: 0.58; }
tbody tr.stock-row { cursor: pointer; }
tbody tr.stock-row:hover, tbody tr.stock-row.selected { background: rgba(118, 103, 255, 0.08); }
tbody tr.stock-row:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.stock-name { display: block; margin-bottom: 0.18rem; font-weight: 760; }
.stock-symbol { color: var(--muted); font: 0.76rem ui-monospace, SFMono-Regular, monospace; }
.state-dot { display: inline-block; width: 0.48rem; height: 0.48rem; margin-right: 0.45rem; border-radius: 50%; background: var(--red); }
.state-dot.active { background: var(--green); box-shadow: 0 0 0.8rem rgba(72, 213, 151, 0.5); }
.quote-pending { color: var(--muted); }
.action-column { text-align: right; }
td.action-column .button { min-height: 2.15rem; padding: 0.4rem 0.7rem; font-size: 0.76rem; }
.empty-state { padding: 2.4rem 1rem; color: var(--muted); text-align: center; }

.chart-panel {
    margin-top: 1.2rem;
    padding-top: 1.35rem;
    border-top: 1px solid var(--panel-border);
}
.chart-panel[hidden], .chart-loading[hidden] { display: none; }
.chart-header { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 1.1rem; }
.chart-header h3 { margin: 0; font-size: 1.35rem; }
.chart-symbol { margin-bottom: 0.25rem; color: var(--muted); font: 0.78rem ui-monospace, SFMono-Regular, monospace; }
.chart-quote { text-align: right; }
.chart-quote strong, .chart-quote span { display: block; }
.chart-quote strong { font-size: 1.7rem; }
.chart-quote span { margin-top: 0.2rem; color: var(--muted); font-size: 0.82rem; }
.chart-quote.up strong, .chart-quote.up span { color: #ff667d; }
.chart-quote.down strong, .chart-quote.down span { color: #5c9dff; }
.chart-close { min-height: 2.2rem; padding: 0.4rem 0.75rem; }
.market-overview {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.55rem;
    margin-top: 1rem;
}
.market-overview > div {
    min-width: 0;
    padding: 0.72rem 0.8rem;
    border: 1px solid #252c3c;
    border-radius: 0.65rem;
    background: rgba(13, 18, 30, 0.72);
}
.market-overview span, .market-overview strong { display: block; }
.market-overview span { color: var(--muted); font-size: 0.68rem; }
.market-overview strong { margin-top: 0.28rem; font-size: 0.95rem; }
.market-overview small { color: #697287; font-size: 0.62rem; }
.market-overview .up { color: var(--red); }
.market-overview .down { color: #5c9dff; }
.overview-message { min-height: 1rem; margin: 0.45rem 0 0; color: var(--muted); font-size: 0.7rem; }
.overview-message.error { color: var(--red); }
.chart-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.8rem; margin: 1rem 0 0.55rem; color: var(--muted); font-size: 0.72rem; }
.chart-periods { display: inline-flex; gap: 0.35rem; }
.chart-toolbar .period { padding: 0.32rem 0.65rem; border: 1px solid #3a4358; border-radius: 0.4rem; color: var(--muted); background: transparent; font: inherit; cursor: pointer; }
.chart-toolbar .period:hover { color: var(--text); border-color: #59647d; }
.chart-toolbar .period.active { color: var(--text); border-color: var(--accent); background: rgba(118, 103, 255, 0.14); }
.chart-time-zone { color: #778197; font: 0.64rem ui-monospace, SFMono-Regular, monospace; }
.legend::before { content: ""; display: inline-block; width: 0.65rem; height: 0.18rem; margin-right: 0.3rem; vertical-align: middle; background: currentColor; }
.legend.candle { color: #ff667d; }
.legend.ma5 { color: #55d98b; }
.legend.ma20 { color: #ff856e; }
.legend.ma60 { color: #6b8cff; }
.legend.volume { color: #8b95aa; }
.chart-canvas-wrap { position: relative; min-height: 460px; border: 1px solid #252c3c; border-radius: 0.8rem; overflow: hidden; background: #0d121e; }
#price-chart { display: block; width: 100%; height: 460px; }
.chart-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); background: rgba(13, 18, 30, 0.84); }
.chart-message { min-height: 1.2rem; margin: 0.55rem 0 0; color: var(--muted); font-size: 0.78rem; }
.chart-message.error { color: var(--red); }

.trade-history-panel {
    margin-top: 1.5rem;
    padding-top: 1.35rem;
    border-top: 1px solid var(--panel-border);
}
.trade-history-heading { margin-bottom: 0.8rem; }
.activity-tabs { display: flex; gap: 0.45rem; }
.activity-tab {
    min-height: 2.35rem;
    padding: 0.5rem 0.85rem;
    color: var(--muted);
    border: 1px solid #343c51;
    border-radius: 0.58rem;
    background: #131927;
    cursor: pointer;
    font-weight: 750;
}
.activity-tab:hover { color: var(--text); border-color: #59647d; }
.activity-tab.active { color: var(--text); border-color: var(--accent); background: rgba(118, 103, 255, 0.16); }
.activity-tab-panel[hidden] { display: none; }
.activity-panel-summary { display: flex; align-items: center; justify-content: flex-end; gap: 0.75rem; min-height: 2.5rem; margin-bottom: 0.55rem; }
.trade-history-summary { justify-content: space-between; }
.trade-account-filter { display: flex; align-items: center; gap: 0.55rem; color: var(--muted); font-size: 0.78rem; font-weight: 700; }
.trade-account-filter select { min-width: 12rem; min-height: 2.25rem; padding: 0.4rem 2rem 0.4rem 0.65rem; color: var(--text); border: 1px solid #343c51; border-radius: 0.55rem; background: #131927; }
.trade-history-count { color: var(--muted); font-size: 0.75rem; }
.trade-history-table-wrap { overflow-x: auto; border: 1px solid #252c3c; border-radius: 0.8rem; background: #0d121e; }
.trade-history-table { min-width: 760px; }
.trade-history-table th, .trade-history-table td { padding: 0.72rem 0.7rem; }
.trade-history-row { cursor: pointer; }
.trade-history-row:hover { background: rgba(118, 103, 255, 0.09); }
.trade-history-row:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.stock-news-table { min-width: 880px; }
.stock-news-table th:nth-child(1) { width: 9.5rem; }
.stock-news-table th:nth-child(2) { width: 8rem; }
.stock-news-table th:nth-child(3) { width: 30%; }
.stock-news-link { color: var(--text); font-weight: 700; line-height: 1.45; text-decoration: none; }
.stock-news-link:hover { color: var(--accent-strong); text-decoration: underline; }
.stock-news-summary { min-width: 18rem; color: var(--muted); line-height: 1.45; }
.trade-side { display: inline-flex; min-width: 2.8rem; justify-content: center; padding: 0.25rem 0.45rem; border-radius: 999px; font-size: 0.72rem; font-weight: 850; }
.trade-side.buy { color: #ffd4db; background: rgba(255, 102, 125, 0.15); }
.trade-side.sell { color: #d1e3ff; background: rgba(92, 157, 255, 0.15); }
.trade-history-empty { padding: 2rem 1rem; color: var(--muted); text-align: center; font-size: 0.82rem; }
.trade-history-empty.error { color: var(--red); }
.trade-history-pagination { display: flex; align-items: center; justify-content: center; gap: 0.35rem; min-height: 2.5rem; margin-top: 0.85rem; }
.trade-history-pagination button { min-width: 2rem; min-height: 2rem; padding: 0.3rem 0.55rem; color: var(--muted); border: 1px solid #343c51; border-radius: 0.45rem; background: #131927; cursor: pointer; }
.trade-history-pagination button:hover:not(:disabled) { color: var(--text); border-color: #59647d; }
.trade-history-pagination button.active { color: var(--text); border-color: var(--accent); background: rgba(118, 103, 255, 0.16); }
.trade-history-pagination button:disabled { cursor: default; opacity: 0.35; }
.pagination-gap { color: var(--muted); }

body.modal-open { overflow: hidden; }
.trade-detail-modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 1rem; }
.trade-detail-modal[hidden] { display: none; }
.trade-detail-backdrop { position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; border: 0; background: rgba(3, 5, 10, 0.78); backdrop-filter: blur(6px); cursor: default; }
.trade-detail-card { position: relative; z-index: 1; width: min(620px, 100%); max-height: min(760px, calc(100vh - 2rem)); overflow-y: auto; padding: 1.3rem; border: 1px solid #3a4358; border-radius: 1rem; background: #111725; box-shadow: 0 2rem 6rem rgba(0, 0, 0, 0.58); }
.trade-detail-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.trade-detail-header h3 { margin: 0; }
.trade-detail-summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.55rem; margin-top: 1rem; }
.trade-detail-summary > div { padding: 0.75rem; border: 1px solid #293145; border-radius: 0.65rem; background: #0d121e; }
.trade-detail-summary span, .trade-detail-summary strong { display: block; }
.trade-detail-summary span { color: var(--muted); font-size: 0.7rem; }
.trade-detail-summary strong { margin-top: 0.28rem; font-size: 0.92rem; }
.trade-detail-section { margin-top: 1rem; }
.trade-detail-section h4 { margin: 0 0 0.55rem; color: var(--muted); font-size: 0.75rem; letter-spacing: 0.04em; }
.trade-detail-comment { margin: 0; padding: 0.9rem; border: 1px solid #293145; border-radius: 0.65rem; background: #0d121e; line-height: 1.65; white-space: pre-wrap; }
.trade-detail-news { display: grid; gap: 0.5rem; }
.trade-detail-news a { display: block; padding: 0.8rem; color: var(--text); border: 1px solid #293145; border-radius: 0.65rem; background: #0d121e; text-decoration: none; }
.trade-detail-news a:hover { border-color: var(--accent); background: rgba(118, 103, 255, 0.08); }
.trade-detail-news strong, .trade-detail-news span { display: block; }
.trade-detail-news strong { line-height: 1.45; }
.trade-detail-news span { margin-top: 0.3rem; color: var(--muted); font-size: 0.7rem; }
.trade-detail-news-empty { margin: 0; padding: 1rem; color: var(--muted); border: 1px dashed #343c51; border-radius: 0.65rem; text-align: center; }

@media (max-width: 860px) {
    .topbar, .hero { align-items: stretch; flex-direction: column; }
    .topbar-controls { align-items: stretch; }
    .topbar-meta { align-self: flex-end; }
    .key-control { grid-template-columns: 1fr auto; }
    .key-control > label { grid-column: 1 / -1; }
    #watch-form { grid-template-columns: 1fr 1fr; }
    .search-field { grid-column: 1 / -1; }
    .submit-button { align-self: end; }
    .chart-header { grid-template-columns: 1fr auto; }
    .chart-close { grid-column: 1 / -1; justify-self: end; }
    .market-overview { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .trade-detail-card { padding: 1rem; }
}

@media (max-width: 520px) {
    main { width: min(100% - 1rem, 1180px); padding-top: 1.5rem; }
    .topbar { padding: 0.9rem; }
    .key-control { display: block; }
    .key-control > label, .key-field, .key-control .status { margin-top: 0.5rem; }
    .key-control .status { display: inline-block; }
    .hero { gap: 1.2rem; }
    .summary div { min-width: 0; flex: 1; padding-inline: 0.7rem; }
    #watch-form { grid-template-columns: 1fr; }
    .search-field { grid-column: auto; }
    .chart-canvas-wrap { min-height: 360px; }
    #price-chart { height: 360px; }
    .trade-detail-summary { grid-template-columns: 1fr; }
    .trade-history-summary { align-items: stretch; flex-direction: column; }
    .trade-account-filter { justify-content: space-between; }
    .trade-account-filter select { min-width: 0; width: 70%; }
}
