/* RAONX 영수증 처리 시스템 — Refined Korean Office aesthetic
   v12 — Design tokens, dark mode, oklch, accessibility, fluid typography */

/* ==========================================
   1. DESIGN TOKENS (CSS custom properties)
   ========================================== */
:root {
  color-scheme: light dark;

  /* Brand — deep teal-slate (절제된 신뢰감) */
  --c-brand-50: oklch(0.97 0.01 220);
  --c-brand-100: oklch(0.93 0.02 220);
  --c-brand-200: oklch(0.85 0.04 220);
  --c-brand-300: oklch(0.72 0.06 220);
  --c-brand-400: oklch(0.58 0.08 220);
  --c-brand-500: oklch(0.45 0.09 220);  /* primary */
  --c-brand-600: oklch(0.36 0.08 220);
  --c-brand-700: oklch(0.28 0.06 220);
  --c-brand-800: oklch(0.20 0.04 220);

  /* Accent — warm amber (인주) */
  --c-accent-100: oklch(0.96 0.04 75);
  --c-accent-300: oklch(0.85 0.10 75);
  --c-accent-500: oklch(0.72 0.16 75);
  --c-accent-600: oklch(0.62 0.16 70);
  --c-accent-700: oklch(0.52 0.14 65);

  /* Status (절제된 신호색) */
  --c-success-bg: oklch(0.95 0.04 155);
  --c-success-fg: oklch(0.40 0.10 155);
  --c-warn-bg: oklch(0.96 0.05 85);
  --c-warn-fg: oklch(0.45 0.12 75);
  --c-danger-bg: oklch(0.96 0.04 25);
  --c-danger-fg: oklch(0.50 0.18 25);
  --c-info-bg: oklch(0.96 0.03 220);
  --c-info-fg: oklch(0.40 0.08 220);

  /* Neutral — warm tinted (종이톤) */
  --c-bg: oklch(0.985 0.005 85);
  --c-bg-elev: oklch(1 0 0);
  --c-bg-subtle: oklch(0.965 0.006 85);
  --c-bg-muted: oklch(0.94 0.008 85);
  --c-fg: oklch(0.20 0.01 220);
  --c-fg-soft: oklch(0.40 0.01 220);
  --c-fg-mute: oklch(0.55 0.01 220);
  --c-fg-faint: oklch(0.70 0.01 220);
  --c-border: oklch(0.90 0.005 220);
  --c-border-strong: oklch(0.80 0.008 220);

  /* Spacing scale (8px rhythm with intentional variations) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;
  --sp-8: 64px;

  /* Radii — subtle, not playful */
  --r-1: 4px;
  --r-2: 6px;
  --r-3: 10px;
  --r-4: 14px;

  /* Typography — modular scale with fluid sizing */
  --fs-xs: clamp(0.72rem, 0.70rem + 0.10vw, 0.80rem);
  --fs-sm: clamp(0.83rem, 0.80rem + 0.12vw, 0.92rem);
  --fs-base: clamp(0.94rem, 0.90rem + 0.18vw, 1.05rem);
  --fs-md: clamp(1.06rem, 1.00rem + 0.30vw, 1.20rem);
  --fs-lg: clamp(1.25rem, 1.18rem + 0.45vw, 1.50rem);
  --fs-xl: clamp(1.50rem, 1.40rem + 0.65vw, 1.95rem);
  --fs-2xl: clamp(1.85rem, 1.70rem + 1vw, 2.50rem);

  --lh-tight: 1.2;
  --lh-snug: 1.35;
  --lh-normal: 1.55;
  --lh-loose: 1.75;

  /* Shadows — subtle, low elevation */
  --shadow-1: 0 1px 2px oklch(0.20 0.01 220 / 0.05);
  --shadow-2: 0 1px 3px oklch(0.20 0.01 220 / 0.06), 0 1px 2px oklch(0.20 0.01 220 / 0.04);
  --shadow-3: 0 4px 12px oklch(0.20 0.01 220 / 0.08), 0 2px 4px oklch(0.20 0.01 220 / 0.04);

  /* Motion */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --d-fast: 140ms;
  --d-base: 220ms;
  --d-slow: 360ms;

  /* Layout */
  --content-max: 1600px;
  --tap-target: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --c-brand-50: oklch(0.18 0.02 220);
    --c-brand-100: oklch(0.22 0.03 220);
    --c-brand-200: oklch(0.30 0.05 220);
    --c-brand-300: oklch(0.40 0.07 220);
    --c-brand-400: oklch(0.55 0.09 220);
    --c-brand-500: oklch(0.70 0.10 220);
    --c-brand-600: oklch(0.80 0.08 220);
    --c-brand-700: oklch(0.88 0.06 220);
    --c-brand-800: oklch(0.94 0.04 220);

    --c-accent-100: oklch(0.20 0.05 75);
    --c-accent-300: oklch(0.32 0.10 75);
    --c-accent-500: oklch(0.78 0.16 75);

    --c-success-bg: oklch(0.20 0.05 155);
    --c-success-fg: oklch(0.85 0.12 155);
    --c-warn-bg: oklch(0.22 0.06 85);
    --c-warn-fg: oklch(0.85 0.14 85);
    --c-danger-bg: oklch(0.22 0.05 25);
    --c-danger-fg: oklch(0.82 0.16 25);
    --c-info-bg: oklch(0.20 0.04 220);
    --c-info-fg: oklch(0.82 0.10 220);

    --c-bg: oklch(0.16 0.008 220);
    --c-bg-elev: oklch(0.20 0.010 220);
    --c-bg-subtle: oklch(0.22 0.010 220);
    --c-bg-muted: oklch(0.26 0.012 220);
    --c-fg: oklch(0.95 0.005 85);
    --c-fg-soft: oklch(0.82 0.005 85);
    --c-fg-mute: oklch(0.65 0.008 85);
    --c-fg-faint: oklch(0.50 0.008 85);
    --c-border: oklch(0.30 0.012 220);
    --c-border-strong: oklch(0.42 0.015 220);

    --shadow-1: 0 1px 2px oklch(0 0 0 / 0.30);
    --shadow-2: 0 1px 3px oklch(0 0 0 / 0.40), 0 1px 2px oklch(0 0 0 / 0.30);
    --shadow-3: 0 4px 12px oklch(0 0 0 / 0.50), 0 2px 4px oklch(0 0 0 / 0.30);
  }
}

