/* ==========================================================================
   Iyola — controlo financeiro pessoal
   Tokens · Layout · Componentes · Responsivo
   ========================================================================== */

/* ---------- 1. Tokens ---------- */

:root {
  /* superfícies (tema claro) */
  --bg:            #F4F6F9;
  --bg-grad:       radial-gradient(1200px 600px at 80% -10%, #E3ECF7 0%, transparent 60%);
  --surface:       #FFFFFF;
  --surface-2:     #F7F9FC;
  --surface-3:     #EEF2F7;
  --line:          #E2E8F0;
  --line-soft:     #EDF1F6;

  /* texto */
  --text:          #101828;
  --text-2:        #475467;
  --text-3:        #8A94A6;

  /* marca e semântica */
  --brand:         #0E9E77;
  --brand-2:       #14B88A;
  --brand-soft:    rgba(20, 184, 138, .12);
  --income:        #12A575;
  --income-soft:   rgba(18, 165, 117, .12);
  --expense:       #E05252;
  --expense-soft:  rgba(224, 82, 82, .12);
  --warn:          #D98324;
  --warn-soft:     rgba(217, 131, 36, .14);
  --accent:        #4B7BEC;

  /* forma */
  --r-sm: 9px;
  --r:    14px;
  --r-lg: 20px;
  --r-xl: 26px;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow:    0 4px 16px rgba(16, 24, 40, .07);
  --shadow-lg: 0 24px 60px rgba(16, 24, 40, .16);

  --sidebar-w: 250px;
  --pad: 26px;

  --ease: cubic-bezier(.4, 0, .2, 1);
}

[data-theme="dark"] {
  --bg:            #0B1017;
  --bg-grad:       radial-gradient(1100px 620px at 85% -12%, rgba(20,184,138,.10) 0%, transparent 62%),
                   radial-gradient(900px 520px at 5% 105%, rgba(75,123,236,.09) 0%, transparent 60%);
  --surface:       #121A24;
  --surface-2:     #16202C;
  --surface-3:     #1D2836;
  --line:          #22303F;
  --line-soft:     #1A2532;

  --text:          #ECF1F7;
  --text-2:        #9FB0C3;
  --text-3:        #6B7C90;

  --brand:         #14B88A;
  --brand-2:       #35D6A6;
  --brand-soft:    rgba(20, 184, 138, .16);
  --income:        #35D6A6;
  --income-soft:   rgba(53, 214, 166, .14);
  --expense:       #FF6B6B;
  --expense-soft:  rgba(255, 107, 107, .14);
  --warn:          #E9B44C;
  --warn-soft:     rgba(233, 180, 76, .16);
  --accent:        #6D9BFF;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow:    0 6px 22px rgba(0, 0, 0, .34);
  --shadow-lg: 0 28px 70px rgba(0, 0, 0, .55);
}

/* ---------- 2. Base ---------- */

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: Sora, Inter, system-ui, sans-serif;
  margin: 0;
  letter-spacing: -.02em;
  font-weight: 600;
}

p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--brand-2);
  outline-offset: 2px;
  border-radius: 6px;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 10px; border: 3px solid var(--bg); }

/* ---------- 3. Layout ---------- */

.app-shell { display: flex; min-height: 100vh; }

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 0 var(--pad) 40px;
}

.views { flex: 1; }

.view { display: none; animation: rise .32s var(--ease); }
.view.is-active { display: block; }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

.foot {
  margin-top: 34px;
  padding-top: 18px;
  border-top: 1px solid var(--line-soft);
  font-size: 12.5px;
  color: var(--text-3);
  text-align: center;
}

/* ---------- 4. Sidebar ---------- */

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  border-right: 1px solid var(--line-soft);
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  backdrop-filter: blur(12px);
  z-index: 40;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 0 6px; }

