:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", sans-serif;
  --bg: #fbf8f4;
  --surface: #ffffff;
  --text: #131313;
  --muted: #88837e;
  --line: #eeebe7;
  --accent: #f25316;
  --danger: #ef3e37;
  --shadow: 0 12px 34px rgba(74, 52, 36, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  min-height: 100dvh;
  overscroll-behavior: none;
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(100%, 480px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 10px calc(96px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 20px;
}

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

.summary-card {
  min-width: 0;
  padding: 15px 12px 16px;
  border-radius: 17px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.summary-card span {
  display: block;
  margin-bottom: 8px;
  color: #6f6b67;
  font-size: 13px;
  white-space: nowrap;
}

.summary-card strong {
  display: block;
  overflow: hidden;
  color: var(--accent);
  font-size: clamp(20px, 6.4vw, 31px);
  font-weight: 750;
  letter-spacing: -0.03em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-card {
  flex: 1;
  min-height: 440px;
  overflow: hidden;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.table-grid {
  display: grid;
  grid-template-columns: 22px 42px minmax(90px, 1fr) 58px 68px 68px;
  align-items: center;
  column-gap: 4px;
}

.table-head {
  min-height: 54px;
  padding: 0 10px;
  background: linear-gradient(180deg, #ffffff 0%, #fafafa 100%);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.table-head span:nth-child(n+4),
.record-content > span:nth-child(n+4) { text-align: right; }

.records { position: relative; }

.record-row {
  position: relative;
  height: 64px;
  overflow: hidden;
  border-top: 1px solid var(--line);
  background: #f5a623;
  touch-action: pan-y;
}

.record-content {
  position: relative;
  z-index: 2;
  height: 100%;
  padding: 0 10px;
  background: var(--surface);
  transition: transform 180ms ease;
  -webkit-user-select: none;
  user-select: none;
  will-change: transform;
  cursor: pointer;
}

.record-row.is-open .record-content { transform: translateX(-140px); }

.row-number {
  color: #aaa49e;
  font-size: 13px;
  text-align: center !important;
}

.channel-icon {
  display: block;
  width: 25px;
  height: 25px;
  margin: auto;
  border-radius: 7px;
  object-fit: cover;
}

.record-name {
  overflow: hidden;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.numeric {
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  white-space: nowrap;
}

.row-actions {
  position: absolute;
  z-index: 1;
  top: 0;
  right: 0;
  display: flex;
  width: 140px;
  height: 100%;
}

.row-action {
  width: 70px;
  height: 100%;
  border: 0;
  color: white;
  font-size: 15px;
  font-weight: 650;
}

.edit-action { background: #f5a623; }
.delete-action { background: var(--danger); }

.empty-state {
  padding: 72px 20px;
  color: var(--muted);
  text-align: center;
}

.empty-icon {
  width: 42px;
  height: 42px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: #f5f0eb;
  color: #aaa098;
  font-size: 28px;
  line-height: 40px;
}

.empty-state p { margin: 0 0 6px; color: #5d5853; font-weight: 650; }
.empty-state span { font-size: 13px; }

.add-button {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  width: min(calc(100% - 24px), 456px);
  height: 58px;
  transform: translateX(-50%);
  border: 0;
  border-radius: 17px;
  background: var(--accent);
  box-shadow: 0 12px 28px rgba(242, 83, 22, 0.25);
  color: white;
  font-size: 19px;
  font-weight: 700;
}

.add-button:active { transform: translateX(-50%) scale(0.985); }

.sheet-backdrop {
  position: fixed;
  z-index: 20;
  inset: 0;
  background: rgba(25, 18, 13, 0.3);
  backdrop-filter: blur(2px);
}

.editor-sheet {
  position: fixed;
  z-index: 21;
  right: 0;
  bottom: 0;
  left: 0;
  width: min(100%, 520px);
  max-height: 90dvh;
  margin: auto;
  padding: 7px 18px calc(22px + env(safe-area-inset-bottom));
  overflow-y: auto;
  border-radius: 22px 22px 0 0;
  background: #fff;
  box-shadow: 0 -16px 45px rgba(0, 0, 0, 0.12);
  animation: sheet-in 190ms ease-out;
}

@keyframes sheet-in {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.sheet-handle {
  width: 38px;
  height: 5px;
  margin: 0 auto 6px;
  border-radius: 99px;
  background: #d5d1cd;
}

.sheet-header {
  display: grid;
  grid-template-columns: 60px 1fr 60px;
  align-items: center;
  min-height: 48px;
}

.sheet-header h2 { margin: 0; font-size: 17px; text-align: center; }
.text-button { padding: 10px 0; border: 0; background: transparent; color: #77716c; }
.text-button:last-child { text-align: right; }
.text-button.accent { color: var(--accent); font-weight: 700; }

.channel-fieldset { margin: 8px 0 15px; padding: 0; border: 0; }
.channel-fieldset legend, .form-field > span { margin-bottom: 8px; color: #77716c; font-size: 13px; }

.channel-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.channel-picker input { position: absolute; opacity: 0; pointer-events: none; }
.channel-picker span {
  display: flex;
  height: 50px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid #e7e2de;
  border-radius: 13px;
  background: #fbfaf9;
  font-size: 15px;
}
.channel-picker img { width: 26px; height: 26px; border-radius: 7px; }
.channel-picker input:checked + span { border-color: var(--accent); background: #fff5ef; color: #d9470f; font-weight: 650; }

.form-field {
  display: flex;
  flex-direction: column;
  margin-bottom: 15px;
}

.form-field > input, .money-input {
  width: 100%;
  height: 50px;
  border: 1px solid #e7e2de;
  border-radius: 13px;
  outline: 0;
  background: #fbfaf9;
  font-size: 16px;
}

.form-field > input { padding: 0 14px; }
.form-field > input:focus, .money-input:focus-within { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px rgba(242,83,22,.1); }
.money-input { display: flex; align-items: center; padding: 0 14px; }
.money-input b { margin-right: 5px; font-weight: 500; }
.money-input input {
  flex: 1;
  width: auto;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  border-radius: 0;
  outline: 0;
  background: transparent;
  box-shadow: none;
}

.calculated-field {
  display: flex;
  min-height: 50px;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px;
  color: #77716c;
  font-size: 14px;
}
.calculated-field strong { color: var(--text); font-size: 17px; font-variant-numeric: tabular-nums; }
.form-error { min-height: 20px; margin: 4px 0 0; color: var(--danger); font-size: 13px; text-align: center; }

.toast {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  max-width: calc(100% - 40px);
  padding: 10px 16px;
  transform: translate(-50%, 18px);
  border-radius: 99px;
  background: rgba(20, 20, 20, 0.88);
  color: white;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: 180ms ease;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

[hidden] { display: none !important; }

@media (max-width: 390px) {
  .app-shell { padding-inline: 7px; }
  .summary-card { padding-inline: 8px; }
  .summary-card span { font-size: 12px; }
  .table-grid { grid-template-columns: 18px 36px minmax(76px, 1fr) 52px 61px 62px; column-gap: 2px; }
  .table-head, .record-content { padding-inline: 7px; }
  .table-head { font-size: 13px; }
  .numeric { font-size: 13px; }
}

@media (min-width: 700px) {
  body { background: #efeae4; }
  .app-shell { background: var(--bg); box-shadow: 0 0 50px rgba(38, 29, 22, .12); }
}
