@import url("https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700&display=swap");

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-dim: #0ea5e9;
  --danger: #f87171;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --font: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --tap: 48px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  background: linear-gradient(165deg, #0f172a 0%, #1e1b4b 45%, #0f172a 100%);
  color: var(--text);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) calc(1.5rem + env(safe-area-inset-bottom)) env(safe-area-inset-left);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--surface2);
  padding: 1rem 1rem 0.75rem;
}

.top-inner {
  max-width: 560px;
  margin: 0 auto;
}

.title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0.2rem 0 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.app-nav {
  max-width: 560px;
  margin: 0.65rem auto 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: center;
  padding-bottom: 0.15rem;
}

.app-nav-link {
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--muted);
  padding: 0.4rem 0.55rem;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.app-nav-link:hover {
  color: var(--text);
  border-color: var(--surface2);
  background: rgba(30, 41, 59, 0.6);
}

.app-nav-link.is-active {
  color: #0f172a;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dim) 100%);
  border-color: transparent;
}

.month-bar {
  max-width: 560px;
  margin: 0.85rem auto 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: center;
}

.month-label {
  flex: 1;
  max-width: 200px;
}

.month-label input[type="month"] {
  width: 100%;
  min-height: var(--tap);
  padding: 0 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--surface2);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
}

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  border-radius: 12px;
  border: 1px solid var(--surface2);
  background: var(--surface);
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
}

.icon-btn:active {
  transform: scale(0.96);
}

.main {
  max-width: 560px;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem;
  box-shadow: var(--shadow);
  border: 1px solid rgba(148, 163, 184, 0.12);
}

.card-title {
  margin: 0 0 1rem;
  font-size: 1rem;
  font-weight: 600;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.summary-label {
  color: var(--muted);
  font-size: 0.9rem;
}

.summary-total {
  font-size: 1.65rem;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.breakdown {
  display: grid;
  gap: 0.65rem;
}

.breakdown-block h3 {
  margin: 0 0 0.35rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.breakdown-rows {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.break-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.break-row span:first-child {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 65%;
}

.break-row span:last-child {
  color: var(--muted);
  font-weight: 500;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
  color: var(--muted);
}

.optional {
  font-weight: 400;
  opacity: 0.8;
}

.field input {
  width: 100%;
  min-height: var(--tap);
  padding: 0 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--surface2);
  background: #0f172a;
  color: var(--text);
  font: inherit;
  font-size: 1rem;
}

.field input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn {
  min-height: var(--tap);
  padding: 0 1.1rem;
  border-radius: 12px;
  border: none;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dim) 100%);
  color: #0f172a;
}

.btn.primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--surface2);
}

.btn.danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.35);
  min-height: 40px;
  padding: 0 0.65rem;
  font-size: 0.85rem;
}

.form-msg {
  margin: 0;
  min-height: 1.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.form-msg.error {
  color: var(--danger);
}

.form-msg.ok {
  color: #4ade80;
}

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.list-head .card-title {
  margin: 0;
}

.badge {
  background: var(--surface2);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.expense-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.expense-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem 0.75rem;
  align-items: start;
  padding: 0.85rem 0.9rem;
  background: #0f172a;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.1);
}

.expense-main {
  min-width: 0;
}

.expense-top {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.65rem;
}

.expense-cat {
  font-weight: 600;
  text-transform: capitalize;
}

.expense-amt {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.expense-meta {
  margin-top: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
}

.expense-actions {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  align-items: stretch;
}

.empty {
  margin: 0.5rem 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.empty[hidden] {
  display: none;
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

@media (min-width: 480px) {
  .modal {
    align-items: center;
    padding: 1rem;
  }
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.modal-panel {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 1.15rem;
  border: 1px solid var(--surface2);
  box-shadow: var(--shadow);
}

@media (min-width: 480px) {
  .modal-panel {
    border-radius: var(--radius);
  }
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.modal-actions .btn {
  flex: 1;
}

.top-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.user-bar {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
  flex-shrink: 0;
}

.user-email {
  font-size: 0.8rem;
  color: var(--muted);
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-sm {
  min-height: 40px;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
}

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
}

.login-wrap {
  width: 100%;
  max-width: 400px;
  padding: 1rem;
}

.login-card {
  text-align: center;
}

.login-title {
  font-size: 1.5rem;
}

.login-sub {
  margin-bottom: 1.25rem;
}

.google-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  text-decoration: none;
  margin-top: 0.5rem;
}

.hint {
  margin: 0 0 0.85rem;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
}

.profile-dl {
  margin: 0;
  display: grid;
  grid-template-columns: 6rem 1fr;
  gap: 0.5rem 1rem;
  font-size: 0.9rem;
}

.profile-dl dt {
  margin: 0;
  color: var(--muted);
  font-weight: 500;
}

.profile-dl dd {
  margin: 0;
}

.profile-pic-wrap {
  grid-column: 1 / -1;
  margin-bottom: 0.35rem;
}

.profile-pic {
  border-radius: 50%;
  border: 2px solid var(--surface2);
  display: block;
}

.profile-local {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.45;
}

.profile-stat {
  margin: 0.5rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.category-option-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.category-option-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  background: #0f172a;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.1);
}

.category-option-name {
  font-weight: 500;
  text-transform: capitalize;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.category-option-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  flex-shrink: 0;
}

.form-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.export-actions .btn {
  flex: 1;
  min-width: 8rem;
  justify-content: center;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.dashboard-charts {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.chart-card .chart-wrap {
  position: relative;
  min-height: 220px;
  max-height: 320px;
}

.chart-wrap--wide {
  min-height: 260px;
  max-height: 360px;
}

.chart-placeholder {
  margin: 0;
  padding: 1rem 1.15rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid rgba(148, 163, 184, 0.12);
}

.chart-placeholder[hidden] {
  display: none;
}
