:root {
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-light: #e0f2fe;
  --success: #16a34a;
  --success-bg: #f0fdf4;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.5;
  padding-bottom: 80px;
}

/* Header */
.app-header {
  background: #0f172a;
  color: #ffffff;
  padding: 10px 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

.header-container {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.brand-logo {
  height: 38px;
  width: 38px;
  object-fit: contain;
  background: #ffffff;
  border-radius: 8px;
  padding: 2px;
}

.brand-text h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}

.brand-subname {
  color: #38bdf8;
  font-weight: 600;
  font-size: 0.95rem;
}

.brand-text p {
  font-size: 0.72rem;
  color: #94a3b8;
  margin: 0;
}

/* Mode Switcher (Dispatcher vs Engineer) */
.mode-toggle {
  display: flex;
  background: #1e293b;
  padding: 3px;
  border-radius: 9999px;
  border: 1px solid #334155;
}

.mode-btn {
  padding: 5px 12px;
  border: none;
  background: transparent;
  color: #94a3b8;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 9999px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 4px;
}

.mode-btn.active {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

/* Dashboard Metric Cards */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

@media (min-width: 768px) {
  .metrics-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}

.metric-card:hover {
  box-shadow: var(--shadow-md);
}

.metric-card.active-filter {
  border: 2px solid var(--primary);
}

.metric-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
}

.metric-value {
  font-size: 1.6rem;
  font-weight: 800;
  margin-top: 2px;
  color: var(--text-primary);
}

.metric-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Nav Tabs */
.nav-tabs {
  display: flex;
  gap: 6px;
  background: #e2e8f0;
  padding: 4px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  overflow-x: auto;
  scrollbar-width: none;
}

.nav-tabs::-webkit-scrollbar { display: none; }

.tab-btn {
  flex: 1;
  min-width: fit-content;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

.tab-btn.active {
  background: #ffffff;
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* Dispatch Calendar */
.calendar-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 8px;
}

.cal-views-toggle {
  display: flex;
  background: #f1f5f9;
  padding: 2px;
  border-radius: var(--radius-sm);
}

.cal-view-btn {
  padding: 5px 10px;
  border: none;
  background: transparent;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 4px;
}

.cal-view-btn.active {
  background: #ffffff;
  color: var(--text-primary);
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

@media (max-width: 640px) {
  .calendar-grid {
    grid-template-columns: 1fr;
  }
}

.cal-day-col {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  min-height: 140px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cal-day-col.today {
  border-color: var(--primary);
  background: #f0f9ff;
}

.cal-day-header {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
  display: flex;
  justify-content: space-between;
}

.cal-job-chip {
  background: #ffffff;
  border-left: 4px solid var(--primary);
  border-radius: 4px;
  padding: 6px;
  font-size: 0.72rem;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.1s;
}

.cal-job-chip:hover {
  transform: translateY(-1px);
}

.cal-job-chip.urgent {
  border-left-color: var(--danger);
  background: #fff5f5;
}

.cal-job-chip .chip-time {
  font-weight: 700;
  color: var(--text-muted);
}

.cal-job-chip .chip-title {
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cal-job-chip .chip-cust {
  color: var(--text-secondary);
  font-size: 0.68rem;
}

/* Job Cards */
.job-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.job-card.active-border {
  border-left: 5px solid var(--primary);
}

.job-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.job-number {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-light);
  padding: 2px 8px;
  border-radius: 4px;
}

.status-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 9999px;
  text-transform: uppercase;
}

.status-SCHEDULED { background: #f1f5f9; color: #475569; }
.status-TRAVEL_OUTBOUND { background: #e0f2fe; color: #0369a1; }
.status-ON_SITE { background: #fef3c7; color: #b45309; }
.status-SIGNED_ON_SITE { background: #f3e8ff; color: #6b21a8; }
.status-TRAVEL_RETURN { background: #fed7aa; color: #c2410c; }
.status-COMPLETED { background: #dcfce7; color: #15803d; }

.job-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-top: 4px;
}

.job-meta {
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.engineer-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 0.72rem;
  font-weight: 600;
  color: #ffffff;
  background: #0284c7;
}

/* Stage Step Progress Bar */
.step-bar {
  display: flex;
  justify-content: space-between;
  background: #f8fafc;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
}

.step-item.active {
  color: var(--primary);
  font-weight: 700;
}

.step-item.done {
  color: var(--success);
}

/* Action Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  font-size: 0.85rem;
  font-weight: 700;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  touch-action: manipulation;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger { background: #ef4444; color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-outline { background: #fff; color: var(--text-primary); border: 1px solid var(--border); }
.btn-danger-outline { background: #fff; color: #dc2626; border: 1px solid #fca5a5; }
.btn-danger-outline:hover { background: #fef2f2; border-color: #ef4444; }
.btn-full { width: 100%; }

.stage-action-box {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Time Summary Table */
.time-pill-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  text-align: center;
  font-size: 0.72rem;
  margin-top: 6px;
}

.time-pill {
  background: #f1f5f9;
  padding: 6px;
  border-radius: 6px;
}

.time-pill strong {
  display: block;
  font-size: 0.95rem;
  color: var(--text-primary);
}

/* Signature Modal & Canvas */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}

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

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.signature-pad-container {
  border: 2px dashed #94a3b8;
  border-radius: 8px;
  background: #ffffff;
  position: relative;
  touch-action: none;
}

canvas#sigCanvas {
  width: 100%;
  height: 180px;
  display: block;
  cursor: crosshair;
}

.disclaimer-box {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 12px;
  font-size: 0.78rem;
  color: #92400e;
  line-height: 1.4;
}

/* Cards */
.asset-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
}

.asset-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: #0f172a;
}

.asset-specs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.spec-badge {
  background: #f1f5f9;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.72rem;
  color: #334155;
  font-weight: 600;
}

/* Forms */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 9px 12px;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  outline: none;
  background: #ffffff;
}

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

/* Mobile Sticky Bottom Nav */
.mobile-bottom-nav {
  display: flex;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #ffffff;
  border-top: 1px solid var(--border);
  padding: 6px 4px;
  z-index: 99;
  justify-content: space-around;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

@media (min-width: 768px) {
  .mobile-bottom-nav { display: none; }
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 4px 8px;
  cursor: pointer;
}

.mobile-nav-item.active {
  color: var(--primary);
}