@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Manrope:wght@500;600;700;800&display=swap');

:root {
  color-scheme: dark;
  --bg: #0a0f16;
  --panel: #121b26;
  --panel-raised: #172331;
  --input: #0d151f;
  --border: #263646;
  --text: #edf3f8;
  --muted: #95a6b6;
  --mint: #55d8b8;
  --blue: #9aaafa;
  --gold: #f0c36e;
  --red: #fb858d;
  --shadow: 0 18px 60px rgba(0, 0, 0, .28);
  font-family: 'DM Sans', 'Segoe UI', sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(ellipse at 78% -12%, rgba(40, 122, 112, .13), transparent 38rem),
    var(--bg);
  color: var(--text);
}

button, input, select { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: min(100%, 438px);
  padding: 34px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: linear-gradient(145deg, rgba(23, 35, 49, .96), rgba(17, 26, 37, .98));
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 28px 0 8px; font: 700 27px/1.18 Manrope, sans-serif; letter-spacing: -.04em; }
.brand-row { display: flex; align-items: center; gap: 12px; }
.brand-link { text-decoration: none; color: inherit; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 14px; color: #0a1716; background: linear-gradient(140deg, #7be6ca, #3db99d); font: 800 22px Manrope, sans-serif; box-shadow: 0 8px 28px rgba(85, 216, 184, .2); }
.eyebrow { margin: 0; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase; }
.brand-row .eyebrow { color: var(--text); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.accent-text { color: var(--mint); }

.stack-form { display: grid; gap: 16px; margin-top: 24px; }
label { display: grid; gap: 8px; color: #c8d2dc; font-size: 12px; font-weight: 600; }
input, select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  background: var(--input);
  color: var(--text);
  transition: border-color .16s ease, box-shadow .16s ease;
}
input:focus, select:focus { border-color: rgba(85, 216, 184, .78); box-shadow: 0 0 0 3px rgba(85, 216, 184, .12); }
input::placeholder { color: #687b8b; }
input[type="date"] { color-scheme: dark; }

.button, .icon-button, .text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background .16s ease, border-color .16s ease, transform .16s ease, color .16s ease;
}
.button { min-height: 40px; padding: 0 15px; border-radius: 12px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.button:hover, .icon-button:hover { transform: translateY(-1px); }
.button.primary { background: linear-gradient(135deg, #69dfc1, #49c5a8); color: #071714; box-shadow: 0 8px 22px rgba(66, 198, 166, .16); }
.button.primary:hover { background: #83ead0; }
.button.secondary { background: #203c40; border-color: #315d58; color: #b7f1df; }
.button.secondary:hover { background: #294d4e; }
.button.ghost { background: rgba(255, 255, 255, .025); border-color: var(--border); color: #c4d0da; }
.button.ghost:hover { border-color: #496174; background: var(--panel-raised); }
.button.compact { min-height: 34px; padding: 0 12px; border-radius: 10px; font-size: 11px; }
.button.full { width: 100%; min-height: 46px; }
.icon-button { width: 38px; height: 38px; padding: 0; border-color: var(--border); border-radius: 12px; background: rgba(255,255,255,.025); color: var(--text); font-size: 24px; line-height: 1; }
.icon-button:hover { background: var(--panel-raised); border-color: #496174; }
.text-button { display: flex; width: 100%; margin-top: 13px; border: 0; background: transparent; color: var(--mint); font-size: 12px; font-weight: 700; }
.text-button.subtle { margin-top: 10px; color: var(--muted); font-weight: 500; }
.text-button:hover { color: #a2f1dc; }
.status-message { min-height: 19px; margin: 16px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.status-message.error, .form-error { color: var(--red); }

.app-shell { min-height: 100vh; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 76px;
  padding: 12px max(24px, calc((100vw - 1440px) / 2));
  border-bottom: 1px solid rgba(74, 98, 117, .22);
  background: rgba(10, 15, 22, .72);
  backdrop-filter: blur(18px);
}
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.sync-status { display: inline-flex; align-items: center; gap: 7px; margin-right: 7px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.sync-status i { width: 7px; height: 7px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 9px rgba(85, 216, 184, .35); }
.sync-status.saving i { background: var(--gold); }
.sync-status.error i { background: var(--red); }
.file-button { cursor: pointer; }

.dashboard { width: min(100% - 48px, 1440px); margin: 0 auto; padding: 36px 0 28px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 28px; margin-bottom: 24px; }
.page-heading h1 { margin: 7px 0 5px; font: 700 clamp(25px, 3vw, 34px)/1.12 Manrope, sans-serif; letter-spacing: -.045em; }
.page-heading p:not(.eyebrow) { margin: 0; font-size: 13px; }
.view-controls { display: flex; align-items: center; justify-content: flex-end; gap: 9px; flex-wrap: wrap; }
.month-control { display: flex; align-items: center; gap: 8px; padding: 3px; border: 1px solid var(--border); border-radius: 14px; background: rgba(18, 27, 38, .8); }
.month-control .icon-button { width: 32px; height: 32px; border: 0; background: transparent; }
.month-label { min-width: 116px; text-align: center; font-size: 12px; font-weight: 700; }

.summary-grid { display: grid; grid-template-columns: 1.18fr 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.card { border: 1px solid rgba(65, 85, 102, .54); border-radius: 19px; background: linear-gradient(145deg, rgba(20, 30, 42, .98), rgba(16, 25, 36, .98)); box-shadow: 0 8px 32px rgba(0,0,0,.12); }
.summary-card { min-height: 188px; padding: 20px 21px 16px; }
.card-heading, .section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.metric { margin: 11px 0 0; font: 700 clamp(24px, 3vw, 31px)/1.15 Manrope, sans-serif; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.metric.positive { color: var(--mint); }
.metric.negative { color: var(--red); }
.metric-notes { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 11px; font-size: 11px; }
.unexpected-note { color: var(--red); }
.discount-note { color: var(--mint); }
.card-footnote { margin: 14px 0 0; color: var(--muted); font-size: 11px; }
.balance-line { display: flex; justify-content: space-between; gap: 10px; margin-top: 19px; color: #8396a8; font-size: 10px; }
.mini-list { display: flex; gap: 5px; margin-top: 13px; max-height: 71px; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; scrollbar-color: #344b5c transparent; }
.mini-list.empty { align-items: center; color: #8293a1; font-size: 11px; }
.income-chip { display: flex; min-width: 190px; max-width: 220px; flex: 0 0 auto; align-items: center; gap: 8px; padding: 7px 8px; border: 1px solid rgba(79, 121, 115, .22); border-radius: 10px; background: rgba(85, 216, 184, .045); }
.income-chip-copy { min-width: 0; flex: 1; }
.income-chip-title { overflow: hidden; color: #dbe7e8; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.income-chip-date { margin-top: 2px; color: var(--muted); font-size: 9px; }
.income-chip-amount { color: var(--mint); font-size: 10px; font-weight: 700; white-space: nowrap; }
.income-chip-actions { display: flex; gap: 3px; }
.income-chip-actions .tiny-button { min-width: 25px; height: 24px; padding-inline: 4px; }

.content-grid { display: grid; grid-template-columns: minmax(320px, .95fr) minmax(440px, 1.35fr); gap: 16px; }
.allocation-card, .expenses-card, .calendar-card { padding: 21px; }
.section-heading { align-items: center; margin-bottom: 19px; }
.section-heading h2, .modal-heading h2 { margin: 0; font: 700 17px/1.2 Manrope, sans-serif; letter-spacing: -.025em; }
.section-heading p { margin: 5px 0 0; }
.allocation-list { display: grid; gap: 11px; }
.allocation-row { padding: 13px 14px 12px; border: 1px solid rgba(66, 85, 101, .44); border-radius: 14px; background: rgba(10, 16, 24, .55); }
.allocation-top, .allocation-bottom { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.category-name { display: flex; align-items: center; gap: 9px; font-size: 12px; font-weight: 700; }
.category-dot { width: 8px; height: 8px; border-radius: 50%; }
.needs-color { background: var(--mint); }
.investment-color { background: var(--blue); }
.personal-color { background: var(--gold); }
.allocation-budget { color: #c5d1da; font-size: 11px; font-variant-numeric: tabular-nums; }
.progress-track { height: 5px; margin: 11px 0 8px; overflow: hidden; border-radius: 99px; background: #273544; }
.progress-fill { height: 100%; border-radius: inherit; transition: width .25s ease; }
.progress-fill.over { background: var(--red) !important; }
.allocation-bottom { color: var(--muted); font-size: 10px; }
.allocation-bottom .left-positive { color: var(--mint); }
.allocation-bottom .left-negative { color: var(--red); }
.expense-list { display: grid; gap: 8px; max-height: 458px; overflow-y: auto; padding-right: 3px; scrollbar-width: thin; scrollbar-color: #344b5c transparent; }
.expense-item { display: flex; align-items: center; gap: 12px; min-height: 66px; padding: 11px 12px; border: 1px solid rgba(66, 85, 101, .38); border-radius: 13px; background: rgba(10, 16, 24, .55); }
.expense-stripe { width: 3px; align-self: stretch; flex: 0 0 3px; border-radius: 10px; }
.expense-copy { min-width: 0; flex: 1; }
.expense-name { overflow: hidden; font-size: 12px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.expense-meta { overflow: hidden; margin-top: 5px; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.expense-amount-block { text-align: right; }
.expense-amount { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.expense-discount { margin-top: 3px; color: var(--mint); font-size: 9px; white-space: nowrap; }
.expense-actions { display: flex; gap: 5px; }
.tiny-button { min-width: 30px; height: 29px; padding: 0 7px; border: 1px solid #304455; border-radius: 8px; background: transparent; color: #b8c7d2; cursor: pointer; font-size: 10px; }
.tiny-button:hover { border-color: #597487; background: var(--panel-raised); }
.tiny-button.delete:hover { border-color: rgba(251, 133, 141, .65); color: var(--red); }
.empty-state { padding: 24px 14px; color: var(--muted); text-align: center; font-size: 12px; }

.calendar-card { margin-top: 16px; }
.calendar-heading { margin-bottom: 15px; }
.calendar-legend { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 10px; }
.calendar-legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; }
.income-dot { background: var(--mint); }
.expense-dot { background: var(--gold); }
.unexpected-dot { background: var(--red); }
.calendar-weekdays, .calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.calendar-weekdays { margin-bottom: 8px; color: #7f91a2; font-size: 10px; font-weight: 700; text-transform: uppercase; }
.calendar-weekdays span { padding: 7px 9px; }
.calendar-grid { border-top: 1px solid rgba(65, 85, 102, .4); border-left: 1px solid rgba(65, 85, 102, .4); overflow: hidden; border-radius: 10px; }
.calendar-day, .calendar-empty { min-height: 58px; border: 0; border-right: 1px solid rgba(65, 85, 102, .4); border-bottom: 1px solid rgba(65, 85, 102, .4); background: rgba(8, 14, 21, .36); }
.calendar-day { display: flex; align-items: flex-start; justify-content: space-between; padding: 9px; color: var(--text); cursor: pointer; text-align: left; }
.calendar-day:hover { background: rgba(85, 216, 184, .08); }
.calendar-day.today .day-number { color: var(--mint); font-weight: 800; }
.calendar-day.selected { background: rgba(85, 216, 184, .09); box-shadow: inset 0 0 0 1px rgba(85, 216, 184, .55); }
.calendar-day.outside { opacity: .35; }
.day-markers { display: flex; gap: 4px; padding-top: 4px; }
.day-markers .dot { width: 6px; height: 6px; }

.app-footer { display: flex; justify-content: space-between; gap: 12px; padding: 22px 3px 0; color: #738698; font-size: 10px; }
.modal { width: min(100% - 30px, 470px); max-height: min(90vh, 780px); padding: 0; overflow: auto; border: 1px solid #344959; border-radius: 20px; background: #131e2a; color: var(--text); box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(2, 6, 10, .76); backdrop-filter: blur(6px); }
.modal-form { display: grid; gap: 16px; padding: 23px; }
.modal-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 2px; }
.modal-heading h2 { margin-top: 5px; font-size: 21px; }
.modal-heading .icon-button { width: 33px; height: 33px; font-size: 20px; }
.two-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; align-items: end; }
.check-row { display: flex; flex-wrap: wrap; gap: 12px 22px; }
.check-label { display: inline-flex; grid-template-columns: none; align-items: center; gap: 9px; color: #d0dbe3; cursor: pointer; font-size: 12px; }
.check-label input { width: 16px; min-height: 16px; height: 16px; margin: 0; accent-color: var(--mint); }
.field-help { align-self: center; margin: 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.form-error { min-height: 0; margin: -8px 0 0; font-size: 11px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 4px; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 20; max-width: min(420px, calc(100vw - 32px)); padding: 12px 15px; border: 1px solid #365164; border-radius: 12px; background: #1a2937; color: var(--text); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(10px); transition: opacity .2s ease, transform .2s ease; font-size: 12px; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 980px) {
  .topbar { padding-inline: 20px; }
  .dashboard { width: min(100% - 40px, 760px); padding-top: 28px; }
  .page-heading { align-items: flex-start; flex-direction: column; gap: 18px; }
  .view-controls { width: 100%; justify-content: flex-start; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .income-summary { grid-column: 1 / -1; }
  .content-grid { grid-template-columns: 1fr; }
  .expense-list { max-height: 400px; }
}

@media (max-width: 600px) {
  .topbar { min-height: 66px; padding: 10px 15px; gap: 8px; }
  .topbar .brand-mark { width: 36px; height: 36px; border-radius: 12px; font-size: 19px; }
  .topbar-actions { gap: 5px; }
  .topbar-actions .sync-status { margin-right: 1px; }
  .sync-status span { display: none; }
  .topbar-actions .compact { min-height: 31px; padding-inline: 8px; font-size: 10px; }
  .topbar-actions #exportData, .topbar-actions .file-button { display: none; }
  .dashboard { width: min(100% - 28px, 460px); padding-top: 25px; }
  .page-heading h1 { font-size: 27px; }
  .page-heading p:not(.eyebrow) { max-width: 100%; font-size: 12px; line-height: 1.5; }
  .view-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
  .month-control { grid-column: 1 / -1; justify-content: space-between; }
  .month-control .month-label { flex: 1; }
  .view-controls > .button { width: 100%; min-height: 38px; padding-inline: 8px; font-size: 11px; }
  .summary-grid { grid-template-columns: 1fr; gap: 10px; }
  .income-summary { grid-column: auto; }
  .summary-card { min-height: 155px; padding: 17px; }
  .income-summary { min-height: 180px; }
  .metric { font-size: 27px; }
  .card-heading .button { padding-inline: 10px; }
  .content-grid { gap: 10px; }
  .allocation-card, .expenses-card, .calendar-card { padding: 16px; border-radius: 17px; }
  .section-heading { align-items: flex-start; gap: 8px; }
  .section-heading h2 { font-size: 16px; }
  .section-heading > .button { padding-inline: 9px; }
  .expense-item { gap: 8px; padding: 10px 8px; }
  .expense-actions { gap: 3px; }
  .tiny-button { min-width: 28px; padding-inline: 5px; }
  .expense-amount { font-size: 11px; }
  .calendar-heading { flex-direction: column; }
  .calendar-legend { flex-wrap: wrap; gap: 11px; }
  .calendar-weekdays span { padding-inline: 3px; text-align: center; font-size: 8px; }
  .calendar-day, .calendar-empty { min-height: 46px; }
  .calendar-day { padding: 6px; }
  .day-markers { gap: 2px; }
  .calendar-legend { font-size: 9px; }
  .app-footer { flex-direction: column; padding-top: 18px; }
  .modal-form { gap: 14px; padding: 19px; }
  .two-columns { gap: 9px; }
}

@media (max-width: 370px) {
  .topbar .brand-row .muted { display: none; }
  .income-chip { min-width: 178px; }
  .expense-discount { white-space: normal; }
}
