/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0f172a;
  --bg2: #1e293b;
  --bg3: #293548;
  --border: #334155;
  --text: #f1f5f9;
  --text2: #94a3b8;
  --text3: #64748b;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #4f46e520;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --sidebar-w: 240px;
}
html { font-size: 14px; }
body { background: var(--bg); color: var(--text); font-family: -apple-system, 'Pretendard', 'Noto Sans KR', sans-serif; line-height: 1.6; min-height: 100vh; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; color: inherit; font: inherit; }
input, textarea, select { font: inherit; color: inherit; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 14px; width: 100%; transition: border-color .2s; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 100px; }
.hidden { display: none !important; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ===== BUTTONS ===== */
.btn-primary { background: var(--primary); color: white; border-radius: var(--radius-sm); padding: 10px 20px; font-weight: 600; transition: background .2s, transform .1s; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:active { transform: scale(.98); }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 18px; font-weight: 500; transition: background .2s; }
.btn-secondary:hover { background: var(--bg2); }
.btn-danger { background: var(--danger); color: white; border-radius: var(--radius-sm); padding: 9px 18px; font-weight: 500; transition: background .2s; }
.btn-danger:hover { background: #dc2626; }
.btn-full { width: 100%; display: block; text-align: center; }
.btn-icon { width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; transition: background .2s; color: var(--text2); }
.btn-icon:hover { background: var(--bg3); color: var(--text); }
.btn-icon svg { width: 18px; height: 18px; }
.btn-sm { padding: 6px 14px; font-size: 12px; border-radius: 6px; }
.btn-ghost { color: var(--text2); border-radius: var(--radius-sm); padding: 8px 14px; transition: background .2s, color .2s; }
.btn-ghost:hover { background: var(--bg3); color: var(--text); }

/* ===== AUTH MODAL ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.7); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px; }
.modal-overlay.active { display: flex; }
.modal-box { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; width: 100%; max-width: 420px; position: relative; box-shadow: var(--shadow); }
.auth-box { max-width: 380px; }
.auth-logo { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 24px; font-size: 20px; font-weight: 700; }
.auth-tabs { display: flex; gap: 4px; background: var(--bg3); border-radius: var(--radius-sm); padding: 4px; margin-bottom: 24px; }
.auth-tab { flex: 1; padding: 8px; border-radius: 6px; font-weight: 600; color: var(--text2); transition: all .2s; }
.auth-tab.active { background: var(--primary); color: white; }
.auth-form { display: none; flex-direction: column; gap: 16px; }
.auth-form.active { display: flex; }
.auth-error { color: var(--danger); font-size: 12px; min-height: 16px; text-align: center; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: .05em; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ===== LAYOUT ===== */
#app { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: var(--sidebar-w); background: var(--bg2); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; transition: transform .3s; z-index: 100; }
.sidebar-header { display: flex; align-items: center; gap: 10px; padding: 20px 16px; border-bottom: 1px solid var(--border); font-size: 16px; font-weight: 700; }
.sidebar-nav { flex: 1; padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius-sm); color: var(--text2); font-weight: 500; transition: all .2s; }
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary); }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.user-info { flex: 1; display: flex; align-items: center; gap: 10px; cursor: pointer; border-radius: var(--radius-sm); padding: 8px; transition: background .2s; min-width: 0; }
.user-info:hover { background: var(--bg3); }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; color: white; flex-shrink: 0; }
.avatar.lg { width: 56px; height: 56px; font-size: 20px; }
.user-meta { min-width: 0; }
.user-name { display: block; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-sub { display: block; font-size: 11px; color: var(--text3); }
.btn-logout { width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; color: var(--text3); transition: all .2s; flex-shrink: 0; }
.btn-logout:hover { background: var(--danger)20; color: var(--danger); }
.btn-logout svg { width: 16px; height: 16px; }
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.top-header { background: var(--bg2); border-bottom: 1px solid var(--border); padding: 0 20px; height: 56px; display: flex; align-items: center; gap: 12px; flex-shrink: 0; position: relative; }
.page-title { font-size: 16px; font-weight: 700; flex: 1; }
.hamburger { display: none; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.notif-btn { position: relative; }
.notif-badge { position: absolute; top: 4px; right: 4px; background: var(--danger); color: white; border-radius: 50%; width: 16px; height: 16px; font-size: 10px; font-weight: 700; display: flex; align-items: center; justify-content: center; line-height: 1; }
.notif-panel { position: absolute; top: 56px; right: 12px; width: 340px; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); z-index: 200; max-height: 400px; overflow-y: auto; }
.notif-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 13px; }
.notif-header button { font-size: 11px; color: var(--primary); }
.notif-item { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 12px; }
.notif-item.unread { background: var(--primary-light); }
.notif-item .notif-time { color: var(--text3); margin-top: 2px; }
.page-content { flex: 1; overflow-y: auto; padding: 24px; }

