/* ============================================================
   SISTEMA DE ENTREGAS - Lojas Aqui Tem
   Estilo global - Mobile-first, foco em usabilidade
   ============================================================ */

/* --- Reset e base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1a73e8;
  --primary-dark: #1557b0;
  --primary-light: #e8f0fe;
  --success: #0d904f;
  --success-light: #e6f4ea;
  --warning: #e37400;
  --warning-light: #fef7e0;
  --danger: #c5221f;
  --danger-light: #fce8e6;
  --info: #0b57d0;
  --gray-50: #f8f9fa;
  --gray-100: #f1f3f4;
  --gray-200: #e8eaed;
  --gray-300: #dadce0;
  --gray-400: #bdc1c6;
  --gray-500: #9aa0a6;
  --gray-600: #80868b;
  --gray-700: #5f6368;
  --gray-800: #3c4043;
  --gray-900: #202124;
  --white: #ffffff;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.1);
  --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 6px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.06);
  --radius: 8px;
  --radius-lg: 12px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html { font-size: 15px; }
body { 
  font-family: var(--font);
  background: var(--gray-50); 
  color: var(--gray-900);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Layout --- */
.app-container { max-width: 1200px; margin: 0 auto; padding: 16px; }

.app-header {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.app-header h1 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--gray-800);
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-header .user-info {
  font-size: 0.85rem;
  color: var(--gray-600);
  display: flex;
  align-items: center;
  gap: 12px;
}

/* --- Cards --- */
.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.card-header {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* --- Formulários --- */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: 4px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-family: var(--font);
  transition: border-color 0.15s;
  background: var(--white);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,115,232,0.15);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 600px) {
  .form-row { grid-template-columns: 1fr; }
}

/* --- Botões --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
  text-align: center;
}

.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover:not(:disabled) { background: #0a7340; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { background: #a31c1a; }
.btn-warning { background: var(--warning); color: white; }
.btn-outline { background: transparent; border: 1px solid var(--gray-300); color: var(--gray-700); }
.btn-outline:hover { background: var(--gray-100); }
.btn-sm { padding: 6px 12px; font-size: 0.82rem; }
.btn-lg { padding: 14px 28px; font-size: 1rem; }
.btn-block { width: 100%; }
.btn-icon { width: 36px; height: 36px; padding: 0; border-radius: 50%; }

/* --- Tabelas --- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--gray-200);
}

th {
  font-weight: 600;
  color: var(--gray-700);
  background: var(--gray-50);
  position: sticky;
  top: 0;
}

tr:hover { background: var(--gray-50); }

/* --- Badges/Tags de status --- */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
}

.badge-pending { background: var(--warning-light); color: var(--warning); }
.badge-loading { background: #e0f2f1; color: #00695c; }
.badge-in_route, .badge-in-route { background: #e3f2fd; color: #1565c0; }
.badge-delivered { background: var(--success-light); color: var(--success); }
.badge-partial { background: #fff3e0; color: #e65100; }
.badge-failed { background: var(--danger-light); color: var(--danger); }
.badge-overdue { background: var(--danger); color: white; }
.badge-high { background: var(--warning); color: white; }
.badge-urgent { background: var(--danger); color: white; }

/* --- Barra de pesquisa --- */
.search-bar {
  position: relative;
  margin-bottom: 16px;
}

.search-bar input {
  width: 100%;
  padding: 12px 16px 12px 44px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-lg);
  font-size: 1rem;
  background: var(--white);
}

.search-bar input:focus {
  border-color: var(--primary);
  outline: none;
}

.search-bar::before {
  content: '🔍';
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.1rem;
}

/* --- Scanner area (campo grande para scan de código) --- */
.scan-input {
  padding: 16px 20px !important;
  font-size: 1.2rem !important;
  font-family: 'Courier New', monospace;
  letter-spacing: 1px;
  text-align: center;
  border: 2px dashed var(--primary) !important;
  background: var(--primary-light) !important;
}

.scan-input::placeholder {
  font-family: var(--font);
  letter-spacing: 0;
  font-size: 0.95rem;
  color: var(--gray-500);
}

/* --- Item list (itens da nota/entrega) --- */
.item-list {
  list-style: none;
}

.item-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--gray-100);
}

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

.item-check { flex-shrink: 0; }
.item-check input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--primary); }

.item-info { flex: 1; min-width: 0; }
.item-info .item-name { font-weight: 500; font-size: 0.92rem; }
.item-info .item-detail { font-size: 0.8rem; color: var(--gray-600); }

