* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #1a56db;
  --primary-dark: #1e3a5f;
  --primary-light: #e8f0fe;
  --safe: #10b981;
  --safe-bg: #ecfdf5;
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --info: #3b82f6;
  --bg: #f0f2f5;
  --card-bg: #ffffff;
  --text: #1f2937;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -1px rgba(0,0,0,0.04);
  --nav-height: 64px;
  --status-bar: 44px;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  background: #e8eaed;
  display: flex; justify-content: center; align-items: center;
  min-height: 100vh; -webkit-font-smoothing: antialiased;
}
.phone {
  width: 390px; height: 844px; background: var(--bg);
  border-radius: 44px; overflow: hidden;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
  position: relative;
}
.status-bar {
  height: var(--status-bar); background: var(--primary-dark);
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 24px; color: white; font-size: 12px; font-weight: 600; flex-shrink: 0;
}
.status-bar .time { font-weight: 700; font-size: 14px; letter-spacing: 0.5px; }
.status-icons { display: flex; gap: 6px; align-items: center; font-size: 13px; }

.page-header {
  background: var(--primary-dark);
  padding: 8px 20px 16px; color: white; flex-shrink: 0;
}
.page-header h1 { font-size: 20px; font-weight: 700; }
.page-header p { font-size: 13px; opacity: 0.8; margin-top: 2px; }
.header-actions { display: flex; justify-content: space-between; align-items: center; }
.header-actions .avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; cursor: pointer;
}
.content { padding: 16px; padding-bottom: 8px; }
.page-container::-webkit-scrollbar { width: 0; }

.stats-row { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.stat-card {
  background: var(--card-bg); border-radius: var(--radius);
  padding: 10px 10px 8px; box-shadow: var(--shadow);
  cursor: pointer; transition: all 0.2s; position: relative; overflow: hidden;
}
.stat-card:active { transform: scale(0.96); }
.stat-card .stat-icon {
  width: 26px; height: 26px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center; font-size: 13px; margin-bottom: 4px;
}
.stat-card .stat-num { font-size: 22px; font-weight: 800; line-height: 1.1; }
.stat-card .stat-label { font-size: 11px; color: var(--text-secondary); margin-top: 1px; }
.stat-card.normal .stat-icon { background: var(--safe-bg); color: var(--safe); }
.stat-card.normal .stat-num { color: var(--safe); }
.stat-card.alert .stat-icon { background: var(--warning-bg); color: var(--warning); }
.stat-card.alert .stat-num { color: var(--warning); }
.stat-card.order .stat-icon { background: var(--primary-light); color: var(--primary); }
.stat-card.order .stat-num { color: var(--primary); }

.section-title {
  font-size: 16px; font-weight: 700; color: var(--text);
  margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center;
}
.section-title .more { font-size: 13px; color: var(--primary); font-weight: 500; cursor: pointer; }

.alert-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.alert-item {
  background: var(--card-bg); border-radius: var(--radius-sm);
  padding: 12px 14px; box-shadow: var(--shadow);
  display: flex; gap: 12px; cursor: pointer; transition: all 0.15s;
  border-left: 3px solid transparent;
}
.alert-item:active { background: #f9fafb; }
.alert-item.critical { border-left-color: var(--danger); }
.alert-item.warning { border-left-color: var(--warning); }
.alert-item.info { border-left-color: var(--info); }
.alert-item .alert-icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0;
}
.alert-item.critical .alert-icon { background: var(--danger-bg); }
.alert-item.warning .alert-icon { background: var(--warning-bg); }
.alert-item.info .alert-icon { background: var(--primary-light); }
.alert-item .alert-body { flex: 1; }
.alert-item .alert-title { font-size: 14px; font-weight: 600; color: var(--text); }
.alert-item .alert-desc { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.alert-item .alert-meta { font-size: 11px; color: var(--text-muted); margin-top: 4px; display: flex; gap: 12px; }
.alert-item .alert-badge {
  font-size: 10px; padding: 2px 8px; border-radius: 20px;
  font-weight: 600; display: inline-block;
}
.alert-badge.critical { background: var(--danger-bg); color: var(--danger); }
.alert-badge.warning { background: var(--warning-bg); color: var(--warning); }
.alert-badge.info { background: var(--primary-light); color: var(--primary); }
.loading-row { padding: 20px; text-align: center; color: var(--text-muted); font-size: 13px; }

.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 20px; }
.quick-btn {
  background: var(--card-bg); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); text-align: center;
  cursor: pointer; transition: all 0.15s; border: none; font-family: inherit;
}
.quick-btn:active { transform: scale(0.96); }
.quick-btn .qb-icon {
  width: 44px; height: 44px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; font-size: 22px; margin: 0 auto 8px;
}
.quick-btn .qb-label { font-size: 13px; font-weight: 600; color: var(--text); }
.quick-btn .qb-desc { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }

.bottom-nav {
  height: var(--nav-height); background: var(--card-bg);
  border-top: 1px solid var(--border);
  display: flex; align-items: stretch;
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 50;
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; cursor: pointer; transition: all 0.15s;
  color: var(--text-muted); text-decoration: none;
  border: none; background: none; font-family: inherit;
  position: relative; font-size: 10px; font-weight: 500;
}
.nav-item .nav-icon { font-size: 22px; line-height: 1; }
.nav-item.active { color: var(--primary); }
.nav-item.active .nav-icon { font-weight: 600; }
.nav-item.active::before {
  content: ''; position: absolute; top: 0; width: 24px; height: 2px; background: var(--primary);
  border-radius: 0 0 2px 2px;
}
.nav-item .badge-dot {
  position: absolute; top: 9px; right: 50%;
  width: 8px; height: 8px; background: var(--danger);
  border-radius: 50%; border: 2px solid white; margin-right: -16px;
}

/* SCAN */
.scan-screen { position: relative; background: #000; display: flex; flex-direction: column; }
.scan-viewfinder {
  flex: 1; position: relative; display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.scan-viewfinder::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,0.4) 0%, transparent 30%, transparent 70%, rgba(0,0,0,0.4) 100%);
  z-index: 1; pointer-events: none;
}
#scan-video { z-index: 0; }
.scan-grid { width: 240px; height: 240px; position: relative; z-index: 2; }
.scan-grid .corner {
  position: absolute; width: 28px; height: 28px;
  border-color: rgba(255,255,255,0.9); border-style: solid;
}
.scan-grid .corner.tl { top: 0; left: 0; border-width: 3px 0 0 3px; border-radius: 4px 0 0 0; }
.scan-grid .corner.tr { top: 0; right: 0; border-width: 3px 3px 0 0; border-radius: 0 4px 0 0; }
.scan-grid .corner.bl { bottom: 0; left: 0; border-width: 0 0 3px 3px; border-radius: 0 0 0 4px; }
.scan-grid .corner.br { bottom: 0; right: 0; border-width: 0 3px 3px 0; border-radius: 0 0 4px 0; }
.scan-line {
  position: absolute; left: 8px; right: 8px; height: 2px;
  background: linear-gradient(90deg, transparent, #10b981, transparent);
  top: 50%; z-index: 3; animation: scanMove 2s ease-in-out infinite;
  box-shadow: 0 0 8px rgba(16,185,129,0.6);
}
@keyframes scanMove { 0%, 100% { top: 8%; } 50% { top: 88%; } }
.focus-indicator {
  position: absolute; z-index: 3; top: 20px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.5); backdrop-filter: blur(8px);
  padding: 4px 16px; border-radius: 20px; color: white; font-size: 12px;
  display: flex; align-items: center; gap: 6px;
}
.focus-indicator .pulse-green {
  width: 8px; height: 8px; border-radius: 50%; background: var(--safe); animation: pulse 1.5s infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
.flash-toggle {
  position: absolute; z-index: 3; bottom: 50px; right: 24px;
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(255,255,255,0.15); backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.2);
  color: white; font-size: 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all 0.2s;
}
.flash-toggle.on { background: var(--warning); color: #000; }
.flash-toggle:active { transform: scale(0.9); }
.scan-bottom {
  background: rgba(0,0,0,0.8); backdrop-filter: blur(12px);
  padding: 16px 20px 12px; display: flex; flex-direction: column; gap: 10px;
}
.scan-hint { text-align: center; color: rgba(255,255,255,0.7); font-size: 13px; }
.scan-actions { display: flex; gap: 12px; }
.scan-actions button {
  flex: 1; padding: 12px; border-radius: var(--radius);
  border: none; font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit; transition: all 0.15s;
}
.scan-actions button:active { transform: scale(0.97); }
.scan-actions .btn-scan { background: var(--primary); color: white; }
.scan-actions .btn-scan:hover { background: #1d4ed8; }
.scan-actions .btn-register {
  background: rgba(255,255,255,0.1); color: white; border: 1px solid rgba(255,255,255,0.2);
}

/* ORDERS */
.order-tabs {
  display: flex; gap: 4px; margin-bottom: 14px;
  background: #f3f4f6; border-radius: 8px; padding: 3px;
}
.order-tab {
  flex: 1; padding: 8px 0; text-align: center;
  border-radius: 6px; font-size: 13px; font-weight: 500;
  cursor: pointer; border: none; background: none; font-family: inherit;
  color: var(--text-secondary); transition: all 0.15s;
}
.order-tab.active { background: white; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
.order-list { display: flex; flex-direction: column; gap: 8px; }
.order-item {
  background: var(--card-bg); border-radius: var(--radius-sm);
  padding: 14px; box-shadow: var(--shadow); cursor: pointer; transition: all 0.15s;
}
.order-item:active { background: #f9fafb; }
.order-item .order-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.order-item .order-id { font-size: 13px; font-weight: 700; color: var(--primary); }
.order-item .order-status {
  font-size: 11px; padding: 2px 10px; border-radius: 20px; font-weight: 600;
}
.status-pending { background: var(--warning-bg); color: #d97706; }
.status-processing { background: #eff6ff; color: #2563eb; }
.status-done { background: var(--safe-bg); color: var(--safe); }
.order-item .order-title { font-size: 14px; font-weight: 600; color: var(--text); }
.order-item .order-dept {
  font-size: 12px; color: var(--text-secondary);
  margin-top: 4px; display: flex; gap: 6px; align-items: center;
}
.order-item .order-meta {
  font-size: 11px; color: var(--text-muted);
  margin-top: 6px; display: flex; gap: 16px;
}
.create-order-btn {
  display: flex; align-items: center; justify-content: center;
  gap: 8px; width: 100%; padding: 14px; border-radius: var(--radius);
  background: var(--primary); color: white;
  border: none; font-size: 15px; font-weight: 600;
  cursor: pointer; font-family: inherit; margin-bottom: 12px; transition: all 0.15s;
}
.create-order-btn:active { transform: scale(0.98); background: #1d4ed8; }

/* ROUTES */
.route-item {
  background: var(--card-bg); border-radius: var(--radius-sm);
  padding: 14px; box-shadow: var(--shadow);
  margin-bottom: 10px;
  display: flex; justify-content: space-between; align-items: center;
}
.route-item .route-info { flex: 1; }
.route-item .route-name { font-size: 14px; font-weight: 600; color: var(--text); }
.route-item .route-meta {
  font-size: 12px; color: var(--text-secondary);
  margin-top: 2px; display: flex; gap: 12px;
}
.route-item .route-toggle {
  width: 44px; height: 26px; border-radius: 13px;
  background: #d1d5db; position: relative;
  cursor: pointer; transition: all 0.2s; flex-shrink: 0;
}
.route-item .route-toggle.on { background: var(--safe); }
.route-item .route-toggle .knob {
  width: 22px; height: 22px; border-radius: 50%;
  background: white; position: absolute; top: 2px; left: 2px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15); transition: all 0.2s;
}
.route-item .route-toggle.on .knob { left: 20px; }

/* USERS */
.user-search { display: flex; gap: 8px; margin-bottom: 14px; }
.user-search input {
  flex: 1; padding: 10px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); font-size: 14px; font-family: inherit; outline: none; background: var(--card-bg);
}
.user-search input:focus { border-color: var(--primary); }
.user-search button {
  padding: 10px 16px; border-radius: var(--radius-sm);
  background: var(--primary); color: white; border: none; font-weight: 600; cursor: pointer;
  font-family: inherit; font-size: 13px;
}
.user-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--card-bg); border-radius: var(--radius-sm);
  padding: 12px 14px; box-shadow: var(--shadow);
  margin-bottom: 8px; cursor: pointer; transition: all 0.15s;
}
.user-item:active { background: #f9fafb; }
.user-avatar {
  width: 42px; height: 42px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: white; font-weight: 600; flex-shrink: 0;
}
.user-info { flex: 1; }
.user-name { font-size: 14px; font-weight: 600; color: var(--text); }
.user-role { font-size: 12px; color: var(--text-secondary); }
.user-tag {
  font-size: 10px; padding: 2px 8px; border-radius: 20px;
  background: var(--primary-light); color: var(--primary);
  font-weight: 600; display: inline-block;
}
.dept-chip {
  padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 500; cursor: pointer;
  background: #f3f4f6; color: var(--text-secondary);
}
.dept-chip.active { background: var(--primary); color: white; }

/* PAGE CONTAINERS */
.page-container {
  position: absolute; top: 44px; left: 0; right: 0; bottom: 64px;
  overflow-y: auto; background: var(--bg); -webkit-overflow-scrolling: touch;
}
.report-period {
  display: flex; gap: 4px; margin-bottom: 16px;
  background: #f3f4f6; border-radius: 8px; padding: 3px;
}
.report-period button {
  flex: 1; padding: 8px 0; text-align: center;
  border-radius: 6px; font-size: 13px; font-weight: 500;
  cursor: pointer; border: none; background: none; font-family: inherit;
  color: var(--text-secondary); transition: all 0.15s;
}
.report-period button.active { background: white; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
.summary-tile {
  border-radius: 10px; padding: 14px; text-align: center;
  cursor: pointer; transition: all 0.15s;
}
.summary-tile:active { transform: scale(0.97); }

.chart-card {
  background: var(--card-bg); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.chart-card .chart-title { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 12px; }
.chart-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.chart-bar .bar-label {
  width: 60px; font-size: 12px; color: var(--text-secondary); text-align: right; flex-shrink: 0;
}
.chart-bar .bar-track {
  flex: 1; height: 22px; border-radius: 6px;
  background: #f3f4f6; position: relative; overflow: hidden;
}
.chart-bar .bar-fill { height: 100%; border-radius: 6px; transition: width 0.6s ease; }
.chart-bar .bar-val { width: 40px; font-size: 12px; font-weight: 600; color: var(--text); flex-shrink: 0; }
.report-row {
  background: var(--card-bg); border-radius: 10px; padding: 14px;
  box-shadow: var(--shadow); margin-bottom: 8px;
  display: flex; align-items: center; gap: 12px; cursor: pointer;
  transition: all 0.15s;
}
.report-row:active { background: #f9fafb; }

/* MODAL */
.modal-overlay {
  display: none; position: absolute; inset: 0;
  background: rgba(0,0,0,0.5); z-index: 100; align-items: flex-end;
}
.modal-overlay.open { display: flex; }
.modal-sheet {
  background: white; border-radius: 20px 20px 0 0; padding: 20px; width: 100%;
  animation: slideUp 0.25s ease; max-height: 85%; overflow-y: auto;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-handle { width: 36px; height: 4px; border-radius: 2px; background: #d1d5db; margin: 0 auto 16px; }
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 16px; color: var(--text); }
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 4px;
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 14px; font-family: inherit; outline: none; background: #f9fafb;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--primary); background: white;
}
.form-group textarea { min-height: 80px; resize: vertical; }
.btn-primary {
  width: 100%; padding: 14px; background: var(--primary); color: white;
  border: none; border-radius: var(--radius); font-size: 16px; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: all 0.15s;
}
.btn-primary:active { transform: scale(0.98); background: #1d4ed8; }
.btn-secondary {
  width: 100%; padding: 12px; background: #f3f4f6; color: var(--text);
  border: none; border-radius: var(--radius); font-size: 14px; font-weight: 500;
  cursor: pointer; font-family: inherit; margin-top: 8px;
}
.notif-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--danger); display: inline-block; }
.toast {
  position: absolute; top: 60px; left: 20px; right: 20px;
  background: var(--text); color: white;
  padding: 12px 16px; border-radius: 10px;
  font-size: 14px; text-align: center; z-index: 200; display: none;
  animation: toastIn 0.3s ease;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}
.scan-result { text-align: center; padding: 20px 0; }
.scan-result .sr-icon {
  width: 64px; height: 64px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; margin: 0 auto 12px;
}
.scan-result .sr-title { font-size: 16px; font-weight: 700; color: var(--text); }
.scan-result .sr-desc { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }
.scan-result .sr-info {
  background: #f9fafb; border-radius: var(--radius-sm);
  padding: 12px; margin: 12px 0; text-align: left;
}
.scan-result .sr-info .row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; }
.scan-result .sr-info .row .label { color: var(--text-secondary); }
.scan-result .sr-info .row .value { color: var(--text); font-weight: 500; }

.action-btn {
  background: var(--primary-light); color: var(--primary);
  border: none; border-radius: 6px; padding: 4px 12px;
  font-size: 12px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.action-btn.danger { background: var(--danger-bg); color: var(--danger); }
.status-badge {
  font-size: 10px; padding: 2px 8px; border-radius: 20px; font-weight: 600; display: inline-block;
}
.badge-pending { background: var(--warning-bg); color: #d97706; }
.badge-processing { background: #eff6ff; color: #2563eb; }
.badge-done { background: var(--safe-bg); color: var(--safe); }
.badge-critical { background: var(--danger-bg); color: var(--danger); }

.photo-add-btn {
  width: 76px; height: 76px; border: 2px dashed var(--border); border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; background: #fafafa; transition: all 0.15s;
}
.photo-add-btn:active { transform: scale(0.96); }

@media (max-width: 420px) {
  .phone { width: 100%; height: 100vh; border-radius: 0; }
  .status-bar { padding: 0 16px; }
}