/* ===== CARDS ===== */
.card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-size: 14px; font-weight: 700; }
.card-sub { font-size: 12px; color: var(--text2); }

/* ===== GRID ===== */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* ===== STATS CARD ===== */
.stat-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat-label { font-size: 11px; font-weight: 600; color: var(--text3); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.stat-value { font-size: 22px; font-weight: 700; }
.stat-value.up { color: var(--success); }
.stat-value.down { color: var(--danger); }
.stat-change { font-size: 11px; color: var(--text3); margin-top: 2px; }

/* ===== DASHBOARD ===== */
.dashboard-grid { display: flex; flex-direction: column; gap: 20px; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.section-title { font-size: 14px; font-weight: 700; }

/* ===== TRADE TABLE ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 10px 12px; text-align: left; color: var(--text3); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid var(--border)80; vertical-align: middle; }
tr:hover td { background: var(--bg3)50; }
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.badge.buy { background: var(--success)20; color: var(--success); }
.badge.sell { background: var(--danger)20; color: var(--danger); }
.badge.public { background: var(--primary)20; color: var(--primary); }
.badge.private { background: var(--bg3); color: var(--text3); }
.ticker { font-weight: 700; font-family: 'Courier New', monospace; font-size: 13px; }
.pnl.pos { color: var(--success); font-weight: 600; }
.pnl.neg { color: var(--danger); font-weight: 600; }
.pnl.zero { color: var(--text3); }
.empty-state { text-align: center; padding: 48px 20px; color: var(--text3); }
.empty-state svg { width: 48px; height: 48px; margin: 0 auto 12px; opacity: .3; display: block; }
.empty-state p { font-size: 14px; }

/* ===== FILTERS ===== */
.filter-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.filter-bar input, .filter-bar select { width: auto; min-width: 140px; }
.filter-bar input { flex: 1; max-width: 240px; }

/* ===== TRADE FORM ===== */
.trade-type-toggle { display: flex; gap: 4px; background: var(--bg3); border-radius: var(--radius-sm); padding: 4px; }
.trade-type-btn { flex: 1; padding: 8px; border-radius: 6px; font-weight: 600; text-align: center; color: var(--text2); transition: all .2s; }
.trade-type-btn.active.buy { background: var(--success); color: white; }
.trade-type-btn.active.sell { background: var(--danger); color: white; }

/* ===== POSTS ===== */
.post-list { display: flex; flex-direction: column; gap: 12px; }
.post-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; cursor: pointer; transition: border-color .2s, transform .1s; }
.post-card:hover { border-color: var(--primary)60; transform: translateY(-1px); }
.post-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.post-title { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.post-excerpt { font-size: 13px; color: var(--text2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.post-footer { display: flex; align-items: center; gap: 16px; margin-top: 12px; color: var(--text3); font-size: 12px; }
.post-footer span { display: flex; align-items: center; gap: 4px; }
.post-footer svg { width: 13px; height: 13px; }
.category-badge { font-size: 11px; padding: 2px 8px; border-radius: 4px; font-weight: 600; }
.cat-general { background: var(--bg3); color: var(--text2); }
.cat-analysis { background: #0891b220; color: #0891b2; }
.cat-news { background: #d9770620; color: #d97706; }
.cat-question { background: #7c3aed20; color: #7c3aed; }

/* ===== POST DETAIL ===== */
.post-detail-header { margin-bottom: 20px; }
.post-detail-title { font-size: 20px; font-weight: 700; margin-bottom: 12px; }
.post-content { font-size: 14px; line-height: 1.8; color: var(--text); white-space: pre-wrap; word-break: break-word; }
.post-actions { display: flex; align-items: center; gap: 12px; padding: 16px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); margin: 20px 0; }
.like-btn { display: flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 20px; border: 1px solid var(--border); font-size: 13px; font-weight: 600; transition: all .2s; }
.like-btn:hover { border-color: var(--danger); color: var(--danger); }
.like-btn.liked { background: var(--danger)20; border-color: var(--danger); color: var(--danger); }
.like-btn svg { width: 16px; height: 16px; }
.comment-section { margin-top: 24px; }
.comment-section h3 { font-size: 14px; font-weight: 700; margin-bottom: 16px; }
.comment-item { display: flex; gap: 10px; margin-bottom: 16px; }
.comment-body { flex: 1; }
.comment-author { font-size: 12px; font-weight: 600; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.comment-time { color: var(--text3); font-weight: 400; }
.comment-text { font-size: 13px; color: var(--text2); }
.comment-form { display: flex; gap: 10px; margin-top: 16px; }
.comment-form textarea { min-height: 70px; }
.comment-form .btn-primary { align-self: flex-end; white-space: nowrap; }

/* ===== GROUPS ===== */
.group-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.group-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; cursor: pointer; transition: border-color .2s, transform .1s; }
.group-card:hover { border-color: var(--primary)60; transform: translateY(-1px); }
.group-card-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 10px; }
.group-name { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.group-desc { font-size: 12px; color: var(--text2); margin-bottom: 12px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.group-meta { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--text3); }
.group-meta span { display: flex; align-items: center; gap: 4px; }
.group-meta svg { width: 13px; height: 13px; }
.group-detail-tabs { display: flex; gap: 4px; background: var(--bg3); border-radius: var(--radius-sm); padding: 4px; margin-bottom: 20px; }
.group-tab { flex: 1; padding: 8px; border-radius: 6px; font-weight: 600; color: var(--text2); text-align: center; transition: all .2s; }
.group-tab.active { background: var(--primary); color: white; }
.member-list { display: flex; flex-direction: column; gap: 10px; }
.member-item { display: flex; align-items: center; gap: 10px; }
.member-item .role-badge { margin-left: auto; font-size: 11px; padding: 2px 8px; border-radius: 4px; }
.role-badge.admin { background: var(--primary)20; color: var(--primary); }
.role-badge.member { background: var(--bg3); color: var(--text3); }
.invite-box { background: var(--bg3); border-radius: var(--radius-sm); padding: 14px; margin-top: 12px; }
.invite-code { font-family: 'Courier New', monospace; font-size: 22px; font-weight: 700; letter-spacing: 4px; text-align: center; color: var(--primary); margin: 8px 0; }
.invite-hint { font-size: 11px; color: var(--text3); text-align: center; }

/* ===== PORTFOLIO ===== */
.portfolio-table td:first-child { font-weight: 700; }
.progress-bar { height: 6px; background: var(--bg3); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.progress-fill { height: 100%; border-radius: 3px; background: var(--primary); }

/* ===== PROFILE ===== */
.profile-header { display: flex; align-items: center; gap: 20px; margin-bottom: 24px; }
.profile-stats { display: flex; gap: 24px; margin-top: 8px; }
.profile-stat { text-align: center; }
.profile-stat .val { font-size: 20px; font-weight: 700; }
.profile-stat .lbl { font-size: 11px; color: var(--text3); }

/* ===== MODAL ===== */
.modal-overlay.hidden { display: none; }
.modal-close { position: absolute; top: 16px; right: 16px; font-size: 20px; color: var(--text2); transition: color .2s; width: 28px; height: 28px; border-radius: 6px; display: flex; align-items: center; justify-content: center; }
.modal-close:hover { color: var(--text); background: var(--bg3); }
.modal-title { font-size: 16px; font-weight: 700; margin-bottom: 20px; }

/* ===== CHART ===== */
.chart-container { height: 180px; position: relative; }
.chart-bar-wrap { display: flex; align-items: flex-end; gap: 4px; height: 140px; padding: 0 4px; }
.chart-bar { flex: 1; border-radius: 4px 4px 0 0; min-height: 4px; transition: opacity .2s; cursor: pointer; position: relative; }
.chart-bar:hover { opacity: .8; }
.chart-labels { display: flex; gap: 4px; padding: 4px; }
.chart-label { flex: 1; text-align: center; font-size: 10px; color: var(--text3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-tooltip { position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%); background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px; font-size: 11px; white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity .1s; z-index: 10; }
.chart-bar:hover .chart-tooltip { opacity: 1; }

/* ===== COPY BTN ===== */
.copy-btn { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--primary); padding: 4px 10px; border-radius: 6px; transition: background .2s; }
.copy-btn:hover { background: var(--primary-light); }

/* ===== TOAST ===== */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 18px; font-size: 13px; box-shadow: var(--shadow); animation: slideIn .3s ease; pointer-events: auto; display: flex; align-items: center; gap: 8px; max-width: 320px; }
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
.toast.success::before { content: '✓'; color: var(--success); font-weight: 700; }
.toast.error::before { content: '✗'; color: var(--danger); font-weight: 700; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

/* ===== OVERLAY ===== */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 99; }

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow); }
  .sidebar-overlay { display: block; opacity: 0; pointer-events: none; transition: opacity .3s; }
  .sidebar-overlay.visible { opacity: 1; pointer-events: auto; }
  .hamburger { display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; }
  .hamburger svg { width: 20px; height: 20px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .page-content { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .notif-panel { right: 0; width: 100vw; border-radius: 0; }
}
@media (max-width: 480px) {
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar input, .filter-bar select { width: 100%; max-width: none; }
}

/* ===== DIVIDER ===== */
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.text-muted { color: var(--text2); }
.text-sm { font-size: 12px; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mb-3 { margin-bottom: 12px; }
.fw-bold { font-weight: 700; }
