/* === VARIABLES === */
:root {
  --bg:        #0D0F14;
  --surface:   #161922;
  --surface2:  #1E2330;
  --border:    #2A3148;
  --text:      #E8EAF0;
  --text2:     #8892A4;
  --accent:    #6C8EFF;
  --accent2:   #A78BFA;
  --green:     #34D399;
  --yellow:    #FBBF24;
  --red:       #F87171;
  --radius:    12px;
  --radius-sm: 8px;
  --shadow:    0 4px 24px rgba(0,0,0,0.4);
  --font-head: 'Syne', sans-serif;
  --font-body: 'DM Sans', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --transition: 0.2s cubic-bezier(0.4,0,0.2,1);
}

/* === RESET === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  font-size: 15px;
}
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, select, textarea { font-family: inherit; }
a { color: inherit; text-decoration: none; }

/* === LAYOUT === */
.app-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
}

/* === HEADER === */
.app-header {
  padding: 20px 0 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.logo {
  font-family: var(--font-head);
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo span { color: var(--accent); }
.period-badge {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 0.8rem;
  color: var(--text2);
  font-family: var(--font-mono);
}
.header-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* === NAV TABS === */
.nav-tabs {
  display: flex;
  gap: 4px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.nav-tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  flex: 0 0 auto;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text2);
  transition: var(--transition);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tab-btn:hover { background: var(--surface2); color: var(--text); }
.tab-btn.active { background: var(--accent); color: #fff; }

/* === MAIN === */
.main-content { flex: 1; padding: 20px 0; }
.view { display: none; }
.view.active { display: block; }

/* === SALARY BANNER === */
.uncat-alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(251,191,36,0.08);
  border: 1px solid rgba(251,191,36,0.35);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  margin-bottom: 16px;
  font-size: 0.875rem;
  color: var(--yellow);
  cursor: pointer;
  transition: var(--transition);
}
.uncat-alert:hover { background: rgba(251,191,36,0.14); }
.uncat-link { font-weight: 600; white-space: nowrap; }

.salary-banner {
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface2) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
  align-items: center;
}
.salary-stat { text-align: center; }
.salary-stat .label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text2);
  margin-bottom: 4px;
}
.salary-stat .value {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}
.salary-stat .value.positive { color: var(--green); }
.salary-stat .value.negative { color: var(--red); }
.salary-stat .value.warning  { color: var(--yellow); }
.salary-edit-hint { font-size: 0.7rem; opacity: 0.4; cursor: pointer; }
.salary-editable  { cursor: pointer; transition: color var(--transition); }
.salary-editable:hover { color: var(--accent); }
.salary-inline-input {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 700;
  background: none;
  border: none;
  border-bottom: 2px solid var(--accent);
  color: var(--text);
  text-align: center;
  width: 100%;
  outline: none;
  padding: 0 0 2px;
}

/* === CARDS GRID === */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

/* === CATEGORY CARD === */
.cat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  transition: var(--transition);
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.cat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--cat-color, var(--accent));
}
.cat-card:hover { border-color: var(--cat-color, var(--accent)); transform: translateY(-2px); box-shadow: var(--shadow); }
.salary-card { --cat-color: #34D399; cursor: pointer; }
.cat-header { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.cat-icon { font-size: 1.4rem; }
.cat-name { font-family: var(--font-head); font-weight: 700; font-size: 1rem; flex: 1; }
.cat-actions { display: flex; gap: 4px; opacity: 0; transition: var(--transition); }
.cat-card:hover .cat-actions { opacity: 1; }
.icon-btn {
  width: 28px; height: 28px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem;
  transition: var(--transition);
  color: var(--text2);
}
.icon-btn:hover { background: var(--surface2); color: var(--text); }
.icon-btn.danger:hover { background: rgba(248,113,113,0.15); color: var(--red); }

/* === PROGRESS BAR === */
.progress-wrap { margin-bottom: 10px; }
.progress-bar-track {
  height: 8px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 6px;
}
.progress-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.6s cubic-bezier(0.4,0,0.2,1);
  background: var(--cat-color, var(--accent));
}
.progress-bar-fill.over-budget { background: var(--red); animation: pulse-red 1.5s ease-in-out infinite; }
.progress-bar-fill.near-budget { background: var(--yellow); }
@keyframes pulse-red { 0%,100% { opacity:1; } 50% { opacity:0.7; } }

.progress-stats { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--text2); }
.progress-percent { font-family: var(--font-mono); font-weight: 700; }
.progress-percent.over  { color: var(--red); }
.progress-percent.near  { color: var(--yellow); }
.progress-percent.ok    { color: var(--green); }