/* ==========================================
   2. RESET & BASE
   ========================================== */
*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--c-bg);
  color: var(--c-fg);
  font-family: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  font-feature-settings: 'tnum', 'palt';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.01em;
}

h1, h2, h3, h4 {
  margin: 0;
  font-weight: 600;
  line-height: var(--lh-tight);
  letter-spacing: -0.02em;
  color: var(--c-fg);
}

h1 { font-size: var(--fs-xl); font-weight: 700; }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); }
h4 { font-size: var(--fs-base); }

p { margin: 0; }

a {
  color: var(--c-brand-500);
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}
a:hover { color: var(--c-brand-600); }

/* Numbers & code */
.tabular { font-variant-numeric: tabular-nums; }
code, kbd, .mono {
  font-family: 'JetBrains Mono', 'D2Coding', 'SF Mono', ui-monospace, monospace;
  font-feature-settings: 'tnum';
}

/* ==========================================
   3. ACCESSIBILITY: focus, screen-reader, reduced-motion
   ========================================== */
:focus-visible {
  outline: 2px solid var(--c-brand-500);
  outline-offset: 2px;
  border-radius: var(--r-1);
}
:focus:not(:focus-visible) { outline: none; }

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

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* ==========================================
   4. LAYOUT PRIMITIVES
   ========================================== */
.app-shell {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--sp-5) var(--sp-4) calc(env(safe-area-inset-bottom, 0px) + var(--sp-7));
}

@media (min-width: 768px) {
  .app-shell { padding-inline: var(--sp-5); }
}

/* Cards — used sparingly. Prefer borders over shadows. */
.surface {
  background: var(--c-bg-elev);
  border: 1px solid var(--c-border);
  border-radius: var(--r-3);
}

.surface-subtle {
  background: var(--c-bg-subtle);
  border-radius: var(--r-3);
}

.divide-y > * + * { border-top: 1px solid var(--c-border); }

/* ==========================================
   5. HEADER
   ========================================== */
.app-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-4);
  padding-block: var(--sp-3) var(--sp-5);
  border-bottom: 1px solid var(--c-border);
  margin-bottom: var(--sp-5);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: var(--sp-3);
}
.brand-mark {
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--c-accent-600);
  text-transform: uppercase;
}
.brand-title {
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--c-fg);
}
.brand-meta {
  font-size: var(--fs-xs);
  color: var(--c-fg-mute);
  font-variant-numeric: tabular-nums;
}

/* ==========================================
   6. TAB BAR
   ========================================== */
.tab-bar {
  display: flex;
  gap: var(--sp-1);
  border-bottom: 1px solid var(--c-border);
  margin-bottom: var(--sp-5);
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border: none;
  background: transparent;
  color: var(--c-fg-mute);
  font-size: var(--fs-sm);
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  position: relative;
  transition: color var(--d-fast) var(--ease-out);
  min-height: var(--tap-target);
}
.tab-btn:hover { color: var(--c-fg-soft); }
.tab-btn.active {
  color: var(--c-fg);
  font-weight: 600;
}
.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: var(--sp-3);
  right: var(--sp-3);
  height: 2px;
  background: var(--c-accent-500);
  border-radius: 2px 2px 0 0;
}

/* ==========================================
   7. UPLOAD AREA (drop zone)
   ========================================== */
.upload-area {
  border: 1px dashed var(--c-border-strong);
  border-radius: var(--r-3);
  padding: var(--sp-6);
  background: var(--c-bg-subtle);
  transition: border-color var(--d-fast) var(--ease-out), background var(--d-fast) var(--ease-out);
  cursor: pointer;
  text-align: center;
}
.upload-area:hover, .upload-area.drag-over {
  border-color: var(--c-brand-500);
  background: var(--c-brand-50);
}
.upload-area.drag-over { border-style: solid; }

.upload-icon {
  width: 40px; height: 40px;
  margin: 0 auto var(--sp-3);
  border-radius: var(--r-2);
  display: grid;
  place-items: center;
  background: var(--c-bg-muted);
  color: var(--c-fg-mute);
  font-size: 1.1rem;
}

/* ==========================================
   8. BUTTONS
   ========================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  min-height: var(--tap-target);
  font-size: var(--fs-sm);
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--r-2);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--d-fast) var(--ease-out), border-color var(--d-fast), color var(--d-fast), transform var(--d-fast);
  white-space: nowrap;
  letter-spacing: -0.01em;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--c-brand-500);
  color: var(--c-bg-elev);
}
.btn-primary:hover:not(:disabled) { background: var(--c-brand-600); }

.btn-accent {
  background: var(--c-accent-600);
  color: oklch(1 0 0);
}
.btn-accent:hover:not(:disabled) { background: var(--c-accent-700); }

.btn-success {
  background: var(--c-success-fg);
  color: var(--c-bg-elev);
}
.btn-success:hover:not(:disabled) { filter: brightness(1.08); }

.btn-secondary {
  background: var(--c-bg-elev);
  color: var(--c-fg);
  border-color: var(--c-border-strong);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--c-bg-subtle);
  border-color: var(--c-fg-mute);
}

.btn-ghost {
  background: transparent;
  color: var(--c-fg-soft);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) {
  background: var(--c-bg-subtle);
  color: var(--c-fg);
}

.btn-danger {
  background: transparent;
  color: var(--c-danger-fg);
  border-color: var(--c-border);
}
.btn-danger:hover:not(:disabled) {
  background: var(--c-danger-bg);
  border-color: var(--c-danger-fg);
}

.btn-sm {
  padding: var(--sp-2) var(--sp-3);
  min-height: 36px;
  font-size: var(--fs-xs);
}

.btn-block { width: 100%; }

/* Icon-only buttons — must have aria-label */
.btn-icon {
  width: var(--tap-target);
  height: var(--tap-target);
  padding: 0;
  border-radius: var(--r-2);
  background: transparent;
  border: 1px solid transparent;
  color: var(--c-fg-mute);
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  transition: background var(--d-fast), color var(--d-fast);
}
.btn-icon:hover { background: var(--c-bg-subtle); color: var(--c-fg); }
.btn-icon-sm { width: 32px; height: 32px; }

/* ==========================================
   9. FORMS
   ========================================== */
