:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #d9dee8;
  --accent: #14b8a6;
  --accent-strong: #0f766e;
  --danger: #ef4444;
  --navy: #0f172a;
  --amber: #f59e0b;
  --radius: 8px;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
}

button,
input,
textarea {
  font: inherit;
  min-width: 0;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1120px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px;
  overflow-x: clip;
}

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

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: var(--navy);
  font-size: 34px;
  line-height: 1.05;
}

.month-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: var(--panel);
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.sync-chip {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  background: var(--panel);
  color: var(--navy);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #e9edf5;
  margin-bottom: 16px;
}

.tab-button,
.segment,
.sign-button {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.tab-button {
  min-height: 44px;
}

.tab-button.active,
.segment.active,
.sign-button.active {
  background: var(--panel);
  color: var(--navy);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.entry-form,
.csv-layout {
  display: grid;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 22px;
  min-width: 0;
}

.entry-top {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 14px;
  align-items: stretch;
}

.sign-stack {
  display: grid;
  gap: 8px;
}

.sign-button {
  min-height: 58px;
  border: 1px solid var(--line);
  font-size: 30px;
}

.sign-button[data-type="income"].active {
  color: var(--accent-strong);
}

.sign-button[data-type="expense"].active {
  color: var(--danger);
}

label,
.selector-block {
  display: grid;
  gap: 8px;
  min-width: 0;
}

label span,
.selector-label,
.import-heading {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  outline: 0;
}

input {
  min-height: 48px;
  padding: 0 13px;
}

input[type="date"],
input[type="month"] {
  -webkit-appearance: none;
  appearance: none;
  text-align: center;
}

input[type="file"] {
  display: block;
  overflow: hidden;
  padding: 11px;
  white-space: nowrap;
}

textarea {
  min-height: 190px;
  padding: 12px;
  resize: vertical;
}

.amount-field input {
  min-height: 124px;
  font-size: 42px;
  font-weight: 800;
  text-align: right;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.segment {
  flex: 0 1 auto;
  min-width: 0;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: #f8fafc;
}

.text-action {
  justify-self: start;
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  font-weight: 700;
  padding: 2px 0;
}

.primary-button,
.secondary-button,
.icon-button {
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-weight: 800;
  max-width: 100%;
}

.primary-button {
  min-height: 52px;
  background: var(--navy);
  color: #fff;
}

.secondary-button {
  min-height: 46px;
  background: #fff;
  border-color: var(--line);
  color: var(--navy);
}

.toolbar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  min-width: 0;
}

.icon-button {
  width: 46px;
  height: 46px;
  background: var(--panel);
  border-color: var(--line);
  color: var(--navy);
  font-size: 24px;
}

.summary-grid {
  display: grid;
  grid-template-columns: minmax(220px, 320px) 1fr;
  gap: 16px;
  align-items: stretch;
  margin-bottom: 16px;
  min-width: 0;
}

.chart-wrap,
.totals,
.log-row {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.chart-wrap {
  display: grid;
  place-items: center;
  min-height: 260px;
}

.totals {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  background: var(--line);
}

.totals div {
  display: grid;
  gap: 6px;
  padding: 16px;
  background: var(--panel);
}

.totals span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.totals strong {
  font-size: 22px;
}

.log-list {
  display: grid;
  gap: 10px;
}

.log-row {
  display: grid;
  grid-template-columns: 116px 110px 1fr 150px 130px 42px;
  gap: 10px;
  align-items: center;
  padding: 12px;
  min-width: 0;
}

.log-row input,
.log-row select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 8px;
  background: #fff;
}

.amount-cell {
  font-weight: 800;
  text-align: right;
}

.due-cell {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  min-height: 18px;
}

.delete-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--danger);
  font-weight: 900;
}

.csv-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
  min-width: 0;
}

.import-panel {
  display: grid;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
  min-width: 0;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.status-message {
  min-height: 20px;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 800;
}

.status-message.error {
  color: var(--danger);
}

dialog {
  width: min(520px, calc(100% - 28px));
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.3);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.dialog-card {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.dialog-card h2,
.dialog-card p {
  margin: 0;
}

.dialog-card p {
  color: var(--muted);
}

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

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


.sync-chip[data-state="on"] {
  border-color: #99f6e4;
  background: #f0fdfa;
  color: var(--accent-strong);
}

.sync-chip[data-state="saving"],
.sync-chip[data-state="loading"] {
  border-color: #fde68a;
  background: #fffbeb;
  color: #92400e;
}

.sync-chip[data-state="error"] {
  border-color: #fecaca;
  background: #fef2f2;
  color: #b91c1c;
}

.dialog-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.dialog-kicker {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.close-button {
  display: grid;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
}

.close-button:hover,
.password-toggle:hover {
  border-color: #9ca3af;
  color: var(--navy);
}

.sync-overview {
  display: grid;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: #f8fafc;
}

.sync-overview[data-state="on"] {
  border-color: #99f6e4;
  background: #f0fdfa;
}

.sync-overview-heading {
  display: flex;
  align-items: center;
  gap: 9px;
}

.sync-overview p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.sync-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--muted);
}

.sync-overview[data-state="on"] .sync-dot {
  background: var(--accent);
}

.sync-guide {
  border-left: 3px solid var(--accent);
  padding: 2px 0 2px 13px;
}

.sync-guide-title {
  margin: 0 0 7px;
  color: var(--navy);
  font-size: 13px;
  font-weight: 900;
}

.sync-guide ol {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.sync-guide strong {
  color: var(--ink);
}

.sync-password-label small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.sync-password-label code {
  border-radius: 4px;
  padding: 1px 5px;
  background: #e9edf5;
  color: var(--navy);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.password-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.password-toggle {
  min-width: 62px;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--accent-strong);
  font-weight: 800;
}

.sync-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  justify-content: stretch;
}

.sync-actions button {
  min-height: 52px;
  padding: 8px 12px;
  line-height: 1.35;
}

.danger-outline {
  color: #b91c1c;
}


@media (max-width: 720px) {
  .app-shell {
    padding: max(14px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
  }

  h1 {
    font-size: 28px;
  }

  .app-header {
    align-items: flex-start;
  }

  .header-actions {
    align-items: flex-end;
    flex-direction: column-reverse;
  }

  .month-chip {
    font-size: 12px;
  }

  .sync-chip {
    min-height: 34px;
    font-size: 12px;
  }

  .stacked-actions,
  .sync-actions {
    grid-template-columns: 1fr;
  }

  .entry-form,
  .csv-layout {
    padding: 14px;
  }

  .entry-top {
    grid-template-columns: 62px 1fr;
    gap: 10px;
  }

  .sign-button {
    min-height: 52px;
  }

  .amount-field input {
    min-height: 112px;
    font-size: 34px;
  }

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

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

  .log-row {
    grid-template-columns: 1fr 1fr 38px;
    gap: 8px;
  }

  .log-row .detail-edit,
  .log-row .method-edit,
  .log-row .due-cell {
    grid-column: span 2;
  }

  .amount-cell {
    text-align: left;
  }

  .csv-controls {
    grid-template-columns: minmax(0, 1fr);
  }

  .csv-controls .primary-button,
  .csv-controls .secondary-button {
    min-height: 48px;
  }

  .import-mode .segment {
    flex: 1 1 calc(50% - 4px);
    padding: 0 10px;
    font-size: 15px;
  }

  .hint {
    overflow-wrap: anywhere;
  }
}
