/* ============================
   RESET & BASE
   ============================ */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Malgun Gothic', '맑은 고딕', Calibri, 'Segoe UI', sans-serif;
    font-size: 12px;
    background: #c8d4c8;
    overflow: hidden;
    height: 100vh;
}

.excel-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: white;
}

/* ============================
   TITLE BAR
   ============================ */
.title-bar {
    background: #1d6038;
    color: white;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    flex-shrink: 0;
    user-select: none;
}

.title-left {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
}

.file-name {
    font-weight: 600;
    opacity: 0.95;
}

.title-sep {
    opacity: 0.4;
}

.app-title {
    font-size: 13px;
    font-weight: 700;
    opacity: 0.9;
}

.title-right {
    font-size: 11px;
}

.online-badge {
    background: rgba(0,0,0,0.25);
    padding: 3px 10px;
    border-radius: 10px;
    font-size: 11px;
}

/* ============================
   RIBBON
   ============================ */
.ribbon {
    background: #f3f3f3;
    border-bottom: 1px solid #d0d0d0;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 8px;
    flex-shrink: 0;
}

.ribbon-left { display: flex; align-items: center; }

.ribbon-menus { display: flex; gap: 2px; }

.rmenu {
    padding: 5px 10px;
    font-size: 11px;
    color: #333;
    cursor: pointer;
    border-radius: 2px;
    transition: background 0.1s;
}