.field {
  display: grid;
  gap: var(--sp-2);
}
.field-label {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--c-fg-soft);
  letter-spacing: 0.02em;
}
.field-help {
  font-size: var(--fs-xs);
  color: var(--c-fg-mute);
}

.input, .select, .textarea {
  width: 100%;
  padding: 10px var(--sp-3);
  min-height: var(--tap-target);
  background: var(--c-bg-elev);
  color: var(--c-fg);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-2);
  font-size: var(--fs-sm);
  font-family: inherit;
  transition: border-color var(--d-fast), box-shadow var(--d-fast);
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--c-fg-faint); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--c-brand-500);
  box-shadow: 0 0 0 3px var(--c-brand-100);
}
.input::placeholder, .textarea::placeholder { color: var(--c-fg-faint); }

.input[type="date"] { font-variant-numeric: tabular-nums; }

/* ==========================================
   10. TABLE (data entry)
   ========================================== */
.data-entry-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--fs-sm);
}
.data-entry-table th,
.data-entry-table td {
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--c-border);
  border-right: 1px solid var(--c-border);
  white-space: nowrap;
  text-align: left;
}
.data-entry-table th:last-child,
.data-entry-table td:last-child {
  border-right: none;
}
.data-entry-table tbody tr:last-child td {
  border-bottom: none;
}
.data-entry-table th {
  position: sticky;
  top: 0;
  background: var(--c-bg-muted);
  border-bottom: 1px solid var(--c-border-strong);
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--c-fg-mute);
  letter-spacing: 0.04em;
  padding-block: var(--sp-3);
  z-index: 2;
}

/* Column resize handle */
.data-entry-table th { position: relative; }
.col-resize-handle {
  position: absolute;
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 3;
  user-select: none;
  background: transparent;
  transition: background var(--d-fast) var(--ease-out);
}
.col-resize-handle:hover,
.col-resize-handle.dragging {
  background: var(--c-accent);
}
.data-entry-table.resizing { user-select: none; }
.data-entry-table.resizing td.cell-expand .cell-input,
.data-entry-table.resizing td.cell-expand .cell-select { pointer-events: none; }
.data-entry-table tbody tr:hover { background: var(--c-bg-subtle); }
.data-entry-table td.cell-expand { position: relative; white-space: normal; }

td.cell-expand .cell-input,
td.cell-expand .cell-select {
  width: 100%;
  min-height: 36px;
  padding: var(--sp-2);
  background: transparent;
  color: var(--c-fg);
  font-size: var(--fs-sm);
  font-family: inherit;
  border: 1px solid transparent;
  border-radius: var(--r-1);
  transition: background var(--d-fast), border-color var(--d-fast);
}
td.cell-expand .cell-input:hover,
td.cell-expand .cell-select:hover {
  background: var(--c-bg-elev);
  border-color: var(--c-border);
}
td.cell-expand .cell-input:focus,
td.cell-expand .cell-select:focus {
  position: absolute;
  inset: 0;
  z-index: 20;
  min-width: 100%;
  width: max-content;
  max-width: 420px;
  background: var(--c-bg-elev);
  border-color: var(--c-brand-500);
  box-shadow: 0 0 0 3px var(--c-brand-100), var(--shadow-3);
  outline: none;
  padding: 8px var(--sp-3);
}

td.cell-expand input[type="date"].cell-input { cursor: pointer; }
td.cell-expand input[type="date"].cell-input::-webkit-calendar-picker-indicator {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  opacity: 0;
  cursor: pointer;
}

/* Scrollbar — minimal */
.overflow-x-auto {
  scrollbar-width: thin;
  scrollbar-color: var(--c-border-strong) transparent;
}
.overflow-x-auto::-webkit-scrollbar { height: 8px; width: 8px; }
.overflow-x-auto::-webkit-scrollbar-track { background: transparent; }
.overflow-x-auto::-webkit-scrollbar-thumb { background: var(--c-border-strong); border-radius: 4px; }
.overflow-x-auto::-webkit-scrollbar-thumb:hover { background: var(--c-fg-faint); }

/* ==========================================
   11. PROGRESS / STEP INDICATOR
   ========================================== */
.progress-bar {
  height: 6px;
  background: var(--c-bg-muted);
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar > div {
  height: 100%;
  background: var(--c-brand-500);
  transition: width var(--d-slow) var(--ease-out);
}

.step-dot {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 600;
  font-size: var(--fs-xs);
  background: var(--c-bg-muted);
  color: var(--c-fg-mute);
  transition: all var(--d-base) var(--ease-out);
}
.step-dot.active { background: var(--c-brand-500); color: var(--c-bg-elev); }
.step-dot.completed { background: var(--c-success-fg); color: var(--c-bg-elev); }

.step-line { height: 2px; flex: 1; background: var(--c-border); }
.step-line.active { background: var(--c-brand-500); }
.step-line.completed { background: var(--c-success-fg); }

/* ==========================================
   12. BADGES & STATUS
   ========================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px var(--sp-2);
  border-radius: var(--r-1);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge-processing { background: var(--c-warn-bg); color: var(--c-warn-fg); }
.badge-done { background: var(--c-success-bg); color: var(--c-success-fg); }
.badge-error { background: var(--c-danger-bg); color: var(--c-danger-fg); }
.badge-info { background: var(--c-info-bg); color: var(--c-info-fg); }

/* ==========================================
   13. SPINNER
   ========================================== */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--c-border-strong);
  border-top-color: var(--c-brand-500);
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.7s linear infinite;
}
.spinner-lg { width: 36px; height: 36px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================
   14. TOAST
   ========================================== */
.toast {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  background: var(--c-bg-elev);
  color: var(--c-fg);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-2);
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-3);
  animation: slide-in var(--d-base) var(--ease-out);
}
.toast.success { border-left: 3px solid var(--c-success-fg); }
.toast.warning { border-left: 3px solid var(--c-warn-fg); }
.toast.error   { border-left: 3px solid var(--c-danger-fg); }
.toast.info    { border-left: 3px solid var(--c-brand-500); }

