/* ============================================
   TELEGRAM MINI APP — RESTAURANT ORDERING
   ============================================ */

/* --- CSS Custom Properties (Telegram Theme) --- */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg-secondary: var(--tg-theme-secondary-bg-color, #f0f0f0);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #999999);
  --link: var(--tg-theme-link-color, #2481cc);
  --button: var(--tg-theme-button-color, #2481cc);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --subtitle: var(--tg-theme-subtitle-text-color, #6d6d72);
  --header-bg: var(--tg-theme-header-bg-color, #ffffff);
  --section-bg: var(--tg-theme-section-bg-color, #ffffff);
  --section-separator: var(--tg-theme-section-separator-color, #e0e0e0);
  --destructive: var(--tg-theme-destructive-text-color, #ff3b30);

  --safe-top: var(--tg-safe-area-inset-top, 0px);
  --safe-bottom: var(--tg-safe-area-inset-bottom, 0px);
  --content-safe-top: var(--tg-content-safe-area-inset-top, 0px);
  --content-safe-bottom: var(--tg-content-safe-area-inset-bottom, 0px);
  --viewport-height: var(--tg-viewport-stable-height, 100vh);
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-user-select: none;
  user-select: none;
}

input, textarea {
  -webkit-user-select: text;
  user-select: text;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'IBM Plex Sans Arabic', -apple-system, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  direction: rtl;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  min-height: var(--viewport-height);
  padding-top: calc(var(--safe-top) + var(--content-safe-top));
  padding-bottom: calc(var(--safe-bottom) + var(--content-safe-bottom));
}

img {
  max-width: 100%;
  display: block;
}

button {
  border: none;
  background: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-appearance: none;
}

input, textarea {
  border: none;
  font: inherit;
  color: var(--text);
  background: var(--bg-secondary);
  -webkit-appearance: none;
  outline: none;
}

a {
  color: var(--link);
  text-decoration: none;
}

/* --- Screen Container --- */
.screen {
  padding: 0 16px 100px;
  animation: fadeIn 0.2s ease;
}

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

/* --- Home Title --- */
.home-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  margin-bottom: 10px;
}


/* --- Sticky Bar (Search + Pills) --- */
.sticky-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  padding: 12px 16px 0;
  margin: 0 -16px;
  padding-top: calc(16px + var(--safe-top));
  margin-top: calc(-1 * (var(--safe-top) + var(--content-safe-top)));
}

/* --- Search Bar --- */
.search-container {
  position: relative;
  margin-bottom: 8px;
}

.search-container > svg {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--hint);
  pointer-events: none;
}

.search-clear {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--hint);
  opacity: 0.3;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--bg);
  padding: 0;
}

.search-clear:active {
  opacity: 0.5;
}

.search-input {
  width: 100%;
  height: 36px;
  border-radius: 10px;
  padding: 0 36px;
  font-size: 14px;
  background: var(--bg-secondary);
  transition: background 0.2s;
}

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

.search-input:focus {
  background: var(--bg-secondary);
}

/* --- Category Pills --- */
.category-pills {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 10px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

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

.category-pill {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 500;
  background: var(--bg-secondary);
  color: var(--text);
  transition: all 0.2s ease;
  white-space: nowrap;
}

.category-pill.active {
  background: var(--button);
  color: var(--button-text);
}

/* --- Menu Grid --- */
.menu-grid {
  padding-top: 12px;
}

.category-section {
  grid-column: 1 / -1;
}

.category-heading {
  font-size: 17px;
  font-weight: 600;
  padding: 16px 0 8px;
  color: var(--text);
}

.category-items {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* --- Menu Card --- */
.menu-card {
  background: var(--section-bg);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.card-image {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--bg-secondary);
}

.card-placeholder {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--hint);
}

.card-body {
  padding: 8px 10px 10px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.card-name {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-desc {
  font-size: 12px;
  color: var(--hint);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 8px;
  min-height: 33px;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
}

.card-price {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

/* --- Add to Cart Button --- */
.add-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--button);
  transition: transform 0.15s ease;
}

.add-btn:active {
  transform: scale(0.9);
}

/* --- Quantity Pill --- */
.qty-pill {
  display: flex;
  flex-direction: row-reverse;
  align-items: center;
  gap: 0;
  background: var(--button);
  border-radius: 20px;
  height: 32px;
  overflow: hidden;
}

.qty-pill button {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--button-text);
  transition: opacity 0.15s;
}

.qty-pill button:active {
  opacity: 0.7;
}

.qty-pill .qty-value {
  min-width: 20px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--button-text);
}

/* --- Bottom Sheet --- */
.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,0.4);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.sheet-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 101;
  background: var(--bg);
  border-radius: 14px 14px 0 0;
  max-height: 85vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  padding-bottom: calc(16px + var(--safe-bottom));
}

.sheet.active {
  transform: translateY(0);
}

body.sheet-open {
  overflow: hidden;
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px 0;
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--hint);
  opacity: 0.3;
  border-radius: 2px;
  margin: 0 auto;
  flex: 1;
}

.sheet-close-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0,0,0,0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--hint);
  flex-shrink: 0;
  position: absolute;
  left: 12px;
  top: 12px;
  z-index: 2;
}

.sheet-image {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  background: var(--bg-secondary);
}

.sheet-placeholder {
  width: 100%;
  aspect-ratio: 16 / 10;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--hint);
}

