/* My Financial Journey — estilos. Paleta: negro, azul y violeta. */

:root {
  --blue: #3b82f6;
  --violet: #7c5cff;
  --purple: #a855f7;
  --cyan: #22c1ee;
  --pink: #ec4899;
  --ok: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --grad: linear-gradient(135deg, #3b82f6 0%, #7c5cff 55%, #a855f7 100%);
  --radius: 18px;
  --radius-sm: 12px;
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Inter', 'Segoe UI', Roboto, system-ui, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #07070d;
  --bg-2: #0d0d18;
  --surface: rgba(20, 20, 36, 0.78);
  --surface-solid: #141424;
  --surface-2: #1b1b30;
  --border: rgba(140, 130, 255, 0.14);
  --text: #f2f2fa;
  --muted: #9a9ab8;
  --track: rgba(255, 255, 255, 0.08);
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --glow: radial-gradient(1200px 600px at 85% -10%, rgba(124, 92, 255, 0.22), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(59, 130, 246, 0.16), transparent 60%);
}

:root[data-theme='light'] {
  color-scheme: light;
  --bg: #f5f6fb;
  --bg-2: #eceefa;
  --surface: rgba(255, 255, 255, 0.86);
  --surface-solid: #ffffff;
  --surface-2: #f1f1fb;
  --border: rgba(60, 50, 160, 0.12);
  --text: #12121f;
  --muted: #62627e;
  --track: rgba(20, 20, 60, 0.08);
  --shadow: 0 10px 30px rgba(40, 40, 110, 0.08);
  --glow: radial-gradient(1200px 600px at 85% -10%, rgba(124, 92, 255, 0.12), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(59, 130, 246, 0.1), transparent 60%);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  background-image: var(--glow);
  background-attachment: fixed;
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
h3 { font-size: 1.05rem; }
h4 { font-size: 0.98rem; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 12px; top: 12px; z-index: 100; background: var(--surface-solid); padding: 8px 12px; border-radius: 8px; }
:focus-visible { outline: 2px solid var(--violet); outline-offset: 2px; }

/* ---------- Estructura ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; width: 240px; flex-shrink: 0;
  padding: 24px 16px; display: flex; flex-direction: column; gap: 24px;
  border-right: 1px solid var(--border); background: var(--surface); backdrop-filter: blur(20px);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand strong { display: block; font-size: 0.95rem; }
.brand span { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; font-weight: 700; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 12px;
  text-decoration: none; color: var(--muted); font-weight: 500; transition: background 0.2s, color 0.2s;
}
@media (hover: hover) { .nav a:not(.active):hover { background: var(--surface-2); color: var(--text); } }
.nav a.active { background: var(--grad); color: #fff; box-shadow: 0 6px 20px rgba(124, 92, 255, 0.35); }
.nav-icon { width: 22px; text-align: center; }
.sidebar-foot { margin-top: auto; font-size: 0.78rem; color: var(--muted); padding: 0 8px; }

.main { flex: 1; min-width: 0; padding: 24px 32px 48px; max-width: 1280px; margin: 0 auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.topbar-brand { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.topbar h1 { font-size: 1.7rem; }
#view { display: flex; flex-direction: column; gap: 18px; outline: none; }
#view > * { animation: rise 0.35s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Tarjetas ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); backdrop-filter: blur(16px); min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid-cal { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 18px; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stats.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat { position: relative; overflow: hidden; display: flex; flex-direction: column; gap: 4px; padding: 18px; }
.stat::before { content: ''; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--accent, var(--grad)); }
.stat-label { color: var(--muted); font-size: 0.82rem; font-weight: 500; }
.stat-value { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--muted); font-size: 0.78rem; }
.accent-violet { --accent: var(--violet); }
.accent-blue { --accent: var(--blue); }
.accent-cyan { --accent: var(--cyan); }
.accent-pink { --accent: var(--purple); }
.accent-danger { --accent: var(--danger); }
.accent-warn { --accent: var(--warn); }
.accent-danger .stat-value { color: var(--danger); }

.hero { display: flex; gap: 28px; align-items: center; background: var(--surface); position: relative; overflow: hidden; }
.hero::after { content: ''; position: absolute; inset: -40% -10% auto auto; width: 320px; height: 320px; background: var(--grad); filter: blur(90px); opacity: 0.25; pointer-events: none; }
.hero-text { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.hero-text h2 { font-size: 1.45rem; }
.hero-text p { margin: 0; font-size: 0.9rem; }
.hero-bars { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 6px; }
.eyebrow { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--purple); font-weight: 700; }
.ring-text { font-size: 24px; font-weight: 700; fill: var(--text); }
.ring-fill { transition: stroke-dasharray 0.8s ease; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-weight: 600; font-size: 0.9rem;
  cursor: pointer; text-decoration: none; white-space: nowrap; min-height: 42px;
  transition: transform 0.15s, box-shadow 0.2s, background 0.2s, opacity 0.2s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--grad); color: #fff; border-color: transparent; box-shadow: 0 6px 18px rgba(124, 92, 255, 0.3); }
.btn.danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.small { padding: 7px 12px; font-size: 0.82rem; min-height: 36px; border-radius: 10px; }
.danger-text { color: var(--danger) !important; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; font-size: 1rem; flex-shrink: 0;
}
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.line-actions .icon-btn { width: 34px; height: 34px; font-size: 0.9rem; background: transparent; }
.link { color: var(--purple); text-decoration: none; font-size: 0.85rem; font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* ---------- Progreso ---------- */
.progress { height: 10px; border-radius: 99px; background: var(--track); overflow: hidden; margin: 6px 0; }
.progress-fill { height: 100%; border-radius: inherit; background: var(--grad); transition: width 0.8s cubic-bezier(0.2, 0.8, 0.2, 1); }

/* ---------- Textos ---------- */
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.mt { margin-top: 16px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.pos { color: var(--ok); }
.neg { color: var(--danger); }
.ok-text { color: var(--ok); margin: 0; }
.warn-text { color: var(--warn); margin: 0; }

/* ---------- Chips ---------- */
.chip { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 99px; font-size: 0.72rem; font-weight: 700; white-space: nowrap; }
.chip.ok { background: rgba(16, 185, 129, 0.15); color: var(--ok); }
.chip.pending { background: rgba(59, 130, 246, 0.15); color: var(--blue); }
.chip.late { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.chip.partial { background: rgba(245, 158, 11, 0.16); color: #d97706; }
:root[data-theme='dark'] .chip.partial { color: var(--warn); }
.event-body + .chip + .chip { margin-left: -6px; }

/* ---------- Banner ---------- */
.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; border-radius: var(--radius-sm); border: 1px solid rgba(168, 85, 247, 0.35);
  background: rgba(124, 92, 255, 0.12); font-size: 0.88rem;
}
.banner.warn { border-color: rgba(245, 158, 11, 0.4); background: rgba(245, 158, 11, 0.12); }

/* ---------- Listas ---------- */
.events, .lines, .mini-goals, .order { list-style: none; margin: 0; padding: 0; }
.event {
  display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.event:last-child { border-bottom: 0; }
.event-date {
  display: grid; place-items: center; width: 46px; height: 46px; border-radius: 12px;
  background: var(--surface-2); line-height: 1.05;
}
.event-date strong { font-size: 1.05rem; }
.event-date span { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; }
.event.late .event-date { background: rgba(239, 68, 68, 0.14); color: var(--danger); }
.event.ok .event-date { background: rgba(16, 185, 129, 0.14); color: var(--ok); }
.event.partial .event-date { background: rgba(245, 158, 11, 0.16); color: var(--warn); }
.event { grid-template-columns: auto 1fr auto auto auto; }
.event:not(:has(.chip + .chip)) { grid-template-columns: auto 1fr auto auto; }
.event-body { display: flex; flex-direction: column; min-width: 0; }
.event-body strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.event-action:empty { display: none; }

.line {
  display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.line:last-child { border-bottom: 0; }
.line > div:first-child, .line > div:nth-child(2) { display: flex; flex-direction: column; min-width: 0; }
.line strong { font-variant-numeric: tabular-nums; }
.lines .line:has(.check-pay) { grid-template-columns: auto 1fr auto auto; }
.line.tx { grid-template-columns: auto 1fr auto auto; }
.line.done > div strong { text-decoration: line-through; opacity: 0.6; }
.line-right { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.line-actions { display: flex; gap: 2px; }
.tx-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); }

.check-pay { position: relative; display: inline-flex; cursor: pointer; }
.check-pay input { position: absolute; opacity: 0; width: 28px; height: 28px; margin: 0; cursor: pointer; }
.check-pay span {
  width: 28px; height: 28px; border-radius: 9px; border: 2px solid var(--border); background: var(--surface-2);
  display: grid; place-items: center; transition: all 0.2s; pointer-events: none;
}
.check-pay input:checked + span { background: var(--grad); border-color: transparent; }
.check-pay input:checked + span::after { content: '✓'; color: #fff; font-weight: 800; font-size: 0.9rem; }
.check-pay input:focus-visible + span { outline: 2px solid var(--violet); outline-offset: 2px; }

.mini-goals { display: flex; flex-direction: column; gap: 14px; }

/* ---------- Deudas y metas ---------- */
.debt { display: flex; flex-direction: column; gap: 10px; border-top: 3px solid var(--c); }
.debt-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.debt-balance { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.debt-balance strong { font-size: 1.6rem; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 14px; margin: 0; }
.facts div { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.facts dt { font-size: 0.72rem; color: var(--muted); }
.facts dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.payments summary { cursor: pointer; color: var(--muted); font-size: 0.85rem; padding: 4px 0; }
.payments ul { list-style: none; padding: 0; margin: 6px 0 0; max-height: 180px; overflow: auto; }
.payments li { display: flex; justify-content: space-between; padding: 5px 0; font-size: 0.85rem; border-bottom: 1px dashed var(--border); }
.goal { display: flex; flex-direction: column; gap: 10px; border-top: 3px solid var(--c); }
.goal-title { display: flex; gap: 12px; align-items: center; }
.goal-icon { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; font-size: 1.5rem; background: var(--surface-2); }
.goal-pct { font-size: 1.3rem; color: var(--c); }
.goal p { margin: 0; }

.strat { display: flex; flex-direction: column; gap: 10px; box-shadow: none; background: var(--surface-2); }
.strat p { margin: 0; }
.strat.best { border-color: rgba(168, 85, 247, 0.6); box-shadow: 0 0 0 1px rgba(168, 85, 247, 0.3), 0 10px 30px rgba(124, 92, 255, 0.15); }
.strat .facts div { background: var(--surface-solid); }
.order { counter-reset: o; display: flex; flex-direction: column; gap: 6px; }
.order li { counter-increment: o; display: flex; justify-content: space-between; gap: 8px; font-size: 0.86rem; }
.order li::before { content: counter(o); width: 22px; height: 22px; border-radius: 50%; background: var(--grad); color: #fff; font-size: 0.72rem; display: grid; place-items: center; flex-shrink: 0; }
.order li span:first-of-type { flex: 1; }
.verdict { margin: 0 0 14px; padding: 12px 14px; border-radius: 12px; background: rgba(124, 92, 255, 0.1); font-size: 0.9rem; }
.inline-form { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.inline-form .field { max-width: 200px; }

/* ---------- Presupuesto ---------- */
.schedule-line { margin: -8px 0 0; }
.period-hero { padding: 16px 20px; }
.period-hero h2 { font-size: 1.3rem; margin: 4px 0; }
.period-hero p { margin: 0; }
.income-line > div:first-child { gap: 2px; }
.line-right .btn { margin-top: 2px; }
.period-nav { display: flex; align-items: center; gap: 8px; }
.period-nav select, .filters select, .filters input {
  min-height: 42px; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2);
}
.table-wrap { overflow-x: auto; margin-top: 12px; }
.table { width: 100%; border-collapse: collapse; font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 0.78rem; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table td { padding: 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table tbody tr { cursor: pointer; transition: background 0.15s; }
.table tbody tr:hover, .table tr.selected { background: rgba(124, 92, 255, 0.1); }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.filters input { flex: 1; min-width: 160px; }

/* ---------- Calendario ---------- */
.cal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.cal-head h3 { flex: 1; text-align: center; font-size: 1.15rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-wd { text-align: center; font-size: 0.72rem; color: var(--muted); font-weight: 600; padding-bottom: 4px; }
.cal-cell {
  position: relative; min-height: 76px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); padding: 6px; display: flex; flex-direction: column; align-items: flex-start;
  gap: 4px; cursor: pointer; text-align: left; transition: transform 0.15s, border-color 0.2s;
}
.cal-cell:hover { transform: translateY(-1px); border-color: var(--violet); }
.cal-cell.empty { background: transparent; border: 0; cursor: default; }
.cal-cell.today { border-color: var(--blue); box-shadow: inset 0 0 0 1px var(--blue); }
.cal-cell.selected { background: rgba(124, 92, 255, 0.18); border-color: var(--violet); }
.cal-cell.late { background: rgba(239, 68, 68, 0.1); }
.cal-cell.pending { background: rgba(59, 130, 246, 0.1); }
.cal-cell.ok { background: rgba(16, 185, 129, 0.08); }
.cal-cell.partial { background: rgba(245, 158, 11, 0.12); }
.cal-num { font-weight: 700; font-size: 0.88rem; }
.cal-dots { display: flex; gap: 3px; flex-wrap: wrap; }
.cal-dots i, .cal-legend i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.ok { --dot: var(--ok); }
.cal-dots i.ok, .cal-legend i.ok { background: var(--ok); }
.cal-dots i.pending, .cal-legend i.pending { background: var(--blue); }
.cal-dots i.late, .cal-legend i.late { background: var(--danger); }
.cal-dots i.partial, .cal-legend i.partial { background: var(--warn); }
.cal-amount { font-size: 0.7rem; color: var(--muted); margin-top: auto; font-variant-numeric: tabular-nums; }
.cal-legend { display: flex; gap: 16px; margin-top: 12px; font-size: 0.8rem; color: var(--muted); flex-wrap: wrap; }
.cal-legend span { display: inline-flex; align-items: center; gap: 6px; }
.segmented { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 12px; margin-bottom: 8px; }
.seg { flex: 1; border: 0; background: transparent; padding: 8px 10px; border-radius: 9px; cursor: pointer; font-size: 0.82rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
.seg.active { background: var(--surface-solid); color: var(--text); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); }

/* ---------- Gráficas ---------- */
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-svg .grid { stroke: var(--track); stroke-width: 1; }
.chart-svg .axis { fill: var(--muted); font-size: 13px; }
.chart-svg .bar { transition: opacity 0.2s; cursor: pointer; }
.chart-svg:hover .bar { opacity: 0.55; }
.chart-svg .bar:hover, .chart-svg .bar:focus { opacity: 1; }
.chart-svg .hit { fill: transparent; cursor: crosshair; }
.chart-svg .hit:hover { fill: var(--track); }
.chart-legend { display: flex; gap: 16px; justify-content: center; margin-top: 8px; flex-wrap: wrap; }
.legend-inline { display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.donut-wrap { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; justify-content: center; }
.donut { max-width: 100%; height: auto; }
.donut-seg { cursor: pointer; transition: stroke-width 0.2s, opacity 0.2s; }
.donut:hover .donut-seg { opacity: 0.6; }
.donut .donut-seg:hover, .donut .donut-seg:focus { opacity: 1; stroke-width: 32; outline: none; }
.donut-label { fill: var(--muted); font-size: 12px; }
.donut-value { fill: var(--text); font-size: 17px; font-weight: 700; }
.legend { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 200px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; }
.legend-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#tooltip {
  position: fixed; left: 0; top: 0; z-index: 1000; pointer-events: none; max-width: 280px;
  padding: 8px 11px; border-radius: 10px; font-size: 0.8rem; font-weight: 500;
  background: #12121f; color: #fff; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  opacity: 0; transition: opacity 0.12s;
}
#tooltip.show { opacity: 1; }

/* ---------- Vacíos ---------- */
.empty { text-align: center; padding: 28px 12px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty-icon { font-size: 2.2rem; }
.empty p { margin: 0; max-width: 360px; }

/* ---------- Formularios / modal ---------- */
.modal {
  border: 0; padding: 0; background: transparent; color: var(--text);
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
}
.modal::backdrop { background: rgba(5, 5, 15, 0.6); backdrop-filter: blur(4px); }
.modal[open] { animation: pop 0.2s ease; }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal-card {
  background: var(--surface-solid); border: 1px solid var(--border); border-radius: 22px;
  padding: 22px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.modal-head h2 { font-size: 1.2rem; }
.modal-desc { margin: 0; font-size: 0.9rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.84rem; font-weight: 600; min-width: 0; }
.field > span { color: var(--muted); }
.field.wide { grid-column: 1 / -1; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); font-size: 16px; font-weight: 500;
}
.field input[type='color'] { padding: 4px; cursor: pointer; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--violet); box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.2); }
.field.check { flex-direction: row; align-items: center; gap: 10px; font-weight: 500; }
.field.check input { width: 20px; height: 20px; min-height: 0; accent-color: var(--violet); }
.field.check > span { color: var(--text); }
.hint { color: var(--muted); font-weight: 400; font-size: 0.75rem; }
.input-prefix { display: flex; align-items: center; position: relative; }
.input-prefix > span { position: absolute; left: 12px; color: var(--muted); font-weight: 600; }
.input-prefix input { padding-left: 26px !important; }
.form-error { margin: 0; color: var(--danger); font-size: 0.86rem; font-weight: 600; }
.form-error[hidden] { display: none; }

#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(24px + var(--safe-bottom)); z-index: 2000; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { padding: 12px 18px; border-radius: 14px; background: #12121f; color: #fff; font-size: 0.88rem; font-weight: 600; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35); border-left: 4px solid var(--violet); animation: rise 0.25s ease; transition: opacity 0.3s; max-width: calc(100vw - 32px); }
.toast.error { border-left-color: var(--danger); }
.toast.out { opacity: 0; }

/* ---------- Tablet ---------- */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-cal { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .sidebar { width: 76px; padding: 20px 10px; }
  .brand div, .nav a span:last-child, .sidebar-foot { display: none; }
  .brand { justify-content: center; padding: 0; }
  .nav a { justify-content: center; padding: 12px; }
  .main { padding: 20px; }
  .grid-2 { grid-template-columns: 1fr; }
}

/* ---------- Teléfono (iPhone) ---------- */
@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .shell { display: block; }
  .sidebar {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; width: 100%; z-index: 50;
    flex-direction: row; padding: 6px 6px calc(6px + var(--safe-bottom)); border-right: 0; border-top: 1px solid var(--border);
    background: var(--surface-solid);
  }
  .brand { display: none; }
  .nav { flex-direction: row; width: 100%; justify-content: space-around; gap: 0; }
  .nav a { flex-direction: column; gap: 2px; padding: 6px 4px; font-size: 0.64rem; flex: 1; border-radius: 10px; }
  .nav a span:last-child { display: block; }
  .nav a.active { box-shadow: none; }
  .nav-icon { font-size: 1.1rem; }
  .main { padding: calc(14px + env(safe-area-inset-top, 0px)) 14px calc(96px + var(--safe-bottom)); }
  .topbar h1 { font-size: 1.4rem; }
  .card { padding: 16px; border-radius: 16px; }
  .stats, .stats.three { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stats.three > :last-child { grid-column: 1 / -1; }
  .stat { padding: 14px; }
  .stat-value { font-size: 1.2rem; }
  .hero { flex-direction: column; text-align: center; gap: 14px; }
  .hero-bars { grid-template-columns: 1fr; text-align: left; }
  .hero-text h2 { font-size: 1.2rem; }
  .cards { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .event, .event:not(:has(.chip + .chip)) { grid-template-columns: auto 1fr auto; }
  .event .chip + .chip { grid-column: 3; }
  .stats > .stat:only-child { grid-column: 1 / -1; }
  .event-action { grid-column: 2 / -1; }
  .event-action .btn { width: 100%; }
  .cal-grid { gap: 3px; }
  .cal-cell { min-height: 52px; padding: 4px; border-radius: 9px; }
  .cal-amount { display: none; }
  .line, .lines .line:has(.check-pay), .line.tx { gap: 8px; }
  .line-actions .icon-btn { width: 30px; height: 30px; }
  .toolbar .actions { width: 100%; }
  .toolbar .actions .btn.primary { flex: 1; }
  .period-nav { width: 100%; }
  .period-nav select { flex: 1; min-width: 0; }
  .modal { width: 100vw; max-width: 100vw; margin: auto 0 0; max-height: 92dvh; }
  .modal-card { border-radius: 22px 22px 0 0; padding-bottom: calc(22px + var(--safe-bottom)); }
  .modal-actions .btn { flex: 1; }
  #toasts { bottom: calc(86px + var(--safe-bottom)); }
  .inline-form .field { max-width: none; flex: 1; }
}

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

@media print {
  .sidebar, .topbar button, .actions, .line-actions, .banner { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; break-inside: avoid; }
}
