:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --panel: #ffffff;
  --sidebar: #101c36;
  --sidebar-soft: #192846;
  --line: #e7ebf2;
  --line-strong: #d9dfeb;
  --text: #172033;
  --muted: #78849a;
  --primary: #316cf4;
  --primary-dark: #2459d1;
  --primary-soft: #edf3ff;
  --green: #169b6b;
  --green-soft: #e9f8f2;
  --amber: #d98215;
  --amber-soft: #fff5e8;
  --red: #cc4958;
  --red-soft: #fff0f1;
  --shadow: 0 12px 30px rgba(27, 43, 75, 0.07);
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(circle at 88% 0%, rgba(49, 108, 244, 0.06), transparent 26rem),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(49, 108, 244, 0.22);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 24px 18px 18px;
  color: #fff;
  background:
    linear-gradient(155deg, rgba(62, 111, 226, 0.18), transparent 38%),
    var(--sidebar);
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 6px 30px;
}

.brand-mark,
.welcome-icon {
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  background: linear-gradient(145deg, #5e8bff, #2860e7);
  box-shadow: 0 10px 24px rgba(36, 89, 209, 0.3);
}

.brand-mark {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 13px;
  font-size: 19px;
}

.brand-title {
  font-size: 18px;
  font-weight: 750;
  letter-spacing: 0.02em;
}

.brand-subtitle {
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.48);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.sidebar-close {
  display: none;
  margin-left: auto;
  color: rgba(255, 255, 255, 0.72);
}

.sidebar-section {
  min-height: 0;
  display: flex;
  flex: 1;
  flex-direction: column;
}

.sidebar-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 8px 10px;
}

.sidebar-label {
  color: rgba(255, 255, 255, 0.55);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.08em;
}

.sidebar-count {
  min-width: 24px;
  padding: 2px 7px;
  border-radius: 99px;
  color: rgba(255, 255, 255, 0.74);
  background: rgba(255, 255, 255, 0.09);
  font-size: 11px;
  text-align: center;
}

.group-list {
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 7px;
  padding-right: 2px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.group-item {
  width: 100%;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 12px;
  color: rgba(255, 255, 255, 0.76);
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.group-item:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.07);
}

.group-item.is-active {
  color: #fff;
  border-color: rgba(111, 152, 255, 0.25);
  background: linear-gradient(110deg, rgba(65, 115, 235, 0.32), rgba(255, 255, 255, 0.06));
}

.group-avatar {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: #bdd0ff;
  background: rgba(100, 143, 244, 0.16);
  font-size: 13px;
  font-weight: 750;
}

.group-name,
.group-meta-mini {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.group-name {
  font-size: 13px;
  font-weight: 650;
}

.group-meta-mini {
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.42);
  font-size: 11px;
}

.group-empty {
  margin: 16px 8px;
  color: rgba(255, 255, 255, 0.46);
  font-size: 13px;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 18px 7px 0;
  padding-top: 15px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.46);
  font-size: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #45d69d;
  box-shadow: 0 0 0 4px rgba(69, 214, 157, 0.1);
}

.content {
  min-width: 0;
  padding: 30px clamp(20px, 3vw, 44px) 60px;
}

.mobile-topbar,
.sidebar-backdrop {
  display: none;
}

.page.hidden,
.hidden {
  display: none !important;
}

.transactions-page {
  width: min(100%, 1440px);
  margin: 0 auto;
}

.page-hero {
  min-height: 76px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.13em;
}

.page-title {
  margin: 0;
  font-size: clamp(25px, 2.2vw, 34px);
  line-height: 1.2;
  letter-spacing: -0.03em;
}

.page-subtitle,
.section-subtitle,
.muted,
.dt2,
.empty-cell {
  color: var(--muted);
}

.page-subtitle {
  margin-top: 7px;
  font-size: 13px;
}

.group-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.tag,
.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 650;
}

.tag {
  min-height: 30px;
  padding: 0 12px;
  color: #536179;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
}

.tag.is-on {
  color: var(--green);
  border-color: #c8eddf;
  background: var(--green-soft);
}

.tag.is-off {
  color: var(--red);
  border-color: #f4d7db;
  background: var(--red-soft);
}

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

