/* ── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: var(--tg-theme-bg-color, #1c1c1e);
  --bg2: var(--tg-theme-secondary-bg-color, #2c2c2e);
  --text: var(--tg-theme-text-color, #ffffff);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #0a84ff);
  --btn: var(--tg-theme-button-color, #0a84ff);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --accent: #30d158;
  --danger: #ff453a;
  --warn: #ffd60a;
  --radius: 12px;
  --radius-sm: 8px;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ──────────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 8px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-title {
  font-size: 17px;
  font-weight: 600;
}

.header-actions { display: flex; gap: 4px; }

.icon-btn {
  background: none;
  border: none;
  color: var(--link);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: background 0.15s;
}
.icon-btn:active { background: var(--bg2); }
.icon-btn svg { width: 20px; height: 20px; }

/* ── Search Bar ──────────────────────────────────────────────────── */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 8px;
  background: var(--bg);
}
.search-bar input {
  flex: 1;
  background: var(--bg2);
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text);
  font-size: 15px;
  outline: none;
}

/* ── Tabs ────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  background: var(--bg);
  position: sticky;
  top: 52px;
  z-index: 9;
}

.tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--hint);
  padding: 10px 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: color 0.2s, border-color 0.2s;
}
.tab.active {
  color: var(--link);
  border-bottom-color: var(--link);
}
.tab.drag-target {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: rgba(48, 209, 88, 0.06);
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.badge {
  background: var(--btn);
  color: var(--btn-text);
  border-radius: 10px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  text-align: center;
}

/* ── Panels ──────────────────────────────────────────────────────── */
.panel {
  display: none;
  height: calc(100vh - 105px);
  overflow-y: auto;
  padding-bottom: 80px;
}
.panel.active { display: block; }

/* ── Product List ────────────────────────────────────────────────── */
.product-list { padding: 8px 0; }

.product-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid rgba(255,255,255,0.05);
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.product-card:active { background: var(--bg2); }
.product-card.selected { background: rgba(10,132,255,0.12); }

.product-thumb {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--bg2);
  flex-shrink: 0;
}

.product-thumb-placeholder {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  background: var(--bg2);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.product-info { flex: 1; min-width: 0; }

.product-title {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 4px;
}

.product-price-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 5px;
}

.price-current {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
}

.price-original {
  font-size: 12px;
  color: var(--hint);
  text-decoration: line-through;
}

.price-error {
  font-size: 13px;
  color: var(--danger);
  font-style: italic;
}

.discount-badge {
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
}

.product-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.tag {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 4px;
  font-weight: 500;
}
.tag-amazon { background: rgba(255,149,0,0.2); color: #ff9500; }
.tag-manual { background: rgba(10,132,255,0.2); color: #0a84ff; }
.tag-adesso { background: rgba(48,209,88,0.2); color: #30d158; }
.tag-multi  { background: rgba(175,82,222,0.2); color: #af52de; }

.select-circle {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--hint);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.select-circle.checked {
  background: var(--btn);
  border-color: var(--btn);
}
.select-circle.checked::after {
  content: '';
  width: 6px;
  height: 10px;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(45deg) translate(-1px, -1px);
}

/* ── Empty State ─────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 20px;
  color: var(--hint);
  font-size: 15px;
  text-align: center;
}
.empty-icon { font-size: 48px; }

/* ── Multi-select bar ────────────────────────────────────────────── */
.multi-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg2);
  border-top: 1px solid rgba(255,255,255,0.1);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 20;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
#multiCount {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.multi-actions { display: flex; gap: 10px; }

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--btn);
  color: var(--btn-text);
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary:active { opacity: 0.75; }

.btn-ghost {
  background: none;
  border: none;
  color: var(--link);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  padding: 8px 12px;
}

/* ── Overlay ─────────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 30;
  opacity: 0;
  transition: opacity 0.25s;
}
.overlay.visible { opacity: 1; }

/* ── Bottom Sheet ────────────────────────────────────────────────── */
.bottom-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg2);
  border-radius: 14px 14px 0 0;
  z-index: 40;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateY(110%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 80vh;
  overflow-y: auto;
}
.bottom-sheet.open { transform: translateY(0); }

.sheet-handle {
  width: 36px;
  height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  margin: 10px auto 14px;
}

.sheet-product-header {
  display: flex;
  gap: 12px;
  padding: 0 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  margin-bottom: 6px;
}
.sheet-thumb {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--bg);
  flex-shrink: 0;
}
.sheet-product-info { flex: 1; min-width: 0; }
.sheet-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 3px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.sheet-price { font-size: 14px; color: var(--accent); font-weight: 600; }
.sheet-tags { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }

