:root {
  --bg-page: #f1f5f9;
  --bg-card: #ffffff;
  --bg-header: #0f172a;
  --bg-subtle: #f8fafc;
  --border: #cbd5e1;
  --border-light: #e2e8f0;
  --text-main: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --success: #059669;
  --success-dark: #047857;
  --success-soft: #ecfdf5;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-page);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  min-height: 100%;
}

.hidden {
  display: none !important;
}

/* State Screens (Loading, Error, Submitted Receipt) */
.state-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(180deg, #0f172a 0%, #1e293b 42%, var(--bg-page) 42%);
}

.state-card {
  width: 100%;
  max-width: 520px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  box-shadow: var(--shadow-md);
  text-align: center;
}

.state-icon {
  font-size: 46px;
  margin-bottom: 12px;
  line-height: 1;
}

.state-card h2 {
  margin: 0 0 8px 0;
  font-size: 22px;
  color: var(--text-main);
}

.state-card p {
  margin: 0 0 14px 0;
  color: var(--text-secondary);
  font-size: 15px;
}

.state-summary-box {
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 14px;
  text-align: left;
  margin: 16px 0;
  font-size: 14px;
}

.spinner {
  width: 38px;
  height: 38px;
  border: 4px solid #e2e8f0;
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 0 auto 16px auto;
  animation: spin 0.8s linear infinite;
}

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

/* Main Shell */
.audit-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 92px;
}

/* Header */
.top-header {
  background: var(--bg-header);
  color: #f8fafc;
  padding: 14px 16px 12px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
}

.top-header-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.header-kicker {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #93c5fd;
  text-transform: uppercase;
  margin-bottom: 3px;
}

.header-title {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  color: #ffffff;
  line-height: 1.2;
}

.header-meta {
  margin-top: 5px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.12);
  color: #e2e8f0;
  padding: 3px 9px;
  border-radius: 999px;
}

.sync-pill {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: rgba(16, 185, 129, 0.16);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.sync-pill.offline {
  background: rgba(245, 158, 11, 0.18);
  color: #fde68a;
  border-color: rgba(245, 158, 11, 0.45);
}

.sync-pill.saving {
  background: rgba(59, 130, 246, 0.2);
  color: #bfdbfe;
  border-color: rgba(59, 130, 246, 0.45);
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.notice-banner {
  max-width: 900px;
  margin: 10px auto 0 auto;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  background: rgba(245, 158, 11, 0.16);
  border: 1px solid rgba(245, 158, 11, 0.4);
  color: #fef3c7;
}

.notice-banner.info {
  background: rgba(59, 130, 246, 0.18);
  border-color: rgba(96, 165, 250, 0.45);
  color: #dbeafe;
}

/* Category Tab Strip */
.category-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.category-scroll {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 14px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.category-scroll::-webkit-scrollbar {
  display: none;
}

.cat-tab {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 13px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text-main);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  min-height: 42px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.cat-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.cat-tab .cat-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  background: #e2e8f0;
  color: #334155;
}

.cat-tab.has-items .cat-badge {
  background: var(--success-soft);
  color: var(--success-dark);
}

.cat-tab.is-none .cat-badge {
  background: #e0f2fe;
  color: #0369a1;
}

.cat-tab.active .cat-badge {
  background: rgba(255, 255, 255, 0.24);
  color: #ffffff;
}

/* Main Content */
.audit-main {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 16px 14px 24px 14px;
  flex: 1;
}

.category-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.category-title {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  color: var(--text-main);
}

.category-subtitle {
  margin: 2px 0 0 0;
  font-size: 13.5px;
  color: var(--text-secondary);
}

.none-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 13px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-secondary);
  cursor: pointer;
  min-height: 40px;
  user-select: none;
}

.none-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  margin: 0;
}

.none-toggle.checked {
  background: #e0f2fe;
  border-color: #0284c7;
  color: #0369a1;
}

/* Entry Form Card */
.entry-card {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
}

.entry-card.editing {
  border-color: var(--warning);
  box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.15);
}

.entry-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.entry-mode-badge {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary-dark);
  background: var(--primary-soft);
  padding: 4px 10px;
  border-radius: 999px;
}

.entry-card.editing .entry-mode-badge {
  color: #b45309;
  background: var(--warning-soft);
}

.fields-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 640px) {
  .fields-grid {
    grid-template-columns: 1fr 1fr;
  }
  .field-group.full-width {
    grid-column: 1 / -1;
  }
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.field-req {
  color: var(--danger);
  margin-left: 2px;
}

.field-opt {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-muted);
}

