:root {
  color-scheme: dark;
  --bg: #111318;
  --panel: #171a20;
  --panel-alt: #1d2129;
  --line: #2a303b;
  --text: #f4f6fb;
  --muted: #9ba3b3;
  --accent: #7ee081;
  --accent-strong: #3dbb66;
  --danger: #ef6b73;
  --warning: #ffbf5a;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(126, 224, 129, 0.08), transparent 38%),
    linear-gradient(180deg, #111318 0%, #0e1014 100%);
  color: var(--text);
  font-family: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

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

.app-shell {
  max-width: 520px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 14px 28px;
}

.topbar,
.section-head,
.card-row,
.meta-row,
.filter-row,
.action-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar {
  margin-bottom: 16px;
}

.top-actions,
.home-head,
.editor-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar {
  align-items: center;
}

.top-title {
  font-size: 24px;
  line-height: 1.1;
  font-weight: 800;
}

.top-actions .ghost-button {
  min-height: 38px;
  padding: 0 12px;
}

.hero-copy h1 {
  margin: 4px 0 0;
  font-size: 24px;
  line-height: 1.1;
}

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

.page-body {
  display: grid;
  gap: 14px;
}

.home-head {
  display: grid;
  grid-template-columns: 1fr;
}

.home-stats {
  display: grid;
  grid-template-columns: 0.8fr 1.4fr 0.8fr;
  gap: 10px;
}

.stat-tile {
  min-height: 92px;
  display: grid;
  align-content: center;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(126, 224, 129, 0.08), rgba(255, 255, 255, 0)), var(--panel);
  box-shadow: var(--shadow);
}

.stat-tile span,
.stat-tile small {
  color: var(--muted);
  font-size: 12px;
}

.stat-tile strong {
  font-size: 22px;
  line-height: 1.15;
}

.money-tile strong {
  font-size: 18px;
}

.card,
.auth-card,
.list-card,
.item-card,
.chip-card,
.metric-card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0)), var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.card,
.auth-card,
.item-card {
  padding: 16px;
}

.auth-card {
  margin-top: 10vh;
}

.hero-copy {
  margin-bottom: 20px;
}

.hero-copy p:last-child {
  color: var(--muted);
  line-height: 1.5;
}

.stack-form,
.stack-list,
.chip-grid,
.flash-stack,
.metric-grid,
.attachment-list {
  display: grid;
  gap: 12px;
}

.stack-form label,
.item-grid label,
.field {
  display: grid;
  gap: 6px;
}

.stack-form span,
.item-grid span,
.field-help {
  color: var(--muted);
  font-size: 12px;
}

.field-help {
  line-height: 1.4;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-alt);
  color: var(--text);
  padding: 12px 13px;
}

textarea {
  resize: vertical;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.wide-button,
.compact-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 8px;
  border: none;
  padding: 0 16px;
  font-weight: 600;
}

.compact-button {
  min-height: 36px;
  padding: 0 12px;
  font-size: 13px;
}

.primary-button {
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: #0d160f;
}

.secondary-button {
  background: #242a34;
  color: var(--text);
}

.ghost-button,
.danger-button {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
}

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

.wide-button {
  width: 100%;
}

.text-link {
  color: var(--accent);
  font-size: 14px;
}

.empty-copy,
.muted,
.list-card p {
  color: var(--muted);
  margin: 0;
}

.bill-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

.bill-main {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.bill-no {
  width: max-content;
  max-width: 100%;
  padding: 3px 8px;
  border: 1px solid rgba(126, 224, 129, 0.24);
  border-radius: 6px;
  color: var(--accent);
  background: rgba(126, 224, 129, 0.08);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.bill-summary-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
}

.bill-summary-line span {
  color: var(--text);
}

.badge,
.chip-label,
.nav-badge,
.filter-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
}

.badge,
.filter-chip {
  background: #252a33;
  color: var(--muted);
}

.badge.synced {
  color: var(--accent);
}

.badge.pending {
  color: var(--warning);
}

.chip-label {
  background: rgba(126, 224, 129, 0.12);
  color: var(--accent);
}

.chip-card,
.list-card {
  padding: 14px;
}

