/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --secondary: #64748b;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --info: #0891b2;
  --info-light: #ecfeff;
  --bg: #f1f5f9;
  --bg-card: #ffffff;
  --text: #0f172a;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --sidebar-w: 260px;
  --topbar-h: 60px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
}

html { overflow-x: hidden; }
body { font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; overflow-x: hidden; }

/* ===== UTILITIES ===== */
.hidden { display: none !important; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.font-bold { font-weight: 700; }
.text-secondary { color: var(--text-secondary); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== ALERTS ===== */
.alert { padding: 10px 14px; border-radius: 8px; font-size: 0.875rem; margin-bottom: 12px; }
.alert-error { background: var(--danger-light); color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: var(--success-light); color: var(--success); border: 1px solid #bbf7d0; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px; border: none;
  font-size: 0.875rem; font-weight: 600; cursor: pointer;
  transition: all .15s; text-decoration: none;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: #d1d5db; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #15803d; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover:not(:disabled) { background: #b45309; }
.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--bg); }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-full { width: 100%; justify-content: center; }
.btn-icon { padding: 8px; width: 36px; height: 36px; justify-content: center; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.875rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
input[type=text], input[type=email], input[type=password], input[type=tel],
input[type=number], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 0.875rem; font-family: inherit;
  background: var(--bg-card); color: var(--text);
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
textarea { resize: vertical; min-height: 80px; }
/* Remove number input spinners (prevent overflow on mobile) */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }

/* ===== BADGES ===== */
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 600;
}
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-secondary { background: #f1f5f9; color: var(--secondary); }
.badge-info { background: var(--info-light); color: var(--info); }

/* ===== LOGIN ===== */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
}
.login-card {
  background: #fff; border-radius: 16px; padding: 40px; width: 100%; max-width: 420px;
  box-shadow: var(--shadow-lg);
}
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo i { font-size: 3rem; color: var(--primary); }
.login-logo h1 { font-size: 1.75rem; font-weight: 800; color: var(--text); margin-top: 8px; }
.login-logo p { color: var(--text-secondary); font-size: 0.9rem; }
.login-demo { text-align: center; margin-top: 16px; color: var(--text-secondary); }

