:root {
  color-scheme: light;
  --page: #f3f6f9;
  --page-deep: #e9eff5;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-raised: #ffffff;
  --ink: #122033;
  --ink-soft: #34445a;
  --muted: #718096;
  --muted-strong: #536277;
  --line: #dfe6ed;
  --line-soft: #edf1f5;
  --brand: #153b5b;
  --brand-deep: #0e2b45;
  --brand-soft: #e9f1f7;
  --primary: #087f75;
  --primary-deep: #06665f;
  --primary-soft: #e4f4f1;
  --success: #15805f;
  --success-soft: #e8f5ef;
  --danger: #c74655;
  --danger-deep: #a83342;
  --danger-soft: #fff0f1;
  --warning: #b67120;
  --warning-soft: #fff7e8;
  --violet: #6657b8;
  --violet-soft: #f0effb;
  --shadow-xs: 0 1px 2px rgba(15, 35, 55, 0.05);
  --shadow-sm: 0 5px 18px rgba(15, 35, 55, 0.07);
  --shadow-md: 0 16px 42px rgba(15, 35, 55, 0.11);
  --shadow-lg: 0 30px 80px rgba(7, 24, 40, 0.2);
  --radius-sm: 9px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 26px;
  --topbar-height: 72px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

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

html {
  min-width: 0;
  background: var(--page);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-width: 0;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% -12%, rgba(21, 59, 91, 0.08), transparent 30rem),
    linear-gradient(180deg, #f7f9fb 0, var(--page) 32rem, var(--page) 100%);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.modal-open { overflow: hidden; }

button,
input,
select,
textarea {
  font: inherit;
}

button,
select,
input[type="date"],
input[type="file"] {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

button:not(:disabled),
select:not(:disabled),
input[type="file"]:not(:disabled),
.upload-area {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

img,
canvas,
svg {
  display: block;
  max-width: 100%;
}

[hidden] {
  display: none !important;
}

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

/* Lucide is the only interface icon language. */
.icon,
[data-lucide],
button svg,
a svg,
.btn svg,
.topbar-btn svg,
.icon-close svg {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  stroke-width: 1.9;
  vector-effect: non-scaling-stroke;
}

.icon--sm,
.btn--small svg {
  width: 16px;
  height: 16px;
  flex-basis: 16px;
}

.icon--lg {
  width: 22px;
  height: 22px;
  flex-basis: 22px;
}

:focus-visible {
  outline: 3px solid rgba(8, 127, 117, 0.24);
  outline-offset: 2px;
}

::selection {
  color: #fff;
  background: var(--brand);
}

/* Login */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(24px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  overflow-y: auto;
  background:
    radial-gradient(circle at 18% 18%, rgba(49, 129, 125, 0.17), transparent 25rem),
    radial-gradient(circle at 83% 84%, rgba(102, 87, 184, 0.12), transparent 28rem),
    linear-gradient(145deg, #0a243a 0%, #123953 55%, #0e2d45 100%);
}

.login-overlay::before {
  position: fixed;
  inset: 0;
  content: "";
  pointer-events: none;
  opacity: 0.18;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.75), transparent 78%);
}

.login-card {
  position: relative;
  z-index: 1;
  width: min(100%, 410px);
  padding: 38px 36px 34px;
  text-align: center;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid rgba(255, 255, 255, 0.68);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  animation: card-in 0.55s var(--ease) both;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  margin: 0 auto 20px;
  color: #fff;
  font-size: 26px;
  font-weight: 760;
  letter-spacing: 0.04em;
  background: linear-gradient(145deg, #1c526f, var(--brand-deep));
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 19px;
  box-shadow: 0 12px 26px rgba(14, 43, 69, 0.25), inset 0 1px rgba(255, 255, 255, 0.22);
}

.brand-mark img,
.logo-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

.login-card h1 {
  margin: 0;
  color: var(--brand-deep);
  font-size: clamp(24px, 6vw, 29px);
  font-weight: 750;
  letter-spacing: 0.015em;
}

.login-card .sub {
  margin: 7px 0 26px;
  color: var(--muted);
  font-size: 14px;
  letter-spacing: 0.08em;
}

.login-card input,
.modal input,
.modal select {
  width: 100%;
  min-height: 46px;
  padding: 10px 13px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid #ced8e2;
  border-radius: var(--radius-sm);
  outline: 0;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.login-card input:hover,
.modal input:hover,
.modal select:hover {
  border-color: #aebdca;
}

.login-card input:focus,
.modal input:focus,
.modal select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(8, 127, 117, 0.11);
}

.login-card > input {
  min-height: 52px;
  padding-inline: 16px;
  font-size: 16px;
}

.captcha-row {
  display: grid;
  grid-template-columns: 1fr 76px;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  margin-top: 12px;
  padding: 7px 7px 7px 15px;
  color: var(--muted-strong);
  text-align: left;
  background: var(--surface-soft);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
}

.captcha-row strong {
  color: var(--brand);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.captcha-row input {
  min-height: 38px;
  padding: 6px 8px;
  text-align: center;
}

.form-error,
.field-error,
.validation-message {
  min-height: 22px;
  margin-top: 8px;
  color: var(--danger);
  font-size: 13px;
  text-align: left;
}

.login-card > button[type="submit"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 50px;
  margin-top: 5px;
  padding: 0 18px;
  color: #fff;
  font-weight: 680;
  letter-spacing: 0.04em;
  background: linear-gradient(180deg, #1b516f, var(--brand));
  border: 1px solid rgba(9, 38, 61, 0.5);
  border-radius: 11px;
  box-shadow: 0 9px 20px rgba(21, 59, 91, 0.21), inset 0 1px rgba(255, 255, 255, 0.18);
  transition: transform 0.18s var(--ease), box-shadow 0.18s ease, filter 0.18s ease;
}

.login-card > button[type="submit"]:hover:not(:disabled) {
  filter: brightness(1.06);
  box-shadow: 0 12px 24px rgba(21, 59, 91, 0.27), inset 0 1px rgba(255, 255, 255, 0.18);
  transform: translateY(-1px);
}

/* App header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: var(--topbar-height);
  padding: 11px max(24px, calc((100vw - 1780px) / 2));
  padding-right: max(24px, env(safe-area-inset-right), calc((100vw - 1780px) / 2));
  padding-left: max(24px, env(safe-area-inset-left), calc((100vw - 1780px) / 2));
  color: #fff;
  background: rgba(14, 43, 69, 0.97);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 26px rgba(9, 28, 44, 0.16);
  backdrop-filter: blur(16px) saturate(140%);
}

.logo {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 19px;
  font-weight: 720;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.logo-mark,
.section-icon {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
}

.logo-mark {
  width: 34px;
  height: 34px;
  color: #dff8f4;
  background: rgba(99, 200, 186, 0.14);
  border: 1px solid rgba(145, 224, 212, 0.22);
  border-radius: 10px;
}

.section-icon {
  width: 32px;
  height: 32px;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 9px;
}

.logo::before {
  position: absolute;
  top: 50%;
  left: 0;
  width: 4px;
  height: 24px;
  content: "";
  background: #63c8ba;
  border-radius: 999px;
  transform: translateY(-50%);
  box-shadow: 0 0 0 4px rgba(99, 200, 186, 0.12);
  display: none;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
}

.current-user {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  margin-right: 4px;
  padding: 6px 12px;
  color: #d5e5ef;
  font-size: 13px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
}

.topbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 7px 11px;
  color: #e8f0f5;
  font-size: 13px;
  font-weight: 590;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  transition: color 0.18s ease, background 0.18s ease, border-color 0.18s ease, transform 0.18s var(--ease);
}

.topbar-btn:hover:not(:disabled) {
  color: #fff;
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.1);
  transform: translateY(-1px);
}

.topbar-btn:active:not(:disabled) {
  transform: translateY(0);
}

/* Layout and panels */
.main-container {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: 18px;
  width: min(100%, 1820px);
  margin: 0 auto;
  padding: 22px 20px max(36px, env(safe-area-inset-bottom));
}

.panel {
  min-width: 0;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(213, 223, 232, 0.92);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.panel:has(.custom-select.is-open) {
  position: relative;
  z-index: 80;
  overflow: visible;
}

.panel-header {
  display: flex;
  align-items: center;
  min-height: 61px;
  padding: 17px 20px 13px;
  border-bottom: 1px solid var(--line-soft);
}

.panel-header h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--brand-deep);
  font-size: 18px;
  font-weight: 720;
  letter-spacing: 0.01em;
}

.panel-header h2 svg {
  width: 20px;
  height: 20px;
  color: var(--primary);
}

.currency-code {
  display: inline-flex;
  align-items: center;
  min-height: 23px;
  padding: 2px 8px;
  color: var(--muted-strong);
  font-size: 10px;
  font-weight: 720;
  letter-spacing: 0.1em;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
}

/* Account summaries */
.balance-cards {
  display: grid;
  gap: 9px;
  padding: 14px 14px 0;
}

.balance-cards--three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.balance-cards--four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.balance-card {
  position: relative;
  min-width: 0;
  min-height: 82px;
  padding: 13px 13px 12px 15px;
  overflow: hidden;
  background: var(--surface-soft);
  border: 1px solid var(--line-soft);
  border-radius: 12px;
}

.balance-card::before {
  position: absolute;
  inset: 11px auto 11px 0;
  width: 3px;
  content: "";
  background: currentColor;
  border-radius: 0 999px 999px 0;
  opacity: 0.75;
}

.balance-card span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 570;
  white-space: nowrap;
}

.balance-card strong {
  display: block;
  overflow: hidden;
  color: currentColor;
  font-size: clamp(17px, 1.5vw, 22px);
  font-weight: 735;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.025em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.balance-card.balance {
  color: var(--brand);
  background: linear-gradient(145deg, #f1f6fa, #f8fafc);
}

.balance-card.expense {
  color: var(--danger);
  background: linear-gradient(145deg, #fff5f5, #fffafa);
}

.balance-card.topup {
  color: var(--success);
  background: linear-gradient(145deg, #eff9f4, #f8fcfa);
}

.balance-card.trx {
  color: var(--violet);
  background: linear-gradient(145deg, #f4f2fb, #fafafe);
}

/* Charts */
.charts-row {
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
  align-items: start;
  gap: 10px;
  padding: 10px 14px 0;
}

.chart-box--expense { grid-column: 1; grid-row: 1; }
.chart-box--trend { grid-column: 2; grid-row: 1; }

.chart-box {
  min-width: 0;
  padding: 14px 12px 12px;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: 13px;
  box-shadow: var(--shadow-xs);
}

.chart-box h3 {
  display: flex;
  align-items: center;
  min-height: 25px;
  margin: 0 2px 8px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 670;
}

.chart-box h3::before {
  width: 3px;
  height: 14px;
  margin-right: 8px;
  content: "";
  background: var(--primary);
  border-radius: 999px;
}

.chart-wrap {
  position: relative;
  width: 100%;
  min-width: 0;
  isolation: isolate;
}

.chart-wrap--doughnut {
  height: 204px;
}

.chart-wrap--bar {
  height: 234px;
}

.chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

.chart-legend {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 6px 10px;
  min-width: 0;
}

.chart-legend--shared {
  grid-column: 1 / -1;
  grid-row: 2;
  margin: 0;
  padding: 10px 12px;
  background: #f8fafb;
  border: 1px solid var(--line-soft);
  border-radius: 11px;
}

.chart-legend:empty {
  display: none;
}

.legend-item,
.chart-legend > button,
.chart-legend > div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 0;
  color: var(--muted-strong);
  font-size: 11px;
  line-height: 1.4;
  text-align: left;
  background: none;
  border: 0;
}

.legend-copy {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.legend-swatch {
  flex: 0 0 8px;
  width: 8px;
  height: 8px;
  background: var(--legend-color, var(--primary));
  border-radius: 999px;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--legend-color, var(--primary)) 14%, transparent);
}

.tone-indigo { --category-color: #6366f1; --category-fill: #4338ca; --legend-color: #6366f1; }
.tone-amber { --category-color: #f59e0b; --category-fill: #854d0e; --legend-color: #f59e0b; }
.tone-orange { --category-color: #f97316; --category-fill: #c2410c; --legend-color: #f97316; }
.tone-sky { --category-color: #0ea5e9; --category-fill: #0369a1; --legend-color: #0ea5e9; }
.tone-violet { --category-color: #8b5cf6; --category-fill: #6d28d9; --legend-color: #8b5cf6; }
.tone-brown { --category-color: #a16207; --category-fill: #713f12; --legend-color: #a16207; }
.tone-slate { --category-color: #64748b; --category-fill: #475569; --legend-color: #64748b; }
.tone-pink { --category-color: #ec4899; --category-fill: #be185d; --legend-color: #ec4899; }
.tone-teal { --category-color: #14b8a6; --category-fill: #0f766e; --legend-color: #14b8a6; }
.tone-green { --category-color: #22c55e; --category-fill: #15803d; --legend-color: #22c55e; }
.tone-cyan { --category-color: #06b6d4; --category-fill: #0e7490; --legend-color: #06b6d4; }
.tone-neutral { --category-color: #94a3b8; --category-fill: #475569; --legend-color: #94a3b8; }
.tone-red { --category-color: #ef4444; --category-fill: #b91c1c; --legend-color: #ef4444; }

.legend-label,
.chart-legend .label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-value,
.chart-legend .value {
  color: var(--ink-soft);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.legend-percent,
.chart-legend small {
  color: var(--muted);
  font-size: 10px;
}

/* Toolbar and controls */
.action-row {
  display: grid;
  grid-template-columns: auto auto minmax(148px, 160px) minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  padding: 14px;
}

.action-row--usdt {
  grid-template-columns: minmax(148px, 160px) minmax(0, 1fr) auto;
}

.btn,
.category-select-trigger,
.pagination button,
.segmented button,
.receipt-button {
  min-height: 42px;
  border-radius: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 650;
  line-height: 1;
  border: 1px solid transparent;
  box-shadow: var(--shadow-xs);
  transition: color 0.18s ease, background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s var(--ease);
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

.btn-primary,
.btn-sync,
.btn-topup {
  color: #fff;
  background: linear-gradient(180deg, #149188, var(--primary));
  border-color: var(--primary-deep);
  box-shadow: 0 7px 14px rgba(8, 127, 117, 0.18), inset 0 1px rgba(255, 255, 255, 0.16);
}

.btn-primary:hover:not(:disabled),
.btn-sync:hover:not(:disabled),
.btn-topup:hover:not(:disabled) {
  background: linear-gradient(180deg, #159b91, #08786f);
  box-shadow: 0 9px 18px rgba(8, 127, 117, 0.23), inset 0 1px rgba(255, 255, 255, 0.16);
}

.btn-expense,
.btn-danger {
  color: var(--danger-deep);
  background: var(--danger-soft);
  border-color: #f2cbd0;
}

.btn-expense:hover:not(:disabled),
.btn-danger:hover:not(:disabled) {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger-deep);
  box-shadow: 0 7px 15px rgba(199, 70, 85, 0.2);
}

.btn-muted {
  color: var(--ink-soft);
  background: var(--surface-soft);
  border-color: var(--line);
}

.btn-muted:hover:not(:disabled) {
  color: var(--brand);
  background: #fff;
  border-color: #b9c7d3;
}

.category-select-wrap {
  position: relative;
  width: 100%;
  min-width: 0;
}

.category-select-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 26px;
  width: 26px;
  height: 26px;
  color: #fff;
  background: var(--category-fill, #475569);
  border-radius: 8px;
  box-shadow: inset 0 1px rgba(255, 255, 255, .2), 0 2px 5px color-mix(in srgb, var(--category-color, #475569) 18%, transparent);
}

.category-select-icon svg { width: 14px; height: 14px; }

.category-select-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 7px 10px 7px 8px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 560;
  text-align: left;
  background-color: var(--surface);
  border: 1px solid #ced8e2;
  border-radius: 10px;
  outline: 0;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.category-select-trigger:hover {
  background: #f8fbfc;
  border-color: #afbdc9;
}

.category-select-trigger:focus-visible,
.custom-select.is-open .category-select-trigger {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(8, 127, 117, 0.1);
}

.category-select-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-select-chevron {
  width: 16px;
  height: 16px;
  margin-left: auto;
  color: var(--muted);
  transition: transform .18s ease;
}

.custom-select.is-open .category-select-chevron { transform: rotate(180deg); }

.category-native-select[hidden] { display: none !important; }

.category-select-menu {
  position: absolute;
  z-index: 95;
  top: calc(100% + 7px);
  left: 0;
  width: max(100%, 190px);
  max-height: min(310px, 48vh);
  padding: 6px;
  overflow: auto;
  background: rgba(255, 255, 255, .98);
  border: 1px solid #cbd6df;
  border-radius: 12px;
  box-shadow: 0 18px 40px rgba(15, 31, 45, .16), 0 4px 12px rgba(15, 31, 45, .08);
  overscroll-behavior: contain;
}

.category-select-menu.is-viewport-menu {
  position: fixed;
  z-index: 120;
  right: auto;
  bottom: auto;
  min-width: 0;
}

.category-select-option {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 18px;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 40px;
  padding: 5px 7px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 590;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 9px;
}

.category-select-option:hover,
.category-select-option:focus-visible {
  background: #e9f1f3;
  outline: 0;
}

.category-select-option.is-selected {
  color: var(--brand);
  background: #e3efef;
}

.category-option-icon {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  color: #fff;
  background: var(--category-fill, #475569);
  border-radius: 8px;
  box-shadow: inset 0 1px rgba(255, 255, 255, .18);
}

.category-option-icon svg { width: 14px; height: 14px; }
.category-option-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.category-option-check { display: inline-grid; place-items: center; color: var(--primary); }
.category-option-check svg { width: 16px; height: 16px; }

.filter-summary {
  display: flex;
  align-items: center;
  min-height: 38px;
  margin: 0;
  padding: 8px 11px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 590;
  background: var(--brand-soft);
  border: 1px solid #d8e6ef;
  border-radius: 9px;
}

.filter-summary > svg { width: 16px; height: 16px; flex: 0 0 16px; margin-right: 7px; }
.sync-status {
  display: grid;
  grid-template-columns: 34px auto;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 5px 10px;
  color: var(--muted-strong);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.sync-status__icon { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; color: var(--primary); background: var(--primary-soft); border-radius: 9px; }
.sync-status__icon svg { width: 17px; height: 17px; }
.sync-status__copy { display: grid; line-height: 1.25; }
.sync-status__copy small { color: var(--muted); font-size: 9px; }
.sync-status__copy strong { color: var(--ink-soft); font-size: 11px; white-space: nowrap; }
.sync-status__copy > span { color: var(--muted-strong); font-size: 10px; }
.sync-status.is-error .sync-status__icon { color: var(--danger); background: var(--danger-soft); }
.sync-status.is-success .sync-status__icon { color: var(--success); background: var(--success-soft); }

.filter-summary:empty {
  display: none;
}

.filter-summary strong,
.filter-total {
  margin-inline: 3px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

/* Records */
.table-wrap {
  margin: 0 14px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.records-table {
  width: 100%;
  border-spacing: 0;
  border-collapse: separate;
  table-layout: fixed;
}

.records-table th {
  height: 39px;
  padding: 9px 8px;
  color: var(--muted-strong);
  font-size: 11px;
  font-weight: 670;
  letter-spacing: 0.025em;
  text-align: left;
  background: #e9eef3;
  border-bottom: 1px solid #cdd7df;
}

.records-table td {
  height: 48px;
  padding: 8px;
  overflow: hidden;
  color: var(--ink-soft);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

.records-table tbody tr {
  position: relative;
  transition: background 0.16s ease;
}

.records-table tbody tr:hover {
  background: #edf4f5;
}

.records-table tbody tr:last-child td {
  border-bottom: 0;
}

.records-table th:nth-child(1),
.records-table td:nth-child(1) {
  width: 91px;
}

.records-table th:nth-child(2),
.records-table td:nth-child(2) {
  width: 104px;
}

.records-table th:nth-child(3),
.records-table td:nth-child(3) {
  width: 98px;
  text-align: right;
}

.records-table th:nth-child(5),
.records-table td:nth-child(5) {
  width: 56px;
  text-align: center;
}

.records-table th:nth-child(6),
.records-table td:nth-child(6) {
  width: 76px;
}

.record-amount,
.amount,
.records-table td:nth-child(3) {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.amount--expense,
.amount-expense,
.is-expense .record-amount,
.record-amount.expense {
  color: var(--danger);
}

.amount--topup,
.amount-topup,
.is-topup .record-amount,
.record-amount.topup {
  color: var(--success);
}

.category-chip,
.type-chip,
.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  min-height: 24px;
  padding: 3px 8px;
  overflow: hidden;
  color: var(--brand);
  font-size: 11px;
  font-weight: 620;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: var(--brand-soft);
  border: 1px solid #d8e6ef;
  border-radius: 999px;
}

.category-chip {
  color: #fff;
  background: var(--category-fill, #334155);
  border-color: color-mix(in srgb, var(--category-fill, #334155) 78%, #111827);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.18), 0 2px 5px color-mix(in srgb, var(--category-color, var(--brand)) 18%, transparent);
}

.muted-text,
.receipt-none { color: var(--muted); }

.empty-state,
.tx-loading {
  display: grid;
  justify-items: center;
  gap: 7px;
  padding: 28px 14px;
  color: var(--muted);
  text-align: center;
}

.empty-state svg,
.tx-loading svg { width: 24px; height: 24px; }
.records-table .empty-state > svg {
  width: 46px;
  height: 46px;
  padding: 11px;
  color: var(--primary);
  background: var(--primary-soft);
  border: 1px solid #c9e2de;
  border-radius: 50%;
}
.empty-state strong { color: var(--ink-soft); }
.empty-state span { font-size: 12px; }

.is-locked {
  color: var(--muted-strong) !important;
  background: var(--surface-soft) !important;
}

.is-income,
.amount--topup { color: var(--success) !important; }
.is-expense,
.amount--expense { color: var(--danger) !important; }

.legend-empty {
  grid-column: 1 / -1;
  display: block !important;
  padding: 8px 2px !important;
  color: var(--muted) !important;
  text-align: center !important;
}

.record-note,
.record-operator {
  color: var(--muted-strong);
}

.receipt-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 36px;
  min-height: 36px;
  padding: 7px;
  color: var(--muted-strong);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  box-shadow: var(--shadow-xs);
  transition: color 0.17s ease, background 0.17s ease, border-color 0.17s ease, transform 0.17s var(--ease), box-shadow 0.17s ease;
}

.receipt-button:hover:not(:disabled) {
  color: var(--primary);
  background: var(--primary-soft);
  border-color: #bcdfda;
  transform: translateY(-1px);
}

.receipt-thumb {
  width: 30px;
  height: 30px;
  max-width: 30px;
  max-height: 30px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.empty-row td,
.records-empty {
  height: auto !important;
  padding: 34px 16px !important;
  color: var(--muted) !important;
  text-align: center !important;
  white-space: normal !important;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 13px 14px 16px;
}

.pagination > .date-filter-wrap {
  position: relative;
}

.pagination .month-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: auto;
  min-width: 154px;
  padding: 0 14px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 680;
  background: #edf2f5;
}

.pagination .month-button svg { width: 16px; height: 16px; color: var(--primary); }
.pagination .month-button.has-date-filter { color: #fff; background: linear-gradient(145deg, var(--brand), var(--primary)); border-color: var(--primary-deep); }
.pagination .month-button.has-date-filter svg,
.pagination .month-button:hover:not(:disabled) svg { color: #fff; }

.pagination .month-button > span {
  min-width: 92px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 650;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.pagination .month-button.has-date-filter > span,
.pagination .month-button:hover:not(:disabled) > span { color: #fff; }

.date-filter-wrap.is-open { z-index: 88; }

.calendar-popover {
  position: absolute;
  z-index: 100;
  bottom: calc(100% + 8px);
  left: 50%;
  width: 286px;
  padding: 13px;
  background: rgba(255, 255, 255, .99);
  border: 1px solid #cbd6df;
  border-radius: 15px;
  box-shadow: 0 20px 48px rgba(15, 31, 45, .2), 0 4px 12px rgba(15, 31, 45, .08);
  transform: translateX(-50%);
}

.calendar-title {
  margin-bottom: 10px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 720;
  text-align: center;
}

.calendar-weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.calendar-weekdays { margin-bottom: 5px; }
.calendar-popover span { min-width: 0; }
.calendar-weekdays span { color: var(--muted); font-size: 10px; font-weight: 650; text-align: center; }
.calendar-blank { min-width: 0; min-height: 32px; }

.calendar-grid .calendar-day {
  width: 100%;
  min-height: 32px;
  padding: 0;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 620;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
}

.calendar-grid .calendar-day:hover,
.calendar-grid .calendar-day:focus-visible {
  color: var(--brand);
  background: #e5f1f0;
  border-color: #b9d6d2;
  outline: 0;
}

.calendar-grid .calendar-day.is-today { color: var(--primary-deep); border-color: #9ccdc6; }
.calendar-grid .calendar-day.is-selected { color: #fff; background: var(--primary); border-color: var(--primary-deep); box-shadow: 0 4px 9px rgba(8, 127, 117, .22); }

.calendar-popover .calendar-clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: 36px;
  margin-top: 10px;
  padding: 6px 10px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 650;
  background: #edf4f5;
  border: 1px solid #cbdadf;
  border-radius: 9px;
}

.calendar-popover .calendar-clear:disabled { color: var(--muted); cursor: default; opacity: .62; }
.calendar-popover .calendar-clear svg { width: 15px; height: 15px; }

.pagination button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  min-height: 40px;
  padding: 0;
  color: var(--brand);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  transition: color 0.17s ease, background 0.17s ease, border-color 0.17s ease, transform 0.17s var(--ease);
}

.pagination button:hover:not(:disabled) {
  color: #fff;
  background: var(--brand);
  border-color: var(--brand);
  transform: translateY(-1px);
}

/* Overlays, panels and forms */
.modal-overlay,
.detail-overlay,
.lightbox-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  visibility: hidden;
  opacity: 0;
  background: rgba(7, 24, 40, 0.52);
  backdrop-filter: blur(7px);
  transition: opacity 0.22s ease, visibility 0s linear 0.22s;
}

.modal-overlay[aria-hidden="false"],
.detail-overlay[aria-hidden="false"],
.lightbox-overlay[aria-hidden="false"],
.modal-overlay.open,
.detail-overlay.open,
.lightbox-overlay.open,
.modal-overlay.show,
.detail-overlay.show,
.lightbox-overlay.show {
  visibility: visible;
  opacity: 1;
  transition-delay: 0s;
}

.modal,
.detail-panel {
  position: relative;
  width: min(100%, 530px);
  max-height: min(90vh, 820px);
  max-height: min(90dvh, 820px);
  padding: 25px;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--surface-raised);
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  transform: translateY(14px) scale(0.985);
  transition: transform 0.3s var(--ease);
}

[aria-hidden="false"] > .modal,
[aria-hidden="false"] > .detail-panel,
.open > .modal,
.open > .detail-panel,
.show > .modal,
.show > .detail-panel {
  transform: translateY(0) scale(1);
}

.detail-overlay {
  justify-items: end;
  padding: 0;
}

.detail-panel {
  width: min(100%, 470px);
  height: 100%;
  max-height: none;
  padding: 29px 28px;
  border-radius: 22px 0 0 22px;
  transform: translateX(28px);
}

[aria-hidden="false"] > .detail-panel,
.open > .detail-panel,
.show > .detail-panel {
  transform: translateX(0);
}

.modal--compact {
  width: min(100%, 470px);
}

.modal--history {
  width: min(100%, 760px);
}

.modal h3,
.detail-panel h3 {
  margin: 0 42px 22px 0;
  color: var(--brand-deep);
  font-size: 20px;
  font-weight: 730;
  line-height: 1.35;
}

.icon-close {
  position: absolute;
  top: 17px;
  right: 17px;
  z-index: 3;
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  color: var(--muted-strong);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  transition: color 0.18s ease, background 0.18s ease, border-color 0.18s ease, transform 0.18s var(--ease);
}

.icon-close:hover:not(:disabled) {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: #efcdd1;
  transform: rotate(3deg);
}

.modal label {
  display: grid;
  gap: 7px;
  margin-bottom: 15px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 620;
}

.field-group {
  display: grid;
  gap: 7px;
  margin-bottom: 15px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 620;
}

.field-label { display: block; }

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

.form-category-select {
  position: relative;
  display: block;
}

.mobile-currency-tabs { display: none; }

.modal-help {
  margin: -9px 0 19px;
  padding: 11px 12px;
  color: var(--muted-strong);
  font-size: 12px;
  line-height: 1.65;
  background: var(--brand-soft);
  border: 1px solid #d8e6ef;
  border-radius: 10px;
}

.upload-label {
  margin-top: 3px;
}

.upload-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 112px;
  padding: 16px;
  color: var(--primary);
  font-weight: 650;
  text-align: center;
  background: #f7fcfb;
  border: 1px dashed #9bcfc7;
  border-radius: 12px;
  transition: color 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.upload-area:hover {
  color: var(--primary-deep);
  background: var(--primary-soft);
  border-color: var(--primary);
}

.upload-area svg {
  width: 24px;
  height: 24px;
}

.upload-area small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.receipt-preview {
  position: relative;
  width: 100%;
  min-height: 120px;
  margin: -4px 0 15px;
  padding: 8px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.receipt-preview img {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  cursor: zoom-in;
  border-radius: 8px;
}

.receipt-preview img:focus-visible,
.detail-receipt img:focus-visible { outline: 3px solid rgba(8, 127, 117, .24); outline-offset: 3px; }

.receipt-preview button {
  position: absolute;
  top: 13px;
  right: 13px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  color: #fff;
  background: rgba(15, 31, 45, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 9px;
  backdrop-filter: blur(8px);
}

.modal-actions,
.detail-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 23px;
}

.modal-actions .btn,
.detail-actions .btn {
  min-width: 104px;
}

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

.detail-grid > div {
  min-width: 0;
  padding: 11px 12px;
  background: #edf2f5;
  border: 1px solid #d2dce4;
  border-radius: 10px;
}

.detail-grid dt {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 580;
}

.detail-grid dd {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 590;
}

.detail-grid .detail-amount {
  color: var(--brand);
  font-size: 17px;
  font-weight: 735;
  font-variant-numeric: tabular-nums;
}

.detail-receipt {
  margin-top: 15px;
}

.detail-receipt > span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 580;
}

.detail-receipt img {
  width: 100%;
  max-height: 310px;
  object-fit: contain;
  cursor: zoom-in;
  background: #edf2f5;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: #edf2f5;
  border-radius: 12px;
}

.segmented button {
  min-height: 38px;
  padding: 7px 14px;
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 650;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.segmented button.active {
  color: var(--brand);
  background: #fff;
  box-shadow: 0 2px 7px rgba(15, 35, 55, 0.09);
}

.tx-list {
  display: grid;
  gap: 8px;
  max-height: min(58vh, 520px);
  margin-top: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #bdc9d4 transparent;
}

.tx-item,
.tx-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px 14px;
  padding: 12px 13px;
  background: var(--surface-soft);
  border: 1px solid var(--line-soft);
  border-radius: 11px;
}

.tx-direction {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-soft);
  font-weight: 650;
}

.tx-row time,
.tx-route { color: var(--muted); font-size: 11px; }
.tx-row > strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.tx-row.is-in > strong { color: var(--success); }
.tx-row.is-out > strong { color: var(--danger); }

.tx-item .tx-amount,
.tx-row .tx-amount {
  color: var(--ink);
  font-weight: 720;
  font-variant-numeric: tabular-nums;
}

.tx-item .tx-meta,
.tx-row .tx-meta,
.tx-item small,
.tx-row small {
  color: var(--muted);
  font-size: 11px;
}

.lightbox-overlay {
  z-index: 300;
}

.lightbox-overlay img {
  width: auto;
  max-width: min(96vw, 1400px);
  max-height: 91vh;
  max-height: 91dvh;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
}

.lightbox-overlay > button {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  z-index: 1;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  color: #fff;
  background: rgba(9, 25, 38, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 11px;
  backdrop-filter: blur(8px);
}

/* Status feedback */
#toastRegion {
  position: fixed;
  z-index: 500;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  display: grid;
  gap: 8px;
  width: min(calc(100vw - 36px), 380px);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  color: #f7fbff;
  font-size: 13px;
  font-weight: 570;
  background: rgba(15, 40, 59, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 11px;
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(12px);
  animation: toast-in 0.3s var(--ease) both;
}

.toast.success {
  background: rgba(12, 103, 79, 0.96);
}

.toast.error {
  background: rgba(158, 44, 57, 0.96);
}

.loading,
.is-loading {
  cursor: progress !important;
}

.is-loading svg,
.spin {
  animation: spin 0.8s linear infinite;
}

/* Keep both desktop ledgers side by side, while giving each chart enough width. */
@media (max-width: 1180px) {
  .charts-row { grid-template-columns: minmax(0, 1fr); }
  .chart-box--expense { grid-column: 1; grid-row: 1; }
  .chart-legend--shared { grid-column: 1; grid-row: 2; }
  .chart-box--trend { grid-column: 1; grid-row: 3; }
  .balance-cards--four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .action-row {
    grid-template-columns: auto auto minmax(0, 1fr);
  }

  .action-row > .category-select-wrap {
    grid-column: 1 / 3;
    grid-row: 2;
    width: 160px;
    justify-self: start;
  }

  .action-row > .filter-summary {
    grid-column: 3;
    grid-row: 2;
  }

  .action-row--usdt {
    grid-template-columns: minmax(148px, 160px) minmax(0, 1fr);
  }

  .action-row--usdt > .category-select-wrap {
    grid-column: 1;
    grid-row: 1;
    width: auto;
  }

  .action-row--usdt > .filter-summary {
    grid-column: 2;
    grid-row: 1;
  }

  .action-row--usdt > .sync-status {
    grid-column: 1 / -1;
    grid-row: 2;
  }
  .balance-card strong {
    font-size: 20px;
  }

  .chart-wrap--doughnut {
    height: 220px;
  }

  .chart-wrap--bar {
    height: 244px;
  }
}

@media (max-width: 980px) {
  .main-container {
    grid-template-columns: minmax(0, 1fr);
    width: min(100%, 940px);
  }

  .charts-row { grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr); }
  .chart-box--expense { grid-column: 1; grid-row: 1; }
  .chart-box--trend { grid-column: 2; grid-row: 1; }
  .chart-legend--shared { grid-column: 1 / -1; grid-row: 2; }
  .chart-legend { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  :root {
    --topbar-height: auto;
  }

  .topbar {
    position: sticky;
    align-items: stretch;
    flex-direction: column;
    gap: 9px;
    padding: 12px 14px 10px;
    padding-right: max(14px, env(safe-area-inset-right));
    padding-left: max(14px, env(safe-area-inset-left));
  }

  .logo {
    align-self: flex-start;
    font-size: 17px;
  }

  .logo::before {
    height: 19px;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .current-user {
    position: absolute;
    top: 11px;
    right: max(14px, env(safe-area-inset-right));
    max-width: 43vw;
    min-height: 30px;
    margin: 0;
    padding: 4px 9px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar-btn {
    min-height: 39px;
    padding: 6px 8px;
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.08);
  }

  .main-container {
    gap: 14px;
    padding: 14px 12px max(28px, env(safe-area-inset-bottom));
  }

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

  .chart-box--expense { grid-column: 1; grid-row: 1; }
  .chart-legend--shared { grid-column: 1; grid-row: 2; }
  .chart-box--trend { grid-column: 1; grid-row: 3; }

  .chart-wrap--doughnut {
    height: clamp(210px, 52vw, 240px);
  }

  .chart-wrap--bar {
    height: clamp(228px, 56vw, 265px);
  }

  .chart-legend {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 680px), (max-width: 900px) and (max-height: 500px) {
  body {
    background: var(--page);
  }

  .main-container {
    padding-inline: 8px;
    padding-bottom: calc(92px + env(safe-area-inset-bottom));
  }

  .mobile-currency-tabs {
    position: fixed;
    z-index: 90;
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
    left: max(10px, env(safe-area-inset-left));
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px;
    padding: 6px;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(203, 213, 225, 0.88);
    border-radius: 17px;
    box-shadow: 0 14px 38px rgba(15, 23, 42, 0.18), 0 3px 9px rgba(15, 23, 42, 0.08);
    backdrop-filter: blur(18px);
  }

  .mobile-currency-tabs button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 47px;
    padding: 8px 12px;
    color: var(--muted-strong);
    font-size: 13px;
    font-weight: 720;
    background: transparent;
    border: 0;
    border-radius: 12px;
    transition: color .18s ease, background .18s ease, box-shadow .18s ease;
  }

  .mobile-currency-tabs button svg { width: 18px; height: 18px; }

  .mobile-currency-tabs button.active {
    color: #fff;
    background: linear-gradient(145deg, var(--brand), #087f75);
    box-shadow: 0 7px 16px rgba(8, 127, 117, 0.24), inset 0 1px rgba(255, 255, 255, 0.18);
  }

  .mobile-currency-tabs button:focus-visible {
    outline: 3px solid rgba(8, 127, 117, 0.22);
    outline-offset: 2px;
  }

  body.modal-open .mobile-currency-tabs { visibility: hidden; }

  .panel {
    border-radius: 16px;
  }

  .panel-header {
    min-height: 55px;
    padding: 14px 15px 11px;
  }

  .panel-header h2 {
    font-size: 17px;
  }

  .balance-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 11px 10px 0;
  }

  .balance-cards--three .balance-card:first-child {
    grid-column: 1 / -1;
  }

  .balance-card {
    min-height: 76px;
    padding: 11px 10px 10px 13px;
  }

  .balance-card span {
    margin-bottom: 6px;
    font-size: 11px;
  }

  .balance-card strong {
    font-size: clamp(17px, 5vw, 21px);
  }

  .charts-row {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 8px 10px 0;
  }

  .chart-box {
    padding: 12px 10px 10px;
  }

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

  .action-row,
  .action-row--usdt {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 11px 10px;
  }

  .action-row .category-select-wrap,
  .action-row--usdt .category-select-wrap {
    grid-column: 1 / -1;
    grid-row: 1;
    width: 100%;
    justify-self: stretch;
  }

  .action-row .filter-summary,
  .action-row--usdt .filter-summary,
  .action-row--usdt .sync-status {
    grid-column: 1 / -1;
  }

  .action-row .filter-summary { grid-row: 3; }
  .action-row--usdt .filter-summary { grid-row: 2; }
  .action-row--usdt .sync-status { grid-row: 3; }

  .btn,
  .category-select-trigger {
    min-height: 45px;
  }

  .category-select-menu {
    width: 100%;
    max-height: min(330px, 52vh);
  }

  .filter-summary {
    min-height: 45px;
    margin: 0;
  }

  /* Mobile records are true cards; no horizontal scroll is required. */
  .table-wrap {
    margin: 0 10px;
    overflow: visible;
    background: transparent;
    border: 0;
    border-radius: 0;
  }

  .records-table,
  .records-table tbody {
    display: block;
    width: 100%;
  }

  .records-table thead {
    display: none;
  }

  .records-table tbody {
    display: grid;
    gap: 10px;
  }

  .records-table tbody tr {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px 11px;
    width: 100%;
    padding: 14px 14px 13px 18px;
    overflow: hidden;
    background: linear-gradient(135deg, #ffffff 0%, #f7fafb 68%, color-mix(in srgb, var(--category-color, #ffffff) 8%, #ffffff) 100%);
    border: 1px solid color-mix(in srgb, var(--category-color, #cbd5df) 24%, #cbd5df);
    border-radius: 17px;
    box-shadow: 0 10px 25px rgba(15, 31, 45, .08), 0 2px 5px rgba(15, 31, 45, .045), inset 0 1px rgba(255, 255, 255, .9);
    transition: transform .18s var(--ease), border-color .18s ease, box-shadow .18s ease, background .18s ease;
  }

  .records-table tbody tr::before {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 5px;
    content: "";
    background: linear-gradient(180deg, var(--category-color, var(--primary)), color-mix(in srgb, var(--category-color, var(--primary)) 62%, #102a43));
  }

  .records-table tbody tr:hover {
    background: linear-gradient(135deg, #ffffff, color-mix(in srgb, var(--category-color, var(--primary)) 9%, white));
    border-color: color-mix(in srgb, var(--category-color, var(--primary)) 40%, #bcc9d3);
    box-shadow: 0 13px 30px rgba(15, 31, 45, .11), 0 3px 7px rgba(15, 31, 45, .05);
    transform: translateY(-1px);
  }

  .records-table tbody tr:focus-visible {
    border-color: var(--primary);
    outline: 3px solid rgba(8, 127, 117, .16);
    outline-offset: 2px;
  }

  .records-table td,
  .records-table th:nth-child(n),
  .records-table td:nth-child(n) {
    display: flex;
    align-items: center;
    width: auto;
    min-width: 0;
    height: auto;
    min-height: 22px;
    padding: 0;
    overflow: visible;
    text-align: left;
    text-overflow: clip;
    white-space: normal;
    border: 0;
  }

  .records-table td::before {
    display: none;
    margin-right: 7px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 560;
    content: attr(data-label);
  }

  .records-table td:nth-child(1),
  .records-table .cell-date,
  .records-table .record-date {
    grid-column: 1;
    grid-row: 1;
    justify-self: start;
    min-height: 25px;
    padding: 3px 8px;
    color: #40566a;
    font-size: 11px;
    font-weight: 680;
    font-variant-numeric: tabular-nums;
    background: #e9eef2;
    border: 1px solid #d3dce3;
    border-radius: 999px;
  }

  .records-table td:nth-child(2),
  .records-table .cell-category,
  .records-table .record-category {
    grid-column: 1;
    grid-row: 2;
    align-self: start;
  }

  .records-table td:nth-child(3),
  .records-table .cell-amount,
  .records-table .record-amount {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: center;
    justify-content: flex-end;
    font-size: 17px;
    text-align: right;
  }

  .records-table td:nth-child(4),
  .records-table .cell-note,
  .records-table .record-note {
    grid-column: 1 / -1;
    grid-row: 3;
    min-height: 38px;
    margin-top: 5px;
    padding: 8px 10px;
    overflow-wrap: anywhere;
    color: var(--ink-soft);
    background: color-mix(in srgb, var(--category-color, #edf2f5) 4%, #edf2f5);
    border: 1px solid color-mix(in srgb, var(--category-color, #d5dee5) 12%, #d5dee5);
    border-radius: 10px;
  }

  .records-table td:nth-child(4)::before,
  .records-table .cell-note::before {
    display: inline;
    content: attr(data-label);
  }

  .records-table td:nth-child(5),
  .records-table .cell-receipt,
  .records-table .record-receipt {
    grid-column: 1;
    grid-row: 4;
    gap: 7px;
    min-height: 42px;
  }

  .records-table td:nth-child(5)::before,
  .records-table .cell-receipt::before {
    display: inline;
  }

  .records-table td:nth-child(6),
  .records-table .cell-operator,
  .records-table .record-operator {
    grid-column: 2;
    grid-row: 4;
    align-self: center;
    justify-content: flex-end;
    color: #6b7e8d;
    font-size: 11px;
  }

  .records-table td:nth-child(6)::before,
  .records-table .cell-operator::before {
    display: inline;
  }

  .receipt-button {
    min-width: 38px;
    min-height: 38px;
  }

  .receipt-button {
    width: 50px;
    min-width: 50px;
    height: 40px;
    min-height: 40px;
    padding: 2px;
    overflow: hidden;
    border-radius: 10px;
  }

  .receipt-thumb {
    width: 44px;
    height: 34px;
    max-width: 44px;
    max-height: 34px;
    object-fit: cover;
    border: 0;
    border-radius: 7px;
  }

  .empty-row,
  .records-empty {
    display: grid !important;
    place-items: center;
    min-height: 184px;
    padding: 0 !important;
    background: linear-gradient(145deg, #fff, #f6fafb) !important;
    border-color: #d5dfe6 !important;
  }

  .empty-row::before,
  .records-empty::before { display: none !important; }

  .empty-row td,
  .records-empty td {
    display: grid !important;
    grid-column: 1 / -1 !important;
    place-items: center;
    width: 100% !important;
    min-height: 182px !important;
    padding: 22px 14px !important;
    text-align: center !important;
  }

  .empty-row .empty-state,
  .records-empty .empty-state {
    place-content: center;
    justify-items: center;
    width: 100%;
    min-height: 136px;
    padding: 0;
  }

  .pagination {
    padding: 12px 10px 14px;
  }

  .pagination .month-button { min-width: 174px; }
  .calendar-popover { width: min(286px, calc(100vw - 36px)); }

  .modal-overlay {
    align-items: end;
    padding: 0;
  }

  .modal,
  .detail-panel {
    width: 100%;
    max-height: calc(94dvh - env(safe-area-inset-top));
    padding: 23px 18px max(19px, env(safe-area-inset-bottom));
    border: 0;
    border-radius: 20px 20px 0 0;
    transform: translateY(42px);
  }

  .detail-overlay {
    align-items: end;
  }

  .detail-panel {
    height: auto;
    max-height: calc(94dvh - env(safe-area-inset-top));
    border-radius: 20px 20px 0 0;
    transform: translateY(42px);
  }

  [aria-hidden="false"] > .detail-panel,
  .open > .detail-panel,
  .show > .detail-panel {
    transform: translateY(0);
  }

  .modal::before,
  .detail-panel::before {
    position: absolute;
    top: 8px;
    left: 50%;
    width: 38px;
    height: 4px;
    content: "";
    background: #d4dce3;
    border-radius: 999px;
    transform: translateX(-50%);
  }

  .modal h3,
  .detail-panel h3 {
    margin-top: 6px;
    font-size: 19px;
  }

  .icon-close {
    top: 15px;
    right: 14px;
  }

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

  .modal-actions,
  .detail-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .modal-actions .btn,
  .detail-actions .btn {
    min-width: 0;
  }

  #toastRegion {
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
    width: calc(100vw - 24px);
  }
}

@media (max-width: 430px) {
  .login-card {
    padding: 31px 20px 27px;
    border-radius: 22px;
  }

  .brand-mark {
    width: 56px;
    height: 56px;
    margin-bottom: 17px;
    border-radius: 17px;
  }

  .topbar-btn {
    gap: 5px;
    font-size: 12px;
  }

  .topbar-btn svg {
    width: 17px;
    height: 17px;
    flex-basis: 17px;
  }

  .balance-card strong {
    font-size: clamp(16px, 5vw, 20px);
  }

  .chart-wrap--doughnut {
    height: clamp(202px, 58vw, 232px);
  }

  .chart-wrap--bar {
    height: clamp(220px, 65vw, 250px);
  }

  .chart-legend {
    gap: 6px 8px;
  }

  .legend-item,
  .chart-legend > button,
  .chart-legend > div {
    font-size: 10px;
  }

  .detail-grid {
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .detail-grid > div {
    display: grid;
    grid-template-columns: 75px minmax(0, 1fr);
    gap: 8px;
    padding: 9px 11px;
  }

  .detail-grid dt {
    margin: 0;
  }
}

@media (max-width: 350px) {
  .chart-legend { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.985);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media print {
  .topbar-actions,
  .action-row,
  .pagination {
    display: none !important;
  }

  body {
    background: #fff;
  }

  .topbar {
    position: static;
    color: var(--ink);
    background: #fff;
    box-shadow: none;
  }

  .main-container {
    display: block;
    padding: 0;
  }

  .panel {
    margin-bottom: 20px;
    break-inside: avoid;
    box-shadow: none;
  }
}