.list-card strong {
  font-size: 16px;
}

.meta-row {
  flex-wrap: wrap;
  justify-content: flex-start;
  color: var(--muted);
  font-size: 12px;
  margin-top: 8px;
}

.flash {
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 14px;
}

.flash-success {
  background: rgba(126, 224, 129, 0.16);
  color: #cbffd0;
}

.flash-error {
  background: rgba(239, 107, 115, 0.16);
  color: #ffd3d7;
}

.two-col,
.metric-grid,
.chip-grid,
.item-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.action-grid {
  align-items: stretch;
}

.metric-card {
  padding: 14px;
}

.metric-card span {
  color: var(--muted);
  font-size: 12px;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 20px;
}

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

.item-card {
  display: grid;
  gap: 12px;
}

.bill-editor {
  display: grid;
  gap: 14px;
}

.image-picker {
  display: grid;
  gap: 8px;
}

.image-picker > span {
  color: var(--muted);
  font-size: 12px;
}

.image-preview {
  min-height: 54px;
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #141820;
  font-size: 13px;
}

.image-preview span:empty {
  display: none;
}

.image-preview img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
}

.hidden {
  display: none !important;
}

.image-state {
  color: var(--accent);
  font-size: 13px;
}

.image-warning {
  color: var(--warning);
}

#invoice-upload-state {
  min-height: 20px;
  line-height: 1.45;
}

.attachment-row {
  padding: 10px 12px;
  border-radius: 8px;
  background: #21262e;
  color: var(--muted);
  font-size: 13px;
}

.attachment-thumb {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 12px;
  align-items: center;
}

.attachment-meta {
  display: grid;
  gap: 8px;
}

.attachment-thumb img {
  width: 88px;
  height: 88px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
}

.settings-sync {
  margin-top: 12px;
}

.export-data-card {
  display: grid;
  gap: 10px;
}

.user-list {
  margin-top: 12px;
}

.checkbox-row {
  display: inline-flex !important;
  grid-template-columns: auto 1fr;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
}

.checkbox-row input {
  width: auto;
}

.variant-block {
  display: grid;
  gap: 10px;
  padding-top: 4px;
}

.variant-head,
.variant-row {
  display: grid;
  gap: 8px;
  align-items: end;
}

.variant-head {
  grid-template-columns: 1fr auto;
  color: var(--muted);
  font-size: 12px;
}

.variant-row {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 86px auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #141820;
}

.variant-row label {
  display: grid;
  gap: 6px;
}

.variant-row span {
  color: var(--muted);
  font-size: 12px;
}

.variant-row input {
  padding: 10px;
}

.korean-reference {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #141820;
  color: var(--muted);
  font-size: 13px;
}

.korean-reference b {
  color: var(--text);
  font-weight: 600;
}

.krw-display {
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0;
}

.krw-display b {
  color: var(--muted);
  font-size: inherit;
  letter-spacing: 0;
  font-weight: 600;
}

.live-summary {
  margin-bottom: 12px;
}

.loading-panel {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 12px;
  border: 1px solid rgba(126, 224, 129, 0.22);
  border-radius: 8px;
  color: var(--accent);
  background: rgba(126, 224, 129, 0.08);
}

.crop-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 14px;
  background: rgba(0, 0, 0, 0.72);
}

.crop-dialog {
  width: min(520px, 100%);
  max-height: 92vh;
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.crop-stage {
  position: relative;
  width: 100%;
  max-height: 70vh;
  overflow: hidden;
  border-radius: 8px;
  background: #080a0d;
  touch-action: none;
}

.crop-stage img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 70vh;
  object-fit: contain;
  user-select: none;
}

.crop-box {
  position: absolute;
  border: 2px solid var(--accent);
  background: rgba(126, 224, 129, 0.08);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.38);
  cursor: move;
}

.crop-box::after {
  content: "";
  position: absolute;
  right: -8px;
  bottom: -8px;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--accent);
  cursor: nwse-resize;
}

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

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 2px solid rgba(126, 224, 129, 0.28);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