/* ===== LAYOUT ===== */
#main-app { display: flex; min-height: 100vh; }

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w); background: #0f172a; color: #fff;
  display: flex; flex-direction: column; position: fixed;
  top: 0; left: 0; bottom: 0; z-index: 1100;
  transition: transform .3s ease;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 16px; border-bottom: 1px solid rgba(255,255,255,.1);
}
.sidebar-logo { display: flex; align-items: center; gap: 10px; }
.sidebar-logo i { font-size: 1.5rem; color: var(--primary); }
.sidebar-logo span { font-size: 1.2rem; font-weight: 800; }
.sidebar-toggle-btn { background: none; border: none; color: #94a3b8; cursor: pointer; font-size: 1rem; }
.sidebar-close-mobile { display: none; background: none; border: none; color: #94a3b8; cursor: pointer; font-size: 1.2rem; padding: 4px 6px; }
.sidebar-overlay { display: none; position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: rgba(0,0,0,.5); z-index: 1050; }
.sidebar-overlay.open { display: block; }

.sidebar-user {
  padding: 16px; display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
.user-avatar i { font-size: 2rem; color: #94a3b8; }
.user-name { display: block; font-weight: 600; font-size: 0.9rem; }
.user-role { display: block; font-size: 0.75rem; color: #64748b; text-transform: uppercase; letter-spacing: .05em; }

.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 8px; color: #94a3b8;
  text-decoration: none; font-size: 0.9rem; font-weight: 500;
  transition: all .15s; margin-bottom: 2px;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item i { width: 18px; text-align: center; }

.sidebar-footer { padding: 12px 8px calc(12px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid rgba(255,255,255,.1); }
.btn-location {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px; background: none; border: none;
  color: #94a3b8; font-size: 0.875rem; cursor: pointer; margin-bottom: 4px;
  transition: all .15s;
}
.btn-location:hover { background: rgba(255,255,255,.08); color: #fff; }
.btn-location.active { color: #4ade80; }
.btn-logout {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px; background: none; border: none;
  color: #94a3b8; font-size: 0.875rem; cursor: pointer; transition: all .15s;
}
.btn-logout:hover { background: rgba(220,38,38,.2); color: #f87171; }

/* ===== MAIN CONTENT ===== */
.main-content {
  flex: 1; margin-left: var(--sidebar-w); display: flex;
  flex-direction: column; min-height: 100vh;
}

/* ===== TOPBAR ===== */
.topbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  padding: var(--status-bar-height, env(safe-area-inset-top, 0px)) 24px 0;
  min-height: calc(var(--topbar-h) + var(--status-bar-height, env(safe-area-inset-top, 0px)));
  position: sticky; top: 0; z-index: 950;
  box-shadow: var(--shadow);
}
.mobile-menu-btn { display: none; background: none; border: none; cursor: pointer; font-size: 1.2rem; color: var(--text-secondary); }
.topbar-title { font-size: 1.1rem; font-weight: 700; flex: 1; }
.location-status { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--success); }
.pulse { animation: pulse 1.5s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

/* ===== PAGES ===== */
.page { display: none; flex: 1; min-width: 0; max-width: 100%; }
.page.active { display: block; }
.page-content { padding: 24px 24px calc(24px + env(safe-area-inset-bottom, 0px)); max-width: 100%; overflow-x: hidden; }
.page-content.no-pad { padding: 0; }
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.page-header h2 { font-size: 1.4rem; font-weight: 700; }

/* ===== STATS GRID ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card {
  background: var(--bg-card); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: row; align-items: center; gap: 12px;
}
.stat-card-clickable {
  cursor: pointer; transition: transform .15s, box-shadow .15s;
}
.stat-card-clickable:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,.1); }
.stat-icon { width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1.2rem; flex-shrink: 0; }
.stat-text { flex: 1; min-width: 0; }
.stat-value { font-size: 1.75rem; font-weight: 800; line-height: 1; }
.stat-label { font-size: 0.78rem; color: var(--text-secondary); font-weight: 500; margin-top: 2px; }

/* ===== DASHBOARD GRID ===== */
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .dashboard-grid { grid-template-columns: 1fr; } }

/* ===== CARDS ===== */
.card { background: var(--bg-card); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-header h3 { font-size: 0.95rem; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.card-header .link { font-size: 0.8rem; color: var(--primary); text-decoration: none; }

/* ===== ORDER LIST (Dashboard) ===== */
.order-list { padding: 8px 0; }
.order-list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background .1s;
}
.order-list-item:last-child { border-bottom: none; }
.order-list-item:hover { background: var(--bg); }
.order-list-item .order-priority-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.order-list-info { flex: 1; min-width: 0; }
.order-list-title { font-size: 0.875rem; font-weight: 600; }
.order-list-meta { font-size: 0.75rem; color: var(--text-secondary); display: flex; gap: 8px; margin-top: 2px; }

/* ===== TECH LIST (Dashboard) ===== */
.tech-list { padding: 8px 0; }
.tech-list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
}
.tech-list-item:last-child { border-bottom: none; }
.tech-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary-light); display: flex; align-items: center; justify-content: center; color: var(--primary); font-weight: 700; font-size: 0.875rem; flex-shrink: 0; }
.tech-info { flex: 1; min-width: 0; }
.tech-name { font-size: 0.875rem; font-weight: 600; }
.tech-meta { font-size: 0.75rem; color: var(--text-secondary); }
.tech-status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-online { background: #4ade80; }
.dot-offline { background: #94a3b8; }

/* ===== MAP ===== */
#map-container { display: flex; height: calc(100vh - var(--topbar-h)); min-height: 300px; }
#map { flex: 1; z-index: 1; min-height: 300px; }
.map-sidebar {
  width: 300px; background: var(--bg-card); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.map-sidebar-header {
  padding: 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.map-sidebar-header h3 { font-size: 1rem; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.map-tech-list { flex: 1; overflow-y: auto; }
.map-tech-item {
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background .1s;
}
.map-tech-item:hover { background: var(--bg); }
.map-tech-item .tech-name { font-weight: 600; font-size: 0.9rem; }
.map-tech-item .tech-detail { font-size: 0.78rem; color: var(--text-secondary); margin-top: 4px; display: flex; flex-direction: column; gap: 2px; }
.map-tech-item .status-chip { display: inline-flex; align-items: center; gap: 4px; font-size: 0.72rem; padding: 2px 6px; border-radius: 4px; }

/* ===== ORDERS GRID ===== */
.orders-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.order-card {
  background: var(--bg-card); border-radius: var(--radius); box-shadow: var(--shadow);
  border-left: 4px solid transparent; overflow: hidden;
  transition: transform .15s, box-shadow .15s; cursor: pointer;
}
.order-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.order-card.priority-urgent { border-left-color: var(--danger); }
.order-card.priority-high { border-left-color: var(--warning); }
.order-card.priority-medium { border-left-color: var(--primary); }
.order-card.priority-low { border-left-color: var(--secondary); }
.order-card-header { padding: 14px 16px 10px; }
.order-card-title { font-weight: 700; font-size: 0.95rem; margin-bottom: 6px; }
.order-card-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.order-card-body { padding: 0 16px 14px; }
.order-card-row { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 5px; }
.order-card-row i { width: 14px; color: var(--primary); }
.order-card-footer {
  padding: 10px 16px; background: var(--bg); border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; font-size: 0.78rem;
}

/* ===== FILTERS BAR ===== */
.filters-bar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 20px; align-items: center; }
.filter-select { padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border); font-size: 0.85rem; background: var(--bg-card); }

/* ===== ORDER MODAL ===== */
.order-detail { display: grid; grid-template-columns: 1fr 340px; gap: 20px; }
.order-detail-main {}
.order-detail-side {}
.order-info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px; }
.order-info-item { background: var(--bg); padding: 12px; border-radius: 8px; }
.order-info-label { font-size: 0.75rem; color: var(--text-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.order-info-value { font-size: 0.9rem; font-weight: 600; word-break: break-word; overflow-wrap: break-word; }
.section-title { font-size: 0.9rem; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.photos-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.photo-item { position: relative; width: 100%; padding-bottom: 100%; border-radius: 8px; overflow: hidden; cursor: pointer; }
.photo-item img, .photo-item > * { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; }
.photo-item img { width: 100%; height: 100%; object-fit: cover; }
.photo-item:hover img { opacity: .85; }
.photo-delete-btn {
  position: absolute; top: 4px; right: 4px; background: rgba(220,38,38,.9);
  border: none; color: #fff; border-radius: 50%; width: 24px; height: 24px;
  font-size: 0.7rem; cursor: pointer; display: none; align-items: center; justify-content: center;
}
.photo-item:hover .photo-delete-btn { display: flex; }

/* Upload zone */
.upload-zone {
  border: 2px dashed var(--border); border-radius: 10px; padding: 20px;
  text-align: center; color: var(--text-secondary); cursor: pointer;
  transition: all .15s; margin-bottom: 16px;
}
.upload-zone:hover, .upload-zone.dragover { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }
.upload-zone i { font-size: 2rem; margin-bottom: 8px; }
.upload-zone p { font-size: 0.85rem; }
.upload-zone input { display: none; }

/* History */
.history-list { max-height: 200px; overflow-y: auto; }
.history-item { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 0.8rem; }
.history-item:last-child { border-bottom: none; }
.history-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); margin-top: 5px; flex-shrink: 0; }
.history-content { flex: 1; }

/* ===== TECHNICIANS GRID ===== */
.technicians-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.technician-card { background: var(--bg-card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.tech-card-header { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.tech-card-avatar { width: 48px; height: 48px; border-radius: 50%; background: var(--primary-light); display: flex; align-items: center; justify-content: center; color: var(--primary); font-weight: 700; font-size: 1.1rem; flex-shrink: 0; }
.tech-card-name { font-weight: 700; font-size: 1rem; }
.tech-card-team { font-size: 0.8rem; color: var(--text-secondary); }
.tech-card-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.tech-stat { background: var(--bg); padding: 10px 12px; border-radius: 8px; text-align: center; }
.tech-stat-value { font-size: 1.5rem; font-weight: 800; }
.tech-stat-label { font-size: 0.72rem; color: var(--text-secondary); }
.tech-card-footer { display: flex; gap: 8px; }

/* ===== TEAMS GRID ===== */
.teams-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.team-card { background: var(--bg-card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.team-card-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 14px; }
.team-name { font-weight: 700; font-size: 1.05rem; }
.team-desc { font-size: 0.8rem; color: var(--text-secondary); margin-top: 2px; }
.team-actions { display: flex; gap: 6px; }
.team-info { font-size: 0.85rem; color: var(--text-secondary); display: flex; flex-direction: column; gap: 6px; }
.team-info span { display: flex; align-items: center; gap: 6px; }

/* ===== USERS TABLE ===== */
.users-table-wrap { background: var(--bg-card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; max-width: 100%; }
.users-table { width: 100%; border-collapse: collapse; }
.users-table th { padding: 12px 16px; text-align: left; font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-secondary); background: var(--bg); border-bottom: 1px solid var(--border); }
.users-table td { padding: 12px 16px; font-size: 0.875rem; border-bottom: 1px solid var(--border); }
.users-table tr:last-child td { border-bottom: none; }
.users-table tr:hover td { background: var(--bg); }

/* ===== MODAL ===== */
.modal { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 10000; display: none; align-items: center; justify-content: center; padding: 16px; }
.modal.active, .modal[style*="display:flex"], .modal[style*="display: flex"] { display: flex; }
.modal-overlay { position: absolute; top: 0; right: 0; bottom: 0; left: 0; background: rgba(0,0,0,.5); z-index: 0; pointer-events: none; }
.modal-container {
  position: relative; background: var(--bg-card); border-radius: 16px;
  width: 100%; max-width: 620px; max-height: 90vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg); z-index: 1;
}
.modal-large { max-width: 900px; }
.modal-small { max-width: 440px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.modal-header h2 { font-size: 1.1rem; font-weight: 700; }
.modal-close { background: none; border: none; cursor: pointer; font-size: 1.1rem; color: var(--text-secondary); padding: 4px; border-radius: 6px; }
.modal-close:hover { background: var(--bg); }
.modal-body { padding: 24px; overflow-y: auto; overflow-x: hidden; flex: 1; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ===== TOAST ===== */
.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #1e293b; color: #fff; padding: 12px 16px; border-radius: 10px;
  font-size: 0.875rem; display: flex; align-items: center; gap: 10px;
  box-shadow: var(--shadow-lg); animation: slideIn .2s ease; max-width: 320px;
}
.toast.toast-success { background: var(--success); }
.toast.toast-error { background: var(--danger); }
.toast.toast-warning { background: var(--warning); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ===== STATUS COLORS ===== */
.status-pending { background: #f1f5f9; color: #475569; }
.status-in_progress { background: var(--primary-light); color: var(--primary); }
.status-completed { background: var(--success-light); color: var(--success); }
.status-cancelled { background: var(--danger-light); color: var(--danger); }
.priority-urgent-badge { background: var(--danger-light); color: var(--danger); }
.priority-high-badge { background: var(--warning-light); color: var(--warning); }
.priority-medium-badge { background: var(--primary-light); color: var(--primary); }
.priority-low-badge { background: #f1f5f9; color: #475569; }

/* ===== COMPLETION FORM ===== */
.completion-section { background: var(--success-light); border: 1px solid #bbf7d0; border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.completion-section h4 { color: var(--success); font-size: 0.95rem; margin-bottom: 12px; }

/* ===== EMPTY STATE ===== */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-secondary); }
.empty-state i { font-size: 3rem; margin-bottom: 12px; opacity: .4; }
.empty-state p { font-size: 0.95rem; }

/* ===== LIGHTBOX ===== */
#lightbox { position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: rgba(0,0,0,.9); z-index: 10001; display: flex; align-items: center; justify-content: center; }
#lightbox img { max-width: 90vw; max-height: 90vh; border-radius: 8px; }
#lightbox-close { position: absolute; top: 16px; right: 16px; background: rgba(255,255,255,.2); border: none; color: #fff; font-size: 1.5rem; cursor: pointer; border-radius: 50%; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); pointer-events: none; }
  .sidebar.open { transform: translateX(0); pointer-events: auto; }
  .main-content { margin-left: 0; }
  .mobile-menu-btn { display: block; }
  .sidebar-close-mobile { display: block; }

  /* Layout */
  .page-content { padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px)); }
  .page-header { flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
  .page-header h2 { font-size: 1.15rem; }

  /* Grids */
  .dashboard-grid { grid-template-columns: 1fr; gap: 12px; }
  .orders-grid { grid-template-columns: 1fr; gap: 10px; }
  .order-detail { grid-template-columns: 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .order-info-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .technicians-grid { grid-template-columns: 1fr; gap: 10px; }
  .teams-grid { grid-template-columns: 1fr; gap: 10px; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }

  /* Stats cards menores no mobile */
  .stat-card { padding: 12px; }
  .stat-value { font-size: 1.5rem; }
  .stat-icon { width: 38px; height: 38px; font-size: 1rem; }

  /* Order cards */
  .order-card-header { padding: 12px 14px 8px; }
  .order-card-body { padding: 0 14px 12px; }
  .order-card-footer { padding: 8px 14px; }

  /* Prevent iOS auto-zoom on input focus */
  input[type=text], input[type=email], input[type=password], input[type=tel],
  input[type=number], select, textarea { font-size: 16px; }

  /* Touch targets */
  .btn { min-height: 44px; }
  .btn-sm { min-height: 38px; padding: 6px 12px; }
  .nav-item { min-height: 48px; }

  /* Modal — bottom sheet */
  .modal { padding: 0; align-items: flex-end; }
  .modal-container {
    max-height: 92vh; border-radius: 20px 20px 0 0;
    width: 100%; max-width: 100vw; overflow: hidden;
  }
  .modal-header { padding: 16px 16px 12px; }
  .modal-header h2 { font-size: 1rem; }
  .modal-body {
    padding: 12px 16px calc(20px + env(safe-area-inset-bottom, 0px));
    overflow-x: hidden; overflow-y: auto;
  }
  .modal-actions { flex-direction: column-reverse; gap: 8px; margin-top: 16px; }
  .modal-actions .btn { width: 100%; justify-content: center; }

  /* Form inside modal */
  #form-modal .modal-body form,
  #order-modal .modal-body form { width: 100%; max-width: 100%; }
  .form-group input, .form-group select, .form-group textarea {
    width: 100%; max-width: 100%;
  }
  input[type="file"] { max-width: 100%; }

  /* Map */
  #map-container { flex-direction: column; }
  .map-sidebar { width: 100%; height: 220px; border-left: none; border-top: 1px solid var(--border); }
  .map-tech-list { flex-direction: row; overflow-x: auto; display: flex; }
  .map-tech-item { min-width: 180px; }

  /* Filters */
  .filters-bar { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
  .filters-bar::-webkit-scrollbar { display: none; }
  .filter-select { flex-shrink: 0; font-size: 0.85rem; }

  /* Photos */
  .photos-grid { grid-template-columns: repeat(2, 1fr); gap: 6px; }

  /* Upload zone */
  .upload-zone { padding: 14px; }
  .upload-zone i { font-size: 1.5rem; }

  /* Toast */
  .toast-container { bottom: 12px; right: 8px; left: 8px; }
  .toast { max-width: 100%; font-size: 0.85rem; }

  /* Login */
  .login-card { padding: 24px 18px; margin: 16px; }
  .login-logo i { font-size: 2.2rem; }
  .login-logo h1 { font-size: 1.5rem; }

  /* Users table — hide less important columns on mobile to keep layout contained */
  .users-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
  .users-table th, .users-table td { padding: 10px 10px; font-size: 0.82rem; }
  .users-table .col-email,
  .users-table .col-team,
  .users-table .col-phone { display: none; }

  /* Topbar */
  .topbar { padding: 0 14px; }
  .topbar-title { font-size: 0.95rem; }

  /* Order info grid menor */
  .order-info-item { padding: 10px; }
  .order-info-value { font-size: 0.85rem; }

  /* Section title */
  .section-title { font-size: 0.8rem; margin-bottom: 8px; }

  /* Dashboard cards */
  .card-header { padding: 12px 14px; }
  .order-list-item { padding: 10px 14px; }
  .tech-list-item { padding: 10px 14px; }
}

/* ===== MOBILE PEQUENO (até 480px) ===== */
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-card { padding: 10px; gap: 8px; }
  .stat-value { font-size: 1.35rem; }
  .stat-label { font-size: 0.72rem; }
  .stat-icon { width: 34px; height: 34px; font-size: 0.9rem; }

  .page-content { padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0px)); }
  .page-header h2 { font-size: 1.05rem; }

  .order-info-grid { grid-template-columns: 1fr; }

  .badge { font-size: 0.7rem; padding: 2px 6px; }
  .order-card-badges { gap: 4px; }

  .modal-header h2 { font-size: 0.95rem; }

  .btn-sm { font-size: 0.78rem; padding: 5px 10px; }
}

/* ===== SIGNATURE PAD OVERLAY ===== */
#sig-overlay {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: rgba(0,0,0,.6); z-index: 10000;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.sig-modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 500px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3); display: flex; flex-direction: column; gap: 12px;
  padding-bottom: 16px; max-height: 90vh; overflow-y: auto;
}
.sig-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 0; position: sticky; top: 0; background: #fff; z-index: 1;
  border-bottom: 1px solid #f1f5f9; padding-bottom: 12px; margin-bottom: -4px;
}
.sig-modal-header h3 { font-size: 1.1rem; color: var(--text); }
.sig-modal-actions {
  display: flex; gap: 10px; padding: 0 16px; justify-content: flex-end;
}
#sig-canvas { height: 180px; width: 100%; display: block; }

@media (max-width: 768px) {
  #sig-overlay { padding: 0; align-items: flex-end; background: rgba(0,0,0,.7); }
  .sig-modal {
    max-width: 100%; border-radius: 20px 20px 0 0;
    max-height: 92vh; padding-bottom: env(safe-area-inset-bottom, 16px);
  }
  .sig-modal-header { padding: 16px 16px 12px; }
  .sig-modal-header h3 { font-size: 1rem; }
  .sig-modal-actions { flex-direction: row; gap: 8px; }
  .sig-modal-actions .btn { flex: 1; justify-content: center; min-height: 48px; font-size: 0.95rem; }
  #sig-canvas { height: 220px; }
  .sig-pdf-iframe { height: 240px !important; }
  .sig-name-input { font-size: 16px !important; padding: 12px !important; }
}

/* ===== SECTION TITLE ===== */
.section-title { font-weight: 600; font-size: 0.9rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 10px; }

/* ===== ROUTE PAGE ===== */
#route-container { display: flex; height: calc(100vh - 60px); overflow: hidden; }
#route-map-wrap { flex: 1; position: relative; isolation: isolate; }
#route-map { width: 100%; height: 100%; }
#route-sidebar {
  width: 360px; min-width: 300px; background: var(--bg-card);
  border-left: 1px solid var(--border); display: flex; flex-direction: column;
  overflow: hidden;
}
.route-sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.route-sidebar-header h3 { font-size: 1rem; font-weight: 700; }
.route-orders-list { overflow-y: auto; flex: 1; padding: 8px; display: flex; flex-direction: column; gap: 8px; }

/* Route order card */
.route-order-card {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px; transition: box-shadow .15s;
}
.route-order-card:hover { box-shadow: var(--shadow); }
.route-order-card.priority-urgent { border-left: 3px solid var(--danger); }
.route-order-card.priority-high { border-left: 3px solid var(--warning); }
.route-order-card.priority-medium { border-left: 3px solid var(--primary); }
.route-order-card.priority-low { border-left: 3px solid #94a3b8; }
.route-order-number {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  color: #fff; font-weight: 700; font-size: 0.85rem;
  display: flex; align-items: center; justify-content: center;
}
.route-order-content { flex: 1; min-width: 0; }
.route-order-title { font-weight: 600; font-size: 0.875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 4px; }
.route-order-meta { font-size: 0.78rem; color: var(--text-secondary); display: flex; flex-direction: column; gap: 2px; margin-bottom: 6px; }
.route-order-meta span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.route-order-badges { display: flex; gap: 4px; flex-wrap: wrap; }
.route-order-actions { display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }

/* Route Manager Modal */
#route-manager-overlay {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: rgba(0,0,0,.55); z-index: 10000;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.route-manager-modal {
  background: var(--bg-card); border-radius: 14px; width: 100%; max-width: 520px;
  max-height: 85vh; display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.route-manager-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.route-manager-header h3 { font-size: 1.05rem; font-weight: 700; }
#route-manager-body { overflow-y: auto; flex: 1; padding: 16px; }
.route-manager-footer {
  padding: 12px 20px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}
.rm-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  margin-bottom: 6px; background: var(--bg); transition: background .15s;
}
.rm-item:hover { background: var(--bg-card); }
.rm-num {
  width: 26px; height: 26px; border-radius: 50%; background: var(--primary);
  color: #fff; font-weight: 700; font-size: 0.8rem;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.rm-info { flex: 1; min-width: 0; }
.rm-title { font-weight: 600; font-size: 0.875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rm-meta { font-size: 0.78rem; color: var(--text-secondary); display: flex; gap: 6px; flex-wrap: wrap; margin-top: 3px; }
.rm-controls { display: flex; gap: 4px; flex-shrink: 0; }

/* Responsive route */
@media (max-width: 768px) {
  #route-container { flex-direction: column; }
  #route-map-wrap { height: 250px; }
  #route-sidebar { width: 100%; border-left: none; border-top: 1px solid var(--border); max-height: calc(100vh - 310px); }
}

/* ─── Offline Banner ─────────────────────────────────────────────────────── */
.offline-banner {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 9999;
  background: #1e293b; color: #f1f5f9;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; font-size: 0.875rem;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.3);
  animation: slideUp .25s ease;
}
.offline-banner.hidden { display: none; }
.offline-banner > i { color: #fbbf24; font-size: 1rem; flex-shrink: 0; }
.offline-msg { flex: 1; }
.offline-sync-btn {
  background: #2563eb; color: #fff; border: none; border-radius: 6px;
  padding: 5px 12px; font-size: 0.8rem; cursor: pointer; display: flex;
  align-items: center; gap: 5px; white-space: nowrap;
}
.offline-sync-btn:hover { background: #1d4ed8; }
.offline-sync-btn.hidden { display: none; }

/* PDF offline badge */
.pdf-offline-badge {
  display: inline-flex; align-items: center; gap: 4px;
  background: #fef3c7; color: #92400e; border-radius: 4px;
  font-size: 0.72rem; padding: 2px 6px; margin-left: 6px; font-weight: 600;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* PDF Signature Position Editor */
.pdf-sig-preview-page {
  position: relative;
  width: 210px;
  height: 297px;
  background: #fff;
  border: 1px solid #e2e8f0;
  box-shadow: 0 2px 12px rgba(0,0,0,.1);
  overflow: hidden;
  border-radius: 2px;
}
.pdf-preview-lines {
  padding: 18px 14px 0;
  pointer-events: none;
}
.pdf-sig-drag-box {
  position: absolute;
  background: rgba(37, 99, 235, 0.12);
  border: 2px dashed #2563eb;
  border-radius: 3px;
  cursor: move;
  user-select: none;
  touch-action: none;
  min-width: 20px;
  min-height: 14px;
  transition: opacity 0.1s;
}
.pdf-sig-drag-box:hover {
  background: rgba(37, 99, 235, 0.2);
}
