/* ═══════════════════════════════════════════════════════════
   COMPONENTS.CSS — Reusable UI Components
   ═══════════════════════════════════════════════════════════ */

/* ─── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 22px;
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  transition: all var(--transition-fast);
  white-space: nowrap;
  flex-shrink: 0;
}

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

.btn-primary:hover, .btn-primary:active {
  background: var(--orange-hover);
  transform: scale(0.98);
}

.btn-secondary {
  background: transparent;
  color: var(--orange);
  border: 1.5px solid var(--orange);
}

.btn-secondary:hover, .btn-secondary:active {
  background: var(--orange-glow);
}

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

.btn-ghost:hover {
  border-color: var(--text-muted);
  color: var(--text-primary);
}

.btn-danger {
  background: transparent;
  color: var(--error);
  border: 1.5px solid var(--error);
}

.btn-danger:hover {
  background: rgba(255, 68, 68, 0.1);
}

.btn-sm {
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 600;
}

.btn-xs {
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
}

.btn-icon {
  padding: 8px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: all var(--transition-fast);
}

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

.btn-icon.active {
  color: var(--orange);
  background: var(--orange-glow);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* ─── FAB (Floating Action Button) ─────────────────────── */
.fab {
  position: fixed;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 20px);
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--orange);
  color: #fff;
  font-size: 26px;
  font-weight: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 20px var(--orange-shadow), 0 4px 16px rgba(0,0,0,0.5);
  transition: all var(--transition-med);
  z-index: 50;
  cursor: pointer;
  border: none;
  line-height: 1;
}

.fab:hover, .fab:active {
  background: var(--orange-hover);
  transform: scale(0.95);
  box-shadow: 0 0 28px var(--orange-shadow);
}

.fab-label {
  position: fixed;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 28px);
  right: 84px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-med);
}

.fab:hover + .fab-label {
  opacity: 1;
}

/* ─── Bottom Tab Bar ────────────────────────────────────── */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  /* Center within the max-width app shell */
  max-width: 430px;
  margin: 0 auto;
  height: calc(var(--nav-height) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  z-index: 60;
  /* Glass effect for premium look */
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  background: rgba(13, 13, 13, 0.92);
}

.nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 4px 2px;
  cursor: pointer;
  color: var(--text-muted);
  transition: color var(--transition-fast);
  position: relative;
  background: none;
  border: none;
  font-family: var(--font-body);
}

.nav-tab .tab-icon {
  font-size: 20px;
  line-height: 1;
  transition: transform var(--transition-fast);
}

.nav-tab .tab-label {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  line-height: 1;
}

.nav-tab.active {
  color: var(--orange);
}

.nav-tab.active .tab-icon {
  transform: translateY(-1px);
}

/* Orange dot indicator under active tab */
.nav-tab.active::after {
  content: '';
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--orange);
}

/* ─── Cards ─────────────────────────────────────────────── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color var(--transition-fast);
}

.card:hover {
  border-color: #3a3a3a;
}

.card-header {
  padding: var(--space-lg);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--space-md);
  user-select: none;
}

.card-body {
  padding: 0 var(--space-lg) var(--space-lg);
  border-top: 1px solid var(--border);
  display: none;
}

.card.expanded .card-body {
  display: block;
}

.card.expanded .chevron {
  color: var(--orange);
  transform: rotate(180deg);
}

.chevron {
  color: var(--text-muted);
  transition: transform var(--transition-med), color var(--transition-fast);
  flex-shrink: 0;
  font-size: 16px;
}

/* ─── Input Fields ──────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.2px;
}

.form-label .required {
  color: var(--orange);
  margin-left: 2px;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font-body);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  -webkit-appearance: none;
}

.form-input::placeholder, .form-textarea::placeholder {
  color: var(--text-muted);
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px var(--orange-ring);
}

.form-select {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23888' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

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

.form-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: -2px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--space-sm);
}

/* ─── Calc Preview Box ──────────────────────────────────── */
.calc-preview {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.calc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-muted);
}

