@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@300;400;500;600;700;800;900&display=swap');

:root {
  --brand-dark: #0d1117;
  --brand-darker: #080d14;
  --brand-card: #161b22;
  --brand-border: #21262d;
  --brand-orange: #f97316;
  --brand-gold: #f59e0b;
  --brand-red: #ef4444;
  --brand-green: #22c55e;
  --brand-gradient: linear-gradient(135deg, #e83a00 0%, #f97316 50%, #f59e0b 100%);

  --navbar-h: 56px;
  --ticker-h: 30px;
  --app-top: 86px;      /* navbar + ticker */
  --sidebar-w: 240px;
  --bottom-nav-h: 60px;
}

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

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--brand-dark);
  color: #e5e7eb;
  font-family: 'Noto Sans KR', sans-serif;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Scrollbar (데스크탑만) */
@media (min-width: 769px) {
  ::-webkit-scrollbar { width: 6px; }
  ::-webkit-scrollbar-track { background: var(--brand-darker); }
  ::-webkit-scrollbar-thumb { background: #374151; border-radius: 3px; }
  ::-webkit-scrollbar-thumb:hover { background: var(--brand-orange); }
}

/* ============================================================
   UTILITY
   ============================================================ */
.gradient-text {
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ============================================================
   CARDS
   ============================================================ */
.glass-card {
  background: rgba(22, 27, 34, 0.8);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(249, 115, 22, 0.1);
  border-radius: 14px;
  transition: all 0.3s ease;
}

.glass-card:hover {
  border-color: rgba(249, 115, 22, 0.3);
  box-shadow: 0 0 30px rgba(249, 115, 22, 0.1);
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn-primary {
  background: var(--brand-gradient);
  border: none;
  color: white;
  padding: 13px 28px;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  font-size: 15px;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: 'Noto Sans KR', sans-serif;
}

.btn-primary::before {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: left 0.5s;
}
.btn-primary:hover::before { left: 100%; }
.btn-primary:hover { box-shadow: 0 0 30px rgba(249, 115, 22, 0.5); }
.btn-primary:active { opacity: 0.85; transform: scale(0.98); }

.btn-secondary {
  background: transparent;
  border: 1px solid rgba(249, 115, 22, 0.5);
  color: var(--brand-orange);
  padding: 13px 28px;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 15px;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: 'Noto Sans KR', sans-serif;
}
.btn-secondary:hover { background: rgba(249, 115, 22, 0.1); border-color: var(--brand-orange); }
.btn-secondary:active { opacity: 0.85; transform: scale(0.98); }

/* ============================================================
   SIGNAL BADGES
   ============================================================ */
.signal-buy {
  background: rgba(34, 197, 94, 0.15);
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: #22c55e;
  padding: 4px 11px;
  border-radius: 18px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
  display: inline-block;
}
.signal-sell {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #ef4444;
  padding: 4px 11px;
  border-radius: 18px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
  display: inline-block;
}
.signal-hold {
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: #f59e0b;
  padding: 4px 11px;
  border-radius: 18px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
  display: inline-block;
}

.price-up   { color: #ef4444; }
.price-down { color: #3b82f6; }

/* ============================================================
   NAVBAR (fixed)
   ============================================================ */
.navbar {
  background: rgba(8, 13, 20, 0.97);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(249, 115, 22, 0.1);
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  height: var(--navbar-h);
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  background: rgba(13, 17, 23, 0.98);
  border-right: 1px solid rgba(249, 115, 22, 0.1);
  width: var(--sidebar-w);
  position: fixed;
  top: var(--navbar-h);
  left: 0; bottom: 0;
  overflow-y: auto;
  transition: transform 0.3s ease;
  z-index: 500;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 20px;
  cursor: pointer;
  transition: all 0.2s ease;
  border-radius: 10px;
  margin: 3px 10px;
  font-size: 14px;
  color: #9ca3af;
  min-height: 48px;
}
.sidebar-item:hover  { background: rgba(249,115,22,0.1); color: var(--brand-orange); }
.sidebar-item.active { background: rgba(249,115,22,0.15); color: var(--brand-orange); border-left: 3px solid var(--brand-orange); }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
  margin-left: var(--sidebar-w);
  margin-top: var(--app-top);
  padding: 20px;
  min-height: calc(100vh - var(--app-top));
}

/* ============================================================
   MISC
   ============================================================ */
.strength-bar  { height: 6px; border-radius: 3px; background: #1f2937; overflow: hidden; }
.strength-fill { height: 100%; border-radius: 3px; transition: width 0.5s ease; }

.badge-kospi {
  background: rgba(59,130,246,0.15); border: 1px solid rgba(59,130,246,0.3);
  color: #60a5fa; padding: 2px 8px; border-radius: 5px; font-size: 11px; font-weight: 700;
  white-space: nowrap; display: inline-block;
}
.badge-kosdaq {
  background: rgba(168,85,247,0.15); border: 1px solid rgba(168,85,247,0.3);
  color: #c084fc; padding: 2px 8px; border-radius: 5px; font-size: 11px; font-weight: 700;
  white-space: nowrap; display: inline-block;
}

.form-input {
  background: rgba(22,27,34,0.8);
  border: 1px solid var(--brand-border);
  color: white;
  padding: 14px 16px;
  border-radius: 10px;
  width: 100%;
  transition: all 0.3s ease;
  font-size: 16px; /* iOS 자동 줌 방지 */
  min-height: 50px;
  font-family: 'Noto Sans KR', sans-serif;
}
.form-input:focus {
  outline: none;
  border-color: var(--brand-orange);
  box-shadow: 0 0 0 3px rgba(249,115,22,0.12);
}
.form-input::placeholder { color: #4b5563; }

/* Select */
select.form-input {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}
select.form-input option {
  background: #161b22;
  color: white;
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes float        { 0%,100%{transform:translateY(0)}  50%{transform:translateY(-20px)} }
@keyframes glow         { 0%,100%{box-shadow:0 0 20px rgba(249,115,22,.3)} 50%{box-shadow:0 0 60px rgba(249,115,22,.6)} }
@keyframes fadeInUp     { from{opacity:0;transform:translateY(20px)} to{opacity:1;transform:none} }
@keyframes slideInLeft  { from{opacity:0;transform:translateX(-20px)} to{opacity:1;transform:none} }
@keyframes fadeIn       { from{opacity:0} to{opacity:1} }
@keyframes slideUp      { from{opacity:0;transform:translateY(28px)} to{opacity:1;transform:none} }
@keyframes fadeOut      { from{opacity:1} to{opacity:0;pointer-events:none} }
@keyframes spin         { to{transform:rotate(360deg)} }
@keyframes ticker       { 0%{transform:translateX(100vw)} 100%{transform:translateX(-100%)} }
@keyframes particleFloat{
  0%  {transform:translateY(100vh) scale(0);opacity:0}
  10% {opacity:1}
  90% {opacity:1}
  100%{transform:translateY(-100px) scale(1);opacity:0}
}

.animate-float       { animation: float 6s ease-in-out infinite; }
.animate-glow        { animation: glow 3s ease-in-out infinite; }
.animate-fadeInUp    { animation: fadeInUp 0.6s ease-out forwards; }
.animate-slideInLeft { animation: slideInLeft 0.6s ease-out forwards; }

/* Particle */
.particle {
  position: absolute; width: 2px; height: 2px;
  background: var(--brand-orange); border-radius: 50%;
  animation: particleFloat linear infinite; opacity: 0;
}

/* ============================================================
   NEWS CARD
   ============================================================ */
.news-card {
  background: rgba(22,27,34,0.8);
  border: 1px solid rgba(249,115,22,0.08);
  border-radius: 12px;
  padding: 15px 16px;
  transition: border-color 0.3s ease;
  cursor: pointer;
}
.news-card:hover  { border-color: rgba(249,115,22,0.28); }
.news-card:active { background: rgba(22,27,34,0.95); }

/* STAT CARD */
.stat-card {
  background: rgba(22,27,34,0.8);
  border-radius: 14px;
  padding: 16px;
  border: 1px solid rgba(249,115,22,0.08);
  transition: border-color 0.3s ease;
}

/* TABLE WRAPPER (가로 스크롤) */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* TABLE */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  background: rgba(22,27,34,0.9);
  padding: 12px 13px; text-align: left;
  font-size: 11px; font-weight: 700; color: #6b7280;
  text-transform: uppercase; letter-spacing: 0.04em;
  border-bottom: 1px solid var(--brand-border);
  white-space: nowrap;
}
.data-table td {
  padding: 12px 13px; border-bottom: 1px solid rgba(33,38,45,0.5);
  font-size: 13px; transition: background 0.2s;
}
.data-table tr:hover td { background: rgba(249,115,22,0.04); }

/* SPINNER */
.spinner {
  width: 34px; height: 34px;
  border: 3px solid rgba(249,115,22,0.1);
  border-top-color: var(--brand-orange);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* ============================================================
   MODAL (하단 시트 스타일)
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0;
  /* 단색 거의 불투명 배경 — backdrop-filter 제거 (차트 매 프레임 redraw 시 GPU 비용 큼) */
  background: rgba(0,0,0,0.92);
  z-index: 2000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s ease;
  padding: 0;
  /* GPU 레이어 분리 → 부모 dashboard와 합성 비용 감소 */
  will-change: opacity;
  contain: layout style paint;
}

.modal-content {
  background: var(--brand-card);
  border: 1px solid rgba(249,115,22,0.2);
  border-radius: 20px 20px 0 0;
  padding: 16px 16px 20px;
  width: 100%;
  max-width: 100%;
  animation: slideUp 0.3s ease;
  height: 96vh;
  max-height: 96vh;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* 모달 핸들 바 */
.modal-content::before {
  content: '';
  display: block;
  width: 40px; height: 4px;
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
  margin: 0 auto 18px;
}

/* ALERT */
.alert-success {
  background: rgba(34,197,94,0.1); border: 1px solid rgba(34,197,94,0.3);
  color: #22c55e; padding: 13px 15px; border-radius: 10px; font-size: 14px;
  display: flex; align-items: flex-start; gap: 9px;
}
.alert-error {
  background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3);
  color: #ef4444; padding: 13px 15px; border-radius: 10px; font-size: 14px;
  display: flex; align-items: flex-start; gap: 9px; margin-bottom: 12px;
}

/* TICKER */
.ticker-tape {
  background: rgba(8,13,20,0.95);
  border-bottom: 1px solid rgba(249,115,22,0.08);
  overflow: hidden; white-space: nowrap; padding: 6px 0;
  height: var(--ticker-h);
  display: flex; align-items: center;
}
.ticker-inner { display: inline-block; animation: ticker 40s linear infinite; }

/* TAB */
.tab-btn {
  padding: 9px 16px; border-radius: 8px; font-weight: 600; font-size: 13px;
  cursor: pointer; transition: all 0.2s ease; color: #6b7280;
  border: 1px solid transparent; background: transparent;
  min-height: 42px; white-space: nowrap;
  font-family: 'Noto Sans KR', sans-serif;
}
.tab-btn.active { background: rgba(249,115,22,0.15); color: var(--brand-orange); border-color: rgba(249,115,22,0.3); }
.tab-btn:hover:not(.active) { color: #e5e7eb; background: rgba(255,255,255,0.05); }
.tab-btn:active { opacity: 0.75; }

/* TOAST */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 9999; padding: 13px 18px; border-radius: 12px;
  font-size: 14px; font-weight: 600;
  display: flex; align-items: center; gap: 9px;
  animation: slideUp 0.3s ease, fadeOut 0.3s ease 2.7s forwards;
  min-width: 240px; max-width: calc(100vw - 28px);
  text-align: center; justify-content: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.toast-success { background: rgba(34,197,94,0.95); color: white; }
.toast-error   { background: rgba(239,68,68,0.95); color: white; }

/* MISC */
.admin-badge {
  background: var(--brand-gradient); color: white;
  padding: 3px 9px; border-radius: 6px; font-size: 11px; font-weight: 700;
  letter-spacing: 0.04em;
}
.trend-up::before   { content: '▲ '; }
.trend-down::before { content: '▼ '; }
.chart-container { position: relative; height: 240px; width: 100%; }
.divider { height: 1px; background: linear-gradient(90deg,transparent,rgba(249,115,22,.3),transparent); margin: 18px 0; }

/* ============================================================
   SIDEBAR OVERLAY (mobile)
   ============================================================ */
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.65); z-index: 499;
  backdrop-filter: blur(3px);
}
.sidebar-overlay.active { display: block; }

/* ============================================================
   BOTTOM NAV (모바일 전용 하단 탭바)
   ============================================================ */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-h); z-index: 600;
  background: rgba(8,13,20,0.98);
  border-top: 1px solid rgba(249,115,22,0.12);
  backdrop-filter: blur(20px);
  /* safe area for iPhone X+ */
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.bottom-nav-items {
  display: flex; height: 100%;
}
.bottom-nav-item {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  cursor: pointer; transition: all 0.2s;
  color: #4b5563; font-size: 9px; font-weight: 600;
  letter-spacing: 0.02em;
  border: none; background: none;
  -webkit-tap-highlight-color: transparent;
  font-family: 'Noto Sans KR', sans-serif;
  padding: 0 4px;
  min-height: 52px;
}
.bottom-nav-item i { font-size: 17px; margin-bottom: 1px; }
.bottom-nav-item.active { color: var(--brand-orange); }
.bottom-nav-item:active { opacity: 0.7; }

/* ============================================================
   RESPONSIVE — MOBILE (≤ 768px)
   ============================================================ */
@media (max-width: 768px) {

  :root {
    --navbar-h: 56px;
    --ticker-h: 30px;
    --app-top: 86px;
  }

  /* ---- Sidebar: 전체화면 드로어 ---- */
  .sidebar {
    top: 0 !important;
    width: 280px;
    transform: translateX(-100%);
    z-index: 700;
    padding-top: 56px;
  }
  .sidebar.open { transform: translateX(0) !important; }

  /* ---- Main ---- */
  .main-content {
    margin-left: 0 !important;
    margin-top: var(--app-top) !important;
    padding: 14px 14px calc(var(--bottom-nav-h) + 16px) !important;
  }

  /* ---- Bottom Nav 표시 ---- */
  .bottom-nav { display: block; }

  /* ---- 카드 ---- */
  .glass-card { border-radius: 12px; }
  .stat-card  { padding: 14px; border-radius: 12px; }
  .news-card  { padding: 13px 14px; }

  /* ---- 탭 ---- */
  .tab-btn { padding: 8px 12px; font-size: 12px; min-height: 40px; }

  /* ---- 테이블 ---- */
  .data-table th { padding: 10px 10px; font-size: 10px; }
  .data-table td { padding: 10px 10px; font-size: 12px; }

  /* ---- 모달 ---- */
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal-content {
    border-radius: 20px 20px 0 0;
    padding: 10px 13px calc(14px + env(safe-area-inset-bottom, 0px));
    height: 95vh;
    max-height: 95vh;
    width: 100%;
  }

  /* ---- Chart ---- */
  .chart-container { height: 170px; }

  /* ---- Toast ---- */
  .toast { bottom: calc(var(--bottom-nav-h) + 12px); }

  /* ---- 폼 입력 ---- */
  .form-input { font-size: 16px; }

  /* ---- 버튼 ---- */
  .btn-primary, .btn-secondary { min-height: 50px; }

  /* ---- 2단 → 1단 ---- */
  .two-col { grid-template-columns: 1fr !important; }
}

/* ============================================================
   RESPONSIVE — SMALL MOBILE (≤ 390px)
   ============================================================ */
@media (max-width: 390px) {
  .tab-btn { padding: 7px 9px; font-size: 11px; }
  .data-table th, .data-table td { padding: 9px 8px; font-size: 11px; }
  .stat-card { padding: 12px; }
  .main-content { padding: 12px 12px calc(var(--bottom-nav-h) + 12px) !important; }
  .news-card { padding: 12px 13px; }
  .signal-buy, .signal-sell, .signal-hold { padding: 3px 9px; font-size: 11px; }
  .bottom-nav-item { font-size: 8px; }
  .bottom-nav-item i { font-size: 16px; }
}

/* ============================================================
   DESKTOP (> 768px) — 데스크탑에서 modal을 중앙 시트로
   ============================================================ */
@media (min-width: 769px) {
  .modal-overlay {
    align-items: center;
    padding: 20px;
  }
  .modal-content {
    border-radius: 20px;
    max-width: 1200px;
    width: 95vw;
    height: 92vh;
    max-height: 92vh;
    padding: 22px 24px 22px;
  }
  .modal-content::before { display: none; }
  .chart-container { height: 240px; }
}
@media (min-width: 1280px) {
  .modal-content { max-width: 1400px; }
}