.brand-mark { width: 38px; height: 38px; flex-shrink: 0; }
.brand-mark svg { width: 100%; height: 100%; display: block; }
.brand-mark rect { fill: var(--brand); }
.brand-mark path { stroke: var(--surface); }
[data-theme="dark"] .brand-mark path { stroke: #0B1017; }

.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text strong { font-family: Sora, sans-serif; font-size: 18px; letter-spacing: -.02em; }
.brand-text span { font-size: 11.5px; color: var(--text-3); }

.nav { display: flex; flex-direction: column; gap: 3px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 13px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  font-size: 14.5px;
  font-weight: 500;
  text-align: left;
  transition: background .18s var(--ease), color .18s var(--ease);
}
.nav-item svg { width: 19px; height: 19px; fill: currentColor; flex-shrink: 0; opacity: .85; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.is-active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-item.is-active svg { opacity: 1; }

.sidebar-foot { margin-top: auto; }

.theme-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 500;
  transition: border-color .18s var(--ease), color .18s var(--ease);
}
.theme-toggle:hover { border-color: var(--brand); color: var(--text); }
.theme-toggle svg { width: 17px; height: 17px; fill: currentColor; stroke: currentColor; }
.theme-toggle .ic-sun { display: none; }
[data-theme="dark"] .theme-toggle .ic-sun { display: block; }
[data-theme="dark"] .theme-toggle .ic-moon { display: none; }
.theme-toggle .ic-sun circle { stroke: none; }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 18, .5);
  backdrop-filter: blur(2px);
  z-index: 35;
}

/* ---------- 5. Topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 22px 0 18px;
  margin-bottom: 6px;
  background: linear-gradient(to bottom, var(--bg) 72%, transparent);
}

.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 { font-size: 25px; }
.topbar-title p { font-size: 13.5px; color: var(--text-3); margin-top: 2px; }

.topbar-actions { display: flex; align-items: center; gap: 12px; }

.period-picker {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.period-label {
  border: 0;
  background: transparent;
  padding: 6px 12px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  border-radius: 999px;
  min-width: 122px;
}
.period-label:hover { background: var(--surface-2); }

.only-mobile { display: none; }

/* ---------- 6. Botões ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 17px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  transition: transform .12s var(--ease), background .18s var(--ease), border-color .18s var(--ease), opacity .18s;
}
.btn svg { width: 17px; height: 17px; fill: currentColor; }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: linear-gradient(135deg, var(--brand-2), var(--brand));
  color: #04140F;
  box-shadow: 0 4px 14px rgba(20, 184, 138, .3);
}
.btn-primary:hover { filter: brightness(1.06); }

.btn-soft { background: var(--surface-2); border-color: var(--line); color: var(--text-2); }
.btn-soft:hover { border-color: var(--text-3); color: var(--text); }

.btn-ghost { background: transparent; color: var(--text-2); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger { background: var(--expense-soft); color: var(--expense); border-color: transparent; }
.btn-danger:hover { background: var(--expense); color: #fff; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  transition: background .18s var(--ease), color .18s var(--ease);
}
.icon-btn svg { width: 19px; height: 19px; fill: currentColor; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- 7. Cartões de estatística ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 18px;
}
.stat-grid-3 { grid-template-columns: repeat(3, 1fr); }

.stat {
  position: relative;
  overflow: hidden;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.stat::after {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--line);
}
.stat-balance::after { background: linear-gradient(90deg, var(--brand-2), var(--accent)); }
.stat-in::after      { background: var(--income); }
.stat-out::after     { background: var(--expense); }
.stat-rate::after    { background: var(--warn); }

.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }

.stat-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-3);
}

.stat-icon {
  display: inline-flex;
  width: 26px; height: 26px;
  align-items: center; justify-content: center;
  border-radius: 8px;
}
.stat-in .stat-icon  { background: var(--income-soft); }
.stat-out .stat-icon { background: var(--expense-soft); }
.stat-icon svg { width: 15px; height: 15px; }
.stat-in .stat-icon svg  { fill: var(--income); }
.stat-out .stat-icon svg { fill: var(--expense); }

.stat-chip {
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-3);
}
.stat-chip.up   { background: var(--income-soft); color: var(--income); }
.stat-chip.down { background: var(--expense-soft); color: var(--expense); }

.stat-value {
  font-family: Sora, sans-serif;
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -.03em;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
.stat-value-sm { font-size: 23px; }
.stat-in  .stat-value { color: var(--income); }
.stat-out .stat-value { color: var(--expense); }

.stat-meta { font-size: 12.5px; color: var(--text-3); margin-top: 6px; }

.progress {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
  margin-top: 12px;
}
.progress-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand-2), var(--brand));
  transition: width .5s var(--ease);
}

/* ---------- 8. Cartões ---------- */

.card {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}
.card-head h2 { font-size: 16.5px; }
.card-head p { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }

.panel-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 18px;
}
.panel-grid > .card { margin-bottom: 18px; }

/* ---------- 9. Gráficos ---------- */

.chart-wrap { width: 100%; height: 240px; }
.chart-wrap-tall { height: 290px; }
.chart-wrap svg { width: 100%; height: 100%; display: block; overflow: visible; }

.grid-line { stroke: var(--line-soft); stroke-width: 1; }
.axis-text  { fill: var(--text-3); font-size: 11px; font-family: Inter, sans-serif; }
.bar-in     { fill: var(--income); }
.bar-out    { fill: var(--expense); }
.bar-in, .bar-out { transition: opacity .18s; }
.chart-wrap g:hover .bar-in, .chart-wrap g:hover .bar-out { opacity: .78; }

.line-path  { fill: none; stroke: var(--brand-2); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.line-area  { fill: url(#lineGrad); }
.line-dot   { fill: var(--surface); stroke: var(--brand-2); stroke-width: 2.5; }

.legend { display: flex; gap: 18px; justify-content: center; margin-top: 12px; font-size: 12.5px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot-in  { background: var(--income); }
.dot-out { background: var(--expense); }

.donut-wrap { height: 190px; display: flex; align-items: center; justify-content: center; }
.donut-wrap svg { width: 190px; height: 190px; overflow: visible; }
.donut-center-value { font-family: Sora, sans-serif; font-size: 17px; font-weight: 700; fill: var(--text); }
.donut-center-label { font-size: 10.5px; fill: var(--text-3); letter-spacing: .06em; }
.donut-seg { transition: opacity .18s var(--ease); cursor: default; }
.donut-seg:hover { opacity: .8; }

.cat-legend { display: flex; flex-direction: column; gap: 9px; margin-top: 18px; }
.cat-legend li { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.cat-legend .swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.cat-legend .cl-name { flex: 1; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-legend .cl-val { font-weight: 600; font-variant-numeric: tabular-nums; }
.cat-legend .cl-pct { color: var(--text-3); font-size: 12px; min-width: 38px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- 10. Filtros ---------- */

.filters {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 10px;
  margin-bottom: 18px;
}

.field-search { position: relative; min-width: 180px; }
.field-search svg {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 17px; height: 17px; fill: var(--text-3); pointer-events: none;
}
.field-search input {
  width: 100%;
  padding: 10px 14px 10px 37px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  outline: none;
  font-size: 14px;
  transition: border-color .18s var(--ease);
}
.field-search input:focus { border-color: var(--brand); }
.field-search input::-webkit-search-cancel-button { filter: grayscale(1) opacity(.5); }

.select, .input {
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-size: 14px;
  outline: none;
  transition: border-color .18s var(--ease);
  max-width: 100%;
}
.select:focus, .input:focus { border-color: var(--brand); }
.select { cursor: pointer; padding-right: 30px; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 14px center, right 9px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
}
.seg button {
  border: 0;
  background: transparent;
  padding: 7px 14px;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-3);
  transition: background .18s var(--ease), color .18s var(--ease);
}
.seg button:hover { color: var(--text); }
.seg button.is-active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow-sm); }
.seg-big { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
.seg-big button { padding: 11px; font-size: 14.5px; }
.seg-big button[data-type="expense"].is-active { color: var(--expense); }
.seg-big button[data-type="income"].is-active  { color: var(--income); }

/* ---------- 11. Lista de transações ---------- */

.tx-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  padding: 12px 14px;
  margin-bottom: 14px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-size: 13px;
  color: var(--text-2);
}
.tx-summary b { color: var(--text); font-variant-numeric: tabular-nums; }
.tx-summary .in b  { color: var(--income); }
.tx-summary .out b { color: var(--expense); }

.day-group + .day-group { margin-top: 6px; }
.day-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 14px 4px 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-3);
  border-bottom: 1px solid var(--line-soft);
}
.day-head .day-total { font-variant-numeric: tabular-nums; letter-spacing: 0; text-transform: none; font-size: 12.5px; }

.tx {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  padding: 13px 10px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: transparent;
  text-align: left;
  border-radius: 10px;
  transition: background .16s var(--ease);
}
.tx:hover { background: var(--surface-2); }

.tx-icon {
  width: 38px; height: 38px;
  flex-shrink: 0;
  border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
  color: #fff;
  letter-spacing: -.02em;
}

.tx-body { flex: 1; min-width: 0; }
.tx-desc {
  font-size: 14.5px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tx-sub { font-size: 12.5px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tx-amount {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  letter-spacing: -.01em;
}
.tx-amount.in  { color: var(--income); }
.tx-amount.out { color: var(--text); }

.empty {
  padding: 46px 20px;
  text-align: center;
  color: var(--text-3);
}
.empty svg { width: 44px; height: 44px; fill: var(--text-3); opacity: .4; margin-bottom: 12px; }
.empty strong { display: block; color: var(--text-2); font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.empty p { font-size: 13.5px; max-width: 340px; margin: 0 auto; }

/* ---------- 12. Orçamentos ---------- */

.budget-list { display: flex; flex-direction: column; gap: 6px; }

.budget {
  display: grid;
  grid-template-columns: 1fr 140px;
  gap: 8px 16px;
  align-items: center;
  padding: 15px 4px;
  border-bottom: 1px solid var(--line-soft);
}
.budget:last-child { border-bottom: 0; }

.budget-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.budget-head .swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.budget-name { font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.budget-input { display: flex; align-items: center; gap: 6px; justify-self: end; }
.budget-input input {
  width: 108px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-size: 13.5px;
  text-align: right;
  outline: none;
  font-variant-numeric: tabular-nums;
}
.budget-input input:focus { border-color: var(--brand); }

.budget-track { grid-column: 1 / -1; height: 7px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.budget-bar { height: 100%; border-radius: 999px; transition: width .5s var(--ease); }
.budget-bar.ok    { background: linear-gradient(90deg, var(--brand-2), var(--brand)); }
.budget-bar.near  { background: var(--warn); }
.budget-bar.over  { background: var(--expense); }

.budget-meta {
  grid-column: 1 / -1;
  display: flex; justify-content: space-between; gap: 12px;
  font-size: 12.5px; color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.budget-meta .over-txt { color: var(--expense); font-weight: 600; }
.budget-meta .near-txt { color: var(--warn); font-weight: 600; }
.budget-meta .ok-txt   { color: var(--income); font-weight: 600; }

/* ---------- 13. Ranking ---------- */

.rank-list { display: flex; flex-direction: column; gap: 14px; }
.rank { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; }
.rank-top { display: flex; align-items: center; gap: 10px; min-width: 0; }
.rank-top .swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.rank-name { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-val { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.rank-track { grid-column: 1 / -1; height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.rank-bar { height: 100%; border-radius: 999px; transition: width .5s var(--ease); }
.rank-pct { grid-column: 1 / -1; font-size: 12px; color: var(--text-3); }

/* ---------- 14. Definições ---------- */

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 0;
  border-bottom: 1px solid var(--line-soft);
}
.settings-row:last-child { border-bottom: 0; padding-bottom: 0; }
.settings-row strong { font-size: 14.5px; font-weight: 600; }
.settings-row p { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }

.cat-manager { display: flex; flex-wrap: wrap; gap: 9px; margin-bottom: 18px; }

.cat-pill {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 13.5px;
}
.cat-pill .swatch { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.cat-pill .cp-name { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-pill .cp-type { font-size: 11px; color: var(--text-3); }
.cat-pill button {
  border: 0; background: transparent; color: var(--text-3);
  width: 20px; height: 20px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .16s, color .16s;
}
.cat-pill button:hover { background: var(--expense-soft); color: var(--expense); }
.cat-pill button svg { width: 12px; height: 12px; fill: currentColor; }

.cat-add {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 9px;
  padding-top: 16px;
  border-top: 1px solid var(--line-soft);
}

.color-input {
  width: 44px; height: 40px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  cursor: pointer;
}
.color-input::-webkit-color-swatch-wrapper { padding: 0; }
.color-input::-webkit-color-swatch { border: 0; border-radius: 6px; }

.data-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.note { margin-top: 14px; font-size: 12.5px; color: var(--text-3); }

/* ---------- 15. Modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal.is-open { display: flex; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 12, 18, .58);
  backdrop-filter: blur(3px);
  animation: fade .2s var(--ease);
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  position: relative;
  width: 100%;
  max-width: 460px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: pop .26s var(--ease);
}
.modal-sm { max-width: 380px; }
@keyframes pop {
  from { opacity: 0; transform: translateY(14px) scale(.97); }
  to   { opacity: 1; transform: none; }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 22px 0;
}
.modal-head h2 { font-size: 18px; }

.modal-body { padding: 18px 22px 22px; display: flex; flex-direction: column; gap: 14px; }

.fl { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.fl > span { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.fl > span em { font-style: normal; font-weight: 400; color: var(--text-3); }
.fl-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.amount-field {
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  overflow: hidden;
  transition: border-color .18s var(--ease);
}
.amount-field:focus-within { border-color: var(--brand); }
.amount-field .cur {
  padding: 0 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-3);
  border-right: 1px solid var(--line);
  align-self: stretch;
  display: flex;
  align-items: center;
}
.amount-field input {
  flex: 1;
  min-width: 0;
  padding: 13px 14px;
  border: 0;
  background: transparent;
  outline: none;
  font-family: Sora, sans-serif;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}

.form-error {
  font-size: 13px;
  color: var(--expense);
  background: var(--expense-soft);
  padding: 9px 12px;
  border-radius: var(--r-sm);
}

.modal-foot { display: flex; align-items: center; gap: 9px; margin-top: 4px; }
.modal-foot .spacer { flex: 1; }
.btn-del { color: var(--expense); border-color: transparent; }
.btn-del:hover { background: var(--expense-soft); color: var(--expense); }

.confirm-text { font-size: 14.5px; color: var(--text-2); }

/* ---------- 16. Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 20px);
  z-index: 200;
  padding: 12px 20px;
  border-radius: 999px;
  background: var(--text);
  color: var(--surface);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity .26s var(--ease), transform .26s var(--ease);
  max-width: calc(100vw - 40px);
  text-align: center;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 17. Responsivo ---------- */

@media (max-width: 1180px) {
  .panel-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 960px) {
  :root { --pad: 18px; }

  .sidebar {
    position: fixed;
    left: 0; top: 0;
    transform: translateX(-100%);
    transition: transform .28s var(--ease);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    backdrop-filter: none;
  }
  .sidebar.is-open { transform: none; }
  .sidebar-backdrop.is-on { display: block; }
  .only-mobile { display: inline-flex; }

  .topbar { flex-wrap: wrap; padding-top: 16px; }
  .topbar-title { order: 2; width: 100%; }
  .topbar-title h1 { font-size: 22px; }
  .topbar-actions { order: 3; width: 100%; justify-content: space-between; }
  .menu-slot { order: 1; }

  .filters { grid-template-columns: 1fr 1fr; }
  .field-search { grid-column: 1 / -1; }
  .seg { grid-column: 1 / -1; }
  .seg button { flex: 1; }

  .cat-add { grid-template-columns: 1fr auto; }
  .cat-add .btn { grid-column: 1 / -1; }
}

@media (max-width: 620px) {
  .stat-grid, .stat-grid-3 { grid-template-columns: 1fr; }
  .card { padding: 17px; border-radius: var(--r); }
  .stat { padding: 17px; border-radius: var(--r); }

  .btn-primary .btn-label { display: none; }
  .btn-primary { padding: 10px 13px; }

  .period-label { min-width: 104px; font-size: 13px; padding: 6px 8px; }

  .card-head { flex-direction: column; align-items: flex-start; gap: 10px; }
  .settings-row { flex-direction: column; align-items: stretch; gap: 10px; }
  .settings-row .select, .settings-row .input { width: 100%; }

  .fl-row { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr; }

  .budget { grid-template-columns: 1fr auto; }
  .budget-input input { width: 92px; }

  .modal { padding: 0; align-items: flex-end; }
  .modal-card { max-width: none; border-radius: var(--r-xl) var(--r-xl) 0 0; max-height: 92vh; }
  @keyframes pop { from { transform: translateY(30px); } to { transform: none; } }

  .modal-foot { flex-wrap: wrap; }
  .modal-foot .btn { flex: 1; }
  .modal-foot .spacer { display: none; }

  .data-actions .btn { flex: 1 1 46%; }
  .chart-wrap { height: 210px; }
  .toast { bottom: 16px; }
}

@media (max-width: 400px) {
  .stat-value { font-size: 24px; }
  .tx-icon { width: 34px; height: 34px; font-size: 13px; }
}
