:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e6e8ec;
  --border-strong: #d7dae0;
  --text: #101828;
  --muted: #667085;
  --muted-2: #98a2b3;
  --primary: #0f766e;
  --primary-strong: #115e59;
  --primary-soft: #e7f3f1;
  --green: #059669;
  --green-soft: #e8f6f0;
  --red: #dc2626;
  --red-soft: #fdeaea;
  --amber: #b45309;
  --amber-soft: #fdf3e3;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 20px 48px rgba(16, 24, 40, 0.18);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button {
  font-family: inherit;
}

.app {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 224px;
  flex: 0 0 auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 8px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 17px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-text strong {
  font-size: 15px;
  font-weight: 700;
}

.brand-text span {
  font-size: 12px;
  color: var(--muted-2);
  margin-top: 2px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-item svg {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
}

.nav-item:hover {
  background: #f2f4f7;
  color: var(--text);
}

.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.sidebar-foot {
  margin-top: auto;
}

/* Main */
.main {
  flex: 1;
  min-width: 0;
  padding: 28px 32px 48px;
}

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

.page-header h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.page-header p {
  margin: 6px 0 0;
}

#headerActions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

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

.content {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease,
    box-shadow 0.15s ease;
}

.btn svg {
  width: 16px;
  height: 16px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-strong);
}

.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-ghost:hover {
  background: #f2f4f7;
}

.btn-block {
  width: 100%;
}

.btn-icon {
  padding: 7px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  border-color: transparent;
}

.btn-icon:hover {
  background: #f2f4f7;
  color: var(--text);
}

.btn-danger {
  color: var(--red);
}

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

.btn-sm {
  padding: 6px 10px;
  font-size: 13px;
}

/* Stat cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.stat-label {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 8px;
}

.stat-value {
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.stat-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 7px;
}

.stat-meta.positive {
  color: var(--green);
  font-weight: 600;
}

.stat-meta.negative {
  color: var(--red);
  font-weight: 600;
}

/* Cards & charts */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 16px;
}

.card-title .hint {
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.chart-wrap {
  position: relative;
  height: 280px;
}

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

.donut-layout {
  display: flex;
  align-items: center;
  gap: 20px;
}

.donut-canvas {
  width: 190px;
  height: 190px;
  flex: 0 0 auto;
}

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.legend .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.legend .legend-name {
  color: var(--text);
}

.legend .legend-amount {
  margin-left: auto;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Filter chips */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.chip:hover {
  color: var(--text);
  border-color: var(--muted-2);
}

.chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Lists & rows */
.list {
  margin: 0;
}

.group {
  margin-bottom: 8px;
}

.group-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 4px;
}

.group-head strong {
  font-size: 14px;
}

.group-head .subtotal {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 120px 120px 120px 120px 110px;
  align-items: center;
  gap: 12px;
  padding: 13px 4px;
  border-top: 1px solid var(--border);
}

.row-5 {
  grid-template-columns: minmax(170px, 1fr) 120px 120px 120px 90px;
}

.row-head {
  border-top: 0;
  padding: 8px 4px 10px;
  font-size: 12px;
  color: var(--muted-2);
  font-weight: 500;
}

.row .cell-main {
  min-width: 0;
}

.row .cell-main strong {
  display: block;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row .cell-main span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.num.positive {
  color: var(--green);
  font-weight: 600;
}

.num.negative {
  color: var(--red);
  font-weight: 600;
}

.stat-value.positive {
  color: var(--green);
}

.stat-value.negative {
  color: var(--red);
}

.positive-text {
  color: var(--green);
}

.negative-text {
  color: var(--red);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}

.cell-actions {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
}

/* Empty state */
.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 20px;
}

.empty p {
  margin: 0 0 16px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
  animation: fade 0.15s ease;
}

.modal {
  background: var(--surface);
  border-radius: 16px;
  width: min(500px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  box-shadow: var(--shadow-lg);
  animation: pop 0.16s ease;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 0;
}

.modal-head h3 {
  margin: 0;
  font-size: 17px;
}

.modal-body {
  padding: 18px 22px 22px;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0 22px 22px;
}

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes pop {
  from { opacity: 0; transform: translateY(6px) scale(0.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Form */
.field {
  margin-bottom: 15px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 7px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.field textarea {
  resize: vertical;
  min-height: 76px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #101828;
  color: #fff;
  padding: 11px 16px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  animation: pop 0.18s ease;
}

.toast.error {
  background: var(--red);
}

/* Responsive */
@media (max-width: 1000px) {
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 860px) {
  .app {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .brand-text span {
    display: none;
  }

  .nav {
    flex-direction: row;
    flex: 1;
    overflow-x: auto;
  }

  .nav-item {
    width: auto;
    padding: 8px 11px;
  }

  .nav-item span {
    display: none;
  }

  .sidebar-foot {
    display: none;
  }

  .main {
    padding: 20px 16px 40px;
  }

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

  .card.list {
    overflow-x: auto;
  }

  .row {
    min-width: 840px;
  }

  .row-5 {
    min-width: 680px;
  }

  .donut-layout {
    flex-direction: column;
    align-items: stretch;
  }

  .donut-canvas {
    align-self: center;
  }
}

.hidden {
  display: none !important;
}

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.auth-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px;
  box-shadow: var(--shadow-lg);
}

.auth-brand {
  justify-content: center;
  margin-bottom: 22px;
  padding: 0;
}

.auth-title {
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 4px;
}

.auth-sub {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 20px;
}

.auth-error {
  color: var(--red);
  font-size: 13px;
  margin: 0 0 12px;
}

.sidebar-foot {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
