:root {
  --bg: #0d0f14;
  --surface: #161921;
  --surface2: #1e2230;
  --surface3: #252a3a;
  --border: #2d3348;
  --border2: #3d4460;
  --accent: #4f8ef7;
  --accent2: #38c97b;
  --accent3: #f7a94f;
  --accent4: #f75f5f;
  --accent5: #bf6fff;
  --text: #e8eaf2;
  --text2: #9299b8;
  --text3: #5d6485;
  --opex-color: #4f8ef7;
  --capex-color: #f7a94f;
  --asset-color: #bf6fff;
  --fixed-color: #38c97b;
  --variable-color: #4f8ef7;
  --invest-color: #f7a94f;
}

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

body {
  font-family: 'Noto Sans KR', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
}

/* ===== LAYOUT ===== */
.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: 56px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* TOPBAR */
.topbar {
  grid-column: 1 / -1;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  z-index: 100;
}
.topbar-logo {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  color: var(--accent);
  font-weight: 500;
  letter-spacing: 0.05em;
  display: flex; align-items: center; gap: 8px;
}
.topbar-logo svg { width: 20px; height: 20px; }
.topbar-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.topbar-actions {
  margin-left: auto;
  display: flex;
  gap: 10px;
  align-items: center;
}
.btn {
  padding: 7px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-family: 'Noto Sans KR', sans-serif;
  font-weight: 500;
  transition: all 0.15s;
  display: flex; align-items: center; gap: 6px;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: #3a7ae8; }
.btn-secondary { background: var(--surface3); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-success { background: var(--accent2); color: #0d1a12; }
.btn-success:hover { background: #2db36a; }
.btn-danger { background: var(--accent4); color: white; }
.btn-danger:hover { background: #e04444; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn svg { width: 14px; height: 14px; }

/* SIDEBAR */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.sidebar-section {
  padding: 0 12px;
  margin-bottom: 8px;
}
.sidebar-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--text3);
  text-transform: uppercase;
  padding: 4px 8px;
  margin-bottom: 2px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text2);
  transition: all 0.15s;
  position: relative;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: rgba(79,142,247,0.15); color: var(--accent); }
.nav-item.active::before {
  content: '';
  position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 60%; background: var(--accent);
  border-radius: 0 2px 2px 0;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-badge {
  margin-left: auto;
  font-size: 10px; font-family: 'JetBrains Mono', monospace;
  background: var(--surface3); padding: 2px 6px; border-radius: 10px;
  color: var(--text3);
}
.nav-separator { height: 1px; background: var(--border); margin: 8px 12px; }

/* MAIN CONTENT */
.main-content {
  overflow-y: auto;
  background: var(--bg);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* PAGE SECTION */
.page { display: none; padding: 24px; }
.page.active { display: block; }
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 24px;
}
.page-title { font-size: 22px; font-weight: 700; color: var(--text); }
.page-subtitle { font-size: 13px; color: var(--text2); margin-top: 4px; }
.page-actions { display: flex; gap: 8px; }

/* STAT CARDS */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s;
}
.stat-card:hover { border-color: var(--border2); }
.stat-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
}
.stat-card.opex::before { background: var(--opex-color); }
.stat-card.capex::before { background: var(--capex-color); }
.stat-card.asset::before { background: var(--asset-color); }
.stat-card.total::before { background: var(--accent2); }
.stat-label { font-size: 12px; color: var(--text2); margin-bottom: 8px; font-weight: 500; }
.stat-value { font-size: 22px; font-weight: 700; font-family: 'JetBrains Mono', monospace; }
.stat-value.opex { color: var(--opex-color); }
.stat-value.capex { color: var(--capex-color); }
.stat-value.asset { color: var(--asset-color); }
.stat-value.total { color: var(--accent2); }
.stat-sub { font-size: 12px; color: var(--text3); margin-top: 4px; }

/* TABLES */
.table-wrapper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 24px;
}
.table-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.table-title { font-size: 14px; font-weight: 600; }
.table-count { font-size: 12px; color: var(--text3); font-family: 'JetBrains Mono', monospace; }
.table-header-actions { margin-left: auto; display: flex; gap: 8px; }

