:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #0f766e;
  --primary-soft: #ccfbf1;
  --accent: #fbbf24;
  --danger: #dc2626;
  --income: #16a34a;
  --shadow: 0 12px 30px rgba(17, 24, 39, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  margin: 0;
}

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

button {
  border: 0;
}

.app-shell {
  margin: 0 auto;
  max-width: 720px;
  min-height: 100vh;
  padding-bottom: calc(78px + env(safe-area-inset-bottom));
}

.topbar {
  align-items: center;
  display: flex;
  justify-content: space-between;
  padding: calc(18px + env(safe-area-inset-top)) 18px 12px;
}

.brand {
  align-items: center;
  display: flex;
  gap: 12px;
}

.brand img {
  border-radius: 16px;
  box-shadow: var(--shadow);
  height: 52px;
  width: 52px;
}

.brand h1 {
  font-size: 22px;
  line-height: 1.1;
  margin: 0;
}

.brand p,
.eyebrow,
.hint,
.muted {
  color: var(--muted);
}

.brand p {
  margin: 4px 0 0;
}

.view {
  padding: 8px 18px 24px;
}

.card {
  background: var(--card);
  border: 1px solid rgba(229, 231, 235, 0.82);
  border-radius: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  padding: 18px;
}

.summary-card {
  background: linear-gradient(135deg, #ffffff 0%, #ecfeff 100%);
}

.balance {
  font-size: 40px;
  font-weight: 800;
  margin: 8px 0 18px;
}

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

.summary-grid.three {
  grid-template-columns: 1fr 1fr 1fr;
}

.summary-grid div {
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

.summary-grid span {
  color: var(--muted);
  display: block;
  font-size: 13px;
  margin-bottom: 4px;
}

.summary-grid strong {
  font-size: 18px;
}

h2 {
  font-size: 18px;
  margin: 22px 0 12px;
}

.primary,
.secondary,
.icon-button,
.chip {
  border-radius: 12px;
  cursor: pointer;
  min-height: 44px;
  padding: 0 16px;
}

.primary {
  background: var(--primary);
  color: #ffffff;
  font-weight: 700;
}

.secondary,
.icon-button {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
}

.full {
  display: block;
  margin-bottom: 12px;
  width: 100%;
}

.tabbar {
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  left: 50%;
  max-width: 720px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  position: fixed;
  transform: translateX(-50%);
  width: 100%;
  z-index: 10;
}

.tabbar button {
  background: transparent;
  border-radius: 10px;
  color: var(--muted);
  min-height: 48px;
}

.tabbar button.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 800;
}

label {
  color: #374151;
  display: block;
  font-weight: 700;
  margin-bottom: 14px;
}

input,
select,
textarea {
  background: #f9fafb;
  border: 1px solid var(--line);
  border-radius: 12px;
  display: block;
  margin-top: 8px;
  min-height: 46px;
  padding: 12px;
  width: 100%;
}

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

.segmented {
  background: #eef2ff;
  border-radius: 14px;
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 18px;
  padding: 8px;
}

.segmented button {
  background: transparent;
  border-radius: 12px;
  min-height: 44px;
}

.segmented button.active.expense-active {
  background: var(--danger);
  color: #ffffff;
  font-weight: 800;
}

.segmented button.active.income-active {
  background: var(--income);
  color: #ffffff;
  font-weight: 800;
}

.section-head,
.record-row,
.rank-row {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.section-head h2 {
  margin: 0;
}

.smart-card textarea {
  margin: 16px 0 12px;
}

.batch-card textarea {
  margin: 16px 0 12px;
}

.batch-actions {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

.batch-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.batch-preview {
  margin-top: 14px;
}

.batch-summary {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 10px;
}

.batch-item {
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: 12px;
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  padding: 12px;
}

.batch-item.ok {
  background: #f0fdf4;
  border-color: #bbf7d0;
}

.batch-item.error {
  background: #fef2f2;
  border-color: #fecaca;
}

.batch-index {
  align-items: center;
  background: #ffffff;
  border-radius: 999px;
  color: var(--muted);
  display: flex;
  flex: 0 0 28px;
  font-size: 13px;
  font-weight: 800;
  height: 28px;
  justify-content: center;
  width: 28px;
}

.batch-source {
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}

.record-card {
  align-items: center;
  display: flex;
  gap: 12px;
}

.record-main {
  flex: 1;
  min-width: 0;
}

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

.record-subtitle {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  margin-top: 4px;
}

.record-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.record-actions button {
  min-height: 34px;
  padding: 0 10px;
}

.dot {
  align-items: center;
  border-radius: 50%;
  color: #ffffff;
  display: flex;
  flex: 0 0 44px;
  height: 44px;
  justify-content: center;
  width: 44px;
}

.expense {
  color: var(--danger);
}

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

.empty {
  color: var(--muted);
  padding: 48px 0;
  text-align: center;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.chip {
  background: #f3f4f6;
  color: #374151;
  min-height: 38px;
}

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

.filters input,
.filters select {
  margin-bottom: 8px;
}

.date-filter,
.category-form {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

.category-form {
  grid-template-columns: 1fr 88px 64px;
}

.category-form input[type="color"] {
  height: 46px;
  padding: 4px;
}

.category-row {
  align-items: center;
  border-top: 1px solid #f3f4f6;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 12px 0;
}

.rank-row {
  margin-bottom: 12px;
}

.keyword-card {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.keyword {
  background: #f3f4f6;
  border-radius: 999px;
  color: #374151;
  padding: 8px 12px;
}

.suggestion {
  border-bottom: 1px solid #f3f4f6;
  line-height: 1.6;
  padding: 10px 0;
}

.suggestion:last-child {
  border-bottom: 0;
}

.review-headline {
  color: #374151;
  line-height: 1.7;
}

.import-label {
  background: var(--primary-soft);
  border-radius: 12px;
  color: var(--primary);
  cursor: pointer;
  min-height: 44px;
  padding: 12px 16px;
  text-align: center;
}

.import-label input {
  display: none;
}

@media (max-width: 380px) {
  .summary-grid.three {
    grid-template-columns: 1fr;
  }

  .date-filter,
  .category-form {
    grid-template-columns: 1fr;
  }

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