:root {
  --ink: #17201b;
  --muted: #646c66;
  --line: #d9ded6;
  --paper: #f7f4ea;
  --panel: #fffdf6;
  --carbon: #222822;
  --accent: #d34f2a;
  --green: #246b4b;
  --gold: #7d5d0d;
  --shadow: 0 18px 50px rgb(35 40 34 / 12%);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgb(23 32 27 / 4%) 1px, transparent 1px),
    linear-gradient(0deg, rgb(23 32 27 / 4%) 1px, transparent 1px),
    var(--paper);
  background-size: 34px 34px;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", Georgia, serif;
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 28px;
  /* Extend the dark rail under the status bar / left notch on iOS (env()=0 elsewhere). */
  padding-top: calc(28px + env(safe-area-inset-top));
  padding-left: calc(28px + env(safe-area-inset-left));
  color: #f4efe1;
  background: var(--carbon);
  display: flex;
  flex-direction: column;
  gap: 28px;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  color: var(--carbon);
  background: #f4efe1;
  border-radius: 6px;
  font-weight: 700;
}

.brand p {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.brand span,
.rail-nav a,
.compliance-note p {
  color: rgb(244 239 225 / 70%);
}

.rail-nav {
  display: grid;
  gap: 10px;
}

.rail-nav a {
  text-decoration: none;
  padding: 10px 0;
  border-bottom: 1px solid rgb(244 239 225 / 14%);
}

.compliance-note {
  margin-top: auto;
  padding: 18px;
  border: 1px solid rgb(244 239 225 / 20%);
  border-radius: 8px;
}

.readiness {
  padding: 18px;
  border: 1px solid rgb(244 239 225 / 20%);
  border-radius: 8px;
}

.readiness p {
  margin: 12px 0 0;
  color: rgb(244 239 225 / 70%);
  line-height: 1.6;
  font-size: 13px;
}

.ring {
  display: grid;
  place-items: center;
  width: 112px;
  height: 112px;
  margin-top: 16px;
  border-radius: 50%;
  background: conic-gradient(#f4efe1 var(--p), rgb(244 239 225 / 15%) 0);
}

.ring span {
  display: grid;
  place-items: center;
  width: 78px;
  height: 78px;
  color: #f4efe1;
  background: var(--carbon);
  border-radius: 50%;
  font-size: 24px;
  font-weight: 700;
}

.compliance-note p {
  margin: 8px 0 0;
  line-height: 1.7;
  font-size: 13px;
}

.workspace {
  padding: 34px;
  /* Clear the home indicator / right notch on iOS (env()=0 elsewhere). */
  padding-right: calc(34px + env(safe-area-inset-right));
  padding-bottom: calc(34px + env(safe-area-inset-bottom));
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 430px;
  gap: 28px;
  align-items: end;
  margin-bottom: 26px;
}

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

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  max-width: 820px;
  font-size: clamp(42px, 6vw, 86px);
  line-height: 0.96;
}

h2 {
  font-size: 22px;
}

.hero-copy {
  max-width: 720px;
  color: var(--muted);
  line-height: 1.8;
  font-size: 16px;
}

.hero-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.hero-metrics div {
  padding: 20px;
  border-right: 1px solid var(--line);
}

.hero-metrics div:last-child {
  border-right: 0;
}

.hero-metrics span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.hero-metrics strong {
  display: block;
  margin-top: 8px;
  font-size: 22px;
}

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

.packet-grid {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.muted-note {
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

.checkbox {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.checkbox input {
  width: auto;
}

.checkbox.wide {
  grid-column: 1 / -1;
}

.guide-list {
  margin: 12px 0 0;
  padding-left: 18px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.8;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.kind-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  color: var(--green);
  background: rgb(36 107 75 / 12%);
}

.attachment-pdf {
  display: inline-block;
  margin-bottom: 14px;
  font-weight: 700;
  color: var(--accent);
}

.panel {
  margin-bottom: 18px;
  padding: 22px;
  background: rgb(255 253 246 / 92%);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.settings-panel {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 24px;
  align-items: end;
}

.onboarding {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) auto;
  gap: 24px;
  align-items: center;
}

.onboarding ol {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.8;
}

.settings-form,
.filter-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.filter-form {
  grid-template-columns: 1.3fr 0.5fr 0.8fr 0.8fr 0.8fr;
  margin-bottom: 18px;
}

.notice {
  margin-bottom: 18px;
  padding: 14px 16px;
  color: var(--green);
  background: rgb(36 107 75 / 10%);
  border: 1px solid rgb(36 107 75 / 22%);
  border-radius: 8px;
  font-weight: 700;
}

.notice.undo {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.notice.undo button {
  min-height: 34px;
  color: #fffdf6;
  background: var(--green);
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: start;
  margin-bottom: 18px;
}

textarea {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffcf2;
  color: var(--ink);
  line-height: 1.7;
}

.compact-textarea {
  min-height: 96px;
  font-family: "Hiragino Sans", "Yu Gothic", sans-serif;
  font-size: 13px;
}

.drop-zone {
  display: grid;
  place-items: center;
  min-height: 118px;
  margin-bottom: 14px;
  padding: 18px;
  text-align: center;
  color: var(--ink);
  background: #f3ead7;
  border: 1px dashed #b9aa87;
  border-radius: 8px;
  cursor: pointer;
}

/* Keep file inputs out of view but still focusable/operable by keyboard
   (display:none would drop them from the tab order and accessibility tree). */
.drop-zone input,
.import-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.drop-zone:focus-within,
.import-button:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.drop-zone span {
  font-size: 17px;
  font-weight: 700;
}

.drop-zone small {
  max-width: 360px;
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.6;
}

.receipt-preview {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  margin-bottom: 14px;
  background: #f3ead7;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.receipt-preview.small {
  max-height: 170px;
}

/* Estimated tax-savings card (motivator) */
.savings-card {
  background: radial-gradient(120% 90% at 0% 0%, #f4ece0 0%, #efe6d4 100%);
}
.savings-figure {
  font-size: 44px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
  margin: 6px 0 8px;
}
.savings-figure span {
  font-size: 16px;
  font-weight: 600;
  color: var(--muted);
  margin-left: 8px;
}

/* Pro status card in settings */
.pro-card {
  margin-top: 14px;
  padding: 14px 16px;
  background: #faf4e6;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.pro-card.is-pro {
  background: #eef3ec;
  border-color: #b8c9b3;
}
.pro-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
}
.pro-badge {
  font-family: "Hiragino Kaku Gothic ProN", sans-serif;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  background: rgba(34, 40, 34, 0.06);
  border-radius: 999px;
  padding: 2px 10px;
}
.pro-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

/* Contextual paywall overlay */
.paywall-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  padding-top: calc(20px + env(safe-area-inset-top));
  background: rgba(23, 27, 23, 0.55);
  backdrop-filter: blur(3px);
  overflow: auto;
}
.paywall {
  position: relative;
  width: 100%;
  max-width: 460px;
  background:
    radial-gradient(120% 80% at 50% -10%, #f8f1e2 0%, #f3ead7 60%, #ecdfc6 100%);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 24px 20px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.4);
  animation: paywall-rise 0.28s ease;
}
@keyframes paywall-rise {
  from { transform: translateY(14px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.paywall-close {
  position: absolute;
  top: 12px;
  right: 14px;
  border: none;
  background: transparent;
  font-size: 26px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}
.paywall-mark {
  width: 56px;
  height: 56px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: var(--paper);
  font-size: 34px;
  font-weight: 700;
}
.paywall h2 {
  margin: 14px 0 6px;
  font-size: 26px;
}
.paywall-lead {
  color: var(--muted);
  line-height: 1.6;
  margin: 0 0 14px;
}
.paywall-benefits {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  display: grid;
  gap: 9px;
}
.paywall-benefits li {
  padding-left: 28px;
  position: relative;
  line-height: 1.5;
}
.paywall-benefits li::before {
  content: "✓";
  position: absolute;
  left: 0;
  top: 0;
  color: #4f7a43;
  font-weight: 700;
}
.paywall-options {
  display: grid;
  gap: 10px;
}
.paywall-buy {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  padding: 14px 18px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  text-align: left;
}
.paywall-buy.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.paywall-buy:disabled { opacity: 0.6; cursor: default; }
.po-title { font-weight: 700; font-size: 16px; }
.po-price { font-size: 14px; opacity: 0.92; }
.paywall-status { text-align: center; color: var(--muted); margin: 10px 0 0; font-size: 13px; }
.paywall-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
  margin-top: 16px;
  font-size: 13px;
}
.paywall .link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  text-decoration: underline;
  padding: 0;
}
.paywall-fine {
  margin: 12px 0 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--muted);
  text-align: center;
}

/* Native (iOS) capture buttons — only rendered in the Capacitor shell */
.native-capture {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.native-capture small {
  flex-basis: 100%;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

/* Batch drag-and-drop highlight */
.drop-zone.drag-over {
  background: #ece0c4;
  border-color: var(--accent);
  border-style: solid;
}

/* Per-record re-OCR + rate-split disclosures in the review panel */
.reocr,
.rate-split {
  margin: 10px 0;
  padding: 10px 12px;
  background: #faf4e6;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.reocr > summary,
.rate-split > summary {
  font-weight: 600;
  cursor: pointer;
}

.reocr textarea {
  width: 100%;
  min-height: 64px;
  margin: 8px 0;
}

.field-help {
  margin: 6px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

/* Each rate row: a label (8%/10%) then 税込金額・税額・区分. */
.split-grid {
  display: grid;
  grid-template-columns: auto 1fr 1fr 1.2fr;
  align-items: end;
  gap: 8px;
  margin: 8px 0;
}

.split-grid strong {
  align-self: center;
  font-size: 13px;
}

.split-grid label {
  display: grid;
  gap: 4px;
  font-size: 13px;
}

.split-grid select {
  width: 100%;
}

@media (max-width: 560px) {
  .split-grid {
    grid-template-columns: 1fr 1fr;
  }
  .split-grid strong {
    grid-column: 1 / -1;
  }
}

#bulkCategorySelect {
  max-width: 170px;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin-top: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

button {
  min-height: 42px;
  padding: 0 16px;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.primary {
  color: #fffdf6;
  background: var(--green);
}

.button-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.button-column {
  display: grid;
  gap: 10px;
  margin: 16px 0;
}

.import-button {
  display: grid;
  place-items: center;
  min-height: 42px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}

.ghost {
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
}

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

.record-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.wide {
  grid-column: 1 / -1;
}

.review-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.review-actions span,
.muted {
  color: var(--muted);
}

.review-actions > div {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.registry-link {
  color: var(--green);
  font-weight: 700;
  text-decoration: none;
}

.errors {
  margin: 0 0 14px;
  padding: 12px 14px 12px 30px;
  color: #8f2d19;
  background: rgb(211 79 42 / 10%);
  border: 1px solid rgb(211 79 42 / 22%);
  border-radius: 8px;
  line-height: 1.7;
}

.import-errors ul {
  margin: 0;
  padding-left: 20px;
  color: #8f2d19;
  line-height: 1.8;
}

.ok {
  margin-bottom: 14px;
  padding: 12px 14px;
  color: var(--green);
  background: rgb(36 107 75 / 10%);
  border: 1px solid rgb(36 107 75 / 18%);
  border-radius: 8px;
}

.warn {
  margin-bottom: 14px;
  padding: 12px 14px;
  color: var(--gold);
  background: rgb(125 93 13 / 10%);
  border: 1px solid rgb(125 93 13 / 22%);
  border-radius: 8px;
  font-weight: 700;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-family: "Hiragino Sans", "Yu Gothic", sans-serif;
}

th,
td {
  padding: 14px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
}

tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #faf3e2;
}

tbody tr:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

tr.selected {
  background: #f3ead7;
}

tbody tr.deleted td {
  opacity: 0.5;
  text-decoration: line-through;
}

.history {
  margin-top: 16px;
  font-size: 13px;
  color: var(--ink);
}

.history summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 700;
}

.history ul {
  margin: 10px 0 0;
  padding-left: 18px;
  line-height: 1.8;
}

.history .hist-when {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.history .hist-action {
  font-weight: 700;
}

.status {
  display: inline-block;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.status.reviewed {
  color: var(--green);
  background: rgb(36 107 75 / 12%);
}

.status.needs-review {
  color: var(--gold);
  background: rgb(185 139 29 / 16%);
}

.bars {
  display: grid;
  gap: 16px;
  margin-top: 18px;
}

.bar-row div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 8px;
}

.bar-row span {
  color: var(--muted);
}

.bar-row i {
  display: block;
  width: 100%;
  height: 9px;
  background: #e4dfd1;
  border-radius: 999px;
  overflow: hidden;
}

.bar-row i::before {
  content: "";
  display: block;
  width: var(--w);
  height: 100%;
  background: var(--accent);
}

.source-card p {
  color: var(--muted);
  line-height: 1.7;
}

.source-card a {
  color: var(--green);
  font-weight: 700;
}

.duplicate-box {
  margin: 14px 0;
  padding: 12px 14px;
  color: #8f2d19;
  background: rgb(211 79 42 / 10%);
  border: 1px solid rgb(211 79 42 / 22%);
  border-radius: 8px;
}

.handoff-list {
  display: grid;
  gap: 10px;
  margin: 16px 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.handoff-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.handoff-item span {
  color: var(--muted);
}

.handoff-item em {
  font-style: normal;
  font-weight: 700;
}

.handoff-item.ok em {
  color: var(--green);
}

.handoff-item.attention em {
  color: var(--gold);
}

.duplicate-box ul {
  margin: 8px 0 0;
  padding-left: 18px;
  line-height: 1.7;
}

.empty {
  display: grid;
  place-items: center;
  min-height: 260px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.empty.mini {
  min-height: 90px;
}

.empty-cell {
  padding: 32px 12px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1100px) {
  .shell,
  .hero,
  .grid,
  .packet-grid {
    grid-template-columns: 1fr;
  }

  .rail {
    position: static;
    height: auto;
  }

  .table-wrap {
    max-width: calc(100vw - 36px);
  }
}

@media (max-width: 640px) {
  html,
  body {
    overflow-x: hidden;
  }

  .workspace,
  .rail {
    padding: 18px;
    width: 100%;
    min-width: 0;
  }

  /* Stacked layout: rail is at the top (clear the status bar), workspace at the
     bottom (clear the home indicator). */
  .rail {
    padding-top: calc(18px + env(safe-area-inset-top));
  }

  .workspace {
    padding-right: 18px;
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
  }

  .hero-metrics,
  .field-row,
  .record-form,
  .settings-panel,
  .onboarding,
  .settings-form,
  .filter-form,
  .button-row,
  .button-column {
    grid-template-columns: 1fr;
  }

  .button-row {
    display: grid;
    width: 100%;
  }

  button,
  .import-button {
    width: 100%;
    white-space: normal;
  }

  .panel {
    padding: 16px;
  }

  .panel-heading {
    display: grid;
  }

  .table-wrap {
    max-width: calc(100vw - 68px);
  }

  table {
    min-width: 720px;
  }

  h1 {
    font-size: 42px;
  }
}
