:root {
  --bg-body: #0b0f17;
  --bg-shell: #121824;
  --bg-card: #1a2232;
  --bg-elevated: #212b3f;
  --bg-input: #0f1521;
  --border: #263248;
  --border-strong: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --emerald: #22c55e;
  --emerald-bg: rgba(34, 197, 94, 0.15);
  --emerald-border: rgba(34, 197, 94, 0.45);

  --amber: #f59e0b;
  --amber-bg: rgba(245, 158, 11, 0.14);
  --amber-border: rgba(245, 158, 11, 0.55);

  --sky: #38bdf8;
  --sky-bg: rgba(56, 189, 248, 0.14);
  --sky-border: rgba(56, 189, 248, 0.45);

  --rose: #f43f5e;
  --rose-bg: rgba(244, 63, 94, 0.14);
  --rose-border: rgba(244, 63, 94, 0.45);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --nav-height: 68px;
  --shell-width: 520px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  background-color: var(--bg-body);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

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

.app-shell {
  min-height: 100vh;
  max-width: var(--shell-width);
  margin: 0 auto;
  background-color: var(--bg-shell);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 12px);
}

@media (max-width: 520px) {
  .app-shell {
    border-left: none;
    border-right: none;
  }
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(18, 24, 36, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.header-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Main content */
.tab-content {
  padding: 14px 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Controls & Inputs */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toolbar-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.input,
.select,
.textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text-primary);
  min-height: 40px;
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--emerald);
}

.textarea {
  resize: vertical;
  min-height: 84px;
}

.search-wrap {
  position: relative;
  flex: 1;
}

.search-input {
  padding-right: 34px;
}

.clear-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border-radius: 999px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.clear-btn:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

/* Chip bars */
.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.chip-row::-webkit-scrollbar {
  display: none;
}

.chip {
  flex-shrink: 0;
  min-height: 34px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chip.is-active {
  background: var(--emerald-bg);
  border-color: var(--emerald-border);
  color: var(--emerald);
  font-weight: 600;
}

.chip.is-warn.is-active {
  background: var(--rose-bg);
  border-color: var(--rose-border);
  color: var(--rose);
}

/* Buttons */
.btn {
  min-height: 38px;
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  border: 1px solid transparent;
  transition: opacity 0.15s ease, background-color 0.15s ease;
}

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

.btn-primary {
  background: var(--emerald);
  color: #052e16;
}

.btn-secondary {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-secondary);
}

.btn-danger {
  background: var(--rose-bg);
  border-color: var(--rose-border);
  color: var(--rose);
}

.btn-sm {
  min-height: 32px;
  padding: 5px 10px;
  font-size: 12px;
}

.btn-icon {
  min-width: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Cards */
.card-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-flagged {
  border-color: var(--rose-border);
}

.card-banner {
  position: relative;
  min-height: 92px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
}

.card-banner::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.12) 0%, rgba(15, 23, 42, 0.72) 100%);
  pointer-events: none;
}

.card-banner > * {
  position: relative;
  z-index: 1;
}

.banner-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.banner-source {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #f8fafc;
}

.banner-title {
  font-size: 17px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.01em;
  margin-top: 12px;
}

.card-body {
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 12px;
}

.meta-dot {
  color: var(--text-muted);
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.badge-onhand {
  background: var(--emerald-bg);
  border-color: var(--emerald-border);
  color: var(--emerald);
}

.badge-sale {
  background: var(--amber-bg);
  border-color: var(--amber-border);
  color: var(--amber);
}

.badge-seasonal {
  background: var(--sky-bg);
  border-color: var(--sky-border);
  color: var(--sky);
}

.badge-excluded {
  background: var(--rose-bg);
  border-color: var(--rose-border);
  color: var(--rose);
}

.badge-neutral {
  background: var(--bg-elevated);
  border-color: var(--border);
  color: var(--text-secondary);
}

.card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 2px;
}

.card-actions-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.source-link {
  font-size: 12px;
  font-weight: 600;
  color: var(--sky);
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--sky-border);
  background: var(--sky-bg);
}

/* Price tags: verified vs estimate */
.price-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.price-verified {
  background: var(--emerald-bg);
  border: 1px solid var(--emerald-border);
  color: var(--emerald);
}

.price-estimate {
  background: var(--amber-bg);
  border: 1px dashed var(--amber-border);
  color: var(--amber);
}

.price-unknown {
  background: var(--bg-elevated);
  border: 1px dashed var(--border-strong);
  color: var(--text-muted);
}