.sheet-content {
  padding: 16px;
}

.sheet-name {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 4px;
}

.sheet-desc {
  font-size: 14px;
  color: var(--hint);
  line-height: 1.6;
  margin-bottom: 12px;
}

.sheet-price {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 16px;
}

.sheet-add-btn {
  width: 100%;
  height: 48px;
  border-radius: 12px;
  background: var(--button);
  color: var(--button-text);
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity 0.15s;
}

.sheet-add-btn:active {
  opacity: 0.85;
}

.sheet-qty-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

.sheet-qty-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--button);
  transition: transform 0.15s;
}

.sheet-qty-btn:active {
  transform: scale(0.9);
}

.sheet-qty-btn.delete {
  color: var(--destructive);
}

.sheet-qty-value {
  font-size: 22px;
  font-weight: 700;
  min-width: 32px;
  text-align: center;
}

/* --- Skeleton Loading --- */
.skeleton {
  background: var(--bg-secondary);
  border-radius: 14px;
  overflow: hidden;
  position: relative;
}

.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255,255,255,0.3) 50%,
    transparent 100%
  );
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { transform: translateX(100%); }
  100% { transform: translateX(-100%); }
}

.skeleton-image {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--bg-secondary);
}

.skeleton-text {
  height: 14px;
  border-radius: 4px;
  background: var(--bg-secondary);
  margin: 8px 10px;
}

.skeleton-text.short {
  width: 60%;
}

.skeleton-text.price {
  width: 40%;
  height: 16px;
  margin-top: 12px;
}

/* --- Checkout Screen --- */
.checkout-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--section-separator);
}

.checkout-item-image {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.checkout-item-placeholder {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--hint);
  flex-shrink: 0;
}

.checkout-item-info {
  flex: 1;
  min-width: 0;
}

.checkout-item-name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.checkout-item-price {
  font-size: 13px;
  color: var(--hint);
}

.checkout-total {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  font-size: 15px;
  font-weight: 500;
  color: var(--hint);
  border-bottom: 0.5px solid var(--section-separator);
}

.checkout-total.delivery {
  font-size: 14px;
  font-weight: 400;
}

.checkout-total.grand {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  border-bottom: none;
  padding-top: 14px;
}

.comment-field {
  width: 100%;
  min-height: 80px;
  border-radius: 12px;
  padding: 12px;
  font-size: 14px;
  resize: none;
  margin-top: 8px;
  background: var(--bg-secondary);
}

.comment-field::placeholder {
  color: var(--hint);
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--hint);
  text-transform: uppercase;
  padding: 20px 0 8px;
  letter-spacing: 0.5px;
}

/* --- Order Submit Form --- */
.form-group {
  margin-bottom: 4px;
}

.form-card {
  background: var(--section-bg);
  border-radius: 12px;
  overflow: hidden;
}

.form-row {
  display: flex;
  align-items: center;
  padding: 0 16px;
  min-height: 48px;
  border-bottom: 0.5px solid var(--section-separator);
  gap: 8px;
  overflow: hidden;
}

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

.form-label {
  font-size: 14px;
  color: var(--text);
  width: 70px;
  flex-shrink: 0;
  white-space: nowrap;
}

.form-input {
  flex: 1;
  min-width: 0;
  height: 48px;
  padding: 0 8px;
  font-size: 14px;
  text-align: start;
  background: transparent;
  direction: rtl;
}

.form-input[type="tel"] {
  direction: ltr;
  text-align: right;
}

.form-input::placeholder {
  color: var(--hint);
}

.form-status {
  font-size: 14px;
  color: var(--button);
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  flex: 1;
  min-width: 0;
}

.form-status.pending {
  color: var(--hint);
}

.form-status.rejected {
  color: var(--destructive);
}

.form-hint {
  font-size: 12px;
  color: var(--hint);
  padding: 6px 16px 0;
}

/* --- Success Screen --- */
.success-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(var(--viewport-height) - var(--safe-top) - var(--content-safe-top) - 100px);
  text-align: center;
  padding: 32px 16px;
}

.success-check {
  width: 88px;
  height: 88px;
  margin-bottom: 24px;
}

.success-circle {
  fill: none;
  stroke: var(--button);
  stroke-width: 3;
  stroke-dasharray: 240;
  stroke-dashoffset: 240;
  animation: drawCircle 0.6s ease forwards;
}

.success-tick {
  fill: none;
  stroke: var(--button);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 50;
  stroke-dashoffset: 50;
  animation: drawTick 0.4s ease 0.5s forwards;
}

@keyframes drawCircle {
  to { stroke-dashoffset: 0; }
}

@keyframes drawTick {
  to { stroke-dashoffset: 0; }
}

.success-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
}

.success-subtitle {
  font-size: 15px;
  color: var(--hint);
  margin-bottom: 32px;
}

.success-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 280px;
}

.btn-primary {
  height: 48px;
  border-radius: 12px;
  background: var(--button);
  color: var(--button-text);
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s;
}

.btn-primary:active {
  opacity: 0.85;
}

.btn-secondary {
  height: 48px;
  border-radius: 12px;
  background: transparent;
  color: var(--button);
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- Empty State --- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 16px;
  color: var(--hint);
  text-align: center;
}

.empty-state svg {
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 15px;
}

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