button:disabled {
  opacity: 0.62;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.compact-list {
  box-shadow: none;
}

.editor-actions {
  position: sticky;
  bottom: 12px;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  background: rgba(14, 16, 20, 0.92);
  backdrop-filter: blur(10px);
}

.filter-row {
  justify-content: flex-start;
  gap: 8px;
  overflow-x: auto;
}

.filter-chip.active {
  background: rgba(126, 224, 129, 0.18);
  color: var(--accent);
}

@media (max-width: 420px) {
  .two-col,
  .metric-grid,
  .chip-grid,
  .item-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: center;
  }

  .top-actions {
    flex-direction: row;
    align-items: center;
  }

  .home-stats,
  .bill-row {
    grid-template-columns: 1fr;
  }

  .variant-row {
    grid-template-columns: 1fr 1fr;
  }

  .variant-row .remove-variant {
    grid-column: 1 / -1;
  }
}

/* Warm paper UI refresh. UI-only overrides; no behavior changes. */
:root {
  color-scheme: light;
  --bg: #f6f2ea;
  --paper: #fffdf8;
  --panel: #fffaf1;
  --panel-alt: #fbf4e7;
  --line: #dfd3bf;
  --line-strong: #c9b99d;
  --text: #2a241d;
  --muted: #7d7162;
  --accent: #3f7f68;
  --accent-strong: #27614d;
  --accent-soft: #e8f1eb;
  --danger: #bd4b43;
  --danger-soft: #fbebe8;
  --warning: #a86516;
  --shadow: 0 10px 28px rgba(80, 58, 31, 0.09);
  --shadow-tight: 0 3px 12px rgba(80, 58, 31, 0.08);
}

body {
  background:
    linear-gradient(90deg, rgba(90, 70, 42, 0.025) 1px, transparent 1px),
    linear-gradient(180deg, #fbf7ef 0%, #f2ebdf 100%);
  background-size: 22px 22px, auto;
  color: var(--text);
  font-family: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

.app-shell {
  max-width: 560px;
  padding: 18px 14px 34px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: -18px -14px 16px;
  padding: 16px 14px 12px;
  background: rgba(246, 242, 234, 0.92);
  border-bottom: 1px solid rgba(201, 185, 157, 0.55);
  backdrop-filter: blur(12px);
}

.top-title {
  color: #241d15;
  font-size: 23px;
  font-weight: 850;
}

.page-body {
  gap: 16px;
}

.home-stats {
  gap: 12px;
}

.stat-tile,
.card,
.auth-card,
.list-card,
.item-card,
.chip-card,
.metric-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-tight);
}

.card,
.auth-card {
  padding: 17px;
}

.stat-tile {
  min-height: 88px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(250, 243, 231, 0.92)),
    var(--paper);
}

.stat-tile span,
.stat-tile small,
.stack-form span,
.item-grid span,
.field-help,
.empty-copy,
.muted,
.list-card p,
.meta-row,
.metric-card span,
.image-picker > span,
.variant-head,
.variant-row span,
.krw-display,
.krw-display b {
  color: var(--muted);
}

.stat-tile strong,
.metric-card strong,
.list-card strong,
.bill-summary-line span,
.korean-reference b {
  color: var(--text);
}

.card .section-head,
.item-card .card-row {
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(223, 211, 191, 0.72);
}

.section-head h2 {
  margin: 0;
  color: #241d15;
  font-size: 20px;
  letter-spacing: 0;
}

input,
textarea,
select {
  border: 1px solid var(--line);
  background: #fffefa;
  color: var(--text);
  border-radius: 9px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: rgba(63, 127, 104, 0.72);
  box-shadow: 0 0 0 3px rgba(63, 127, 104, 0.13);
}