@keyframes slide-in {
  from { transform: translateY(-8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ==========================================
   15. MODAL / DIALOG
   ========================================== */
.modal-overlay {
  background: oklch(0.20 0.01 220 / 0.45);
  animation: fade-in var(--d-base) var(--ease-out);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal-panel {
  background: var(--c-bg-elev);
  border: 1px solid var(--c-border);
  border-radius: var(--r-4);
  box-shadow: var(--shadow-3);
}

/* ==========================================
   16. DRAG & DROP rows
   ========================================== */
.drag-handle {
  cursor: grab;
  user-select: none;
  color: var(--c-fg-faint);
  font-size: 13px;
  text-align: center;
  width: var(--tap-target);
  min-width: 32px;
  transition: color var(--d-fast);
  touch-action: none;
}
.drag-handle:hover { color: var(--c-brand-500); }
.drag-handle:active { cursor: grabbing; }

tr.dragging { opacity: 0.4; background: var(--c-brand-50) !important; }
tr.drag-over-top { box-shadow: inset 0 2px 0 var(--c-brand-500); }
tr.drag-over-bottom { box-shadow: inset 0 -2px 0 var(--c-brand-500); }

/* ==========================================
   17. APPLY-DOWN BUTTON (table)
   ========================================== */
.dropdown-wrap { display: flex; align-items: center; gap: 2px; }
.dropdown-wrap .cell-select { flex: 1; min-width: 0; }

.btn-apply-down {
  display: grid; place-items: center;
  width: 28px; height: 28px;
  border: none;
  background: transparent;
  color: var(--c-fg-faint);
  border-radius: var(--r-1);
  cursor: pointer;
  font-size: 11px;
  flex-shrink: 0;
  transition: all var(--d-fast);
}
.btn-apply-down:hover { background: var(--c-brand-50); color: var(--c-brand-600); }

.apply-down-menu {
  position: absolute;
  right: 0; top: 100%;
  z-index: 30;
  background: var(--c-bg-elev);
  border: 1px solid var(--c-border);
  border-radius: var(--r-2);
  box-shadow: var(--shadow-3);
  padding: var(--sp-1);
  min-width: 160px;
  animation: fade-in var(--d-fast);
}
.apply-down-menu button {
  display: block;
  width: 100%;
  padding: 8px var(--sp-3);
  text-align: left;
  font-size: var(--fs-xs);
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: var(--r-1);
  color: var(--c-fg);
  font-family: inherit;
}
.apply-down-menu button:hover { background: var(--c-bg-subtle); }

/* ==========================================
   18. THUMBNAILS
   ========================================== */
.receipt-thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: var(--r-2);
  background: var(--c-bg-muted);
}

/* ==========================================
   19. UTILITIES (replacing some Tailwind reliance)
   ========================================== */
.text-mute { color: var(--c-fg-mute); }
.text-soft { color: var(--c-fg-soft); }
.text-faint { color: var(--c-fg-faint); }
.text-brand { color: var(--c-brand-500); }
.text-accent { color: var(--c-accent-700); }
.text-danger { color: var(--c-danger-fg); }
.text-success { color: var(--c-success-fg); }
.tnum { font-variant-numeric: tabular-nums; }
.kr-balance { word-break: keep-all; line-break: strict; }

/* Mobile safe area */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .safe-bottom { padding-bottom: env(safe-area-inset-bottom); }
}

/* ==========================================
   20. RESPONSIVE
   ========================================== */
@media (max-width: 767px) {
  .data-entry-table { font-size: var(--fs-xs); }
  .data-entry-table th { padding: var(--sp-2) var(--sp-2); font-size: 0.65rem; }
  td.cell-expand .cell-input,
  td.cell-expand .cell-select { font-size: var(--fs-xs); min-height: 32px; }

  .table-scroll-hint {
    background: var(--c-warn-bg);
    color: var(--c-warn-fg) !important;
    text-align: center;
    font-weight: 500;
    border-radius: var(--r-1);
    padding: 4px var(--sp-2);
    margin-bottom: 4px;
  }
}

/* PWA icon (legacy) */
.legacy-icon-circle {
  width: 40px; height: 40px;
  border-radius: var(--r-2);
  display: grid; place-items: center;
  background: var(--c-bg-muted);
  color: var(--c-fg-mute);
}

/* ==========================================
   21. MOBILE UI — .ui-mobile (수동 PC/모바일 토글로 <html> 에 부착)
   ------------------------------------------
   미디어 쿼리를 스위치로 쓰지 않는다. 앱에 수동 토글이 있어서
   @media (max-width: 767px) 는 사용자의 선택을 덮어쓸 수 없다.
   새 색 토큰 없음 — 위쪽 --c-* 팔레트만 재사용하므로 다크모드 블록이 그대로 적용된다.
   여기서 새로 만드는 커스텀 프로퍼티는 전부 레이아웃 수치다.
   ========================================== */
.ui-mobile {
  /* 고정 크롬 높이 (레이아웃 수치, 색 아님) */
  --m-appbar-h: 52px;
  --m-actionbar-h: 52px;
  --m-topchrome: calc(var(--m-appbar-h) + env(safe-area-inset-top, 0px));
  --m-botchrome: calc(var(--m-actionbar-h) + env(safe-area-inset-bottom, 0px));

  /* 리스트 메트릭 */
  --m-gutter: var(--sp-4);
  --m-thumb: 72px;
  --m-measure: 680px;

  /* --m-vvoff / --m-vvh 는 JS 가 visualViewport 이벤트에서 써 넣는다.
     여기서 기본값을 선언하지 않는다 — 소비하는 쪽에서 var(..., fallback) 로 받는다. */
}

/* [hidden] 이 display:flex/grid 에 지지 않도록 */
.ui-mobile [hidden] { display: none !important; }

/* 시트 열림 동안 뒤 페이지 스크롤 잠금 (JS 가 <html> 에 부착) */
.ui-mobile.is-sheet-open,
.ui-mobile.is-sheet-open body { overflow: hidden; }

/* 한글 조판 기준: 줄간격 1.5+, letter-spacing 0 이하, 단어 단위 줄바꿈 */
.ui-mobile .m-shell,
.ui-mobile .m-sheet {
  line-height: 1.55;
  letter-spacing: -0.01em;
  word-break: keep-all;
  line-break: strict;
}

/* ---- 21.1 SHELL ---- */
.ui-mobile .m-shell {
  max-width: var(--m-measure);
  margin: 0 auto;
  padding-top: 0;
  padding-inline: 0;              /* 거터는 각 컴포넌트가 갖는다 — sticky 헤더 풀블리드용 */
  /* 액션바 + 세이프에어리어 만큼 비워둔다 */
  padding-bottom: calc(var(--m-botchrome) + var(--sp-5));
  min-height: 100vh;
  min-height: 100svh;
  background: var(--c-bg);
}

/* ---- 21.2 APPBAR ---- */
.ui-mobile .m-appbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: var(--m-topchrome);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: 0;
  padding-left: max(var(--sp-3), env(safe-area-inset-left, 0px));
  padding-right: max(var(--sp-3), env(safe-area-inset-right, 0px));
  background: var(--c-bg-elev);
  border-bottom: 1px solid var(--c-border);
}

.ui-mobile .m-appbar-title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: var(--fs-md);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--c-fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ⋯ 메뉴 — 아이콘 전용이므로 aria-label 필수 */
.ui-mobile .m-appbar-menu {
  flex: 0 0 auto;
  width: var(--tap-target);
  height: var(--tap-target);
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--r-2);
  background: transparent;
  color: var(--c-fg-mute);
  font: inherit;
  font-size: var(--fs-md);
  line-height: 1;
  cursor: pointer;
  transition: background var(--d-fast) var(--ease-out), color var(--d-fast);
}
.ui-mobile .m-appbar-menu:hover { background: var(--c-bg-subtle); color: var(--c-fg); }
.ui-mobile .m-appbar-menu:active { background: var(--c-bg-muted); }

