:root {
  --bg: #eef2f7;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  --line: #e4e9f0;
  --accent: #4f46e5;
  --accent-dark: #4338ca;
  --accent-soft: #eef2ff;
  --green: #047857;
  --green-soft: #ecfdf5;
  --amber: #b45309;
  --amber-soft: #fffbeb;
  --red: #b91c1c;
  --red-soft: #fef2f2;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 10px 28px rgba(15, 23, 42, 0.05);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    radial-gradient(900px 400px at 85% -10%, rgba(99, 102, 241, 0.1), transparent 65%),
    var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, p {
  margin: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

.wrap {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 22px;
}

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 62px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.02em;
}

.brand svg {
  color: var(--accent);
}

.nav {
  display: flex;
  gap: 4px;
}

.nav a {
  padding: 8px 14px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  transition: background 0.15s ease, color 0.15s ease;
}

.nav a:hover {
  background: #f1f5f9;
  color: var(--ink);
}

.nav a.active {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.nav-form {
  margin: 0;
  display: inline-flex;
}

.nav-lock {
  border: none;
  background: transparent;
  padding: 8px 14px;
  border-radius: 9px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-lock:hover {
  background: var(--red-soft);
  color: var(--red);
}

/* ---------- Page structure ---------- */

.main {
  flex: 1;
  padding-top: 30px;
  padding-bottom: 40px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 6px;
}

.page-head h1 {
  font-size: clamp(25px, 3vw, 33px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.date-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.date-picker label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.date-picker input,
.month-nav input {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 9px;
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
}

.date-picker input:focus,
.month-nav input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.footer {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 10px;
  padding-bottom: 30px;
  font-size: 12px;
  color: var(--faint);
}

/* ---------- Flash messages ---------- */

.flashes {
  margin-bottom: 16px;
}

.flash {
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  border: 1px solid transparent;
  margin-bottom: 8px;
}

.flash-success {
  background: var(--green-soft);
  border-color: #a7f3d0;
  color: #065f46;
}

.flash-error {
  background: var(--red-soft);
  border-color: #fecaca;
  color: #991b1b;
}

/* ---------- Credit card tiles ---------- */

.cards-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.credit-card {
  position: relative;
  overflow: hidden;
  border-radius: 20px;
  padding: 22px 24px;
  color: #ffffff;
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.16);
}

.credit-card::before {
  content: "";
  position: absolute;
  width: 260px;
  height: 260px;
  right: -90px;
  top: -120px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.22), transparent 62%);
  pointer-events: none;
}

.credit-card::after {
  content: "";
  position: absolute;
  width: 200px;
  height: 200px;
  right: 10px;
  bottom: -140px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  pointer-events: none;
}

.tone-1 {
  background: linear-gradient(135deg, #312e81 0%, #4f46e5 58%, #6366f1 100%);
}

.tone-2 {
  background: linear-gradient(135deg, #064e3b 0%, #0f766e 58%, #14b8a6 100%);
}

.cc-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  z-index: 1;
}

.cc-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 2.2px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.72);
}

.cc-chip {
  width: 34px;
  height: 25px;
  border-radius: 6px;
  background: linear-gradient(135deg, #fde68a, #f59e0b);
  box-shadow: inset 0 0 0 1px rgba(120, 53, 15, 0.28);
}

.cc-name {
  position: relative;
  z-index: 1;
  margin-top: 16px;
  font-size: 15px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
}

.cc-amount {
  position: relative;
  z-index: 1;
  margin-top: 2px;
  font-size: clamp(26px, 3vw, 34px);
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.cc-caption {
  position: relative;
  z-index: 1;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.68);
}

.cc-footer {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.18);
  font-size: 12px;
  color: rgba(255, 255, 255, 0.72);
}

.cc-footer span em {
  display: block;
  margin-top: 2px;
  font-style: normal;
  font-size: 10.5px;
  color: rgba(255, 255, 255, 0.58);
}

.cc-footer strong {
  color: #ffffff;
  font-variant-numeric: tabular-nums;
}

/* ---------- Stats strip ---------- */

.stats-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px 4px;
}