.sheet-multi-header {
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  padding: 0 16px 12px;
  color: var(--hint);
}

.sheet-actions { padding: 0 12px; }

.sheet-action-btn {
  display: block;
  width: 100%;
  background: var(--bg);
  border: none;
  color: var(--text);
  font-size: 15px;
  padding: 14px 16px;
  text-align: left;
  cursor: pointer;
  border-radius: var(--radius-sm);
  margin-bottom: 2px;
  transition: background 0.15s;
}
.sheet-action-btn:active { background: rgba(255,255,255,0.08); }
.sheet-action-btn.danger { color: var(--danger); }
.sheet-action-btn.cancel {
  color: var(--link);
  font-weight: 600;
  text-align: center;
  background: none;
  margin-top: 8px;
}

/* ── Utilities ───────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Loader ──────────────────────────────────────────────────────── */
.loader {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
}
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--link);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Drag handle ─────────────────────────────────────────────────── */
.drag-handle {
  color: var(--hint);
  cursor: grab;
  padding: 12px 6px 12px 0;
  touch-action: none;
  flex-shrink: 0;
  font-size: 20px;
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
}
.drag-handle:active { cursor: grabbing; }
.card-ghost { opacity: 0.35 !important; }

/* ── Drag action overlay ─────────────────────────────────────────── */
.drag-overlay {
  display: none;
  position: fixed;
  top: 52px;
  left: 0;
  right: 0;
  height: 56px;
  z-index: 28;
  flex-direction: row;
}
.drag-overlay.dz-active { display: flex; }

.drag-zone {
  flex: 1;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.15s;
  border-bottom: 2px solid transparent;
}
.drag-zone-queue {
  background: #1a3a5c;
  border-bottom-color: var(--link);
  border-right: 1px solid rgba(255,255,255,0.1);
}
.drag-zone-delete {
  background: #4a1a1a;
  border-bottom-color: var(--danger);
}
.drag-zone-queue.dz-over  { background: #1e4c7a; }
.drag-zone-delete.dz-over { background: #6b2020; }

.drag-zone-icon  { font-size: 18px; line-height: 1; }
.drag-zone-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

/* SortableJS fallback clone — must not intercept pointer events */
.sortable-fallback {
  pointer-events: none !important;
  opacity: 0.75 !important;
  z-index: 9999 !important;
}

/* ── Toast notification ──────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 88px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: rgba(44, 44, 46, 0.96);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  white-space: nowrap;
  max-width: 85vw;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Schedule Picker ────────────────────────────────────────────── */
.sched-picker {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 50;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.sched-picker.hidden { display: none !important; }

.sched-picker-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 16px max(16px, env(safe-area-inset-bottom));
  gap: 12px;
}

.sched-picker-head {
  border-bottom: 1px solid rgba(255,255,255,0.08);
  padding-bottom: 12px;
}
.sched-picker-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 4px;
}
.sched-picker-subtitle {
  font-size: 13px;
  color: var(--hint);
  line-height: 1.3;
}

.sched-section-box {
  background: var(--bg2);
  border-radius: var(--radius);
  overflow: hidden;
}

.sched-section-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.sched-nav-btn {
  background: none;
  border: none;
  color: var(--link);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 6px;
  flex-shrink: 0;
}
.sched-nav-btn:active { background: rgba(255,255,255,0.08); }

.sched-section-label {
  flex: 1;
  text-align: center;
}
.sched-section-name {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--hint);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 2px;
}
.sched-day-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--link);
}

.sched-list-content {
  padding: 8px 12px;
  min-height: 36px;
}
.sched-list-empty {
  font-size: 13px;
  color: var(--hint);
  text-align: center;
  padding: 8px 0;
}

.sched-prog-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 13px;
}
.sched-prog-item:last-child { border-bottom: none; }
.sched-prog-time {
  font-weight: 700;
  color: var(--warn);
  flex-shrink: 0;
  width: 40px;
}
.sched-prog-title {
  color: var(--hint);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.sched-slots-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px;
}
.sched-slot {
  background: rgba(10,132,255,0.15);
  color: var(--link);
  border: 1px solid rgba(10,132,255,0.35);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.sched-slot:active { background: rgba(10,132,255,0.3); }
.sched-slot.taken {
  background: rgba(255,255,255,0.05);
  color: var(--hint);
  border-color: rgba(255,255,255,0.1);
  cursor: default;
  text-decoration: line-through;
}

.sched-manual-row {
  display: flex;
  gap: 12px;
}
.sched-manual-field {
  flex: 1;
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.sched-manual-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--hint);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.sched-manual-input {
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  outline: none;
  color-scheme: dark;
}

.sched-bottom {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}
.sched-confirm-btn {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  border-radius: var(--radius);
}
