/* ═══════════════════════════════════════
   InsightNote Design System v2
   Simple · Flat · Readable
═══════════════════════════════════════ */

/* [A] Reset ─────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Font Awesome 보호 */
.fa, .fas, .far, .fab, .fal, .fad,
[class^="fa-"], [class*=" fa-"] {
  font-family: 'Font Awesome 6 Free', 'Font Awesome 6 Brands' !important;
  font-size: 13px;
}

/* [B] Tokens ────────────────────────── */
:root {
  --blue:         #3478F6;
  --blue-light:   #EBF2FF;
  --green:        #059669;
  --red:          #DC2626;
  --orange:       #F97316;
  --amber:        #F59E0B;
  --sky:          #0EA5E9;
  --rose:         #F43F5E;
  --violet:       #8B5CF6;

  --bg-page:      #F7F8FA;
  --bg-card:      #FFFFFF;
  --bg-hover:     #F9FAFB;
  --bg-section:   #F9FAFB;
  --bg-warning:   #FFF5F5;

  --text-900:     #111827;
  --text-700:     #374151;
  --text-500:     #6B7280;
  --text-400:     #9CA3AF;

  --border:       #E5E7EB;
  --border-light: #F3F4F6;

  --sidebar-w:    240px;
  --radius-sm:    6px;
  --radius-md:    8px;
  --radius-lg:    12px;
  --shadow:       0 1px 3px rgba(0,0,0,0.06);
}

/* [C] Base ──────────────────────────── */
.bg-page-bg { background-color: #F7F8FA !important; }

html, body {
  background: var(--bg-page) !important;
  color: var(--text-900) !important;
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, sans-serif !important;
  font-size: 13px !important;
  line-height: 1.6 !important;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

/* [D] Layout ────────────────────────── */
#sidebar {
  width: var(--sidebar-w) !important;
  background: #F7F8FA !important;
  border-right: 1px solid #E5E7EB !important;
}

#main-content, #page-content {
  background: #FFFFFF !important;
}

/* Sidebar 내부 — clobe.ai style */
#sidebar-nav {
  scrollbar-width: thin;
  scrollbar-color: #E5E7EB transparent;
}
#sidebar-nav::-webkit-scrollbar { width: 4px; }
#sidebar-nav::-webkit-scrollbar-thumb { background: #E5E7EB; border-radius: 2px; }
#sidebar-nav::-webkit-scrollbar-track { background: transparent; }

.nav-sub:hover .acc-more-btn { opacity: 1 !important; }

.nav-sub .drag-handle,
.nav-sub [class*="drag"] {
  display: none !important;
}

/* 드래그 오버 표시 */
.acc-drag-over {
  background: #F3F4F6 !important;
  box-shadow: inset 0 -2px 0 #9CA3AF;
}

/* [E] Page Header ───────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
}
.page-header h1,
.page-header .page-title {
  font-size: 20px !important;
  font-weight: 700 !important;
  color: var(--text-900) !important;
  letter-spacing: -0.02em;
  margin: 0 0 4px 0;
}
.page-header p,
.page-header .page-subtitle {
  font-size: 13px !important;
  color: var(--text-400) !important;
  margin: 0;
}

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

/* [F] Card ──────────────────────────── */
.card {
  background: var(--bg-card) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow) !important;
  padding: 20px 24px;
}

/* [G] Stat Grid ─────────────────────── */
.stat-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px; }
.stat-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.stat-grid-5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 20px; }
/* backward compat */
.stat-cards  { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.summary-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  box-shadow: var(--shadow);
  position: relative;
}
.stat-card .label {
  font-size: 12px;
  color: var(--text-500);
  margin-bottom: 6px;
}
.stat-card .value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-900);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.stat-card .sub {
  font-size: 11px;
  color: var(--text-400);
  margin-top: 6px;
}

/* backward compat for summary-card */
.summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
}
.summary-card .s-label { font-size: 11px; color: var(--text-400); margin-bottom: 6px; }
.summary-card .s-value { font-size: 22px; font-weight: 700; color: var(--text-900); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }

/* [H] Tabs ──────────────────────────── */
.tabs,
.tab-group {
  display: inline-flex;
  background: var(--border-light);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}
.tab-btn {
  padding: 4px 12px;
  font-size: 12px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--text-500);
  cursor: pointer;
  transition: all 0.1s;
  font-family: 'Pretendard', sans-serif;
  font-variant-numeric: tabular-nums;
}
.tab-btn:hover { color: var(--text-900); }
.tab-btn.active {
  background: var(--bg-card);
  color: var(--text-900);
  font-weight: 500;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* [I] Buttons ───────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  font-size: 13px;
  font-family: 'Pretendard', sans-serif;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-900);
  cursor: pointer;
  transition: background 0.1s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); }
.btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-primary:hover { background: #2563EB; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-danger { color: var(--red); border-color: var(--red); }
.btn-danger:hover { background: #FFF0F0; }

/* [J] Inputs ────────────────────────── */
input, select, textarea {
  font-family: 'Pretendard', sans-serif !important;
  font-size: 13px !important;
  color: var(--text-900) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-md) !important;
  background: var(--bg-card) !important;
  outline: none !important;
  transition: border-color 0.1s !important;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--blue) !important;
  box-shadow: 0 0 0 3px rgba(52,120,246,0.1) !important;
}

.search-input {
  padding: 8px 14px 8px 36px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  width: 100%;
}
.search-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(52,120,246,0.1);
}

/* [K] Tables ────────────────────────── */
.tbl-wrap,
.table-wrap {
  overflow: hidden;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-card);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  background: var(--bg-card);
}
thead tr { border-bottom: 1px solid var(--border); background: var(--bg-card); }
thead th {
  font-size: 12px !important;
  font-weight: 500 !important;
  color: var(--text-500) !important;
  padding: 10px 14px !important;
  text-align: right;
  white-space: nowrap;
  background: var(--bg-card) !important;
}
thead th:first-child,
thead th:nth-child(2) { text-align: left; }

tbody tr { border-bottom: 1px solid var(--border-light); transition: background 0.1s; }
tbody tr:hover { background: var(--bg-hover) !important; }
tbody td {
  padding: 11px 14px !important;
  color: var(--text-900) !important;
  font-size: 13px !important;
  text-align: right;
}
tbody td:first-child,
tbody td:nth-child(2) { text-align: left; }

.table-section-header td {
  background: var(--bg-section) !important;
  font-weight: 600 !important;
  font-size: 12px !important;
  color: var(--text-700) !important;
  padding: 8px 14px !important;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.table-total-row td {
  font-weight: 700 !important;
  font-size: 13px !important;
  color: var(--text-900) !important;
  border-top: 1px solid var(--border) !important;
  background: var(--bg-card) !important;
}

/* [L] Profit Colors ─────────────────── */
.pos   { color: var(--green) !important; font-weight: 600; }
.neg   { color: var(--red) !important; font-weight: 600; }
.dividend { color: #8B5CF6 !important; font-weight: 600; }
.pos-bg {
  display: inline-block;
  background: #ECFDF5; color: var(--green);
  font-size: 12px; font-weight: 600;
  padding: 2px 8px; border-radius: 4px;
}
.neg-bg {
  display: inline-block;
  background: #FFF0F2; color: var(--red);
  font-size: 12px; font-weight: 600;
  padding: 2px 8px; border-radius: 4px;
}
.rate-pos { color: var(--green); font-weight: 600; }
.rate-neg { color: var(--red); font-weight: 600; }

/* backward compat */
.text-positive, .profit { color: var(--green) !important; font-weight: 500; }
.text-negative, .loss   { color: var(--red) !important; font-weight: 500; }
.text-blue-val          { color: var(--blue) !important; font-weight: 500; }
.text-muted             { color: var(--text-400) !important; }

/* [M] Badges ────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}
.badge-blue   { background: var(--blue-light); color: var(--blue); }
.badge-green  { background: #ECFDF5; color: var(--green); }
.badge-red    { background: #FFF0F2; color: var(--red); }
.badge-gray   { background: var(--border-light); color: var(--text-500); }
.badge-buy    { background: #FFF7ED; color: var(--orange); }
.badge-sell   { background: #F5F3FF; color: var(--violet); }
.badge-div    { background: #ECFDF5; color: var(--green); }

/* [N] Ratio Bar ─────────────────────── */
.ratio-cell {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  font-size: 12px;
  color: var(--text-500);
}
.ratio-bar {
  width: 48px;
  height: 6px;
  background: var(--border-light);
  border-radius: 3px;
  overflow: hidden;
}
.ratio-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--blue);
  min-width: 4px;
}