.stats-strip > div {
  padding: 0 20px;
}

.stats-strip > div + div {
  border-left: 1px solid var(--line);
}

.stat-label {
  display: block;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 3px;
}

.stats-strip strong {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

/* ---------- Panels ---------- */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-top: 18px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  margin-top: 18px;
}

.layout .panel {
  margin-top: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-head h2 {
  font-size: 15.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.hint {
  font-size: 12px;
  color: var(--faint);
  font-weight: 500;
}

.muted {
  color: var(--muted);
}

.tiny {
  font-size: 11.5px;
  line-height: 1.5;
}

/* ---------- Form ---------- */

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.optional {
  font-weight: 400;
  color: var(--faint);
  font-size: 11px;
}

.field input,
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfcfe;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input::placeholder {
  color: var(--faint);
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
  background: #ffffff;
}

.span-3 {
  grid-column: span 3;
}

.submit-field {
  justify-content: flex-end;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 16px;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.btn:hover {
  border-color: #cbd5e1;
  background: #f8fafc;
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  box-shadow: 0 6px 14px rgba(79, 70, 229, 0.22);
}

.btn.primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.btn.ghost {
  background: #ffffff;
}

.btn.small {
  padding: 7px 11px;
  font-size: 12.5px;
  border-radius: 8px;
}

.btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.btn[disabled]:hover {
  background: var(--accent);
  border-color: var(--accent);
}

.report-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.report-actions form {
  margin: 0;
}

/* ---------- Report side panel ---------- */

.report-panel .panel-head {
  margin-bottom: 10px;
}

.report-panel p {
  font-size: 13.5px;
  line-height: 1.6;
}

.report-panel .report-actions {
  margin-top: 16px;
}

.report-panel .tiny {
  margin-top: 12px;
  color: var(--faint);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  white-space: nowrap;
}

.status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.status.ok {
  background: var(--green-soft);
  color: var(--green);
}

.status.warn {
  background: var(--amber-soft);
  color: var(--amber);
}

.status.bad {
  background: var(--red-soft);
  color: var(--red);
}

/* ---------- Tables ---------- */

.table-scroll {
  overflow-x: auto;
  margin: 0 -6px;
  padding: 0 6px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  text-align: left;
  padding: 9px 12px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--faint);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.data-table td {
  padding: 12px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 14px;
  vertical-align: middle;
}

.data-table tbody tr:hover {
  background: #fafbff;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.strong {
  font-weight: 650;
}

.note-cell {
  color: var(--muted);
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.actions-col {
  width: 46px;
  text-align: right;
}

.icon-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--faint);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
  background: var(--red-soft);
  color: var(--red);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.badge.tone-1 {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.badge.tone-2 {
  background: var(--green-soft);
  color: var(--green);
}

.empty {
  text-align: center;
  padding: 34px 16px;
  color: var(--ink);
}

.empty p {
  margin-bottom: 6px;
  font-size: 14px;
}

.empty.compact {
  padding: 22px 12px;
}

.empty .btn {
  margin-top: 10px;
}

/* ---------- Category + recent lists ---------- */

.split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.category-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.category-list li + li {
  margin-top: 14px;
}

.category-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 13.5px;
}

.category-row > span:first-child {
  flex: 1;
  font-weight: 600;
}

.category-row .muted {
  font-size: 11.5px;
}

.category-row strong {
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}

.bar {
  height: 6px;
  margin-top: 7px;
  border-radius: 999px;
  background: #eef2f7;
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #818cf8, var(--accent));
}

.recent-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.recent-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #f1f5f9;
}

.recent-list li:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.recent-list li > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.recent-list strong {
  font-size: 13.5px;
  font-weight: 650;
}

.recent-list .muted {
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-meta {
  text-align: right;
  flex-shrink: 0;
}

.recent-meta strong {
  font-variant-numeric: tabular-nums;
}

.link {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent);
}

.link:hover {
  color: var(--accent-dark);
  text-decoration: underline;
}

/* ---------- History ---------- */

.month-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 16px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.stat-card strong {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat-card .muted {
  font-size: 12px;
}

.stat-card.accent {
  background: linear-gradient(135deg, #0f172a, #1e293b);
  border-color: #1e293b;
  color: #ffffff;
}

.stat-card.accent .stat-label {
  color: var(--faint);
}

.stat-card.accent .muted {
  color: #cbd5e1;
}

.day-panel .panel-head h2 {
  font-size: 15px;
}

/* ---------- Report page ---------- */

.report-picker {
  width: 100%;
  min-width: 0;
}

.report-controls {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 12px;
}

.report-controls .field {
  flex: 1 1 160px;
}

.report-controls [hidden] {
  display: none !important;
}

.report-dates,
#report-help {
  margin-top: 10px;
  font-size: 12.5px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.toolbar-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toolbar-info strong {
  font-size: 15px;
  font-weight: 650;
}

.toolbar-info .muted {
  font-size: 12.5px;
}

.notice {
  margin-top: 16px;
  padding: 14px 18px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.65;
}

.notice.warn {
  background: var(--amber-soft);
  border: 1px solid #fde68a;
  color: #92400e;
}

.notice code,
.report-panel code {
  background: rgba(15, 23, 42, 0.06);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.92em;
}

.preview-panel {
  padding-bottom: 18px;
}

#email-preview {
  display: block;
  width: 100%;
  height: 900px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #eef1f5;
}

/* ---------- Login ---------- */

.login-shell {
  display: flex;
  justify-content: center;
  padding: 6vh 0 4vh;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 34px 32px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.08);
  text-align: center;
}

.login-icon {
  width: 54px;
  height: 54px;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  background: var(--accent-soft);
  color: var(--accent);
}

.login-card h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.login-card > .muted {
  font-size: 13.5px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 24px;
  text-align: left;
}

.login-form label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.login-form input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfcfe;
  font: inherit;
  font-size: 14px;
}

.login-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
  background: #ffffff;
}