.kpi-card {
  position: relative;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 19px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.kpi-card::after {
  content: "";
  position: absolute;
  right: -32px;
  bottom: -45px;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  opacity: 0.12;
}

.kpi-income::after { background: var(--green); }
.kpi-due::after { background: var(--primary); }
.kpi-paid::after { background: var(--amber); }
.kpi-pending::after { background: var(--red); }

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

.kpi-value {
  margin: 6px 0 2px;
  overflow: hidden;
  font-size: clamp(23px, 2.2vw, 31px);
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: -0.04em;
}

.kpi-income .kpi-value { color: var(--green); }
.kpi-due .kpi-value { color: var(--primary); }
.kpi-paid .kpi-value { color: var(--amber); }
.kpi-pending .kpi-value { color: var(--red); }

.kpi-meta {
  color: #98a2b4;
  font-size: 11px;
}

.surface {
  margin-bottom: 16px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.section-head,
.card-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.section-head {
  margin-bottom: 16px;
}

.section-title,
.card-title {
  font-size: 16px;
  font-weight: 750;
}

.section-subtitle {
  margin-top: 3px;
  font-size: 12px;
}

.filter-layout {
  display: grid;
  grid-template-columns: minmax(250px, 0.75fr) 1px minmax(560px, 1.7fr);
  gap: 18px;
  align-items: end;
}

.quick-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 76px;
  gap: 8px;
  align-items: end;
}

.filter-divider {
  align-self: stretch;
  background: var(--line);
}

.toolbar-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

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

.field-label {
  color: #58667d;
  font-size: 12px;
  font-weight: 650;
}

.field-select,
.field-input,
.primary-btn,
.ghost-btn {
  min-height: 40px;
  border-radius: 10px;
  transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.field-select,
.field-input {
  width: 100%;
  min-width: 0;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  color: var(--text);
  background: #fff;
}

.field-select:hover,
.field-input:hover {
  border-color: #b8c4d8;
}

.field-select:focus,
.field-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(49, 108, 244, 0.1);
}

.primary-btn,
.ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 15px;
  border: 1px solid transparent;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
}

.primary-btn {
  color: #fff;
  border-color: var(--primary);
  background: var(--primary);
  box-shadow: 0 6px 16px rgba(49, 108, 244, 0.18);
}