/* [O] Stock Icon ────────────────────── */
.stock-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--border-light);
  font-size: 10px;
  font-weight: 700;
  color: var(--text-500);
  flex-shrink: 0;
}

.stock-name { font-size: 13px; font-weight: 500; color: var(--text-900); }
.stock-code { font-size: 11px; color: var(--text-400); margin-left: 4px; }
.row-rank   { font-size: 12px; color: var(--text-400); min-width: 20px; }

/* [P] Budget ────────────────────────── */
.month-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-900);
  margin-bottom: 16px;
}
.month-nav button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-400);
  font-size: 14px;
  padding: 4px;
  border-radius: 4px;
  transition: color 0.1s;
}
.month-nav button:hover { color: var(--text-900); }

.budget-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.budget-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-900);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
}
.budget-dot { width: 8px; height: 8px; border-radius: 50%; }
.budget-dot-green { background: var(--green); }
.budget-dot-red   { background: var(--red); }

.progress-bar-wrap {
  height: 8px;
  background: var(--border-light);
  border-radius: 4px;
  overflow: hidden;
  margin: 8px 0;
}
.progress-bar-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--rose);
  transition: width 0.3s;
}

.budget-total-row td {
  font-weight: 700 !important;
  border-top: 1px solid var(--border) !important;
  color: var(--text-900) !important;
  padding: 10px 14px !important;
}

/* [Q] Refund Card ───────────────────── */
.refund-card {
  background: var(--bg-warning);
  border: 1px solid #FFC9D0;
  border-radius: var(--radius-md);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.refund-label { font-size: 13px; color: var(--text-500); }
.refund-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--red);
  font-variant-numeric: tabular-nums;
}

/* [R] Toast / Animation ─────────────── */
.toast {
  animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.7s;
}
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeIn 0.2s ease; }
.animate-in { animation: fadeIn 0.2s ease; }

/* Chart.js 범례 */
.chart-legend { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 10px; }
.chart-legend-item { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text-500); }
.chart-legend-dot { width: 8px; height: 8px; border-radius: 50%; }

/* Hero numbers */
.hero-number {
  font-size: 30px; font-weight: 700; color: var(--text-900);
  font-variant-numeric: tabular-nums; letter-spacing: -0.02em; line-height: 1.2;
}
.hero-change { font-size: 12px; color: var(--text-500); margin-top: 4px; }

/* Utility */
.tabular  { font-variant-numeric: tabular-nums; }
.divider  { height: 1px; background: var(--border-light); margin: 16px 0; }
.text-sm  { font-size: 12px !important; }
.text-xs  { font-size: 11px !important; }
.fw-500   { font-weight: 500 !important; }
.fw-700   { font-weight: 700 !important; }

/* [S] Mobile ────────────────────────── */
@media (max-width: 767px) {
  :root { --sidebar-w: 0px; }
  #main-content, main { margin-left: 0; padding: 16px; }
  .stat-grid-3, .stat-grid-4, .stat-grid-5, .stat-cards { grid-template-columns: 1fr 1fr; }
  .summary-cards { grid-template-columns: 1fr 1fr; }
  .budget-grid { grid-template-columns: 1fr; }
}
