﻿/* ============================================================
   hoga-orderbook.css  —  호가창 오더북 완전 재정의
   클래스 prefix: ob- (orderbook)
   ============================================================ */

/* ── CSS 변수 ── */
:root {
    /* 배경 */
    --ob-bg: #080808;
    --ob-bg-sell: #0a0a0f;
    --ob-bg-sell-alt: #0c0c14;
    --ob-bg-buy: #090f0a;
    --ob-bg-buy-alt: #0a120b;
    --ob-bg-current: #141000;
    --ob-bg-limit-up: #1a0000;
    --ob-bg-limit-dn: #00001a;
    --ob-bg-header: #0f0f0f;
    /* 가격 색상 */
    --ob-up: #e84040; /* 상승 — 빨간 */
    --ob-dn: #3d7bff; /* 하락 — 파란 */
    --ob-eq: #d0d0d0; /* 보합 — 회색 */
    /* 잔량·체결 텍스트 */
    --ob-vol: #bfbfbf;
    --ob-exec-px: #ffffff; /* 체결가 흰색 */
    --ob-exec-vol-buy: var(--ob-up); /* 매수 체결량 — 빨강 */
    --ob-exec-vol-sell: var(--ob-dn); /* 매도 체결량 — 파랑 */
    /* 한도가 */
    --ob-limit-up-clr: #ff3333;
    --ob-limit-dn-clr: #4466ff;
    /* 현재가 테두리 */
    --ob-cur-border: #f0c040;
    --ob-cur-bg: rgba(240,192,64,.08);
    /* diff 변화량 */
    --ob-diff-up: #e84040;
    --ob-diff-dn: #3d7bff;
    /* 구분선 */
    --ob-border: rgba(255,255,255,.05);
    --ob-sep: rgba(255,255,255,.08);
    /* 행 높이 & 폰트 */
    --ob-row-h: 36px;
    --ob-fs-price: 16px;
    --ob-fs-rate: 13.5px;
    --ob-fs-vol: 15px;
    --ob-fs-exec: 13.5px;
    --ob-fs-label: 13px;
    /* 컬럼 비율 */
    --ob-col-left: 36%;
    --ob-col-mid: 40%;
    --ob-col-right: 24%;
    /* 폰트 */
}

/* ── 전체 리셋 (호가창 범위 내) ── */
.ob-wrap *,
.ob-wrap *::before,
.ob-wrap *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ============================================================
   LAYOUT — 전체 래퍼
   ============================================================ */

/* 호가 섹션 전체 컨테이너 */
.ob-wrap {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    background: var(--ob-bg);
    overflow: hidden;
}

/* 스크롤 영역 */
.ob-scroll {
    /*flex: 1;*/
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: #2a2a2a transparent;
    background: var(--ob-bg); /* 하한가 아래 빈 공간 배경 통일 */
}

    .ob-scroll::-webkit-scrollbar {
        width: 3px;
    }

    .ob-scroll::-webkit-scrollbar-track {
        background: transparent;
    }

    .ob-scroll::-webkit-scrollbar-thumb {
        background: #2a2a2a;
        border-radius: 2px;
    }

/* ============================================================
   ROW — 공통 행
   ============================================================ */

