/* ==========================================================================
   DESIGN TOKENS GLOBAIS
   ========================================================================== */
:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-hover: #f4f4f5;
  --ink: #09090b;
  --muted: #71717a;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  
  --success: #10b981;
  --success-soft: #ecfdf5;
  --warning: #f59e0b;
  --warning-soft: #fffbeb;
  --danger: #ef4444;
  --danger-soft: #fef2f2;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-full: 9999px;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.08);

  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
}

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

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; }
img { max-width: 100%; display: block; }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  
  padding: 12px 16px;
  background: rgba(250, 250, 250, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  width: 100%;
}

.topbar-kitchen {
  background: rgba(9, 9, 11, 0.94);
  color: #f4f4f5;
  border-bottom-color: #27272a;

  .brand p { color: #a1a1aa; }
  .btn-ghost { color: #f4f4f5; border-color: #3f3f46; }
  .table-badge { background: #27272a; color: #fff; }
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  font-size: 1.15rem;
  background: var(--primary-soft);
  color: var(--primary);
  width: 36px; 
  height: 36px;
  display: grid; 
  place-items: center;
  border-radius: var(--radius-sm);
  font-weight: 700;
  flex-shrink: 0;
}

.brand div {
  min-width: 0;
}

.brand h1 {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand p {
  font-size: 0.7rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap; /* Permite que os itens quebrem linha em ecrãs muito estreitos */
  gap: 10px;
  padding: 12px 16px;
  background: rgba(250, 250, 250, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  width: 100%;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* ---------- Ajuste específico para ecrãs de telemóvel ---------- */
@media (max-width: 540px) {
  .topbar {
    padding: 10px 12px;
    gap: 8px;
  }

  /* Esconde o texto do título da marca se não houver espaço, mantendo o ícone visível */
  /*.brand h1,
  .brand p {
    display: none;
  }*/

  .topbar-actions {
    flex: 1;
    justify-content: flex-end;
    gap: 6px;
  }

  .table-badge {
    padding: 5px 8px;
    font-size: 0.72rem;
  }

  .topbar-actions .btn {
    padding: 6px 10px;
    font-size: 0.78rem;
  }
}

.table-badge {
  background: #f4f4f5;
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  white-space: nowrap;
}

/* ---------- Botões ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.15s ease;
  text-decoration: none;
  user-select: none;
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-hover); border-color: var(--border-strong); }

.btn-block {
  width: 100%;
  justify-content: center;
  padding: 12px;
  font-size: 0.9rem;
}

.btn-icon {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.9rem;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.btn-icon:hover { background: var(--surface-hover); }

.cart-count {
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-full);
  min-width: 18px; 
  height: 18px;
  display: inline-grid; 
  place-items: center;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0 4px;
}

/* ---------- Categorias (Filtros) ---------- */
.categories {
  display: flex;
  gap: 6px;
  padding: 12px 16px 4px;
  overflow-x: auto;
  scrollbar-width: none;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}
.categories::-webkit-scrollbar { display: none; }

.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: var(--radius-full);
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  transition: all 0.15s ease;
  flex-shrink: 0;
}
.chip:hover { border-color: var(--border-strong); color: var(--ink); background: var(--surface-hover); }
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ---------- Grade de Pratos ---------- */
.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  padding: 16px 16px 100px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.dish-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
  margin: 10px;
}

/* O contêiner agora não tem altura travada (130px), ele acompanha a foto */
.dish-image {
  background: #f4f4f5;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: auto;
  overflow: hidden;

}

/* A imagem assume 100% da largura e a altura ajusta-se sozinha, sem cortes */
.dish-image img { 
  width: 100%;       
  height: 100%;      
  display: block;
  object-fit: cover; 
}

.dish-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.dish-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
}

.dish-title-row h3 {
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.dish-category {
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 2px 6px;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.dish-desc {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
  flex: 1;

  /* Regras para o corte de linhas (compatibilidade total) */
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2; /* Propriedade padrão moderna exigida pelos linters */
  overflow: hidden;
}

.dish-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.price {
  font-weight: 600;
  font-size: 0.9rem;
}

.btn-add {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-weight: 500;
  font-size: 0.75rem;
}
.btn-add:hover { background: var(--primary-hover); }

/* ---------- Estados (Skeleton / Erro) ---------- */
.skeleton-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}
.skeleton-img, .skeleton-line {
  background: linear-gradient(90deg, #f4f4f5 25%, #e4e4e7 50%, #f4f4f5 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
}
.skeleton-img { height: 130px; }
.skeleton-line { height: 12px; border-radius: 6px; margin: 10px 12px; }
.skeleton-line.w60 { width: 60%; }
.skeleton-line.w40 { width: 40%; }
@keyframes shimmer { to { background-position: -200% 0; } }

.empty, .load-error {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  padding: 32px 16px;
  font-size: 0.88rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.load-error { color: var(--danger); background: var(--danger-soft); border-color: #fecaca; }

/* ---------- Carrinho (Drawer) ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(9, 9, 11, 0.45);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 50;
}
.overlay.show { opacity: 1; pointer-events: auto; }

.cart-drawer {
  position: fixed;
  top: 0; right: 0;
  height: 100dvh;
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  z-index: 60;
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  border-left: 1px solid var(--border);
}
.cart-drawer.open { transform: translateX(0); }

.cart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.cart-header h2 { font-size: 1.05rem; font-weight: 600; }

.cart-items {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.cart-empty { text-align: center; color: var(--muted); margin-top: 32px; font-size: 0.85rem; }

.cart-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--surface);
}

.cart-item-info { display: flex; justify-content: space-between; gap: 8px; font-size: 0.85rem; font-weight: 500; }
.cart-item-price { color: var(--muted); }
.cart-item-controls { display: flex; align-items: center; justify-content: space-between; }

.qty { display: inline-flex; align-items: center; gap: 6px; }
.qty button {
  width: 24px; height: 24px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.8rem;
  font-weight: 600;
  display: grid;
  place-items: center;
}
.qty span { font-weight: 600; font-size: 0.82rem; min-width: 16px; text-align: center; }

.notes-input {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 0.78rem;
  width: 100%;
  background: var(--bg);
}
.notes-input:focus { outline: none; border-color: var(--primary); background: var(--surface); }

.cart-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.cart-total-row { display: flex; justify-content: space-between; font-size: 0.9rem; color: var(--muted); align-items: center; }
.cart-total-row strong { font-size: 1.1rem; color: var(--ink); }

/* ---------- Modais ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  background: rgba(9, 9, 11, 0.45);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  padding: 16px;
}
.modal.open { opacity: 1; pointer-events: auto; }

.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  transform: scale(0.96);
  transition: transform 0.2s ease;
}
.modal.open .modal-card { transform: scale(1); }
.modal-card h2 { font-size: 1.1rem; font-weight: 600; }
.modal-card p { color: var(--muted); font-size: 0.82rem; line-height: 1.4; }
.modal-card input {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--bg);
  width: 100%;
}
.modal-card input:focus { outline: none; border-color: var(--primary); background: var(--surface); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* ---------- Toasts ---------- */
.toast-container {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  width: calc(100vw - 24px);
  max-width: 360px;
  pointer-events: none;
}
.toast {
  background: var(--ink);
  color: #fff;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.2s ease;
  text-align: center;
  pointer-events: auto;
  border: 1px solid rgba(255,255,255,0.1);
  width: 100%;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }

/* ---------- Cozinha ---------- */
.kitchen-body { background: #f4f4f5; }
.kitchen-connection {
  width: calc(100% - 32px);
  max-width: 1300px;
  margin: 12px auto 0;
  padding: 10px 14px;
  border: 1px solid #fcd34d;
  border-radius: var(--radius-sm);
  background: #fffbeb;
  color: #92400e;
  font-size: 0.85rem;
}
.kitchen-connection[hidden] { display: none; }
.kitchen-connection button { margin-left: 10px; }
.kitchen-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  padding: 16px 16px 40px;
  max-width: 1300px;
  margin: 0 auto;
  width: 100%;
}

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  border: 1px solid var(--border);
}
.panel-orders { min-height: 280px; }

.panel-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill {
  background: var(--primary);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  border-radius: var(--radius-full);
  min-width: 18px; 
  height: 18px;
  display: inline-grid;
  place-items: center;
  padding: 0 4px;
}

.calls-list, .orders-list { display: flex; flex-direction: column; gap: 10px; }

.call-card {
  border: 1px solid var(--border);
  border-left: 3px solid var(--warning);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--surface);
}
.call-card strong { display: block; font-size: 0.85rem; }
.call-card time { font-size: 0.68rem; color: var(--muted); }
.call-card .btn { padding: 4px 10px; font-size: 0.72rem; }

.order-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.order-head {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.order-table {
  font-weight: 600;
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius-full);
  padding: 2px 8px;
  font-size: 0.72rem;
}
.order-status {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: var(--radius-full);
}
.st-pending   { border-left: 3px solid var(--warning); .order-status { background: var(--warning-soft); color: #d97706; } }
.st-preparing { border-left: 3px solid var(--primary); .order-status { background: var(--primary-soft); color: var(--primary); } }
.st-ready     { border-left: 3px solid var(--success); .order-status { background: var(--success-soft); color: var(--success); } }

.order-head time { margin-left: auto; font-size: 0.68rem; color: var(--muted); }
.order-items { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.order-items li { font-size: 0.82rem; display: flex; flex-direction: column; }

.order-notes {
  font-size: 0.7rem;
  color: var(--muted);
  background: var(--bg);
  border-radius: 4px;
  padding: 2px 6px;
  margin-top: 2px;
  width: fit-content;
  border: 1px solid var(--border);
}

.order-foot {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.order-foot strong { font-size: 0.95rem; }
.order-foot .btn { padding: 6px 10px; font-size: 0.75rem; }

/* ---------- Responsivo Desktop (Acima de 860px) ---------- */
@media (min-width: 860px) {
  .kitchen-layout { grid-template-columns: 320px 1fr; padding: 20px 24px 40px; }
  .topbar { padding: 12px 24px; }
  .categories { padding: 16px 24px 4px; }
  .menu-grid { padding: 20px 24px 100px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
  .dish-image { height: 140px; font-size: 2.5rem; }
  .dish-body { padding: 14px; }
  .brand h1 { font-size: 1rem; }
}

/* ---------- Responsivo Mobile Super Pequeno (Abaixo de 420px) ---------- */
@media (max-width: 420px) {
  .menu-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 12px;
  }
  .dish-card {
    border-radius: 10px;
  }
  .dish-image {
    height: 100px;
    font-size: 1.8rem;
  }
  .dish-body {
    padding: 10px;
  }
  .dish-title-row h3 {
    font-size: 0.82rem;
  }
  .price {
    font-size: 0.82rem;
  }
  .btn-add {
    padding: 5px 8px;
    font-size: 0.7rem;
  }
}