/* ---- 21.3 SAVE CHIP ----
   토스트는 4초 뒤 사라진다. 사용자가 "내 작업이 안전하다"를 확인할 수 있는
   유일한 지속 증거이므로 항상 앱바에 남아 있고 한눈에 읽혀야 한다. */
.ui-mobile .m-savechip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 0 var(--sp-2) 0 var(--sp-2);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-1);
  background: var(--c-bg-subtle);
  color: var(--c-fg-soft);
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.5;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.ui-mobile .m-savechip::before {
  content: '';
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: currentColor;
}
/* 저장 필요 — 앰버 */
.ui-mobile .m-savechip.is-dirty {
  background: var(--c-warn-bg);
  color: var(--c-warn-fg);
  border-color: var(--c-warn-fg);
}
/* 저장 중 — 차분한 맥박, 글로우 없음 */
.ui-mobile .m-savechip.is-saving {
  background: var(--c-info-bg);
  color: var(--c-info-fg);
  border-color: var(--c-info-fg);
}
.ui-mobile .m-savechip.is-saving::before {
  animation: m-pulse 1.4s var(--ease-in-out) infinite;
}
/* 저장 완료 */
.ui-mobile .m-savechip.is-saved {
  background: var(--c-success-bg);
  color: var(--c-success-fg);
  border-color: var(--c-success-fg);
}
/* 눌러서 즉시 저장하게 만들 경우 탭 타깃 확보 */
.ui-mobile button.m-savechip,
.ui-mobile a.m-savechip {
  min-height: var(--tap-target);
  padding-inline: var(--sp-3);
  font-family: inherit;
  cursor: pointer;
}

/* ---- 21.4 DAY HEADER (일자별 sticky) ----
   "2026.07.28 (화) · 3건 · 47,800원"
   앱바 바로 아래에 물려 붙는다: top = 앱바 높이 + safe-area, z-index 는 앱바보다 낮게. */
.ui-mobile .m-dayhead {
  position: sticky;
  top: var(--m-topchrome);
  z-index: 20;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  min-height: 38px;
  padding: var(--sp-2) var(--m-gutter);
  background: var(--c-bg-muted);
  border-top: 1px solid var(--c-border);
  border-bottom: 1px solid var(--c-border);
  color: var(--c-fg-soft);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  word-break: keep-all;
}
.ui-mobile .m-dayhead-date { flex: 0 0 auto; }
.ui-mobile .m-dayhead-sum {
  flex: 0 0 auto;
  color: var(--c-fg-mute);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---- 21.5 LIST & CARD ---- */
.ui-mobile .m-list {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
  background: var(--c-bg-elev);
  border-bottom: 1px solid var(--c-border);
}
.ui-mobile .m-list > li + li,
.ui-mobile .m-list > .m-card + .m-card { border-top: 1px solid var(--c-border); }
.ui-mobile .m-list > li > .m-card { width: 100%; }

/* 카드 전체가 하나의 탭 타깃. 카드 안의 카드 금지 — 테두리 한 줄로만 구분한다. */
.ui-mobile .m-card {
  display: grid;
  grid-template-columns: var(--m-thumb) minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  min-height: calc(var(--m-thumb) + var(--sp-4));
  margin: 0;
  padding: var(--sp-3) var(--m-gutter);
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--c-fg);
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  scroll-margin-top: calc(var(--m-topchrome) + 46px);
  transition: background var(--d-fast) var(--ease-out);
}
.ui-mobile .m-card:hover { background: var(--c-bg-subtle); }
.ui-mobile .m-card:active { background: var(--c-bg-muted); }
.ui-mobile .m-card:focus-visible {
  outline: 2px solid var(--c-brand-500);
  outline-offset: -3px;
  border-radius: 0;
}

/* 썸네일 — 그림자 대신 얇은 테두리 */
.ui-mobile .m-card-thumb {
  width: var(--m-thumb);
  height: var(--m-thumb);
  flex: 0 0 auto;
  display: block;
  object-fit: cover;
  background: var(--c-bg-muted);
  border: 1px solid var(--c-border);
  border-radius: var(--r-1);
}

.ui-mobile .m-card-body {
  min-width: 0;
  display: grid;
  gap: 3px;
}
.ui-mobile .m-card-vendor {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--c-fg);
  letter-spacing: -0.01em;
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ui-mobile .m-card-amount {
  font-size: var(--fs-md);
  font-weight: 700;
  color: var(--c-fg);
  letter-spacing: -0.015em;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
}
.ui-mobile .m-card-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-1);
  font-size: var(--fs-xs);
  color: var(--c-fg-mute);
  line-height: 1.5;
}
/* 계정과목 칩 (표시 전용) */
.ui-mobile .m-card-chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 1px var(--sp-2);
  border: 1px solid var(--c-border);
  border-radius: var(--r-1);
  background: var(--c-bg-subtle);
  color: var(--c-fg-soft);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* 우측 진입 표식 */
.ui-mobile .m-card-go {
  flex: 0 0 auto;
  color: var(--c-fg-faint);
  font-size: var(--fs-sm);
  line-height: 1;
}

