:root {
  --bg: #f5f6f3;
  --surface: #ffffff;
  --surface-2: #eef3ee;
  --ink: #1f2522;
  --muted: #66706a;
  --line: #dce3dd;
  --accent: #167c69;
  --accent-dark: #0e5d4e;
  --accent-soft: #dff1eb;
  --warn: #b74e2b;
  --gold: #c78a24;
  --shadow: 0 16px 50px rgba(25, 36, 32, 0.1);
  font-family: Inter, "Noto Sans JP", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  background: #17211d;
  color: #f7fbf8;
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  gap: 34px;
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #f2c14e;
  color: #17211d;
  font-weight: 900;
  font-size: 1.35rem;
}

.brand h1,
.brand p,
.section-heading h3,
.topbar h2,
.metric strong {
  margin: 0;
}

.brand h1 {
  font-size: 1.05rem;
  line-height: 1.25;
}

.brand p {
  color: #b8c7c0;
  font-size: 0.78rem;
  margin-top: 4px;
}

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

.tab-button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  color: #dce9e3;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  text-align: left;
}

.tab-button span:first-child {
  width: 22px;
  text-align: center;
  font-size: 1.1rem;
}

.tab-button:hover,
.tab-button.active {
  background: #24332e;
  color: #ffffff;
}

.workspace {
  padding: 28px;
  overflow: hidden;
}

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

.topbar h2 {
  font-size: clamp(1.45rem, 2.5vw, 2.1rem);
  line-height: 1.2;
}

.topbar-actions,
.filter-row {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-dark);
  font-size: 0.73rem;
  font-weight: 800;
  letter-spacing: 0;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.notice {
  border: 1px solid #e1cf9a;
  background: #fff7df;
  color: #59440d;
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
  line-height: 1.5;
}

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

.metric,
.section-block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 20px;
  min-height: 132px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.metric span,
.metric small {
  color: var(--muted);
}

.metric strong {
  font-size: clamp(1.4rem, 2.4vw, 2.15rem);
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.dashboard-grid,
.split-layout,
.settings-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.9fr) minmax(420px, 1.2fr);
  gap: 18px;
  align-items: start;
}

.settings-grid {
  grid-template-columns: repeat(3, minmax(260px, 1fr));
}

.section-block {
  padding: 18px;
}

.report-block {
  margin-top: 18px;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  margin-bottom: 16px;
}

.section-heading h3 {
  font-size: 1.12rem;
}

.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.field input,
.field select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

.field input[type="color"] {
  padding: 4px;
}

.field input:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field.compact {
  min-width: 150px;
}

.search-field {
  min-width: 210px;
}

.field.compact input,
.field.compact select {
  min-height: 38px;
}

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

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

.report-card {
  min-height: 94px;
  background: #fbfcfb;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  gap: 7px;
}

.report-card span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.report-card strong {
  font-size: 1.25rem;
  overflow-wrap: anywhere;
}

.category-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.category-row header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.category-row strong,
.record-main strong {
  overflow-wrap: anywhere;
}

.budget-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 6px;
}

.bar {
  height: 10px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.bar .over {
  background: var(--warn);
}

.chart-wrap {
  min-height: 280px;
}

#dailyChart {
  width: 100%;
  height: 280px;
}

.scan-stage {
  display: grid;
  gap: 14px;
}

.scan-drop {
  min-height: 220px;
  border: 1px dashed #9eb6ac;
  border-radius: 8px;
  background: #f9fbfa;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  color: var(--muted);
}

.scan-drop input {
  display: none;
}

.scan-drop strong {
  display: block;
  color: var(--ink);
  font-size: 1.05rem;
}

.scan-icon {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 1.7rem;
  margin-bottom: 10px;
}

.receipt-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #111;
  max-height: 360px;
}

.receipt-preview img {
  width: 100%;
  display: block;
  object-fit: contain;
  max-height: 360px;
}

.hidden {
  display: none;
}

.scan-status {
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 12px;
  line-height: 1.5;
}

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

.form-actions,
.backup-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.backup-actions {
  align-items: center;
}

.primary-button,
.ghost-button,
.icon-button,
.import-button {
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  font-weight: 800;
}

.primary-button {
  background: var(--accent);
  color: white;
}

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

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.ghost-button,
.import-button {
  background: #ffffff;
  color: var(--ink);
  border-color: var(--line);
}

.ghost-button:hover,
.import-button:hover {
  border-color: #9eb6ac;
}

.import-button input {
  display: none;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  color: var(--ink);
}

.toggle-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.record-card {
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
}

.record-card.with-thumb {
  grid-template-columns: 64px minmax(0, 1fr) auto;
}

.receipt-thumb {
  width: 64px;
  height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: cover;
  background: #111;
}

.receipt-button {
  width: 64px;
  height: 64px;
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: transparent;
}

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

.record-main p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.record-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.amount {
  font-weight: 900;
  white-space: nowrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  padding: 0 10px;
  font-size: 0.76rem;
  font-weight: 900;
}

.pill.warn {
  background: #ffe8df;
  color: var(--warn);
}

.swatch {
  width: 16px;
  height: 16px;
  border-radius: 99px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  display: inline-block;
}

.icon-button {
  width: 36px;
  min-height: 36px;
  padding: 0;
  background: white;
  color: var(--ink);
  border-color: var(--line);
}

.icon-button.danger {
  color: var(--warn);
}

.settings-list {
  margin-top: 16px;
}

.helper-text,
.empty-state {
  color: var(--muted);
  line-height: 1.6;
}

dialog {
  width: min(92vw, 720px);
  border: 0;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.32);
}

dialog::backdrop {
  background: rgba(15, 22, 19, 0.56);
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

#receiptDialogImage {
  width: 100%;
  max-height: 72vh;
  object-fit: contain;
  border-radius: 8px;
  background: #111;
}

@media (max-width: 1180px) {
  .summary-grid,
  .settings-grid,
  .report-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 14px;
    gap: 14px;
  }

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

  .tab-button {
    justify-content: center;
    padding: 0 8px;
  }

  .tab-button span:last-child {
    display: none;
  }

  .workspace {
    padding: 18px;
  }

  .summary-grid,
  .dashboard-grid,
  .split-layout,
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .topbar,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .filter-row {
    align-items: stretch;
    flex-direction: column;
  }

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

  .record-card,
  .record-card.with-thumb {
    grid-template-columns: 1fr;
  }

  .receipt-thumb {
    width: 100%;
    height: 120px;
  }

  .record-meta {
    justify-content: space-between;
    flex-wrap: wrap;
  }
}
