/* ===== RESET ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ===== DESIGN TOKENS ===== */
:root {
  --sidebar-w: 280px;

  /* Accent */
  --accent:        #0070f3;
  --accent-hover:  #0060df;
  --accent-subtle: rgba(0,112,243,.08);
  --accent-border: rgba(0,112,243,.22);

  /* Surfaces */
  --bg:            #f5f5f5;
  --surface:       #ffffff;
  --surface-hover: #fafafa;

  /* Borders */
  --border:        rgba(0,0,0,.08);
  --border-strong: rgba(0,0,0,.13);

  /* Typography */
  --text:          #111111;
  --text-2:        #555555;
  --text-3:        #999999;

  /* Radius */
  --r:    12px;
  --r-sm:  8px;
  --r-lg: 16px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06);
  --shadow:    0 4px 16px rgba(0,0,0,.07);

  /* Sidebar */
  --sb-bg:      #ffffff;
  --sb-border:  rgba(0,0,0,.08);
  --sb-text:    #111111;
  --sb-sub:     #666666;
  --sb-hover:   rgba(0,0,0,.04);
  --sb-active:  rgba(0,112,243,.08);
  --sb-active-border: rgba(0,112,243,.2);
  --sb-brand:   #111111;
}

/* ===== DARK MODE ===== */
[data-theme="dark"] {
  --bg:            #0a0a0a;
  --surface:       #111111;
  --surface-hover: #161616;

  --border:        rgba(255,255,255,.08);
  --border-strong: rgba(255,255,255,.13);

  --text:  #ededed;
  --text-2: #888888;
  --text-3: #555555;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
  --shadow:    0 4px 16px rgba(0,0,0,.35);

  --accent-subtle: rgba(0,112,243,.14);
  --accent-border: rgba(0,112,243,.3);

  --sb-bg:     #111111;
  --sb-border: rgba(255,255,255,.08);
  --sb-text:   #ededed;
  --sb-sub:    #888888;
  --sb-hover:  rgba(255,255,255,.05);
  --sb-active: rgba(0,112,243,.12);
  --sb-active-border: rgba(0,112,243,.28);
  --sb-brand:  #ededed;
}

/* ===== BASE ===== */
html, body {
  font-family: "Pretendard", "Inter", "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body {
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  max-width: var(--sidebar-w);
  background: var(--sb-bg);
  border-right: 0.5px solid var(--sb-border);
  min-height: 100vh;
  padding: 20px 12px;
  overflow-y: auto;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar h1 {
  font-size: 15px;
  font-weight: 700;
  color: var(--sb-brand);
  padding: 4px 12px 16px;
  letter-spacing: -0.01em;
  border-bottom: 0.5px solid var(--sb-border);
  margin-bottom: 8px;
}

.sidebar-section { margin-bottom: 2px; }

.sidebar-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--sb-text);
  padding: 7px 12px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background .12s;
  text-decoration: none !important;
  border: 0.5px solid transparent;
  word-break: keep-all;
}

.sidebar-section-title:hover { background: var(--sb-hover); }

.sidebar-section.active > .sidebar-section-title {
  background: var(--sb-active);
  border-color: var(--sb-active-border);
  color: var(--accent);
}

.sub-menu {
  display: none;
  padding: 2px 0 4px 12px;
}

.sub-menu a {
  display: block;
  text-decoration: none;
  padding: 6px 12px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--sb-sub);
  transition: background .12s, color .12s;
  border: 0.5px solid transparent;
  word-break: keep-all;
  margin-bottom: 1px;
}

.sub-menu a:hover {
  background: var(--sb-hover);
  color: var(--sb-text);
}

.sub-menu a.active-link {
  background: var(--sb-active);
  border-color: var(--sb-active-border);
  color: var(--accent);
}

.sidebar-section:hover .sub-menu,
.sidebar-section.active .sub-menu { display: block; }

/* ===== MAIN ===== */
.main {
  flex: 1;
  min-width: 0;
  padding: 32px 32px 48px;
  background: var(--bg);
}

.main .wrap {
  max-width: 1280px;
  margin: 0 auto;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 20px;
}

/* ===== CARD SYSTEM ===== */
.card, .panel, .box, .tile, .kpi, .section {
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 0.5px solid var(--border) !important;
  border-radius: var(--r) !important;
  box-shadow: var(--shadow-sm);
}

.card, .panel, .box, .tile, .kpi { padding: 20px; }

h1, h2, h3, h4 { color: var(--text); letter-spacing: -0.02em; }

.card p, p, small, .muted, .sub, .hint, .meta, .desc {
  color: var(--text-2) !important;
}

/* ===== BUTTONS ===== */
button, .btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 0.5px solid var(--border-strong) !important;
  border-radius: var(--r-sm);
  padding: 7px 14px;
  cursor: pointer;
  transition: background .1s, border-color .1s, transform .08s;
  white-space: nowrap;
}

button:hover, .btn:hover {
  background: var(--surface-hover) !important;
  border-color: var(--border-strong) !important;
}