/* ---- 21.6 CARD: 대기(OCR 진행) 스켈레톤 ---- */
.ui-mobile .m-card.is-pending { cursor: progress; }
.ui-mobile .m-card.is-pending .m-card-thumb,
.ui-mobile .m-skel {
  animation: m-pulse 1.6s var(--ease-in-out) infinite;
}
.ui-mobile .m-skel {
  display: block;
  height: 12px;
  border-radius: var(--r-1);
  background: var(--c-bg-muted);
}
.ui-mobile .m-skel-vendor { width: 55%; }
.ui-mobile .m-skel-amount { width: 38%; height: 16px; }
.ui-mobile .m-skel-chip { width: 28%; height: 10px; }

/* ---- 21.7 CARD: 인식 실패 ----
   눈에는 띄되 경보처럼 굴지 않는다. 좌측 3px 표시 + 아주 옅은 배경 + 재시도 버튼. */
.ui-mobile .m-card.is-error {
  background: var(--c-danger-bg);
  box-shadow: inset 3px 0 0 var(--c-danger-fg);
  cursor: default;
}
.ui-mobile .m-card.is-error:hover { background: var(--c-danger-bg); }
.ui-mobile .m-card.is-error .m-card-vendor { color: var(--c-danger-fg); }
.ui-mobile .m-card-errmsg {
  font-size: var(--fs-xs);
  color: var(--c-danger-fg);
  line-height: 1.5;
  word-break: keep-all;
}
/* 재시도 — is-error 카드는 <div> 로 두고 이 버튼만 인터랙티브하게 (버튼 중첩 금지) */
.ui-mobile .m-card-retry {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
  min-height: var(--tap-target);
  min-width: var(--tap-target);
  padding: 0 var(--sp-3);
  border: 1px solid var(--c-danger-fg);
  border-radius: var(--r-2);
  background: var(--c-bg-elev);
  color: var(--c-danger-fg);
  font: inherit;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--d-fast) var(--ease-out);
}
.ui-mobile .m-card-retry:hover { background: var(--c-danger-bg); }

/* ---- 21.8 날짜 없음 배지 ----
   이 행들은 맨 아래로 밀리고 하이웍스 임포트를 조용히 깨뜨린다. 무조건 눈에 띄어야 한다. */
.ui-mobile .m-badge-nodate {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px var(--sp-2);
  border: 1px solid var(--c-warn-fg);
  border-radius: var(--r-1);
  background: var(--c-warn-bg);
  color: var(--c-warn-fg);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.5;
  white-space: nowrap;
}
.ui-mobile .m-badge-nodate::before { content: '!'; font-weight: 800; }

/* ---- 21.9 BOTTOM SHEET ----
   ★ 시각 뷰포트에 고정한다. iOS Safari 는 키보드가 올라와도 레이아웃 뷰포트를
     줄이지 않으므로 position:fixed; bottom:0 은 키보드 뒤로 숨는다.
     JS 가 visualViewport 이벤트에서 --m-vvoff (하단 오프셋) 와 --m-vvh (가용 높이) 를 써 넣고,
     값이 없으면 아래 fallback 으로 얌전히 퇴화한다. */
.ui-mobile .m-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 44;
  background: oklch(0.20 0.01 220 / 0.45);
  overscroll-behavior: contain;
  touch-action: none;
  animation: fade-in var(--d-base) var(--ease-out);
}

.ui-mobile .m-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: var(--m-vvoff, 0px);
  z-index: 45;
  display: flex;
  flex-direction: column;
  max-height: var(--m-vvh, 90vh);
  background: var(--c-bg-elev);
  border-top: 1px solid var(--c-border-strong);
  border-radius: var(--r-4) var(--r-4) 0 0;
  box-shadow: var(--shadow-3);
  overscroll-behavior: contain;
  animation: m-sheet-up var(--d-base) var(--ease-out);
}

/* 손잡이 — 44px 드래그 영역, 표시는 4px 바 */
.ui-mobile .m-sheet-grip {
  flex: 0 0 auto;
  position: relative;
  display: block;
  width: 100%;
  height: var(--tap-target);
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: grab;
  touch-action: none;
}
.ui-mobile .m-sheet-grip:active { cursor: grabbing; }
.ui-mobile .m-sheet-grip::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--c-border-strong);
}
.ui-mobile .m-sheet-grip:focus-visible { outline-offset: -4px; }

.ui-mobile .m-sheet-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--m-gutter) var(--sp-3);
  border-bottom: 1px solid var(--c-border);
}
.ui-mobile .m-sheet-title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: var(--fs-md);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.4;
  color: var(--c-fg);
  word-break: keep-all;
}
.ui-mobile .m-sheet-close {
  flex: 0 0 auto;
  width: var(--tap-target);
  height: var(--tap-target);
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--r-2);
  background: transparent;
  color: var(--c-fg-mute);
  font: inherit;
  font-size: var(--fs-md);
  line-height: 1;
  cursor: pointer;
}
.ui-mobile .m-sheet-close:hover { background: var(--c-bg-subtle); color: var(--c-fg); }

.ui-mobile .m-sheet-body {
  flex: 1 1 auto;
  display: grid;
  align-content: start;
  gap: var(--sp-4);
  padding: var(--sp-4) var(--m-gutter);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;   /* 시트를 끝까지 스크롤해도 뒤 페이지가 밀리지 않는다 */
  touch-action: pan-y;
}

.ui-mobile .m-sheet-foot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding-top: var(--sp-3);
  padding-bottom: calc(var(--sp-3) + env(safe-area-inset-bottom, 0px));
  padding-left: max(var(--m-gutter), env(safe-area-inset-left, 0px));
  padding-right: max(var(--m-gutter), env(safe-area-inset-right, 0px));
  background: var(--c-bg-elev);
  border-top: 1px solid var(--c-border);
}
.ui-mobile .m-sheet-foot > .btn,
.ui-mobile .m-sheet-foot > button { flex: 1 1 0; min-height: var(--tap-target); }
/* 키보드가 올라와 --m-vvoff 가 살아 있을 때는 세이프에어리어 여백이 필요 없다.
   JS 가 <html> 에 is-kb 를 붙여 준다. */
.ui-mobile.is-kb .m-sheet-foot { padding-bottom: var(--sp-3); }

