* { margin: 0; padding: 0; box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: #f5f5f5;
  color: #333;
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Login */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 16px;
}

.login-container {
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  padding: 24px;
  width: 100%;
  max-width: 420px;
}

.login-header {
  text-align: center;
  margin-bottom: 30px;
}

.login-header h1 {
  font-size: 24px;
  color: #1f2937;
  margin-bottom: 8px;
}

.login-header p {
  color: #6b7280;
  font-size: 14px;
}

.login-form .form-group {
  margin-bottom: 20px;
}

.login-form label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  color: #374151;
  font-size: 14px;
}

.login-form input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  font-size: 16px; /* evita zoom no iOS */
  min-height: 48px;
}

.login-form input:focus {
  outline: none;
  border-color: #dc2626;
}

.error-message {
  background: #fef2f2;
  color: #b91c1c;
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
}

.btn {
  padding: 14px 20px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
  color: white;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
}

.btn-secondary {
  background: #3b82f6;
  color: white;
}

.btn-secondary:hover {
  background: #2563eb;
}

.btn-block { width: 100%; }

.login-hint {
  margin-top: 20px;
  font-size: 12px;
  color: #9ca3af;
  text-align: center;
}

.login-hint code {
  background: #f3f4f6;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
}

.api-url-details {
  margin-bottom: 20px;
}
.api-url-details summary {
  font-size: 14px;
  color: #6b7280;
  cursor: pointer;
  padding: 4px 0;
}
.api-url-details[open] summary {
  margin-bottom: 12px;
}

.api-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.preset-btn {
  padding: 8px 14px;
  border: 2px solid #e5e7eb;
  background: white;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: #374151;
  -webkit-tap-highlight-color: transparent;
}

.preset-btn:hover {
  border-color: #dc2626;
  color: #dc2626;
}

.preset-btn.preset-prod {
  border-color: #22c55e;
  color: #16a34a;
}

.preset-btn.preset-prod:hover {
  background: #dcfce7;
}

.preset-btn.preset-save {
  font-size: 12px;
  color: #6b7280;
  border-style: dashed;
}

.preset-btn.preset-save:hover {
  border-color: #9ca3af;
  color: #374151;
}

