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

:root {
    --bg-primary: #0a0b0f;
    --bg-secondary: #11131a;
    --surface: rgba(22, 26, 38, 0.85);
    --surface-hover: rgba(30, 35, 50, 0.95);
    --border: rgba(55, 65, 90, 0.4);
    --text: #eef0f6;
    --text-secondary: #8a90a8;
    --text-tertiary: #5a6078;
    --green: #22dd6e;
    --green-bg: rgba(34, 221, 110, 0.1);
    --green-glow: rgba(34, 221, 110, 0.3);
    --red: #ff4757;
    --red-bg: rgba(255, 71, 87, 0.1);
    --red-glow: rgba(255, 71, 87, 0.3);
    --blue: #4d7cff;
    --blue-bg: rgba(77, 124, 255, 0.1);
    --yellow: #ffc53d;
    --yellow-bg: rgba(255, 197, 61, 0.1);
    --purple: #8b5cf6;
    --purple-bg: rgba(139, 92, 246, 0.1);
    --cyan: #06d6a0;
    --radius: 12px;
    --radius-sm: 6px;
    --shadow: 0 2px 16px rgba(0, 0, 0, 0.3);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

.app { max-width: 1500px; margin: 0 auto; padding: 10px; }

/* === HEADER === */
.header {
    display: flex; align-items: center; justify-content: space-between;
    gap: 8px; padding: 12px 18px;
    background: var(--surface);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    box-shadow: var(--shadow);
    flex-wrap: wrap;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-logo { font-size: 18px; font-weight: 800; color: var(--green); white-space: nowrap; }
.header-logo span { color: var(--text); }
.header-status { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; color: var(--text-secondary); background: var(--surface-hover); border: 1px solid var(--border); border-radius: 22px; padding: 6px 10px 6px 12px; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-tertiary); flex-shrink: 0; }
.status-dot.online { background: var(--green); box-shadow: 0 0 10px var(--green-glow); }
.status-dot.offline { background: var(--red); box-shadow: 0 0 6px var(--red-glow); }
.status-dot.trading { background: var(--yellow); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.6; } }
.header-right { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.balance-display {
    padding: 6px 14px;
    background: linear-gradient(135deg, rgba(34, 221, 110, 0.08), rgba(6, 214, 160, 0.05));
    border: 1px solid rgba(34, 221, 110, 0.15);
    border-radius: 16px;
    font-size: 13px; font-weight: 700;
    display: flex; align-items: center; gap: 4px;
    white-space: nowrap;
}
.balance-display .currency { font-weight: 400; color: var(--text-secondary); font-size: 11px; }

/* === BUTTONS === */
.btn {
    padding: 12px 22px; border: none; border-radius: var(--radius-sm); font-size: 15px;
    font-weight: 600; cursor: pointer;
    display: inline-flex; align-items: center; gap: 7px;
    white-space: nowrap;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: linear-gradient(135deg, var(--green), #17b85a); color: #000; }
.btn-primary:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-danger { background: linear-gradient(135deg, var(--red), #e03847); color: #fff; }
.btn-danger:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--text-secondary); padding: 8px 14px; }
.btn-sm { padding: 8px 16px; font-size: 13px; }
.btn-xs { padding: 6px 12px; font-size: 12px; border-radius: 6px; }
.btn-test { background: rgba(139,92,246,.15); color: #a78bfa; border: 1px solid rgba(139,92,246,.4); font-size: 13px; padding: 11px 16px; }
.btn-test:hover { background: rgba(139,92,246,.25); }
.btn-test.active { background: rgba(139,92,246,.35); color: #c4b5fd; border-color: #a78bfa; box-shadow: 0 0 8px rgba(139,92,246,.45); }

/* === ORDER TYPE SWITCH === */
.order-type-switch { display:flex; border-radius:8px; overflow:hidden; border:1px solid var(--border); height:40px; }
.order-type-btn { flex:1; padding:0 14px; font-size:12px; font-weight:700; border:none; cursor:pointer; background:var(--surface); color:var(--text-secondary); transition:background .18s,color .18s; letter-spacing:.3px; -webkit-appearance:none; appearance:none; white-space:nowrap; }
.order-type-btn.market.active { background:#22dd6e; color:#000; }
.order-type-btn.limit.active  { background:#f59e0b; color:#000; }

/* === GRID === */
.grid { display: grid; gap: 10px; }
.grid-4 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: 1fr; }
.grid-main { grid-template-columns: 1fr; }
@media (min-width: 1200px) {
    .grid-4 { grid-template-columns: repeat(4, 1fr); }
    .grid-3 { grid-template-columns: repeat(3, 1fr); }
    .grid { gap: 14px; }
}

/* === CARDS === */
.card {
    background: var(--surface);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow);
}
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 10px; font-size: 10px; font-weight: 600; color: var(--text-secondary);
    text-transform: uppercase; letter-spacing: 0.6px;
}

/* === STAT CARDS === */
.stat-card { position: relative; min-height: 88px; }
.stat-card .icon-bg {
    position: absolute; top: 12px; right: 12px; width: 28px; height: 28px;
    border-radius: 6px; display: flex; align-items: center; justify-content: center;
    opacity: 0.1;
}
.stat-card .icon-bg svg { width: 16px; height: 16px; }
.stat-value { font-size: 24px; font-weight: 700; letter-spacing: -0.3px; }
.stat-label { font-size: 10px; color: var(--text-secondary); margin-top: 3px; }
.stat-change { font-size: 11px; font-weight: 600; margin-top: 4px; }
.stat-change.positive { color: var(--green); }
.stat-change.negative { color: var(--red); }

/* === CHART === */
.chart-card {
    background: var(--surface);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 18px;
    box-shadow: var(--shadow);
}
.chart-card canvas { width: 100% !important; height: 100px !important; }
@media (min-width: 768px) { .chart-card canvas { height: 180px !important; } }
@media (min-width: 1200px) { .chart-card canvas { height: 240px !important; } }

/* === LOG === */
.log-container {
    border-radius: var(--radius-sm);
    max-height: 200px; overflow-y: auto;
    background: rgba(0,0,0,0.25);
}
.log-entry {
    padding: 6px 12px; font-size: 11px; font-family: 'JetBrains Mono', monospace;
    border-bottom: 1px solid rgba(55, 65, 90, 0.12);
    display: flex; gap: 6px; line-height: 1.5;
}
.log-tag { font-weight: 600; white-space: nowrap; min-width: 55px; font-size: 10px; flex-shrink: 0; }
.log-msg { color: var(--text-secondary); word-break: break-word; }
/* ── Log tag colours (matched to actual tags used in app.js / index.html) ── */
.log-tag.WIN    { color: var(--green); }
.log-tag.LOSS   { color: var(--red); }
.log-tag.ERR    { color: var(--red); }
.log-tag.WARN   { color: var(--yellow); }
.log-tag.BOT    { color: var(--blue); }
.log-tag.ML     { color: var(--purple); }
.log-tag.SIGNAL { color: var(--yellow); }
.log-tag.STOP   { color: var(--red); font-weight: 700; }
.log-tag.CONFIG { color: var(--blue); }
.log-tag.WS     { color: var(--cyan); }
.log-tag.CONN   { color: var(--green); }
.log-tag.ORDER  { color: var(--text); }
.log-tag.ACCT   { color: var(--cyan); }
.log-tag.LEV    { color: var(--yellow); }
.log-tag.POS    { color: var(--yellow); }
.log-tag.DICA   { color: var(--text-tertiary); }
.log-tag.AVISO  { color: var(--yellow); }  /* backward compat */
@media (min-width: 768px) { .log-container { max-height: 300px; } }

/* === INDICATORS === */
.indicator-bar { height: 6px; background: rgba(0,0,0,0.3); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.indicator-fill { height: 100%; border-radius: 3px; transition: width 0.4s ease; }
.indicator-label { display: flex; justify-content: space-between; font-size: 11px; margin-bottom: 2px; }
.indicator-value { font-weight: 600; }

/* === TABLES === */
.trades-table-wrapper { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
.trades-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12px; min-width: 500px; }
.trades-table th {
    text-align: left; padding: 8px 8px; font-size: 9px; text-transform: uppercase;
    color: var(--text-tertiary); font-weight: 600; border-bottom: 1px solid var(--border);
    letter-spacing: 0.4px;
}
.trades-table td { padding: 8px 8px; border-bottom: 1px solid rgba(55, 65, 90, 0.12); white-space: nowrap; }
.trades-table tr:last-child td { border-bottom: none; }
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 8px; border-radius: 4px;
    font-size: 10px; font-weight: 700;
}
.badge-win { background: var(--green-bg); color: var(--green); }
.badge-loss { background: var(--red-bg); color: var(--red); }
.badge-neutral { background: var(--blue-bg); color: var(--blue); }

/* === PRICE TICKER === */
.price-ticker {
    font-family: 'JetBrains Mono', monospace;
    font-size: 28px; font-weight: 700;
    transition: color 0.2s;
}
.price-ticker.up { color: var(--green); }
.price-ticker.down { color: var(--red); }

/* === STRATEGY BADGE === */
.strategy-badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px; border-radius: 5px; font-size: 10px; font-weight: 600;
}
.strategy-badge.aggressive { background: var(--red-bg); color: var(--red); }
.strategy-badge.moderate { background: var(--yellow-bg); color: var(--yellow); }
.strategy-badge.conservative { background: var(--green-bg); color: var(--green); }
.strategy-badge.ml { background: var(--purple-bg); color: var(--purple); }

/* === UTILITY === */
.user-info { display: flex; align-items: center; gap: 8px; }
.empty-state { text-align: center; padding: 32px 18px; color: var(--text-tertiary); font-size: 13px; }
.fade-in { animation: fadeIn 0.4s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* === DIGIT FREQ === */
.digit-freq-bar { height: 36px; background: rgba(0,0,0,0.2); border-radius: 3px; position: relative; margin-top: 2px; }
.digit-freq-fill { position: absolute; bottom: 0; left: 0; right: 0; border-radius: 3px; transition: height 0.3s; }

/* === ML === */
.ml-bar-track { height: 100%; border-radius: 2px; background: rgba(0,0,0,0.3); }
.ml-bar-fill { height: 100%; border-radius: 2px; transition: width 0.5s ease; }

/* ── LIGHT THEME ── */
[data-theme="light"] {
    --bg-primary: #f0f2f5;
    --bg-secondary: #e4e8ef;
    --surface: rgba(255, 255, 255, 0.95);
    --surface-hover: rgba(245, 247, 250, 0.98);
    --border: rgba(150, 162, 195, 0.7); /* 버튼 테두리 가시성 강화 */
    --text: #1a1d28;
    --text-secondary: #3d4460; /* 5.8:1 대비비 */
    --text-tertiary: #505A7A; /* 대비비 개선: #66728e(4.1:1) → #505A7A(5.7:1) — 봇 1·2·3 버튼 가시성 */
    --shadow: 0 2px 16px rgba(0, 0, 0, 0.08);
}
[data-theme="light"] .log-container { background: rgba(0,0,0,0.05); }
[data-theme="light"] .log-entry { border-bottom-color: rgba(180,190,210,0.25); }
[data-theme="light"] .indicator-bar,
[data-theme="light"] .ml-bar-track { background: rgba(0,0,0,0.1); }
[data-theme="light"] .digit-freq-bar { background: rgba(0,0,0,0.08); }
[data-theme="light"] .sym-pos-box { background: rgba(0,0,0,0.05); }
[data-theme="light"] .trades-table td { border-bottom-color: rgba(180,190,210,0.2); }
[data-theme="light"] .bottom-nav {
    background: rgba(245,247,250,.97) !important;
    border-top-color: rgba(180,190,210,.5) !important;
    box-shadow: 0 -2px 12px rgba(0,0,0,.1) !important;
}