/* ---- 21.10 FIELD (시트 내부 입력) ----
   ★ 모든 input 은 16px 이상. 16px 미만이면 iOS 가 포커스 시 자동 확대하고 되돌리지 않는다.
     style.css:817 이 .cell-input 을 ~11.5px 로 낮추므로 시트에서는 반드시 되돌린다. */
.ui-mobile .m-field {
  display: grid;
  gap: var(--sp-2);
}
.ui-mobile .m-field-label {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--c-fg-soft);
  letter-spacing: 0;
  line-height: 1.5;
  word-break: keep-all;
}
.ui-mobile .m-field-help {
  font-size: var(--fs-xs);
  color: var(--c-fg-mute);
  line-height: 1.5;
  word-break: keep-all;
}
.ui-mobile .m-field .m-input,
.ui-mobile .m-field input,
.ui-mobile .m-field select,
.ui-mobile .m-field textarea {
  width: 100%;
  min-height: var(--tap-target);
  padding: 10px var(--sp-3);
  background: var(--c-bg-elev);
  color: var(--c-fg);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-2);
  font-family: inherit;
  font-size: 16px;          /* iOS 자동 확대 방지 — 절대 낮추지 말 것 */
  line-height: 1.5;
  letter-spacing: -0.01em;
  transition: border-color var(--d-fast), box-shadow var(--d-fast);
}
.ui-mobile .m-field textarea { min-height: 88px; resize: vertical; }
.ui-mobile .m-field input:focus,
.ui-mobile .m-field select:focus,
.ui-mobile .m-field textarea:focus,
.ui-mobile .m-field .m-input:focus {
  outline: none;
  border-color: var(--c-brand-500);
  box-shadow: 0 0 0 3px var(--c-brand-100);
}
.ui-mobile .m-field input::placeholder,
.ui-mobile .m-field textarea::placeholder { color: var(--c-fg-faint); }
/* 금액·사업자번호 등 숫자 입력 */
.ui-mobile .m-field input[inputmode="numeric"],
.ui-mobile .m-field input[inputmode="decimal"],
.ui-mobile .m-field input[type="date"],
.ui-mobile .m-field .m-input-num {
  font-variant-numeric: tabular-nums;
}
.ui-mobile .m-field .m-input-num { text-align: right; font-weight: 600; }
/* 테이블용 축소 규칙이 시트로 새어 들어오는 것을 차단 (style.css:816-817) */
.ui-mobile .m-sheet .cell-input,
.ui-mobile .m-sheet .cell-select {
  font-size: 16px;
  min-height: var(--tap-target);
}

/* ---- 21.11 계정과목 빠른 선택 칩 ----
   63개짜리 <select> 는 폰에서 고문이다. 최근 6개를 가로 스크롤 칩으로. */
.ui-mobile .m-chiprow {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin: 0;
  padding: var(--sp-1) 0;          /* 포커스 링 잘림 방지 */
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scroll-behavior: smooth;
  scrollbar-width: none;           /* 스크롤바 숨김, 키보드 접근은 유지 */
  -ms-overflow-style: none;
}
.ui-mobile .m-chiprow::-webkit-scrollbar { width: 0; height: 0; display: none; }

.ui-mobile .m-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap-target);
  padding: 0 var(--sp-3);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-2);
  background: var(--c-bg-elev);
  color: var(--c-fg-soft);
  font-family: inherit;
  font-size: var(--fs-sm);
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1.5;
  white-space: nowrap;
  cursor: pointer;
  scroll-snap-align: start;
  scroll-margin-inline: var(--m-gutter);
  transition: background var(--d-fast) var(--ease-out), border-color var(--d-fast), color var(--d-fast);
}
.ui-mobile .m-chip:hover { background: var(--c-bg-subtle); color: var(--c-fg); }
.ui-mobile .m-chip:active { background: var(--c-bg-muted); }
.ui-mobile .m-chip.is-active {
  background: var(--c-brand-500);
  border-color: var(--c-brand-500);
  color: var(--c-bg-elev);
  font-weight: 600;
}
.ui-mobile .m-chip:focus-visible { outline: 2px solid var(--c-brand-500); outline-offset: 2px; }

/* ---- 21.12 ACTION BAR ----
   촬영(좌) / 저장(우). 삭제는 절대 여기 두지 않는다 — 엄지 존은 생성적 액션 전용. */
.ui-mobile .m-actionbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: var(--m-botchrome);
  padding-top: var(--sp-1);
  padding-bottom: calc(var(--sp-1) + env(safe-area-inset-bottom, 0px));
  padding-left: max(var(--m-gutter), env(safe-area-inset-left, 0px));
  padding-right: max(var(--m-gutter), env(safe-area-inset-right, 0px));
  background: var(--c-bg-elev);
  border-top: 1px solid var(--c-border);
}
.ui-mobile .m-actionbar > * { flex: 0 0 auto; min-height: var(--tap-target); }
.ui-mobile .m-actionbar-save { margin-left: auto; }
.ui-mobile .m-actionbar-save.btn { min-height: var(--tap-target); }
/* 방어 규칙: 파괴적 액션이 실수로 액션바에 들어오면 렌더하지 않는다 */
.ui-mobile .m-actionbar .btn-danger,
.ui-mobile .m-actionbar [data-destructive] { display: none; }
/* 시트가 열리면 액션바를 숨겨 시트 하단과 겹치지 않게 */
.ui-mobile.is-sheet-open .m-actionbar { display: none; }

/* 촬영 — 가장 닿기 쉬운 자리의 주 액션. 둥근 아이콘 박스가 아니라 넓은 직사각 버튼. */
.ui-mobile .m-fab-capture {
  flex: 1 1 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--tap-target);
  padding: 0 var(--sp-5);
  border: 1px solid transparent;
  border-radius: var(--r-2);
  background: var(--c-accent-600);
  color: oklch(1 0 0);
  font-family: inherit;
  font-size: var(--fs-base);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.5;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--d-fast) var(--ease-out), transform var(--d-fast);
}
.ui-mobile .m-fab-capture:hover:not(:disabled) { background: var(--c-accent-700); }
.ui-mobile .m-fab-capture:active:not(:disabled) { transform: translateY(1px); }
.ui-mobile .m-fab-capture:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ---- 21.13 EMPTY STATE ---- */
.ui-mobile .m-empty {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: var(--sp-4);
  padding: var(--sp-8) var(--m-gutter);
  text-align: center;
}
.ui-mobile .m-empty-title {
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--c-fg);
  letter-spacing: -0.02em;
  line-height: 1.5;
  word-break: keep-all;
}
.ui-mobile .m-empty-desc {
  max-width: 24em;
  font-size: var(--fs-sm);
  color: var(--c-fg-mute);
  line-height: 1.6;
  word-break: keep-all;
}
.ui-mobile .m-empty .m-fab-capture,
.ui-mobile .m-empty .btn { flex: 0 0 auto; min-width: 200px; }

