:root {
  --bg: #f4f7f6;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #6b7280;
  --line: #d9e1df;
  --primary: #0f8b6f;
  --primary-dark: #0b6f59;
  --danger: #d84c4c;
  --warning: #d97706;
  --shadow: 0 10px 30px rgba(20, 35, 45, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  background: #12312b;
  color: #fff;
  padding: 24px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 32px;
  min-width: 0;
}

.brand > div:last-child {
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  place-items: center;
  border-radius: 8px;
  background: #f59e0b;
  color: #1f2933;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
  word-break: keep-all;
}

.brand p {
  margin: 4px 0 0;
  color: rgba(255, 255, 255, 0.7);
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  border: 0;
  border-radius: 6px;
  padding: 12px 14px;
  background: transparent;
  color: rgba(255, 255, 255, 0.82);
  line-height: 1.25;
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.content {
  padding: 28px;
  overflow: auto;
}

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

.data-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.parser-panel {
  display: grid;
  grid-template-columns: minmax(180px, 260px) minmax(0, 1fr) auto;
  gap: 14px;
  align-items: end;
  margin-bottom: 18px;
}

.parser-panel h3 {
  margin-bottom: 6px;
}

.parser-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.parser-panel textarea {
  min-height: 118px;
}

.parser-actions {
  display: grid;
  gap: 10px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
}

h2,
h3 {
  margin: 0;
}

h2 {
  font-size: 28px;
}

h3 {
  margin-bottom: 18px;
  font-size: 18px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.grid {
  display: grid;
  gap: 18px;
}

.two-columns {
  grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
  align-items: start;
}

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

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 20px;
}

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

.panel-header h3 {
  margin-bottom: 0;
}

form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 8px;
  color: #344054;
  font-size: 14px;
  font-weight: 600;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  min-height: 42px;
  padding: 9px 11px;
  outline: none;
}

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

textarea {
  min-height: 96px;
  resize: vertical;
}

.primary-button,
.secondary-button,
.danger-button {
  border: 0;
  border-radius: 6px;
  min-height: 40px;
  padding: 9px 14px;
  font-weight: 700;
}

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

.primary-button:hover {
  background: var(--primary-dark);
}

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

.danger-button {
  background: #fff0f0;
  color: var(--danger);
}

.amount-line {
  border-radius: 6px;
  background: #fff7ed;
  color: var(--warning);
  padding: 12px;
  font-size: 16px;
}

.record-list,
.stat-list {
  display: grid;
  gap: 10px;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.record-card,
.stat-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfdfc;
}

.record-card {
  display: grid;
  gap: 6px;
}

.record-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.record-title {
  font-weight: 800;
}

.record-meta,
.record-line {
  color: var(--muted);
  font-size: 14px;
}

.record-money {
  color: var(--danger);
  font-weight: 800;
}

.record-actions {
  display: flex;
  gap: 12px;
  flex-shrink: 0;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--danger);
  padding: 0;
  font-weight: 700;
}

.text-button.edit {
  color: var(--primary);
}

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

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

.summary-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 18px;
  box-shadow: var(--shadow);
  animation: rise-in 0.42s ease both;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.summary-card:hover,
.chart-panel:hover,
.stat-card:hover {
  transform: translateY(-2px);
  border-color: rgba(15, 139, 111, 0.28);
  box-shadow: 0 16px 36px rgba(20, 35, 45, 0.12);
}

.summary-card span {
  display: block;
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 8px;
}

.summary-card strong {
  font-size: 24px;
}

.summary-card.total {
  border-color: rgba(15, 139, 111, 0.35);
  background: linear-gradient(135deg, #eef9f5, #fff7ed);
}

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

.chart-panel {
  min-height: 340px;
  position: relative;
  overflow: hidden;
  animation: rise-in 0.46s ease both;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.chart-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(15, 139, 111, 0.08), transparent 42%);
  pointer-events: none;
}

.chart-panel canvas {
  position: relative;
  display: block;
  width: 100%;
  height: 260px;
  opacity: 1;
  transform: translateY(0);
}

.chart-panel canvas.refreshing {
  animation: chart-refresh 0.45s ease both;
}

.stat-card strong {
  display: block;
  margin-bottom: 8px;
}

.stat-card {
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.8;
}

.stat-row.total {
  color: var(--text);
  font-weight: 800;
}

.report {
  min-height: 220px;
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  border: 1px solid rgba(15, 139, 111, 0.18);
  border-radius: 8px;
  background: linear-gradient(180deg, #fbfdfc, #ffffff);
  color: #243447;
  font-family: "SFMono-Regular", Consolas, monospace;
  line-height: 1.7;
  padding: 18px;
  box-shadow: inset 4px 0 0 rgba(15, 139, 111, 0.35);
  animation: report-in 0.38s ease both;
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes chart-refresh {
  from {
    opacity: 0.3;
    transform: scale(0.98) translateY(6px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes report-in {
  from {
    opacity: 0.45;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.42);
}

.modal[hidden] {
  display: none;
}

.modal-panel {
  width: min(560px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
  padding: 20px;
}

.edit-fields {
  display: grid;
  gap: 14px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  border-radius: 8px;
  background: rgba(17, 24, 39, 0.92);
  color: #fff;
  padding: 10px 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    overflow-x: hidden;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 16px;
    width: 100%;
    max-width: 100vw;
    overflow: hidden;
  }

  .brand {
    align-items: center;
    gap: 14px;
    margin-bottom: 14px;
  }

  .brand h1 {
    font-size: 22px;
  }

  .brand p {
    font-size: 14px;
  }

  .nav {
    display: flex;
    gap: 8px;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 2px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .nav::-webkit-scrollbar {
    display: none;
  }

  .nav-item {
    flex: 0 0 auto;
    width: auto;
    max-width: none;
    padding: 10px 12px;
    text-align: center;
    white-space: nowrap;
  }

  .two-columns,
  .three-columns,
  .chart-grid,
  .filters,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .content {
    padding: 18px;
    overflow-x: hidden;
  }

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

  .data-actions {
    width: 100%;
    justify-content: stretch;
  }

  .data-actions button {
    flex: 1;
  }

  .parser-panel {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .parser-actions {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 430px) {
  .sidebar {
    padding: 18px 14px 14px;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
  }

  .brand h1 {
    font-size: 20px;
  }

  .brand p {
    font-size: 13px;
  }

  .nav-item {
    font-size: 15px;
  }
}