.ob-row {
    display: grid;
    grid-template-columns: var(--ob-col-left) var(--ob-col-mid) var(--ob-col-right);
    height: var(--ob-row-h);
    align-items: center;
    border-bottom: 1px solid var(--ob-border);
    cursor: pointer;
    transition: filter .08s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

    .ob-row:active,
    .ob-row:hover {
        filter: brightness(1.25);
    }

/* ── 매도 행 ── */
.ob-row--sell {
    background: var(--ob-bg-sell);
}

    .ob-row--sell.ob-row--alt {
        background: var(--ob-bg-sell-alt);
    }

/* ── 매수 행 ── */
.ob-row--buy {
    background: var(--ob-bg-buy);
}

    .ob-row--buy.ob-row--alt {
        background: var(--ob-bg-buy-alt);
    }

/* ── 현재가 행 ── */
.ob-row--current {
    background: var(--ob-cur-bg);
    border-top: 1px solid var(--ob-cur-border);
    border-bottom: 1px solid var(--ob-cur-border);
    height: calc(var(--ob-row-h) + 2px);
    position: relative;
    z-index: 1;
}

/* ── 상한가·하한가 행 ── */
.ob-row--limit {
    height: var(--ob-row-h);
}

.ob-row--upper-limit {
    background: var(--ob-bg-limit-up);
}

.ob-row--lower-limit {
    background: var(--ob-bg-limit-dn);
}

/* ============================================================
   CELL — 셀
   ============================================================ */

.ob-cell {
    display: flex;
    align-items: center;
    height: 100%;
    overflow: hidden;
    min-width: 0;
}

/* 왼쪽 셀 — 매도잔량 or 체결내역 */
.ob-cell--left {
    justify-content: flex-end;
    gap: 4px;
    padding: 0 5px 0 3px;
    border-right: 1px solid var(--ob-sep);
}

/* 중앙 셀 — 가격 + 등락률 */
.ob-cell--mid {
    justify-content: space-between;
    padding: 0 6px;
}

/* 오른쪽 셀 — 매수잔량 */
.ob-cell--right {
    justify-content: flex-start;
    gap: 4px;
    padding: 0 3px 0 5px;
    border-left: 1px solid var(--ob-sep);
}

/* ============================================================
   TEXT — 텍스트 원소
   ============================================================ */

/* 호가 가격 */
.ob-price {
    font-size: var(--ob-fs-price);
    font-weight: 600;
    letter-spacing: -.2px;
    line-height: 1;
    white-space: nowrap;
}

.ob-price--current {
    font-size: calc(var(--ob-fs-price) + 1px);
    font-weight: 700;
}

/* 등락률 */
.ob-rate {
    font-size: var(--ob-fs-rate);
    text-align: right;
    white-space: nowrap;
    min-width: 38px;
    line-height: 1;
}

/* 매도잔량 (왼쪽) */
.ob-sell-vol {
    font-size: var(--ob-fs-vol);
    color: var(--ob-vol);
    text-align: right;
    white-space: nowrap;
}

/* 매수잔량 (오른쪽) */
.ob-buy-vol {
    font-size: var(--ob-fs-vol);
    color: var(--ob-vol);
    text-align: left;
    white-space: nowrap;
}

/* 체결가 (매수 행 왼쪽) */
.ob-exec-px {
    font-size: var(--ob-fs-exec);
    color: var(--ob-exec-px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

/* 체결량 (매수 행 왼쪽) */
.ob-exec-vol {
    font-size: var(--ob-fs-exec);
    flex-shrink: 0;
    white-space: nowrap;
}

.ob-exec-vol--buy {
    color: var(--ob-exec-vol-buy);
}

.ob-exec-vol--sell {
    color: var(--ob-exec-vol-sell);
}


/* 변화량 diff */
.ob-diff {
    font-size: 11px;
    flex-shrink: 0;
    line-height: 1;
}

.ob-diff--up {
    color: var(--ob-diff-up);
}

.ob-diff--dn {
    color: var(--ob-diff-dn);
}

/* 한도가 라벨 */
.ob-limit-lbl {
    font-size: var(--ob-fs-label);
    font-weight: 700;
    letter-spacing: .5px;
    white-space: nowrap;
}

/* 현재가 라벨 */
.ob-cur-lbl {
    font-size: var(--ob-fs-label);
    color: var(--ob-cur-border);
    font-weight: 600;
    white-space: nowrap;
    text-align: right;
    flex: 1;
}

/* ── 색상 유틸 ── */
.ob-up {
    color: var(--ob-up);
}

.ob-dn {
    color: var(--ob-dn);
}

.ob-eq {
    color: var(--ob-eq);
}

.ob-limit-up {
    color: var(--ob-limit-up-clr);
}

.ob-limit-dn {
    color: var(--ob-limit-dn-clr);
}

/* ============================================================
   HEADER — 종목 정보 헤더
   ============================================================ */

.ob-header {
    padding: 16px 20px;
    flex-shrink: 0;
    background: rgba(18, 18, 18, 0.95);
    border-radius: 8px 8px 0 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    max-height: 130px;
    overflow: hidden;
    border-bottom: 1px solid var(--ob-sep);
}

.ob-header__title-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.ob-header__name {
    font-size: 18px;
    font-weight: bold;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ob-header__code {
    font-size: 14px;
    color: #ccc;
    font-weight: 500;
    background: linear-gradient(135deg, #333, #444);
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid #555;
    flex-shrink: 0;
}

.ob-header__price-row {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}

.ob-header__cur-price {
    font-size: 24px;
    font-weight: bold;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    line-height: 1;
}

.ob-header__change {
    font-size: 17px;
    font-weight: 500;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.ob-header__vol {
    font-size: 16px;
    color: #ccc;
    margin-left: auto;
}

.ob-header__sub-row {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.ob-header__sub-item {
    font-size: 15px;
    color: #ccc;
}

    .ob-header__sub-item span {
        color: #ccc;
    }

/* ============================================================
   COLUMN HEADER — 컬럼 헤더 (잔량 | 가격 | 잔량)
   ============================================================ */

.ob-col-header {
    display: grid;
    grid-template-columns: var(--ob-col-left) var(--ob-col-mid) var(--ob-col-right);
    height: 20px;
    background: #0f0f0f;
    border-bottom: 1px solid var(--ob-sep);
    flex-shrink: 0;
}

.ob-col-header__cell {
    display: flex;
    align-items: center;
    padding: 0 5px;
    font-size: 15px;
    color: white;
    font-weight: 500;
    letter-spacing: .3px;
}

.ob-col-header__cell--left {
    justify-content: flex-end;
    border-right: 1px solid var(--ob-sep);
}

.ob-col-header__cell--mid {
    justify-content: center;
}

.ob-col-header__cell--right {
    justify-content: flex-start;
    border-left: 1px solid var(--ob-sep);
}

/* ============================================================
   TOTALS BAR — 잔량 합계 표시줄
   ============================================================ */

.ob-totals {
    display: grid;
    grid-template-columns: var(--ob-col-left) var(--ob-col-mid) var(--ob-col-right);
    height: 22px;
    background: #0c0c0c;
    border-top: 1px solid var(--ob-sep);
    flex-shrink: 0;
}

.ob-totals__cell {
    display: flex;
    align-items: center;
    padding: 0 5px;
    font-size: 12px;
}

.ob-totals__cell--left {
    justify-content: flex-end;
    color: var(--ob-up);
    border-right: 1px solid var(--ob-sep);
}

.ob-totals__cell--mid {
    justify-content: center;
    color: white;
    font-size: 11px;
}

.ob-totals__cell--right {
    justify-content: flex-start;
    color: var(--ob-dn);
    border-left: 1px solid var(--ob-sep);
}

/* ============================================================
   NO-DATA / LOADING 상태
   ============================================================ */

.ob-state-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 10px;
    color: #444;
}

.ob-spinner {
    width: 22px;
    height: 22px;
    border: 2px solid #222;
    border-top-color: #4d4d4d;
    border-radius: 50%;
    animation: ob-spin .7s linear infinite;
}

@keyframes ob-spin {
    to {
        transform: rotate(360deg);
    }
}

.ob-state-msg {
    font-size: 11px;
    color: #444;
}

/* ============================================================
   ORDER FORM AREA
   ============================================================ */

.ob-order-area {
    flex-shrink: 0;
    background: #0c0c0c;
    border-top: 1px solid var(--ob-sep);
}

.ob-order-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
}

.ob-tab {
    height: 34px;
    border: none;
    background: #111;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: background .15s, border-color .15s;
}

.ob-tab--buy {
    color: var(--ob-up);
}

    .ob-tab--buy.ob-tab--active {
        background: rgba(232,64,64,.12);
        border-bottom-color: var(--ob-up);
    }

.ob-tab--sell {
    color: var(--ob-dn);
}

    .ob-tab--sell.ob-tab--active {
        background: rgba(61,123,255,.12);
        border-bottom-color: var(--ob-dn);
    }

.ob-order-form {
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.ob-form-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ob-form-label {
    font-size: 13px;
    color: #666;
    width: 52px;
    flex-shrink: 0;
}

.ob-form-select {
    flex: 1;
    height: 26px;
    background: #181818;
    border: 1px solid #2a2a2a;
    border-radius: 3px;
    color: #ccc;
    font-size: 13px;
    padding: 0 6px;
    outline: none;
}

.ob-input-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 3px;
}

.ob-input {
    flex: 1;
    height: 26px;
    min-width: 0;
    background: #181818;
    border: 1px solid #2a2a2a;
    border-radius: 3px;
    color: #ddd;
    font-size: 14px;
    text-align: right;
    padding: 0 6px;
    outline: none;
}

    .ob-input:focus {
        border-color: #404040;
    }

.ob-input-unit {
    font-size: 12px;
    color: #555;
    flex-shrink: 0;
}

.ob-stepper {
    display: flex;
    flex-direction: column;
    gap: 1px;
    flex-shrink: 0;
}

.ob-step-btn {
    width: 20px;
    height: 12px;
    background: #222;
    border: 1px solid #2a2a2a;
    border-radius: 2px;
    color: #888;
    font-size: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

    .ob-step-btn:active {
        background: #333;
    }

.ob-total-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 0;
    border-top: 1px solid var(--ob-border);
}

.ob-total-label {
    font-size: 13px;
    color: #555;
}

.ob-total-val {
    font-size: 14px;
    font-weight: 600;
    color: #aaa;
}

.ob-submit-btn {
    width: 100%;
    height: 36px;
    border: none;
    border-radius: 4px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: filter .12s;
    display: none; /* JS에서 제어 */
}

    .ob-submit-btn:active {
        filter: brightness(.9);
    }

.ob-submit-btn--buy {
    background: var(--ob-up);
    color: #fff;
}

.ob-submit-btn--sell {
    background: var(--ob-dn);
    color: #fff;
}

.ob-submit-btn--link {
    background: #2a2a2a;
    color: #888;
    border: 1px solid #333;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

/* 소형 폰 (≤ 400px) */
@media (max-width: 400px) {
    :root {
        --ob-row-h: 30px;
        --ob-fs-price: 13px;
        --ob-fs-rate: 11px;
        --ob-fs-vol: 12px;
        --ob-fs-exec: 11px;
        --ob-col-left: 34%;
        --ob-col-mid: 42%;
        --ob-col-right: 24%;
    }

    .ob-exec-px {
        max-width: 52px;
    }

    .ob-exec-vol {
        display: none;
    }
    /* 초소형에서 체결량 숨김 */
    .ob-header__cur-price {
        font-size: 17px;
    }
}

/* 극소형 (≤ 330px) */
@media (max-width: 330px) {
    :root {
        --ob-row-h: 27px;
        --ob-fs-price: 12px;
        --ob-fs-rate: 10px;
        --ob-fs-vol: 11px;
        --ob-col-left: 32%;
        --ob-col-mid: 44%;
        --ob-col-right: 24%;
    }

    .ob-exec-px {
        display: none;
    }
}

/* 태블릿 이상 (≥ 600px) */
@media (min-width: 600px) {
    :root {
        --ob-row-h: 36px;
        --ob-fs-price: 15.5px;
        --ob-fs-rate: 13.5px;
        --ob-fs-vol: 14.5px;
        --ob-fs-exec: 13.5px;
    }
}

/* 가로 방향 */
@media (orientation: landscape) and (max-height: 500px) {
    :root {
        --ob-row-h: 28px;
    }

    .ob-header {
        padding: 4px 8px;
    }

    .ob-header__sub-row {
        display: none;
    }
}