.cat-footer { display: flex; justify-content: space-between; font-size: 0.78rem; color: var(--text2); margin-top: 8px; }
.cat-footer strong { color: var(--text); font-family: var(--font-mono); }

/* === EXPENSE LIST === */
.expense-list { display: flex; flex-direction: column; gap: 8px; }
.expense-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: var(--transition);
}
.expense-item:hover { border-color: var(--accent); }
.exp-cat-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.exp-info { flex: 1; min-width: 0; }
.exp-name { font-weight: 500; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.exp-meta { font-size: 0.75rem; color: var(--text2); display: flex; gap: 8px; flex-wrap: wrap; }
.exp-cat-tag {
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.7rem;
  background: var(--surface2);
  border: 1px solid var(--border);
}
.exp-amount { font-family: var(--font-mono); font-weight: 700; font-size: 0.95rem; color: var(--red); white-space: nowrap; }
.exp-amount.positive { color: var(--green); }
.exp-actions { display: flex; gap: 4px; }

/* === FORMS === */
.form-section { max-width: 640px; }
.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text2);
  margin-bottom: 6px;
}
.form-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text);
  font-size: 0.9rem;
  transition: var(--transition);
  outline: none;
}
.form-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(108,142,255,0.15); }
.form-input::placeholder { color: var(--text2); opacity: 0.6; }
textarea.form-input { resize: vertical; min-height: 80px; }
select.form-input option { background: var(--surface2); }

/* Keywords input */
.keywords-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  min-height: 44px;
  cursor: text;
}
.keywords-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(108,142,255,0.15); }
.keyword-tag {
  display: flex; align-items: center; gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.78rem;
  color: var(--text2);
}
.keyword-tag button { color: var(--text2); font-size: 0.9rem; line-height: 1; padding: 0 2px; }
.keyword-tag button:hover { color: var(--red); }
.keywords-input {
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 0.85rem;
  min-width: 80px;
  flex: 1;
}
.kw-preview {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.82rem;
  margin-top: -2px;
  margin-bottom: 4px;
}
.kw-preview .preview-count { font-weight: 600; color: var(--green); display: block; margin-bottom: 6px; }
.kw-preview .preview-empty { color: var(--text2); font-style: italic; }
.kw-preview .preview-list  { margin: 0; padding-left: 0; list-style: none; }
.kw-preview .preview-list li { display: flex; justify-content: space-between; padding: 2px 0; color: var(--text2); font-size: 0.8rem; }
.kw-preview .preview-list li span { color: var(--text); }
.kw-preview .preview-more { font-style: italic; }
.suggest-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.suggest-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 0.78rem;
  color: var(--text2);
  cursor: pointer;
  transition: var(--transition);
}
.suggest-chip:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.suggest-chip small { color: var(--accent); margin-left: 3px; font-size: 0.72rem; }
.suggest-chip:hover small { color: rgba(255,255,255,0.7); }
.retro-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text2);
  cursor: pointer;
  padding: 6px 0 12px;
}
.retro-label input[type="checkbox"] { width: 15px; height: 15px; cursor: pointer; accent-color: var(--accent); }
.exp-kw-suggest {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 8px 10px;
  background: rgba(108,142,255,0.06);
  border: 1px solid rgba(108,142,255,0.2);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
}
.exp-kw-label { color: var(--text2); white-space: nowrap; }
.exp-kw-custom {
  background: none;
  border: 1px dashed var(--border);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 0.78rem;
  color: var(--text);
  outline: none;
  width: 130px;
  font-family: inherit;
}
.exp-kw-custom::placeholder { color: var(--text2); }
.exp-kw-custom:focus { border-color: var(--accent); }
.suggest-chip.chip-added { opacity: 0.4; cursor: default; background: var(--surface2); color: var(--text2); border-color: var(--border); }