.item-qty {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.item-qty input {
  width: 60px;
  padding: 6px;
  text-align: center;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.qty-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--gray-300);
  border-radius: 50%;
  background: var(--white);
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qty-btn:active { background: var(--gray-100); }

/* --- Stats/Dashboard cards --- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  border-left: 4px solid var(--primary);
}

.stat-card .stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--gray-900);
}

.stat-card .stat-label {
  font-size: 0.78rem;
  color: var(--gray-600);
  margin-top: 2px;
}

.stat-card.stat-pending { border-left-color: var(--warning); }
.stat-card.stat-route { border-left-color: var(--info); }
.stat-card.stat-delivered { border-left-color: var(--success); }
.stat-card.stat-partial { border-left-color: #e65100; }
.stat-card.stat-failed { border-left-color: var(--danger); }
.stat-card.stat-overdue { border-left-color: var(--danger); background: var(--danger-light); }

/* --- Delivery card (motorista) --- */
.delivery-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: box-shadow 0.15s;
  border-left: 4px solid var(--gray-300);
}

.delivery-card:active { box-shadow: var(--shadow-lg); }
.delivery-card.priority-high { border-left-color: var(--warning); }
.delivery-card.priority-urgent { border-left-color: var(--danger); }
.delivery-card.overdue { border-left-color: var(--danger); background: #fff5f5; }

.delivery-card .dc-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  margin-bottom: 8px;
}

.delivery-card .dc-customer {
  font-weight: 600;
  font-size: 0.95rem;
}

.delivery-card .dc-address {
  font-size: 0.85rem;
  color: var(--gray-600);
  margin-bottom: 4px;
}

.delivery-card .dc-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--gray-500);
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--gray-100);
}

/* --- Bairro group (motorista) --- */
.neighborhood-group {
  margin-bottom: 20px;
}

.neighborhood-group h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--gray-700);
  padding: 8px 12px;
  background: var(--gray-100);
  border-radius: var(--radius);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.neighborhood-group h3 .count {
  background: var(--primary);
  color: white;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.78rem;
}

/* --- Tabs --- */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--gray-200);
  margin-bottom: 16px;
  overflow-x: auto;
}

.tab {
  padding: 10px 18px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--gray-600);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: all 0.15s;
}

.tab:hover { color: var(--gray-800); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

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

/* --- Filters --- */
.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}

.filters select, .filters input {
  padding: 7px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-family: var(--font);
  background: var(--white);
}

/* --- Modal / Dialog --- */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}

.modal-body { padding: 20px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--gray-200); display: flex; gap: 8px; justify-content: flex-end; }

.modal-close {
  width: 32px; height: 32px; border: none; background: none;
  font-size: 1.3rem; cursor: pointer; color: var(--gray-600);
  border-radius: 50%;
}
.modal-close:hover { background: var(--gray-100); }

/* --- Toast notifications --- */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 0.88rem;
  animation: slideIn 0.3s ease;
  min-width: 280px;
  max-width: 400px;
}

.toast-success { background: var(--success); color: white; }
.toast-error { background: var(--danger); color: white; }
.toast-warning { background: var(--warning); color: white; }
.toast-info { background: var(--info); color: white; }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* --- Loading spinner --- */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 0.8s linear infinite;
}

.spinner-dark {
  border-color: var(--gray-300);
  border-top-color: var(--primary);
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(255,255,255,0.8);
  z-index: 250;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
}

/* --- Signature canvas area --- */
.signature-area {
  border: 2px solid var(--gray-300);
  border-radius: var(--radius);
  background: var(--white);
  touch-action: none;
  cursor: crosshair;
}

/* --- Timeline (eventos) --- */
.timeline { padding-left: 24px; border-left: 2px solid var(--gray-200); }
.timeline-item { padding: 8px 0 8px 16px; position: relative; font-size: 0.85rem; }
.timeline-item::before {
  content: '';
  width: 10px; height: 10px;
  background: var(--primary);
  border-radius: 50%;
  position: absolute;
  left: -30px;
  top: 13px;
}
.timeline-item .tl-time { font-size: 0.78rem; color: var(--gray-500); }
.timeline-item .tl-text { color: var(--gray-800); }

/* --- Clickable contact links (motorista) --- */
.contact-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--gray-100);
  border-radius: var(--radius);
  font-size: 0.88rem;
  color: var(--gray-800);
  text-decoration: none;
  margin: 4px 4px 4px 0;
}
.contact-link:hover { background: var(--gray-200); text-decoration: none; }
.contact-link.whatsapp { background: #dcf8c6; color: #128c7e; }
.contact-link.maps { background: #e8f0fe; color: #1a73e8; }
.contact-link.phone { background: #fce8e6; color: #c5221f; }

/* --- Empty state --- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--gray-500);
}
.empty-state .emoji { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { font-size: 0.95rem; }

/* --- Login page --- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1a73e8 0%, #0d47a1 100%);
  padding: 20px;
}

.login-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.login-card h1 {
  font-size: 1.5rem;
  margin-bottom: 8px;
  color: var(--gray-900);
}

.login-card .subtitle {
  font-size: 0.88rem;
  color: var(--gray-600);
  margin-bottom: 28px;
}

/* --- Utilities --- */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-small { font-size: 0.82rem; }
.text-muted { color: var(--gray-600); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.hidden { display: none !important; }
.w-full { width: 100%; }

/* --- Print --- */
@media print {
  .app-header, .btn, .filters, .tabs, .search-bar { display: none !important; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}