.price-tag-label {
  font-size: 10px;
  font-weight: 600;
  opacity: 0.9;
}

/* Ingredient preview tags */
.ing-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.ing-tag {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.ing-tag.is-have {
  border-color: var(--emerald-border);
  color: var(--emerald);
}

.ing-tag.is-excluded {
  border-color: var(--rose-border);
  color: var(--rose);
}

/* Form panel */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.panel-title {
  font-size: 14px;
  font-weight: 700;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.field-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-secondary);
}

.ing-form-row {
  display: grid;
  grid-template-columns: 1.4fr 0.7fr 0.7fr 1.1fr auto;
  gap: 6px;
  align-items: center;
}

@media (max-width: 440px) {
  .ing-form-row {
    grid-template-columns: 1fr 0.6fr 0.6fr;
  }
}

/* Comparison Box */
.compare-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.compare-cell {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.compare-cell.is-savings {
  border-color: var(--emerald-border);
  background: rgba(34, 197, 94, 0.08);
}

.compare-label {
  font-size: 11px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.compare-value {
  font-size: 17px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.compare-sub {
  font-size: 11px;
  color: var(--emerald);
  font-weight: 600;
}

/* Stepper */
.stepper {
  display: inline-flex;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.stepper-btn {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.stepper-btn:hover {
  background: var(--bg-elevated);
}

.stepper-val {
  min-width: 48px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Picked Item */
.picked-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.picked-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.picked-title {
  font-size: 15px;
  font-weight: 700;
}

.picked-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

/* Grocery List */
.grocery-summary {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.grocery-summary-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.grocery-store {
  font-size: 15px;
  font-weight: 700;
}

.grocery-total-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.grocery-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.category-block {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.category-header {
  background: var(--bg-elevated);
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.grocery-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.grocery-row:last-child {
  border-bottom: none;
}

.grocery-row-info {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.grocery-name {
  font-size: 14px;
  font-weight: 600;
}

.grocery-qty {
  font-size: 12px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.grocery-row-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Pantry & Setup */
.pantry-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.pantry-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.pantry-row-name {
  font-size: 14px;
  font-weight: 500;
  flex: 1;
  min-width: 0;
}

.pantry-row-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.segmented {
  display: inline-flex;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.seg-btn {
  min-height: 28px;
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.seg-btn.is-on {
  background: var(--emerald-bg);
  color: var(--emerald);
}

.seg-btn.is-off {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
}

.setting-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Empty state */
.empty-box {
  background: var(--bg-card);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 24px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--shell-width);
  height: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(15, 21, 33, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  z-index: 30;
}

.nav-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
}

.nav-btn.is-active {
  color: var(--emerald);
}

.nav-icon {
  width: 20px;
  height: 20px;
}

.nav-badge {
  position: absolute;
  top: 7px;
  right: calc(50% - 20px);
  min-width: 17px;
  height: 17px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--emerald);
  color: #052e16;
  font-size: 10px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.nav-badge[hidden] {
  display: none;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(2, 6, 23, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg-shell);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.order-preview {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  max-height: 300px;
  overflow-y: auto;
  color: var(--text-primary);
}

/* Recipe Print Card inside Modal */
.recipe-print-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.print-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.print-ing-list {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px 12px;
}

.print-ing-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
}

.print-steps {
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.print-steps li {
  font-size: 13px;
  line-height: 1.5;
  break-inside: avoid;
}

/* Print Stylesheet */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }

  .app-shell,
  .bottom-nav,
  .no-print {
    display: none !important;
  }

  .modal-backdrop {
    position: static !important;
    background: none !important;
    padding: 0 !important;
  }

  .modal-backdrop:not(.print-active) {
    display: none !important;
  }

  .modal-card {
    max-width: 100% !important;
    max-height: none !important;
    border: none !important;
    background: #ffffff !important;
    color: #000000 !important;
    padding: 0 !important;
    overflow: visible !important;
  }

  .card-banner {
    background: #f3f4f6 !important;
    color: #000000 !important;
    border: 2px solid #111827 !important;
    border-radius: 10px !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .card-banner::after {
    display: none !important;
  }

  .banner-title,
  .banner-source {
    color: #000000 !important;
    background: #ffffff !important;
    border-color: #111827 !important;
  }

  .print-section-title,
  .meta-row {
    color: #111827 !important;
  }

  .print-ing-item {
    background: #ffffff !important;
    border: 1px solid #d1d5db !important;
    color: #000000 !important;
  }
}
