:root {
    --bg: #0b1220;
    --panel: #131c2e;
    --panel-2: #1a2740;
    --line: #243250;
    --text: #e8edf6;
    --muted: #8a98b5;
    --brand: #0b3d2e;
    --up: #2ecc71;
    --down: #ff5d6c;
    --flat: #8a98b5;
    --accent: #34d399;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
    -webkit-font-smoothing: antialiased;
}

.boot {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    color: var(--muted);
}

.app-shell {
    max-width: 1100px;
    margin: 0 auto;
    padding: max(16px, env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}

/* 상단바 */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.topbar h1 {
    font-size: 22px;
    margin: 0;
}

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

.toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 14px;
}

/* 버튼 */
.btn {
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--text);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 15px;
    cursor: pointer;
    min-height: 44px;
}

.btn.primary { background: var(--accent); color: #08231a; border-color: transparent; font-weight: 700; }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; color: var(--down); border-color: var(--down); }
.btn:disabled { opacity: .55; }

/* 자산 요약 (접기/펼치기) */
.summary-section { margin-bottom: 14px; }

.summary-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 14px 16px;
    color: var(--text);
    font-size: 15px;
    cursor: pointer;
    min-height: 48px;
}

.summary-toggle-label { font-weight: 600; }
.summary-caret { color: var(--muted); font-size: 13px; }

/* 요약 카드 */
.summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    margin: 12px 0 8px;
}

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

/* 원화 환산 통합 카드 강조 */
.summary-card.krw-total {
    background: var(--panel-2);
    border-color: var(--accent);
}

.summary-head { color: var(--muted); font-size: 13px; }
.summary-value { font-size: 26px; font-weight: 700; margin: 4px 0; }
.summary-sub { font-size: 15px; font-weight: 600; }
.summary-cost { font-size: 13px; margin-top: 4px; }

.updated { font-size: 12px; margin: 8px 2px 14px; }

/* 보유 종목 */
.holdings {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.holding-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 14px 16px;
    cursor: pointer;
}

.holding-card:active { background: var(--panel-2); }

.holding-main { flex: 1; min-width: 0; }

/* 드래그 핸들(햄버거) — 여기서만 드래그 시작 */
.drag-handle {
    flex-shrink: 0;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 18px;
    line-height: 1;
    padding: 6px 10px 6px 0;
    cursor: grab;
    touch-action: none; /* 핸들 드래그 중 페이지 스크롤 방지(터치) */
    align-self: center;
}

.drag-handle:active { cursor: grabbing; color: var(--text); }

/* SortableJS 드래그 중 잔상/플레이스홀더 */
.sortable-ghost { opacity: .4; }
.sortable-chosen { background: var(--panel-2); }

.holding-name { display: flex; align-items: center; gap: 8px; }
.holding-name .name { font-size: 17px; font-weight: 600; }
.holding-ticker { font-size: 13px; margin-top: 2px; }

.chip {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    color: var(--muted);
}

.holding-figures { text-align: right; min-width: 130px; }
.holding-figures .price { font-size: 15px; }
.holding-figures .price .day { font-size: 12px; margin-left: 6px; }
.holding-figures .value { font-size: 16px; font-weight: 700; margin: 2px 0; }
.holding-figures .pnl { font-size: 13px; font-weight: 600; }

/* 등락 색상 */
.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--flat); }
.muted { color: var(--muted); }

/* 증권가 헤드라인 (상단 우선 노출) */
.news {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 16px 18px;
    margin-bottom: 14px;
}

.news-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

/* 헤드라인 접기/펴기 토글(제목 영역) */
.news-head-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 0;
    background: transparent;
    padding: 0;
    cursor: pointer;
    min-height: 34px;
}

.news-caret { color: var(--muted); font-size: 13px; }

.news-head {
    color: var(--muted);
    font-size: 14px;
    margin: 0;
    font-weight: 700;
}

/* 세그먼트 토글 (증권 일반 / 보유종목) */
.seg {
    display: inline-flex;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 2px;
}

.seg-btn {
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 13px;
    padding: 6px 14px;
    border-radius: 999px;
    cursor: pointer;
    min-height: 34px;
}

.seg-btn.on {
    background: var(--accent);
    color: #08231a;
    font-weight: 700;
}

.news-list {
    margin: 0;
    padding-left: 22px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.news-list li {
    padding: 9px 0;
    border-bottom: 1px solid var(--line);
}

.news-list li::marker { color: var(--muted); font-size: 12px; }
.news-list li:last-child { border-bottom: 0; padding-bottom: 0; }

.news-title {
    color: var(--text);
    text-decoration: none;
    font-size: 15px;
    line-height: 1.45;
    font-weight: 600;
}

.news-title:active { color: var(--accent); }

.news-meta {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-top: 3px;
}

/* 배너 */
.banner {
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 12px;
    font-size: 14px;
}
.banner.error { background: rgba(255, 93, 108, .12); border: 1px solid var(--down); color: #ffc2c8; }

/* 모달 */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 50;
}

.modal {
    width: 100%;
    max-width: 420px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 20px;
}

.modal h2 { margin: 0 0 14px; font-size: 19px; }

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.field > span { font-size: 13px; color: var(--muted); }

.field input, .field select {
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--text);
    padding: 12px;
    font-size: 16px; /* iOS 자동 확대 방지 */
    min-height: 44px;
}

/* 종목 검색 자동완성 */
.search-hint { font-size: 12px; margin: -4px 2px 12px; }

.search-results {
    list-style: none;
    margin: -4px 0 12px;
    padding: 4px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 12px;
    max-height: 220px;
    overflow-y: auto;
}

.search-results li {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    min-height: 44px;
}

.search-results li:active { background: var(--panel); }
.search-results .sr-name { font-size: 15px; font-weight: 600; }
.search-results .sr-meta { font-size: 12px; color: var(--muted); white-space: nowrap; }

.modal-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
}

.modal-actions .spacer { flex: 1; }

/* Blazor 오류 UI */
#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #b3261e;
    color: #fff;
    padding: 12px 16px;
    z-index: 100;
}

#blazor-error-ui .reload { color: #fff; text-decoration: underline; margin-left: 8px; }
#blazor-error-ui .dismiss { cursor: pointer; float: right; }