button:active, .btn:active {
  transform: scale(0.98);
}

.btn.primary, button.primary {
  background: var(--accent) !important;
  color: #fff !important;
  border-color: transparent !important;
}

.btn.primary:hover, button.primary:hover {
  background: var(--accent-hover) !important;
}

/* ===== FORM ELEMENTS ===== */
input, select, textarea {
  font-family: inherit;
  font-size: 13px;
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 0.5px solid var(--border-strong) !important;
  border-radius: var(--r-sm);
  padding: 8px 11px;
  transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

input::placeholder { color: var(--text-3); }

select option { color: var(--text); background: var(--surface); }
select option:checked { background: var(--accent-subtle); }

/* ===== RANGE SLIDER ===== */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--border-strong) !important;
  border: none !important;
  border-radius: 2px;
  padding: 0 !important;
  cursor: pointer;
  outline: none;
  box-shadow: none !important;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
  cursor: pointer;
}

input[type="range"]:focus {
  box-shadow: none !important;
}

/* ===== TABLE ===== */
table {
  border-collapse: separate !important;
  border-spacing: 0;
  overflow: hidden;
  width: 100%;
}

th {
  font-size: 11px !important;
  font-weight: 600 !important;
  color: var(--text-2) !important;
  background: var(--surface-hover) !important;
  border-bottom: 0.5px solid var(--border) !important;
  padding: 9px 12px !important;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

td {
  font-size: 13px;
  color: var(--text) !important;
  border-bottom: 0.5px solid var(--border) !important;
  padding: 10px 12px !important;
  vertical-align: middle;
}

tr:last-child td { border-bottom: none !important; }
tr:hover td { background: var(--surface-hover) !important; }

/* ===== CHIPS / BADGES ===== */
.badge, .chip, .metaChip, .sourceChip, .impactReadonly {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  border-radius: 6px;
  padding: 3px 8px;
  border: 0.5px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.badge.low, .low   { color: #16a34a; background: rgba(34,197,94,.1);  border-color: rgba(34,197,94,.25) !important; }
.badge.mid, .mid   { color: #b45309; background: rgba(245,158,11,.1); border-color: rgba(245,158,11,.25) !important; }
.badge.high, .high { color: #dc2626; background: rgba(239,68,68,.1);  border-color: rgba(239,68,68,.25) !important; }

.sourceChip { color: var(--accent); background: var(--accent-subtle) !important; border-color: var(--accent-border) !important; }

/* ===== NUMBERS (MONOSPACE) ===== */
.score, .v, .metric .v, [class*="Metric"],
.num, .count, .stat {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
}

/* ===== TOAST ===== */
.toast {
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 0.5px solid var(--border-strong) !important;
  border-radius: var(--r);
  box-shadow: var(--shadow);
}

/* ===== DARK MODE TOGGLE BUTTON ===== */
.theme-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface) !important;
  border: 0.5px solid var(--border-strong) !important;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  z-index: 1000;
  transition: transform .15s;
}

.theme-toggle:hover { transform: scale(1.08); }

/* ===== RESPONSIVE ===== */
.sidebar-hamburger { display: none; }
.mobile-header     { display: none; }

@media (max-width: 960px) {
  body { flex-direction: column; }

  .sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px !important;
    min-width: 280px !important;
    max-width: 280px !important;
    height: 100vh;
    min-height: 100vh;
    z-index: 150;
    border-right: 0.5px solid var(--sb-border);
    border-bottom: none;
    transition: left 0.25s ease;
  }

  .sidebar.sidebar-open { left: 0; }

  .main {
    padding: 20px 16px 40px;
    padding-top: 64px;
  }

  /* 기존 float 버튼들 숨김 */
  .theme-toggle { display: none !important; }

  /* ── 모바일 고정 헤더바 ── */
  .mobile-header {
    display: flex;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 48px;
    z-index: 300;
    background: var(--surface);
    border-bottom: 0.5px solid var(--border);
    padding: 0 8px;
    box-shadow: var(--shadow-sm);
  }

  .mobile-header-hamburger,
  .mobile-header-theme {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent !important;
    border: none !important;
    border-radius: var(--r-sm);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    color: var(--text) !important;
    padding: 0 !important;
    flex-shrink: 0;
    box-shadow: none !important;
    transition: background 0.12s;
    white-space: nowrap;
  }

  .mobile-header-hamburger:hover,
  .mobile-header-theme:hover {
    background: var(--sb-hover) !important;
    transform: none;
  }

  .mobile-header-title {
    flex: 1;
    text-align: center;
    font-size: 15px;
    letter-spacing: -0.02em;
    line-height: 1;
    user-select: none;
  }

  .mobile-header-bcms {
    font-weight: 800;
    background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
  }

  .mobile-header-portal {
    font-weight: 300;
    color: #64748b;
    font-size: 14px;
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 140;
  }

  .sidebar-overlay.sidebar-overlay-visible { display: block; }
}