input::placeholder,
textarea::placeholder {
  color: #b0a390;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.wide-button,
.compact-button {
  border-radius: 9px;
  letter-spacing: 0;
}

.primary-button {
  background: linear-gradient(180deg, #4f9278, var(--accent-strong));
  color: #fffdf8;
  box-shadow: 0 7px 16px rgba(39, 97, 77, 0.18);
}

.secondary-button {
  background: #efe4d2;
  color: #33281b;
  border: 1px solid #dccab0;
}

.ghost-button {
  background: rgba(255, 253, 248, 0.72);
  border: 1px solid var(--line);
  color: #44392a;
}

.danger-button {
  background: var(--danger-soft);
  border: 1px solid #efc7c0;
  color: var(--danger);
}

.text-link {
  color: var(--accent-strong);
  font-weight: 700;
}

.flash-success {
  background: #e9f5ec;
  color: #245a45;
  border: 1px solid #c5e0ce;
}

.flash-error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #efc7c0;
}

.list-card {
  padding: 15px;
}

.bill-row {
  background:
    linear-gradient(90deg, rgba(63, 127, 104, 0.08), transparent 34%),
    var(--paper);
}

.bill-no {
  border: 1px solid #c8dfd1;
  color: #27614d;
  background: #edf7f1;
}

.bill-summary-line {
  color: var(--muted);
}

.badge,
.filter-chip {
  background: #efe4d2;
  color: #71634f;
}

.badge.synced,
.filter-chip.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.badge.pending {
  background: #fff4d9;
  color: var(--warning);
}

.chip-label {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.metric-card {
  background: linear-gradient(180deg, #fffefa, #faf2e5);
}

.stack-list {
  gap: 16px;
}

#items-list {
  gap: 18px;
}

.item-card {
  position: relative;
  gap: 14px;
  padding: 0;
  overflow: hidden;
  background: #fffdf8;
  border-color: #d5c5aa;
  box-shadow: 0 12px 30px rgba(80, 58, 31, 0.11);
}

.item-card > * {
  margin-left: 16px;
  margin-right: 16px;
}

.item-card > .card-row {
  margin: 0;
  padding: 13px 16px;
  background: linear-gradient(180deg, #f2e7d5, #eadbc3);
  border-bottom: 1px solid #d4c0a1;
}

.item-card > .card-row strong {
  color: #2f2518;
  font-size: 17px;
  font-weight: 850;
}

.item-card > :last-child {
  margin-bottom: 16px;
}

.item-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: linear-gradient(180deg, #4f9278, #c68a3d);
}

.image-preview,
.attachment-row,
.variant-row,
.korean-reference {
  background: #fbf4e7;
  border-color: var(--line);
}

.image-preview {
  color: var(--muted);
}

.image-preview img,
.attachment-thumb img {
  border-color: #d1bea0;
}

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

.variant-block {
  gap: 12px;
}

.variant-head {
  padding-top: 4px;
}

.variant-row {
  border-radius: 9px;
}

.korean-reference {
  color: var(--muted);
}

.loading-panel {
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-color: #c8dfd1;
}

.spinner {
  border-color: rgba(63, 127, 104, 0.25);
  border-top-color: var(--accent-strong);
}

.editor-actions {
  border: 1px solid rgba(201, 185, 157, 0.72);
  background: rgba(255, 253, 248, 0.92);
  box-shadow: 0 10px 28px rgba(80, 58, 31, 0.14);
}

.crop-modal {
  background: rgba(42, 36, 29, 0.55);
}

.crop-dialog {
  background: var(--paper);
  border-color: var(--line);
}

.crop-stage {
  background: #2c261f;
}

.crop-box {
  border-color: #4f9278;
  background: rgba(79, 146, 120, 0.1);
}

.crop-box::after {
  background: #4f9278;
}

.autocomplete-menu {
  background: #fffefa;
  border-color: var(--line);
  box-shadow: var(--shadow);
}

.autocomplete-option {
  color: var(--text);
}

.autocomplete-option:hover {
  background: #f3eadb;
}

.export-data-card {
  background:
    linear-gradient(135deg, rgba(63, 127, 104, 0.09), transparent 38%),
    var(--paper);
}

@media (max-width: 420px) {
  .app-shell {
    padding: 14px 12px 30px;
  }

  .topbar {
    margin: -14px -12px 14px;
    padding: 14px 12px 10px;
  }

  .card,
  .auth-card {
    padding: 15px;
  }

  .item-card > * {
    margin-left: 14px;
    margin-right: 14px;
  }

  .item-card > .card-row {
    padding: 12px 14px;
  }
}