table { width: 100%; border-collapse: collapse; }
thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
tbody td {
  padding: 9px 14px;
  font-size: 13px;
  color: var(--text);
  vertical-align: middle;
}
tbody td.mono { font-family: 'JetBrains Mono', monospace; font-size: 12px; }
tbody td.num { text-align: right; font-family: 'JetBrains Mono', monospace; font-size: 12px; }

/* BADGES */
.badge {
  display: inline-flex; align-items: center; padding: 2px 8px;
  border-radius: 4px; font-size: 11px; font-weight: 600;
  white-space: nowrap;
}
.badge-opex { background: rgba(79,142,247,0.15); color: var(--opex-color); }
.badge-capex { background: rgba(247,169,79,0.15); color: var(--capex-color); }
.badge-asset { background: rgba(191,111,255,0.15); color: var(--asset-color); }
.badge-fixed { background: rgba(56,201,123,0.15); color: var(--fixed-color); }
.badge-variable { background: rgba(79,142,247,0.15); color: var(--variable-color); }
.badge-invest { background: rgba(247,169,79,0.15); color: var(--invest-color); }

/* FORMS */
.form-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}
.form-section-title {
  font-size: 14px; font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
.form-section-title svg { width: 16px; height: 16px; color: var(--accent); }
.form-row {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
}
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row.cols-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }
.form-row.cols-5 { grid-template-columns: 1fr 1fr 1fr 1fr 1fr; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label { font-size: 12px; color: var(--text2); font-weight: 500; }
.form-label .req { color: var(--accent4); }
.form-control {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text);
  font-family: 'Noto Sans KR', sans-serif;
  transition: border-color 0.15s;
  width: 100%;
  outline: none;
}
.form-control:focus { border-color: var(--accent); }
.form-control::placeholder { color: var(--text3); }
select.form-control option { background: var(--surface2); }
.form-control[readonly] { opacity: 0.6; cursor: not-allowed; }

/* PROGRESS / BARS */
.progress-bar {
  height: 6px; background: var(--surface3);
  border-radius: 3px; overflow: hidden;
  margin-top: 6px;
}
.progress-fill {
  height: 100%; border-radius: 3px;
  transition: width 0.5s ease;
}
.progress-fill.opex { background: var(--opex-color); }
.progress-fill.capex { background: var(--capex-color); }
.progress-fill.total { background: var(--accent2); }

/* MONTH SELECTOR */
.month-selector {
  display: flex; gap: 4px; flex-wrap: wrap;
  margin-bottom: 20px;
}
.month-btn {
  padding: 5px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text2);
  cursor: pointer; font-size: 12px;
  font-family: 'Noto Sans KR', sans-serif;
  transition: all 0.15s;
}
.month-btn:hover { border-color: var(--accent); color: var(--text); }
.month-btn.active { background: var(--accent); border-color: var(--accent); color: white; }
.month-btn.all { font-weight: 600; }

/* FILTER BAR */
.filter-bar {
  display: flex; gap: 10px; align-items: center;
  margin-bottom: 16px; flex-wrap: wrap;
}
.filter-bar input, .filter-bar select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 13px;
  color: var(--text);
  font-family: 'Noto Sans KR', sans-serif;
  outline: none;
}
.filter-bar input:focus, .filter-bar select:focus { border-color: var(--accent); }
.filter-bar input { min-width: 200px; }
.filter-count { font-size: 12px; color: var(--text3); margin-left: auto; font-family: 'JetBrains Mono', monospace; }

/* DASHBOARD SPECIFIC */
.dashboard-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}
.chart-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
}
.chart-box-title { font-size: 14px; font-weight: 600; margin-bottom: 16px; }
.budget-row {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 12px;
}
.budget-row-label { font-size: 12px; color: var(--text2); width: 80px; flex-shrink: 0; }
.budget-row-bar { flex: 1; }
.budget-row-value { font-size: 12px; font-family: 'JetBrains Mono', monospace; color: var(--text3); text-align: right; width: 100px; flex-shrink: 0; }
.budget-pct { font-size: 11px; color: var(--text3); margin-top: 2px; }