/* Color & Icon picker */
.color-grid { display: flex; gap: 8px; flex-wrap: wrap; }
.color-swatch {
  width: 28px; height: 28px;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: var(--transition);
}
.color-swatch.selected, .color-swatch:hover { border-color: var(--text); transform: scale(1.15); }
.icon-grid { display: flex; gap: 6px; flex-wrap: wrap; }
.icon-option {
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  border: 2px solid var(--border);
  cursor: pointer;
  background: var(--surface2);
  transition: var(--transition);
}
.icon-option:hover, .icon-option.selected { border-color: var(--accent); background: rgba(108,142,255,0.15); }

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  transition: var(--transition);
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #5878f0; transform: translateY(-1px); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: rgba(248,113,113,0.15); color: var(--red); border: 1px solid rgba(248,113,113,0.3); }
.btn-danger:hover { background: rgba(248,113,113,0.25); }
.btn-success { background: rgba(52,211,153,0.15); color: var(--green); border: 1px solid rgba(52,211,153,0.3); }
.btn-success:hover { background: rgba(52,211,153,0.25); }
.btn-sm { padding: 6px 14px; font-size: 0.8rem; }

/* === MODAL === */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  opacity: 0; pointer-events: none;
  transition: opacity var(--transition);
}
.modal-backdrop.open { opacity: 1; pointer-events: all; }
@media (min-width: 600px) { .modal-backdrop { align-items: center; } }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(40px);
  transition: transform var(--transition);
  max-width: 560px;
}
@media (min-width: 600px) { .modal { border-radius: var(--radius); transform: scale(0.96); } }
.modal-backdrop.open .modal { transform: translateY(0) scale(1); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-title { font-family: var(--font-head); font-size: 1.1rem; font-weight: 700; }
.modal-close { width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; color: var(--text2); }
.modal-close:hover { background: var(--surface2); color: var(--text); }

/* === ALERTS === */
.alert {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.alert-success { background: rgba(52,211,153,0.15); border: 1px solid rgba(52,211,153,0.3); color: var(--green); }
.alert-error   { background: rgba(248,113,113,0.15); border: 1px solid rgba(248,113,113,0.3); color: var(--red); }
.alert-info    { background: rgba(108,142,255,0.15); border: 1px solid rgba(108,142,255,0.3); color: var(--accent); }

/* === SECTION HEADERS === */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}
.section-title { font-family: var(--font-head); font-size: 1.1rem; font-weight: 700; }
.badge {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 10px;
  font-size: 0.75rem;
  color: var(--text2);
  font-family: var(--font-mono);
}

/* === EMPTY STATE === */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text2);
}
.empty-state .emoji { font-size: 2.5rem; margin-bottom: 12px; }
.empty-state p { font-size: 0.9rem; }

/* === NEW MONTH SECTION === */
.new-month-card {
  background: linear-gradient(135deg, rgba(108,142,255,0.1), rgba(167,139,250,0.1));
  border: 1px solid rgba(108,142,255,0.3);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 480px;
}

/* === TOAST === */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toast-in 0.3s ease forwards;
  min-width: 220px;
}
@keyframes toast-in { from { opacity:0; transform: translateX(20px); } to { opacity:1; transform: none; } }
.toast-item.success { border-color: rgba(52,211,153,0.4); }
.toast-item.error   { border-color: rgba(248,113,113,0.4); }

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

/* === RESPONSIVE === */
@media (max-width: 480px) {
  .form-row { grid-template-columns: 1fr; }
  .salary-banner { grid-template-columns: 1fr 1fr; }
  .cards-grid { grid-template-columns: 1fr; }
  .cat-actions { opacity: 1; }
}

/* === SKELETON LOADER === */
.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* === FILTER BAR === */
.filter-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.filter-bar .form-input { max-width: 300px; }