.rmenu:hover { background: #e0e0e0; }

.ribbon-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.update-badge {
    font-size: 11px;
    color: #555;
    background: #e8e8e8;
    padding: 3px 8px;
    border-radius: 3px;
}

.btn-refresh {
    background: #217346;
    color: white;
    border: none;
    padding: 4px 10px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 11px;
    font-family: inherit;
    transition: background 0.1s;
}

.btn-refresh:hover { background: #165c34; }
.btn-refresh:disabled { background: #8ab8a0; cursor: default; }

.auto-sel {
    font-size: 11px;
    padding: 3px 6px;
    border: 1px solid #ccc;
    border-radius: 3px;
    background: white;
    font-family: inherit;
    cursor: pointer;
}

/* ============================
   FORMULA BAR
   ============================ */
.formula-bar {
    background: white;
    border-bottom: 1px solid #c8c8c8;
    height: 26px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.cell-ref {
    width: 80px;
    border-right: 1px solid #c8c8c8;
    padding: 0 8px;
    font-size: 11px;
    color: #333;
    height: 100%;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.fx-label {
    width: 30px;
    border-right: 1px solid #c8c8c8;
    padding: 0 6px;
    font-style: italic;
    color: #217346;
    font-weight: bold;
    font-size: 13px;
    height: 100%;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.formula-text {
    padding: 0 10px;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 11px;
    color: #1f3864;
}

/* ============================
   MAIN LAYOUT
   ============================ */
.main-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ============================
   SHEET PANEL (Left)
   ============================ */
.sheet-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-right: 1px solid #c0c0c0;
}

.market-tab-bar {
    background: #f0f0f0;
    border-bottom: 1px solid #d0d0d0;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 3px 6px 0;
    flex-shrink: 0;
}

.mtab {
    padding: 5px 14px;
    font-size: 11px;
    font-family: inherit;
    border: 1px solid transparent;
    border-bottom: none;
    background: #e0e0e0;
    color: #444;
    cursor: pointer;
    border-radius: 3px 3px 0 0;
    transition: background 0.1s;
}

.mtab:hover { background: #d0d0d0; }

.mtab.active {
    background: white;
    color: #217346;
    font-weight: bold;
    border-color: #c0c0c0;
    border-bottom-color: white;
    position: relative;
    bottom: -1px;
    z-index: 1;
}

.tab-spacer { flex: 1; }

.market-status {
    font-size: 10px;
    padding: 3px 8px;
    border-radius: 8px;
    background: #e0e0e0;
    color: #555;
    margin-bottom: 3px;
    white-space: nowrap;
}

.market-status.open-kr { background: #d4edda; color: #155724; }
.market-status.open-us { background: #cce5ff; color: #004085; }

.sheet-scroll {
    flex: 1;
    overflow: auto;
    background: white;
}

/* ============================
   SPREADSHEET TABLE
   ============================ */
.sheet-table {
    border-collapse: collapse;
    table-layout: fixed;
    width: 100%;
    min-width: 320px;
}

.col-rn { width: 36px; }
.col-label { width: 170px; }
.col-price { width: 130px; }
.col-chg { width: 100px; }

.col-letters th {
    background: #e0e0e0;
    border: 1px solid #c8c8c8;
    text-align: center;
    color: #666;
    font-size: 11px;
    font-weight: normal;
    height: 20px;
    user-select: none;
}

.rn-head {
    background: #e0e0e0 !important;
    width: 36px;
}

.col-names td {
    background: #d9d9d9;
    border: 1px solid #bdbdbd;
    font-weight: 700;
    font-size: 11px;
    color: #333;
    height: 20px;
    padding: 0 6px;
}

.col-names td:not(.rn) { text-align: center; }

/* Row number cell */
.rn {
    background: #ebebeb;
    border: 1px solid #c8c8c8;
    text-align: center;
    font-size: 10px;
    color: #888;
    font-weight: normal;
    user-select: none;
    padding: 0;
}

/* Section header row */
tr.sec-row td {
    background: #217346;
    color: white;
    font-weight: 700;
    font-size: 11px;
    padding: 3px 8px;
    border: 1px solid #1a5c38;
    height: 24px;
}

/* Sub-header row */
tr.subhdr-row td {
    background: #e2efda;
    color: #1a4a28;
    font-weight: 700;
    font-size: 10px;
    text-align: center;
    border: 1px solid #c6dfc0;
    height: 20px;
    padding: 0 4px;
}

/* Data row */
tr.dr td {
    border: 1px solid #e0e0e0;
    height: 22px;
    padding: 0 6px;
    font-size: 11px;
}

tr.dr:nth-child(odd) td { background: #ffffff; }
tr.dr:nth-child(even) td { background: #f9f9f9; }
tr.dr:hover td { background: #e8f4fd !important; }

.cell-label {
    font-weight: 600;
    color: #1f4e79;
}

.cell-price {
    text-align: right;
    font-family: 'D2Coding', 'Consolas', 'Courier New', monospace;
    font-weight: 700;
}

.cell-chg {
    text-align: right;
    font-family: 'D2Coding', 'Consolas', 'Courier New', monospace;
}

/* Korean convention: red=up, blue=down */
.up   { color: #c00000 !important; }
.down { color: #0033cc !important; }
.flat { color: #333333 !important; }

.loading-cell {
    text-align: center;
    padding: 20px;
    color: #888;
    font-size: 12px;
    background: white;
}

/* ============================
   NEWS PANEL (Middle)
   ============================ */
.news-panel {
    width: 360px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-right: 1px solid #c0c0c0;
}

.panel-hdr {
    background: #1f4e79;
    color: white;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 32px;
}

.phdr-title { font-size: 12px; }

.news-cnt {
    font-size: 10px;
    font-weight: normal;
    opacity: 0.75;
}

.news-scroll {
    flex: 1;
    overflow-y: auto;
    background: white;
}

.news-table {
    border-collapse: collapse;
    width: 100%;
}

.news-table thead th {
    background: #d9d9d9;
    border: 1px solid #bdbdbd;
    font-size: 10px;
    font-weight: 700;
    color: #444;
    padding: 3px 6px;
    text-align: left;
    position: sticky;
    top: 0;
    z-index: 1;
}

.news-time-hd { width: 52px; text-align: center !important; }

.news-row {
    cursor: pointer;
    transition: background 0.1s;
}

.news-row:hover td { background: #f0f8ff !important; }

.news-row:nth-child(odd) td { background: white; }
.news-row:nth-child(even) td { background: #fafafa; }

.news-row td {
    border: 1px solid #eeeeee;
    padding: 5px 6px;
    font-size: 11px;
    vertical-align: top;
}

.news-time-cell {
    font-size: 10px;
    color: #888;
    text-align: center;
    white-space: nowrap;
    width: 52px;
}

.news-title-cell {
    color: #1a1a2e;
    line-height: 1.4;
}

.news-src {
    font-size: 9px;
    color: #217346;
    font-weight: 700;
    margin-right: 4px;
}

/* ============================
   CHAT PANEL (Right)
   ============================ */
.chat-panel {
    width: 300px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: white;
}

.chat-hdr {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    height: auto;
    padding: 6px 10px;
}

.chat-tabs {
    display: flex;
    gap: 4px;
}

.ctab {
    padding: 2px 10px;
    font-size: 11px;
    font-family: inherit;
    border: 1px solid rgba(255,255,255,0.4);
    background: rgba(0,0,0,0.2);
    color: white;
    cursor: pointer;
    border-radius: 3px;
    transition: background 0.1s;
}

.ctab.active { background: rgba(255,255,255,0.25); font-weight: 700; }
.ctab:hover { background: rgba(255,255,255,0.2); }

.nick-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background: #f5f5f5;
    border-bottom: 1px solid #e0e0e0;
    flex-shrink: 0;
}

.nick-label {
    font-size: 10px;
    color: #666;
    white-space: nowrap;
}

.nick-input {
    flex: 1;
    padding: 3px 6px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 11px;
    font-family: inherit;
    outline: none;
}

.nick-input:focus { border-color: #217346; }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 6px 8px;
    background: #fafafa;
}

.chat-msg {
    margin-bottom: 7px;
    line-height: 1.45;
}

.chat-msg-top {
    display: flex;
    align-items: baseline;
    gap: 5px;
    margin-bottom: 1px;
}

.chat-author {
    font-weight: 700;
    font-size: 11px;
    color: #1f4e79;
}

.chat-time {
    font-size: 9px;
    color: #ccc;
}

.chat-text {
    font-size: 11px;
    color: #333;
    word-break: break-all;
}

.chat-input-row {
    display: flex;
    padding: 5px 6px;
    border-top: 1px solid #e0e0e0;
    gap: 5px;
    background: white;
    flex-shrink: 0;
}

.msg-input {
    flex: 1;
    padding: 5px 8px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 11px;
    font-family: inherit;
    outline: none;
}

.msg-input:focus { border-color: #217346; }

.send-btn {
    padding: 5px 12px;
    background: #217346;
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 11px;
    font-family: inherit;
    transition: background 0.1s;
}

.send-btn:hover { background: #165c34; }

/* ============================
   BOTTOM SHEET TAB BAR
   ============================ */
.sheet-tab-bar {
    background: #f0f0f0;
    border-top: 1px solid #c8c8c8;
    height: 24px;
    display: flex;
    align-items: center;
    padding: 0 6px;
    gap: 2px;
    flex-shrink: 0;
}

.stab {
    padding: 0 12px;
    height: 100%;
    display: flex;
    align-items: center;
    font-size: 11px;
    color: #444;
    border-right: 1px solid #ccc;
    cursor: pointer;
    transition: background 0.1s;
}

.stab:hover { background: #e0e0e0; }
.stab.active { background: white; color: #217346; font-weight: 700; }

.stab-spacer { flex: 1; }

.copyright {
    font-size: 10px;
    color: #aaa;
    padding-right: 6px;
}

/* ============================
   SCROLLBARS
   ============================ */
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: #f0f0f0; }
::-webkit-scrollbar-thumb { background: #bdbdbd; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #9e9e9e; }

/* ============================
   RESPONSIVE
   ============================ */
@media (max-width: 1024px) {
    .news-panel { width: 300px; }
    .chat-panel { width: 260px; }
    .col-label { width: 140px; }
}

@media (max-width: 768px) {
    .chat-panel { display: none; }
    .news-panel { width: 280px; }
}

@media (max-width: 600px) {
    .main-layout { flex-direction: column; }
    .sheet-panel { flex: none; height: 50%; }
    .news-panel { width: 100%; height: 30%; }
    .chat-panel { display: flex; width: 100%; height: 20%; }
}