.field-input,
.field-select {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  font-size: 16px; /* Prevents iOS Safari zoom on focus */
  font-family: inherit;
  color: var(--text-main);
  background: #ffffff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field-input:focus,
.field-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.16);
}

/* Segmented Toggle (e.g. OH / UG, Regular / Split) */
.segmented-group {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.seg-btn {
  min-height: 46px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text-main);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

/* Quick Preset Chips */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.quick-chip {
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  min-height: 32px;
}

.quick-chip:active,
.quick-chip.selected {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-dark);
}

.validation-msg {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  border: 1px solid #fecaca;
  color: var(--danger);
  font-size: 13.5px;
  font-weight: 700;
}

.entry-actions {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

@media (min-width: 520px) {
  .entry-actions {
    grid-template-columns: 1fr 1fr;
  }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 46px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: transform 0.08s, background 0.15s;
}

.btn:active {
  transform: scale(0.985);
}

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

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

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

.btn-secondary {
  background: var(--primary-soft);
  color: var(--primary-dark);
  border-color: #bfdbfe;
}

.btn-success {
  background: var(--success);
  color: #ffffff;
}

.btn-success:hover {
  background: var(--success-dark);
}

.btn-outline {
  background: #ffffff;
  color: var(--text-main);
  border-color: var(--border);
}

.btn-danger-outline {
  background: #ffffff;
  color: var(--danger);
  border-color: #fecaca;
}

.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  padding: 4px 6px;
}

/* Entered Items List */
.items-section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}

.items-section-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  color: var(--text-main);
}

.items-hint {
  font-size: 12.5px;
  color: var(--text-muted);
}

.items-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-list {
  background: var(--bg-card);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 24px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

.empty-list.confirmed-none {
  background: #f0f9ff;
  border-color: #7dd3fc;
  color: #0369a1;
  font-weight: 600;
}

.emp-group-header {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--primary-dark);
  margin: 6px 0 2px 2px;
}

.item-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 13px 14px;
  box-shadow: var(--shadow-sm);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.item-card-main {
  flex: 1;
  min-width: 0;
}

.item-card-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--text-main);
  word-break: break-word;
}

.item-card-specs {
  margin-top: 5px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.spec-pill {
  font-size: 12.5px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
}

.item-card-notes {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.item-card-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

@media (min-width: 480px) {
  .item-card-actions {
    flex-direction: row;
  }
}

.btn-sm {
  min-height: 36px;
  padding: 6px 11px;
  font-size: 13px;
  border-radius: 7px;
}

/* Sticky Bottom Bar */
.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.08);
  padding: 10px 14px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}

.bottom-bar-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.bottom-count {
  font-size: 14.5px;
  font-weight: 800;
  color: var(--text-main);
}

.bottom-saved {
  font-size: 12px;
  color: var(--text-muted);
}

.bottom-buttons {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.bottom-buttons .btn {
  min-height: 44px;
  padding: 9px 14px;
  font-size: 14px;
}

@media (max-width: 460px) {
  .bottom-bar-inner {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .bottom-summary {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
  }
  .bottom-buttons {
    display: grid;
    grid-template-columns: 1fr 1.3fr;
  }
  .audit-shell {
    padding-bottom: 122px;
  }
}

/* Review Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.65);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

@media (min-width: 600px) {
  .modal-backdrop {
    align-items: center;
    padding: 20px;
  }
}

.modal-sheet {
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  background: var(--bg-card);
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

@media (min-width: 600px) {
  .modal-sheet {
    border-radius: var(--radius-lg);
  }
}

.modal-head {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
}

.icon-close {
  background: none;
  border: none;
  font-size: 28px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
}

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
}

.modal-foot {
  padding: 12px 18px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border-light);
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 10px;
}

.review-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin: 12px 0 16px 0;
}

@media (min-width: 480px) {
  .review-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.review-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  font-size: 14px;
  font-weight: 600;
}

.review-row.warn {
  background: var(--warning-soft);
  border-color: #fde68a;
}

.review-badge {
  font-size: 12.5px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
}

.review-badge.ok {
  background: var(--success-soft);
  color: var(--success-dark);
}

.review-badge.none {
  background: #e0f2fe;
  color: #0369a1;
}

.review-badge.empty {
  background: #fef3c7;
  color: #b45309;
}

.review-warning-box {
  background: var(--warning-soft);
  border: 1px solid #fcd34d;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13.5px;
  color: #92400e;
  margin-bottom: 14px;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  z-index: 200;
  background: #0f172a;
  color: #ffffff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  box-shadow: var(--shadow-md);
  max-width: 92vw;
  text-align: center;
}

.toast.success {
  background: var(--success-dark);
}

.toast.warning {
  background: #b45309;
}

.toast.error {
  background: var(--danger);
}
