:root {
    --bg:          #060d18;
    --surface:     #0b1628;
    --card:        #0f1e35;
    --card-hover:  #132441;
    --border:      #1c3050;
    --border-dim:  #101f33;

    --text:        #dce8f5;
    --text-2:      #6b8cad;
    --text-3:      #3a5470;

    --up:          #f0516a;
    --down:        #3d9eff;
    --accent:      #00c896;
    --accent-bg:   rgba(0, 200, 150, 0.07);
    --accent-bdr:  rgba(0, 200, 150, 0.18);

    --sidebar-w:   252px;
    --r:           10px;
    --r-sm:        6px;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    font-size: 14px;
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */
.app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 18px 16px 16px;
    border-bottom: 1px solid var(--border-dim);
}

.brand-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--accent), #009fa0);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 800;
    color: #fff;
    flex-shrink: 0;
    letter-spacing: -0.5px;
}

.brand-name { font-size: 14px; font-weight: 700; }
.brand-sub  { font-size: 10px; color: var(--text-3); margin-top: 2px; }

.sidebar-search {
    position: relative;
    padding: 12px 12px 8px;
}

.sidebar-search input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    color: var(--text);
    padding: 7px 10px 7px 32px;
    font-size: 12px;
    outline: none;
    transition: border-color 0.15s;
}

.sidebar-search input:focus { border-color: var(--accent); }
.sidebar-search input::placeholder { color: var(--text-3); }

.search-icon {
    position: absolute;
    left: 22px;
    top: 50%;
    transform: translateY(-50%);
    width: 13px;
    height: 13px;
    color: var(--text-3);
    pointer-events: none;
}

.sidebar-label {
    padding: 6px 16px 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-3);
}

.stock-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
}

.stock-list::-webkit-scrollbar { width: 2px; }
.stock-list::-webkit-scrollbar-track { background: transparent; }
.stock-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.stock-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 11px 16px;
    cursor: pointer;
    border-left: 2px solid transparent;
    border-bottom: 1px solid var(--border-dim);
    transition: background 0.12s, border-left-color 0.12s;
}

.stock-item:hover  { background: var(--card); }
.stock-item.active { background: var(--card); border-left-color: var(--accent); }

.item-rank { font-size: 10px; font-weight: 700; color: var(--text-3); width: 14px; flex-shrink: 0; }
.item-info { flex: 1; min-width: 0; }
.item-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-code { font-size: 10px; color: var(--text-3); margin-top: 1px; }
.item-price { text-align: right; flex-shrink: 0; }
.item-price-val { font-size: 12px; font-weight: 600; }
.item-price-pct { font-size: 10px; margin-top: 2px; }

/* ── Main ── */
.main {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Topbar */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 22px;
    border-bottom: 1px solid var(--border-dim);
    flex-shrink: 0;
}

.market-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 100px;
    padding: 5px 14px;
}

.live-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 7px #10b981;
    animation: blink 2.4s ease-in-out infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.4; }
}

.market-name  { font-size: 11px; font-weight: 600; color: var(--text-2); }
.market-value { font-size: 13px; font-weight: 700; }
.market-change { font-size: 11px; font-weight: 600; }
.api-tools {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.api-key-field {
    display: flex;
    align-items: center;
    gap: 7px;
    height: 28px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    padding: 0 8px;
}

.api-key-field span {
    font-size: 10px;
    font-weight: 700;
    color: var(--accent);
}

.api-key-field input {
    width: 124px;
    min-width: 0;
    background: transparent;
    border: 0;
    outline: 0;
    color: var(--text);
    font-size: 11px;
}

.api-key-field input::placeholder { color: var(--text-3); }

.api-save {
    height: 28px;
    border: 1px solid var(--accent-bdr);
    background: var(--accent-bg);
    color: var(--accent);
    border-radius: var(--r-sm);
    padding: 0 10px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
}

.api-save:hover { border-color: var(--accent); }

.update-time  { font-size: 11px; color: var(--text-3); white-space: nowrap; }

/* Hero */
.stock-hero {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 18px 22px 14px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border-dim);
}

.stock-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--accent);
    background: var(--accent-bg);
    border: 1px solid var(--accent-bdr);
    border-radius: 4px;
    padding: 2px 7px;
    margin-bottom: 5px;
}

.stock-name {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.025em;
    line-height: 1;
}

.hero-right { text-align: right; }

.price {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.025em;
    line-height: 1;
}

.price-delta {
    font-size: 13px;
    font-weight: 600;
    margin-top: 5px;
}

/* Content grid */
.content-grid {
    display: grid;
    grid-template-columns: 1fr 210px;
    grid-template-rows: auto auto;
    gap: 12px;
    padding: 14px 22px 20px;
    overflow-y: auto;
    flex: 1;
}

.content-grid::-webkit-scrollbar { width: 3px; }
.content-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

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

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

.card-title { font-size: 12px; font-weight: 700; color: var(--text); }
.card-sub   { font-size: 10px; color: var(--text-3); }

/* Chart */
.chart-card { grid-column: 1; grid-row: 1; }

.chart-wrap {
    position: relative;
    height: 200px;
}

.chart-wrap canvas {
    position: absolute;
    inset: 0;
}

/* Metrics */
.metrics-card { grid-column: 2; grid-row: 1; }

.metrics-list { display: flex; flex-direction: column; }

.metric-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 9px 0;
    border-bottom: 1px solid var(--border-dim);
}

.metric-row:last-child { border-bottom: none; padding-bottom: 0; }
.metric-row:first-child { padding-top: 0; }

.metric-label { font-size: 11px; color: var(--text-2); }
.metric-value { font-size: 12px; font-weight: 700; }

/* News */
.news-card { grid-column: 1 / -1; grid-row: 2; }

.news-content { display: flex; flex-direction: column; gap: 0; }

.news-headline {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-dim);
    margin-bottom: 10px;
    line-height: 1.5;
}

.news-bullet {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 6px 0;
    border-bottom: 1px solid var(--border-dim);
}

.news-bullet:last-child { border-bottom: none; padding-bottom: 0; }

.news-num {
    font-size: 10px;
    font-weight: 700;
    color: var(--accent);
    background: var(--accent-bg);
    border-radius: 3px;
    padding: 1px 5px;
    flex-shrink: 0;
    margin-top: 2px;
    letter-spacing: 0.02em;
}

.news-text { font-size: 12px; line-height: 1.65; color: var(--text); }

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

@media (max-width: 820px) {
    body {
        height: auto;
        min-height: 100vh;
        overflow: auto;
    }

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

    .sidebar {
        max-height: 280px;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .topbar {
        align-items: flex-start;
        gap: 10px;
        flex-direction: column;
    }

    .api-tools {
        width: 100%;
        flex-wrap: wrap;
    }

    .api-key-field {
        flex: 1;
        min-width: 180px;
    }

    .api-key-field input { width: 100%; }

    .stock-hero {
        align-items: flex-start;
        gap: 14px;
        flex-direction: column;
    }

    .hero-right { text-align: left; }

    .content-grid {
        grid-template-columns: 1fr;
        overflow: visible;
    }

    .chart-card,
    .metrics-card,
    .news-card {
        grid-column: 1;
        grid-row: auto;
    }
}