/* MONTHLY GRID */
.monthly-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 4px;
  margin-bottom: 8px;
}
.monthly-cell {
  background: var(--surface3);
  border-radius: 4px;
  padding: 6px 4px;
  text-align: center;
}
.monthly-cell-label { font-size: 10px; color: var(--text3); }
.monthly-cell-bar { height: 40px; display: flex; align-items: flex-end; justify-content: center; margin: 4px 0; }
.monthly-bar-fill {
  width: 70%;
  border-radius: 2px 2px 0 0;
  min-height: 2px;
  transition: height 0.3s;
}
.monthly-cell-val { font-size: 9px; color: var(--text2); font-family: 'JetBrains Mono', monospace; }

/* TOAST */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  display: flex; align-items: center; gap: 10px;
  animation: toast-in 0.25s ease;
  min-width: 240px;
}
.toast.success { background: #0f2e1e; border: 1px solid var(--accent2); color: var(--accent2); }
.toast.error { background: #2e0f0f; border: 1px solid var(--accent4); color: var(--accent4); }
.toast.info { background: #0f1a2e; border: 1px solid var(--accent); color: var(--accent); }
@keyframes toast-in { from { transform: translateX(100%); opacity: 0; } to { transform: none; opacity: 1; } }

/* MODAL */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 500;
  align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 90%; max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  animation: modal-in 0.2s ease;
}
.modal-lg { max-width: 960px; }
@keyframes modal-in { from { transform: scale(0.95); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text2); cursor: pointer; padding: 4px; border-radius: 4px; transition: color 0.15s; }
.modal-close:hover { color: var(--text); }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }

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

/* CHIPS */
.chip-group { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  font-family: 'Noto Sans KR', sans-serif;
}
.chip.opex { border-color: var(--opex-color); color: var(--opex-color); }
.chip.opex.active, .chip.opex:hover { background: var(--opex-color); color: white; }
.chip.capex { border-color: var(--capex-color); color: var(--capex-color); }
.chip.capex.active, .chip.capex:hover { background: var(--capex-color); color: #1a0f00; }
.chip.all { border-color: var(--border); color: var(--text2); }
.chip.all.active, .chip.all:hover { background: var(--text2); color: var(--bg); }

/* EMPTY STATE */
.empty-state { padding: 48px 20px; text-align: center; color: var(--text3); }
.empty-state svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 14px; }

/* ALERT */
.alert { padding: 12px 16px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }
.alert-info { background: rgba(79,142,247,0.1); border: 1px solid rgba(79,142,247,0.3); color: #a0bcf8; }

/* FIXED LIST ITEM */
.fixed-item {
  display: grid;
  grid-template-columns: 30px 1fr 120px 100px 80px 80px;
  gap: 10px; align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.fixed-item:last-child { border-bottom: none; }
.fixed-item:hover { background: var(--surface2); }
.fixed-item-no { font-size: 11px; color: var(--text3); font-family: 'JetBrains Mono'; }
.fixed-item-name { font-size: 13px; }
.fixed-item-account { font-size: 11px; color: var(--text2); }
.fixed-item-amount { font-family: 'JetBrains Mono'; font-size: 12px; text-align: right; }
.fixed-item-period { font-size: 11px; color: var(--text3); text-align: center; }
.fixed-item-actions { display: flex; justify-content: flex-end; gap: 4px; }

/* ACCOUNT LIST */
.account-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 8px;
  display: grid;
  grid-template-columns: 60px 140px 1fr 200px;
  gap: 12px; align-items: center;
}
.account-card:hover { border-color: var(--border2); }

/* RESPONSIVE */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; grid-template-rows: 56px 44px 1fr; }
  .sidebar { display: none; }
  .dashboard-grid { grid-template-columns: 1fr; }
}

/* DELETE ROW */
.btn-del {
  background: none; border: none; cursor: pointer; padding: 3px 6px;
  color: var(--text3); border-radius: 4px; transition: all 0.15s;
  font-size: 14px;
}
.btn-del:hover { color: var(--accent4); background: rgba(247,95,95,0.1); }

/* INLINE EDIT */
td.editable { cursor: pointer; }
td.editable:hover { background: rgba(79,142,247,0.08); }
.inline-input {
  background: var(--surface3);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 3px 8px;
  color: var(--text);
  font-size: 12px;
  font-family: 'Noto Sans KR', sans-serif;
  width: 100%; outline: none;
}

/* YEAR TOTAL ROW */
.year-total-row td { background: rgba(56,201,123,0.06); font-weight: 600; color: var(--accent2); }