.primary-btn:hover {
  border-color: var(--primary-dark);
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.ghost-btn {
  color: #516077;
  border-color: var(--line-strong);
  background: #fff;
}

.ghost-btn:hover {
  color: var(--primary);
  border-color: #b8cbfc;
  background: var(--primary-soft);
}

button:disabled,
input:disabled,
select:disabled {
  opacity: 0.58;
  cursor: not-allowed;
  transform: none !important;
}

.action-row {
  display: flex;
  gap: 8px;
}

.table-card {
  padding: 0;
  overflow: hidden;
}

.card-title-row {
  align-items: center;
  padding: 18px 20px 15px;
  border-bottom: 1px solid var(--line);
}

.card-title {
  display: flex;
  align-items: center;
  gap: 9px;
}

.title-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.income-dot { background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }
.paid-dot { background: var(--amber); box-shadow: 0 0 0 4px var(--amber-soft); }

.count-badge {
  min-height: 27px;
  padding: 0 10px;
  color: var(--primary);
  background: var(--primary-soft);
}

.table-wrapper {
  width: 100%;
  overflow-x: auto;
}

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

.compact-table {
  min-width: 650px;
}

.data-table th,
.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

.data-table th {
  color: #6d798d;
  background: #f8fafe;
  font-size: 12px;
  font-weight: 700;
}

.data-table td {
  font-size: 13px;
}

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

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

.data-table th:last-child,
.data-table td:last-child {
  min-width: 150px;
  white-space: normal;
}

.cell-num {
  font-variant-numeric: tabular-nums;
}

.amount,
.dt1,
.summary-strong {
  font-weight: 700;
}

.dt2 {
  margin-top: 1px;
  font-size: 11px;
}

.text-primary {
  color: var(--primary);
  font-weight: 700;
}

.text-warning {
  color: var(--amber);
  font-weight: 700;
}

.code-text {
  padding: 3px 7px;
  border-radius: 6px;
  color: #56647a;
  background: #f1f4f9;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 11px;
}

.empty-cell {
  padding: 34px !important;
  text-align: center !important;
}

.collapse-item {
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.collapse-item:last-child {
  margin-bottom: 0;
}

.collapse-item summary {
  position: relative;
  padding: 13px 42px 13px 14px;
  list-style: none;
  font-weight: 700;
  background: #fafcff;
  cursor: pointer;
}

.collapse-item summary::-webkit-details-marker {
  display: none;
}

.collapse-item summary::after {
  content: "›";
  position: absolute;
  top: 50%;
  right: 17px;
  color: var(--muted);
  font-size: 21px;
  line-height: 1;
  transform: translateY(-50%);
  transition: transform 0.18s ease;
}

.collapse-item[open] summary {
  border-bottom: 1px solid var(--line);
}

.collapse-item[open] summary::after {
  transform: translateY(-50%) rotate(90deg);
}

.welcome-card {
  width: min(100%, 660px);
  margin: max(8vh, 45px) auto 0;
  padding: clamp(32px, 6vw, 64px);
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
  text-align: center;
}

.welcome-icon {
  width: 70px;
  height: 70px;
  margin: 0 auto 24px;
  border-radius: 20px;
  font-size: 28px;
}

.welcome-card h1 {
  margin: 0;
  font-size: clamp(27px, 4vw, 40px);
  letter-spacing: -0.04em;
}

.welcome-card > p:not(.eyebrow) {
  max-width: 470px;
  margin: 14px auto 0;
  color: var(--muted);
}

.home-menu-btn {
  display: none;
  margin: 24px auto 0;
}

.error-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
  padding: 15px 17px;
  border: 1px solid #f0cdd2;
  border-radius: 13px;
  color: #9b2e3b;
  background: var(--red-soft);
}

.error-panel p {
  margin: 2px 0 0;
  color: #b85a66;
  font-size: 12px;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 13px;
  color: #536179;
  background: rgba(244, 247, 251, 0.72);
  backdrop-filter: blur(3px);
}

.loader {
  width: 34px;
  height: 34px;
  border: 3px solid #dce5f6;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.toast {
  position: fixed;
  z-index: 120;
  right: 24px;
  bottom: 24px;
  max-width: min(390px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: 11px;
  color: #fff;
  background: #1b2941;
  box-shadow: 0 14px 34px rgba(16, 28, 54, 0.22);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.is-error {
  background: #a63846;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
}

body.isolated .app-shell {
  grid-template-columns: minmax(0, 1fr);
}

body.isolated .sidebar,
body.isolated .mobile-topbar,
body.isolated .sidebar-backdrop {
  display: none !important;
}

body.isolated .content {
  padding-left: clamp(20px, 4vw, 60px);
}

@media (max-width: 1180px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filter-layout {
    grid-template-columns: 1fr;
  }

  .filter-divider {
    display: none;
  }
}

@media (max-width: 820px) {
  body.sidebar-open {
    overflow: hidden;
  }

  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    left: 0;
    width: min(84vw, 300px);
    transform: translateX(-102%);
    transition: transform 0.22s ease;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-close {
    display: inline-grid;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 25;
    width: 100%;
    height: 100%;
    border: 0;
    background: rgba(8, 16, 31, 0.5);
  }

  body.sidebar-open .sidebar-backdrop {
    display: block;
  }

  .content {
    padding: 18px 15px 42px;
  }

  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 11px;
    margin-bottom: 23px;
  }

  .mobile-topbar > div {
    min-width: 0;
    display: flex;
    flex-direction: column;
  }

  .mobile-topbar strong {
    font-size: 15px;
  }

  .mobile-topbar span {
    overflow: hidden;
    color: var(--muted);
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .menu-btn {
    color: var(--text);
    border: 1px solid var(--line);
    background: #fff;
  }

  .home-menu-btn {
    display: inline-flex;
  }

  .page-hero {
    min-height: 0;
    flex-direction: column;
    margin-bottom: 18px;
  }

  .group-tags {
    justify-content: flex-start;
  }

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

  .action-row {
    grid-column: 1 / -1;
  }

  .action-row > button {
    flex: 1 1 auto;
  }
}

@media (max-width: 620px) {
  .content {
    padding-inline: 12px;
  }

  .kpi-grid {
    gap: 9px;
  }

  .kpi-card {
    padding: 15px;
    border-radius: 13px;
  }

  .kpi-value {
    font-size: 22px;
  }

  .surface {
    padding: 16px;
    border-radius: 14px;
  }

  .quick-row,
  .toolbar-grid {
    grid-template-columns: 1fr;
  }

  .action-row {
    grid-column: auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .action-row #search-btn {
    grid-column: 1 / -1;
  }

  .table-card {
    padding: 0;
  }

  .card-title-row {
    padding: 16px;
  }

  .transaction-table {
    min-width: 0;
  }

  .transaction-table thead {
    display: none;
  }

  .transaction-table tbody,
  .transaction-table tr,
  .transaction-table td {
    display: block;
    width: 100%;
  }

  .transaction-table tbody {
    padding: 0 14px;
  }

  .transaction-table tr {
    padding: 11px 0;
    border-bottom: 1px solid var(--line);
  }

  .transaction-table tr:last-child {
    border-bottom: 0;
  }

  .transaction-table td {
    min-width: 0 !important;
    display: grid;
    grid-template-columns: 74px minmax(0, 1fr);
    gap: 10px;
    padding: 5px 2px;
    border: 0;
    text-align: right;
    white-space: normal;
  }

  .transaction-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    text-align: left;
  }

  .transaction-table .empty-cell {
    display: block;
  }

  .transaction-table .empty-cell::before {
    display: none;
  }

  .dt2 {
    display: inline;
    margin-left: 4px;
  }

  .error-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .toast {
    right: 16px;
    bottom: 16px;
  }
}

@media (max-width: 400px) {
  .kpi-grid {
    grid-template-columns: 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;
  }
}