/* Painel */
.panel-header {
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
  color: white;
  padding: 20px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.panel-header h1 {
  font-size: 22px;
}

.btn-outline {
  background: transparent;
  border: 2px solid white;
  color: white;
  padding: 8px 16px;
  -webkit-tap-highlight-color: transparent;
}

.btn-outline:hover {
  background: rgba(255,255,255,0.2);
}

.tabs {
  display: flex;
  gap: 4px;
  background: white;
  padding: 12px 24px 0;
  border-bottom: 1px solid #e5e7eb;
}

.tab-btn {
  padding: 12px 20px;
  border: none;
  background: none;
  font-size: 15px;
  font-weight: 600;
  color: #6b7280;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  transition: all 0.2s;
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
}

.tab-btn:hover { color: #374151; }

.tab-btn.active {
  color: #dc2626;
  border-bottom-color: #dc2626;
}

.panel-content {
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
}

.tab-pane { display: none; }
.tab-pane.active { display: block; }

.search-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.search-bar input,
.search-bar select {
  padding: 12px 14px;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  font-size: 14px;
  min-height: 44px;
}

.search-bar input {
  font-size: 16px; /* evita zoom no iOS */
}

.search-bar input {
  flex: 1;
  min-width: 200px;
}

.search-bar .btn {
  flex-shrink: 0;
}

.search-bar input:focus,
.search-bar select:focus {
  outline: none;
  border-color: #dc2626;
}

.orders-table-wrapper,
.users-table-wrapper {
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  overflow: hidden;
}

.orders-table,
.users-table {
  width: 100%;
  border-collapse: collapse;
}

.orders-table th,
.orders-table td,
.users-table th,
.users-table td {
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid #f3f4f6;
}

.orders-table th,
.users-table th {
  background: #f9fafb;
  font-weight: 600;
  color: #374151;
  font-size: 13px;
}

.orders-table tr:hover,
.users-table tr:hover {
  background: #fafafa;
}

.orders-table tr.clickable {
  cursor: pointer;
}

.status-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.status-PENDING { background: #fef3c7; color: #92400e; }
.status-PREPARING { background: #dbeafe; color: #1e40af; }
.status-READY { background: #dcfce7; color: #166534; }
.status-DELIVERING { background: #e0e7ff; color: #3730a3; }
.status-DELIVERED { background: #d1fae5; color: #065f46; }
.status-CANCELLED { background: #fee2e2; color: #991b1b; }

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}

.modal-overlay.open {
  display: flex;
}

.modal-content {
  background: white;
  border-radius: 12px;
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  overflow-x: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  -webkit-overflow-scrolling: touch;
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-size: 18px;
  color: #1f2937;
}

.modal-close {
  background: none;
  border: none;
  font-size: 28px;
  cursor: pointer;
  color: #6b7280;
  padding: 8px;
  min-width: 48px;
  min-height: 48px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.modal-close:hover { color: #dc2626; }

.modal-body {
  padding: 24px;
}

.order-detail-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid #f3f4f6;
  font-size: 14px;
}

.order-detail-row strong { color: #374151; }

.order-items {
  margin-top: 20px;
}

.order-items h4 {
  margin-bottom: 12px;
  font-size: 15px;
  color: #374151;
}

.order-item {
  padding: 12px;
  background: #f9fafb;
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 14px;
}

.order-item-additions {
  margin-left: 16px;
  margin-top: 6px;
  color: #6b7280;
  font-size: 13px;
}

.status-edit {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid #e5e7eb;
}

.status-edit select {
  padding: 10px 14px;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  font-size: 14px;
  min-width: 160px;
}

.loading {
  text-align: center;
  padding: 40px;
  color: #6b7280;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #9ca3af;
}

/* ========== Mobile First ========== */
@media (max-width: 768px) {
  .login-container {
    padding: 20px 16px;
  }
  .login-header h1 {
    font-size: 20px;
  }
  .login-header p {
    font-size: 13px;
  }
  .login-hint {
    font-size: 11px;
  }

  /* Painel header */
  .panel-header {
    padding: 16px;
    padding-top: calc(16px + env(safe-area-inset-top));
  }
  .panel-header h1 {
    font-size: 18px;
  }
  .btn-outline {
    padding: 10px 14px;
  }

  /* Tabs */
  .tabs {
    padding: 8px 12px 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .tab-btn {
    padding: 12px 16px;
    font-size: 14px;
    white-space: nowrap;
  }

  /* Conteúdo */
  .panel-content {
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }

  /* Search bar - empilha no mobile */
  .search-bar {
    flex-direction: column;
    gap: 10px;
  }
  .search-bar input {
    min-width: 100%;
  }
  .search-bar select {
    width: 100%;
    font-size: 16px; /* evita zoom no iOS */
  }

  /* Tabela -> Cards no mobile */
  .orders-table-wrapper,
  .users-table-wrapper {
    overflow: visible;
  }
  .orders-table thead,
  .users-table thead {
    display: none;
  }
  .orders-table tr,
  .users-table tr {
    display: block;
    margin-bottom: 12px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    overflow: hidden;
    border: 1px solid #eee;
  }
  .orders-table tr.clickable {
    cursor: pointer;
  }
  .orders-table td,
  .users-table td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 12px 16px;
    border-bottom: 1px solid #f3f4f6;
  }
  .orders-table td:last-child,
  .users-table td:last-child {
    border-bottom: none;
  }
  .orders-table td::before,
  .users-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #6b7280;
    font-size: 12px;
    margin-right: 12px;
    flex-shrink: 0;
  }
  .orders-table td:first-child::before { content: 'ID'; }
  .orders-table td:nth-child(2)::before { content: 'Cliente'; }
  .orders-table td:nth-child(3)::before { content: 'Estabelecimento'; }
  .orders-table td:nth-child(4)::before { content: 'Endereço'; }
  .orders-table td:nth-child(5)::before { content: 'Total'; }
  .orders-table td:nth-child(6)::before { content: 'Status'; }
  .orders-table td:nth-child(7)::before { content: 'Data'; }
  .users-table td:first-child::before { content: 'ID'; }
  .users-table td:nth-child(2)::before { content: 'Nome'; }
  .users-table td:nth-child(3)::before { content: 'E-mail'; }
  .users-table td:nth-child(4)::before { content: 'Perfil'; }
  .users-table td:nth-child(5)::before { content: 'Telefone'; }

  /* Modal full-screen no mobile */
  .modal-overlay {
    padding: 0;
    align-items: stretch;
  }
  .modal-content {
    max-height: none;
    height: 100%;
    border-radius: 0;
    margin: 0;
  }
  .modal-header {
    padding: 16px;
    padding-top: calc(16px + env(safe-area-inset-top));
  }
  .modal-body {
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }

  /* Status edit empilha */
  .status-edit {
    flex-direction: column;
    align-items: stretch;
  }
  .status-edit select {
    min-width: 100%;
    font-size: 16px; /* evita zoom no iOS */
    min-height: 48px;
  }
  .status-edit label {
    margin-bottom: 4px;
  }

  .order-detail-row {
    flex-wrap: wrap;
    gap: 4px;
  }
}

/* Telas muito pequenas */
@media (max-width: 380px) {
  .login-header h1 {
    font-size: 18px;
  }
  .panel-header h1 {
    font-size: 16px;
  }
}