/* ---- 21.14 복원 안내 바 ---- */
.ui-mobile .m-restore-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--m-gutter);
  background: var(--c-info-bg);
  color: var(--c-info-fg);
  border-bottom: 1px solid var(--c-border);
  font-size: var(--fs-sm);
  line-height: 1.5;
  animation: slide-in var(--d-base) var(--ease-out);
}
.ui-mobile .m-restore-bar-text {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 600;
  letter-spacing: 0;
  word-break: keep-all;
  font-variant-numeric: tabular-nums;
}
.ui-mobile .m-restore-bar-close {
  flex: 0 0 auto;
  width: var(--tap-target);
  height: var(--tap-target);
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--r-2);
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: var(--fs-md);
  line-height: 1;
  cursor: pointer;
}
.ui-mobile .m-restore-bar-close:hover { background: var(--c-bg-elev); }

/* ---- 21.15 SYNC BAR ---- */
.ui-mobile .m-syncbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-2) var(--sp-3);
  padding: var(--sp-3) var(--m-gutter);
  background: var(--c-bg-subtle);
  border-top: 1px solid var(--c-border);
  border-bottom: 1px solid var(--c-border);
  font-size: var(--fs-xs);
  color: var(--c-fg-mute);
  line-height: 1.5;
  word-break: keep-all;
}
.ui-mobile .m-syncbar-time {
  flex: 1 1 auto;
  min-width: 0;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}
.ui-mobile .m-syncbar-pending {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px var(--sp-2);
  border: 1px solid var(--c-warn-fg);
  border-radius: var(--r-1);
  background: var(--c-warn-bg);
  color: var(--c-warn-fg);
  font-weight: 700;
  letter-spacing: 0;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.ui-mobile .m-syncbar-refresh {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
  min-height: var(--tap-target);
  min-width: var(--tap-target);
  padding: 0 var(--sp-3);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-2);
  background: var(--c-bg-elev);
  color: var(--c-fg);
  font-family: inherit;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--d-fast) var(--ease-out), border-color var(--d-fast);
}
.ui-mobile .m-syncbar-refresh:hover { background: var(--c-bg-subtle); border-color: var(--c-fg-mute); }
.ui-mobile .m-syncbar-refresh:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- 21.16 PAIRING CODE ----
   이 하위 섹션만 .ui-mobile 밖에서도 동작해야 한다: 코드는 PC 화면(.ui-mobile 없음)에
   표시되고 폰에서 입력한다. 전부 새 클래스라 기존 규칙과 충돌하지 않는다.
   (스코프 규칙에 대한 이의: PC 표시가 요구사항이라 스코프를 걸 수 없다.) */
.m-paircode {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4) var(--sp-5);
  background: var(--c-bg-subtle);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-3);
  color: var(--c-fg);
  font-family: 'JetBrains Mono', 'D2Coding', 'SF Mono', ui-monospace, monospace;
  font-size: clamp(2rem, 1.3rem + 3.2vw, 3.25rem);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.28em;
  text-indent: 0.28em;             /* 마지막 글자 뒤 자간 보정 (가운데 정렬 유지) */
  font-variant-numeric: tabular-nums slashed-zero;
  text-transform: uppercase;
  user-select: all;
  -webkit-user-select: all;
}
.m-paircode-hint {
  margin-top: var(--sp-2);
  font-size: var(--fs-xs);
  color: var(--c-fg-mute);
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  word-break: keep-all;
}

/* 폰 쪽 6칸 입력 */
.m-paircode-input {
  display: flex;
  justify-content: center;
  gap: var(--sp-2);
  max-width: 360px;
  margin-inline: auto;
}
.m-paircode-box {
  flex: 1 1 0;
  min-width: 0;
  max-width: 56px;
  height: 56px;
  padding: 0;
  text-align: center;
  background: var(--c-bg-elev);
  color: var(--c-fg);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-2);
  caret-color: var(--c-brand-500);
  font-family: 'JetBrains Mono', 'D2Coding', 'SF Mono', ui-monospace, monospace;
  font-size: 24px;                 /* 16px 이상 — iOS 자동 확대 방지 */
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums slashed-zero;
  transition: border-color var(--d-fast), box-shadow var(--d-fast);
}
.m-paircode-box:focus {
  outline: none;
  border-color: var(--c-brand-500);
  box-shadow: 0 0 0 3px var(--c-brand-100);
}
.m-paircode-box.is-filled { border-color: var(--c-fg-faint); }
.m-paircode-box.is-error { border-color: var(--c-danger-fg); background: var(--c-danger-bg); }

/* ---- 21.17 MOTION ---- */
@keyframes m-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
@keyframes m-sheet-up {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* 모션 최소화 — 위 전역 블록(214행)에 더해 이 섹션의 상태를 명시적으로 정지시킨다 */
@media (prefers-reduced-motion: reduce) {
  .ui-mobile .m-sheet,
  .ui-mobile .m-sheet-backdrop,
  .ui-mobile .m-restore-bar { animation: none; }
  .ui-mobile .m-card.is-pending .m-card-thumb,
  .ui-mobile .m-skel,
  .ui-mobile .m-savechip.is-saving::before {
    animation: none;
    opacity: 1;
  }
  .ui-mobile .m-chiprow { scroll-behavior: auto; }
  .ui-mobile .m-card,
  .ui-mobile .m-chip,
  .ui-mobile .m-fab-capture { transition: none; }
}

/* ---- 21.18 안전망: 모바일에서 인터랙티브 요소 최소 44px ---- */
.ui-mobile .m-shell button:not(.m-card),
.ui-mobile .m-shell [role="button"]:not(.m-card),
.ui-mobile .m-sheet button,
.ui-mobile .m-sheet [role="button"],
.ui-mobile .m-actionbar button,
.ui-mobile .m-appbar button {
  min-height: var(--tap-target);
}