.calc-row.total {
  border-top: 1px solid var(--border);
  padding-top: 6px;
  margin-top: 2px;
  font-weight: 600;
  color: var(--orange);
  font-family: var(--font-mono);
  font-size: 14px;
}

/* ─── Badges ────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.badge-orange {
  background: var(--orange-glow);
  color: var(--orange);
  border: 1px solid rgba(255,107,0,0.3);
}

.badge-alert {
  background: rgba(255, 68, 68, 0.15);
  color: var(--error);
  border: 1px solid rgba(255, 68, 68, 0.3);
}

.badge-success {
  background: rgba(0, 200, 150, 0.15);
  color: var(--success);
  border: 1px solid rgba(0, 200, 150, 0.3);
}

.badge-warning {
  background: rgba(255, 184, 0, 0.15);
  color: var(--warning);
  border: 1px solid rgba(255, 184, 0, 0.3);
}

.badge-muted {
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* ─── Margin Health Dot ─────────────────────────────────── */
.health-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.health-dot.healthy  { background: var(--success); box-shadow: 0 0 6px var(--success); }
.health-dot.tight    { background: var(--warning); box-shadow: 0 0 6px var(--warning); }
.health-dot.loss     { background: var(--error);   box-shadow: 0 0 6px var(--error); }

/* ─── True Cost Stacked Bar ─────────────────────────────── */
.cost-bar-wrap {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
  display: flex;
  background: var(--bg-elevated);
}

.cost-bar-segment {
  height: 100%;
  transition: width var(--transition-slow);
}

/* ─── Cost Layer Row ────────────────────────────────────── */
.cost-layer-row {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) 0;
  border-bottom: 1px solid var(--border);
}

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

.cost-layer-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.cost-layer-label {
  flex: 1;
  font-size: 13px;
  color: var(--text-secondary);
}

.cost-layer-amount {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  min-width: 60px;
  text-align: right;
}

.cost-layer-pct {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  min-width: 40px;
  text-align: right;
}

/* ─── Tabs (sub-tabs inside screen) ────────────────────── */
.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.tab-bar::-webkit-scrollbar { display: none; }

.tab-pill {
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: all var(--transition-fast);
  background: none;
  border-left: none;
  border-right: none;
  border-top: none;
}

.tab-pill:hover {
  color: var(--text-secondary);
}

.tab-pill.active {
  color: var(--orange);
  border-bottom-color: var(--orange);
}

.tab-content {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: var(--space-lg);
  padding-bottom: 80px;
}

.tab-content.active {
  display: block;
}

.tab-content::-webkit-scrollbar { display: none; }

/* ─── Modal ─────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
  animation: fadeIn var(--transition-fast);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-sheet {
  background: var(--bg-surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  width: 100%;
  max-width: 430px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  animation: slideUp var(--transition-med);
  overflow: hidden;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.modal-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 12px auto 0;
  flex-shrink: 0;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg) var(--space-lg) var(--space-md);
  flex-shrink: 0;
}

.modal-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 800;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 var(--space-lg) var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.modal-body::-webkit-scrollbar { display: none; }

.modal-footer {
  flex-shrink: 0;
  padding: var(--space-md) var(--space-lg) calc(var(--space-lg) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  display: flex;
  gap: var(--space-sm);
}

.modal-footer .btn {
  flex: 1;
}

/* ─── Search Bar ────────────────────────────────────────── */
.search-wrap {
  position: relative;
  margin-bottom: var(--space-lg);
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 16px;
  pointer-events: none;
}

.search-input {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 11px 16px 11px 40px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font-body);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.search-input::placeholder { color: var(--text-muted); }

.search-input:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px var(--orange-ring);
  outline: none;
}