.login-form .btn {
  margin-top: 6px;
  width: 100%;
  padding: 12px;
}

.login-card .tiny {
  margin-top: 16px;
}

.login-card .notice {
  margin-top: 20px;
  text-align: left;
}

/* ---------- Responsive ---------- */

@media (max-width: 980px) {
  .layout,
  .split {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .span-3 {
    grid-column: span 2;
  }

  .submit-field {
    grid-column: span 2;
  }

  .submit-field .btn {
    width: 100%;
  }
}

@media (max-width: 720px) {
  .cards-grid {
    grid-template-columns: 1fr;
  }

  .stats-strip {
    grid-template-columns: 1fr;
    padding: 6px 0;
  }

  .stats-strip > div {
    padding: 10px 20px;
  }

  .stats-strip > div + div {
    border-left: none;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 600px) {
  .wrap {
    padding: 0 14px;
  }

  .topbar-inner {
    height: auto;
    padding-top: 10px;
    padding-bottom: 10px;
    flex-wrap: wrap;
  }

  .nav a {
    padding: 7px 11px;
    font-size: 13px;
  }

  .main {
    padding-top: 22px;
  }

  .page-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .span-3,
  .submit-field {
    grid-column: span 1;
  }

  .panel {
    padding: 16px;
  }

  .credit-card {
    padding: 20px;
  }

  .note-cell {
    max-width: 180px;
  }

  .report-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .report-controls .field {
    flex: auto;
  }

  .report-controls .report-actions .btn {
    flex: 1;
  }

  .preview-panel .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar {
    align-items: flex-start;
    flex-direction: column;
  }
}