/* ─── Alert Banner ──────────────────────────────────────── */
.alert-banner {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  background: rgba(255, 68, 68, 0.10);
  border: 1px solid rgba(255, 68, 68, 0.25);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--error);
}

.alert-banner .alert-icon { font-size: 16px; flex-shrink: 0; }
.alert-banner .alert-text { flex: 1; line-height: 1.4; }
.alert-banner .alert-action {
  font-size: 12px;
  font-weight: 600;
  color: var(--error);
  text-decoration: underline;
  cursor: pointer;
  flex-shrink: 0;
}

/* ─── Toggle Switch ─────────────────────────────────────── */
.toggle-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) 0;
}

.toggle-label {
  flex: 1;
}

.toggle-label .label-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.toggle-label .label-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle input { display: none; }

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform var(--transition-fast), background var(--transition-fast);
}

.toggle input:checked ~ .toggle-track {
  background: var(--orange-glow);
  border-color: var(--orange);
}

.toggle input:checked ~ .toggle-thumb {
  background: var(--orange);
  transform: translateX(20px);
}

/* ─── Channel Chip Selector ─────────────────────────────── */
.channel-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
  background: none;
  white-space: nowrap;
}

.channel-chip.active {
  border-color: var(--orange);
  color: var(--orange);
  background: var(--orange-glow);
}

/* ─── Price Display ─────────────────────────────────────── */
.price-big {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 700;
  color: var(--orange);
}

.price-med {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.price-sm {
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text-secondary);
}

/* ─── Slider ────────────────────────────────────────────── */
.slider-wrap {
  padding: var(--space-md) 0;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-sm);
}

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

.slider-value {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--orange);
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--bg-elevated);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--orange);
  box-shadow: 0 0 8px var(--orange-shadow);
  cursor: pointer;
  transition: transform var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

/* ─── Table ─────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: var(--space-sm) var(--space-md);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}

.data-table th:hover { color: var(--text-secondary); }
.data-table th.sort-asc::after { content: ' ↑'; color: var(--orange); }
.data-table th.sort-desc::after { content: ' ↓'; color: var(--orange); }

.data-table td {
  padding: var(--space-md);
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table .mono { font-family: var(--font-mono); color: var(--text-primary); }

/* ─── Settings Row ──────────────────────────────────────── */
.settings-row {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) 0;
  border-bottom: 1px solid var(--border);
}

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

.settings-row-info {
  flex: 1;
}

.settings-row-info .row-title {
  font-size: 14px;
  color: var(--text-primary);
  font-weight: 500;
}

.settings-row-info .row-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.settings-row-value {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-muted);
}

.settings-row input.inline-input {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  width: 90px;
  text-align: right;
  transition: border-color var(--transition-fast);
}

.settings-row input.inline-input:focus {
  border-color: var(--orange);
  outline: none;
}

/* ─── Ingredient Item Row ───────────────────────────────── */
.ingredient-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) 0;
  border-bottom: 1px solid var(--border);
}

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

.ingredient-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--orange);
  flex-shrink: 0;
}

.ingredient-name {
  flex: 1;
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 500;
}

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

.ingredient-cost {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--orange);
  min-width: 50px;
  text-align: right;
}

/* ─── Progress Ring ─────────────────────────────────────── */
.margin-ring-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.margin-ring-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ─── Toasts ────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: calc(var(--nav-height) + 80px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: 90%;
  max-width: 380px;
}

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-lg);
  font-size: 13px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  animation: toastIn var(--transition-med) forwards;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
}

.toast.success { border-color: rgba(0,200,150,0.4); }
.toast.error   { border-color: rgba(255,68,68,0.4); }
.toast.info    { border-color: rgba(255,107,0,0.4); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Number Stepper ────────────────────────────────────── */
.stepper {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px;
}

.stepper-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--orange);
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.stepper-btn:hover { background: var(--orange-glow); }

.stepper-value {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  min-width: 32px;
  text-align: center;
}
