:root {
  --primary:        #1f7a8c;
  --primary-strong: #136074;
  --primary-light:  #e8f4f7;
  --bg:             #f5f7fa;
  --card:           #ffffff;
  --border:         #d9e2ec;
  --text:           #1f2933;
  --muted:          #6b7b8c;
  --danger:         #c0392b;
  --danger-light:   #fdf2f1;
  --success:        #2f9e44;
  --success-light:  #ebf9ee;
  --warning:        #d97706;
  --warning-light:  #fef9ec;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Layout ─────────────────────────────────────────────── */
.layout {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

/* ── User bar (sticky) ───────────────────────────────────── */
.user-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.user-bar-left {
  display: flex;
  flex-direction: column;
}

.user-bar-name  { font-size: 14px; font-weight: 700; }
.user-bar-role  { font-size: 12px; color: var(--muted); }

.user-bar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.user-bar-btn {
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 20px;
  border: none;
  background: var(--primary-light);
  color: var(--primary-strong);
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background 0.15s, box-shadow 0.15s;
  box-shadow: 0 1px 3px rgba(31,122,140,0.12);
}
.user-bar-btn:hover {
  background: #d0eaf0;
  box-shadow: 0 2px 6px rgba(31,122,140,0.18);
}
.user-bar-btn.danger {
  background: var(--danger-light);
  color: var(--danger);
  box-shadow: 0 1px 3px rgba(192,57,43,0.10);
}
.user-bar-btn.danger:hover {
  background: #fbe5e3;
  box-shadow: 0 2px 6px rgba(192,57,43,0.18);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  margin-bottom: 16px;
}
.back-link:hover { color: var(--primary); }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  padding: 13px 20px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, transform 0.05s;
  width: 100%;
  font-family: inherit;
}

.btn:active    { transform: translateY(1px); }
.btn:hover     { background: var(--primary-strong); }

.btn.secondary {
  background: var(--card);
  color: var(--text);
  border-color: var(--border);
}
.btn.secondary:hover { background: var(--bg); }

.btn.danger {
  border-color: var(--danger);
  background: var(--danger);
}
.btn.danger:hover { background: #a93226; }

.btn.success {
  border-color: var(--success);
  background: var(--success);
}
.btn.success:hover { background: #278839; }

.btn.warning {
  border-color: var(--warning);
  background: var(--warning);
}
.btn.warning:hover { background: #b45309; }

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.btn.sm {
  padding: 8px 14px;
  font-size: 13px;
  width: auto;
}

.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}
.btn-row .btn { flex: 1; }

/* ── Nav cards (dashboard) ────────────────────────────────── */
.nav-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 16px;
}

.nav-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 16px;
  text-align: center;
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: border-color 0.15s, box-shadow 0.15s;
  position: relative;
}
.nav-card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(31,122,140,0.12);
}
.nav-card .nav-icon  { font-size: 36px; }
.nav-card .nav-label { font-size: 14px; font-weight: 700; }
.nav-card .nav-desc  { font-size: 12px; color: var(--muted); }

.nav-card .badge {
  position: absolute;
  top: 10px; right: 10px;
  background: var(--danger);
  color: #fff;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  min-width: 20px;
  text-align: center;
}

/* ── Forms ────────────────────────────────────────────────── */
.form-group     { margin-bottom: 14px; }

label {
  display: block;
  margin-bottom: 5px;
  font-size: 13px;
  font-weight: 600;
  color: #3d4f62;
}

input[type="text"],
input[type="date"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 12px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31,122,140,0.12);
}

textarea { resize: vertical; min-height: 80px; }

/* ── Family selector ──────────────────────────────────────── */
.familia-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.familia-card {
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  background: #fff;
  user-select: none;
}
.familia-card.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.familia-icon  { font-size: 24px; }
.familia-name  { font-size: 13px; font-weight: 700; margin-top: 4px; line-height: 1.3; }

.familia-longitud {
  display: none;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.familia-card.selected .familia-longitud { display: block; }

.radio-row { display: flex; gap: 8px; }
.radio-opt {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  background: #fff;
}
.radio-opt input[type="radio"] { accent-color: var(--primary); }

/* ── Voladizo toggle ──────────────────────────────────────── */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 16px;
}
.toggle-label { flex: 1; font-size: 14px; font-weight: 600; }

.toggle-switch {
  width: 48px; height: 28px;
  background: var(--border);
  border-radius: 14px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle-switch.on { background: var(--primary); }
.toggle-switch::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 22px; height: 22px;
  background: #fff;
  border-radius: 50%;
  transition: left 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle-switch.on::after { left: 23px; }

/* ── Checklist items ──────────────────────────────────────── */
.check-group-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 12px 0 6px;
}

.check-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 12px;
  border-radius: 8px;
  margin-bottom: 6px;
  background: var(--bg);
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.check-item.checked {
  background: var(--success-light);
  border-color: var(--success);
}
.check-item input[type="checkbox"] {
  width: 22px; height: 22px;
  flex-shrink: 0;
  accent-color: var(--success);
  cursor: pointer;
}
.check-item .check-label {
  font-size: 14px;
  line-height: 1.4;
  cursor: pointer;
  flex: 1;
}

/* ── Family section in checklist ─────────────────────────── */
.familia-section {
  margin-bottom: 20px;
}
.familia-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--primary-light);
  border-radius: 8px;
  margin-bottom: 8px;
}
.familia-section-icon  { font-size: 20px; }
.familia-section-name  { font-size: 15px; font-weight: 700; color: var(--primary-strong); }
.familia-section-badge {
  margin-left: auto;
  font-size: 11px;
  background: var(--primary);
  color: #fff;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
}

/* ── Alerts ───────────────────────────────────────────────── */
.alert {
  padding: 11px 14px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 12px;
}
.alert.warning {
  background: var(--warning-light);
  border-left: 4px solid var(--warning);
  color: #7c4f0a;
}
.alert.danger {
  background: var(--danger-light);
  border-left: 4px solid var(--danger);
  color: #7a1a1a;
}
.alert.success {
  background: var(--success-light);
  border-left: 4px solid var(--success);
  color: #1a5c2a;
}
.alert.info {
  background: var(--primary-light);
  border-left: 4px solid var(--primary);
  color: var(--primary-strong);
}

/* ── Section titles ───────────────────────────────────────── */
.section-title {
  font-size: 16px;
  font-weight: 700;
  margin: 20px 0 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Signature canvas ─────────────────────────────────────── */
.firma-wrap {
  border: 2px dashed var(--border);
  border-radius: 10px;
  background: #fafbfc;
  overflow: hidden;
  position: relative;
}
.firma-wrap canvas {
  display: block;
  width: 100%;
  touch-action: none;
  cursor: crosshair;
}
.firma-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  border-top: 1px solid var(--border);
}
.firma-hint { font-size: 12px; color: var(--muted); }
.firma-clear {
  font-size: 12px; color: var(--danger);
  background: none; border: none;
  cursor: pointer; font-family: inherit;
  text-decoration: underline;
}

/* ── Status chips ─────────────────────────────────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.chip.en_proceso          { background: var(--warning-light); color: var(--warning); }
.chip.pendiente_conductor { background: var(--primary-light);  color: var(--primary); }
.chip.completada          { background: var(--success-light);  color: var(--success); }
.chip.rechazada           { background: var(--danger-light);   color: var(--danger); }

/* ── Order cards (listas) ─────────────────────────────────── */
.orden-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 10px;
  text-decoration: none;
  color: inherit;
  display: block;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.orden-card:hover {
  box-shadow: 0 4px 14px rgba(0,0,0,0.09);
  border-color: var(--primary);
}
.orden-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.orden-matricula {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--primary-strong);
}
.orden-meta {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.5;
}
.orden-familias {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.familia-tag {
  font-size: 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 8px;
  font-weight: 600;
}

/* ── Progress bar ─────────────────────────────────────────── */
.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-bottom: 16px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 2px;
  transition: width 0.3s;
}

/* ── Empty state ──────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty-state .empty-icon { font-size: 52px; }
.empty-state p { margin: 12px 0 0; font-size: 15px; }

/* ── Page title ───────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}
.page-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  flex: 1;
}
.page-header .subtitle {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

/* ── Loader ───────────────────────────────────────────────── */
.loader {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px;
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: 84px;
  right: 18px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
  width: min(390px, calc(100vw - 28px));
}
.toast {
  background: #17212b;
  color: #fff;
  padding: 14px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 12px 30px rgba(0,0,0,0.26);
  animation: slideInNotify 0.2s ease;
  border-left: 5px solid #2b8797;
  display: flex;
  flex-direction: column;
  gap: 4px;
  white-space: normal;
}
.toast strong { font-size: 15px; }
.toast.clickable { cursor: pointer; }
.toast.error  { border-left-color: #ef4444; }
.toast.success { border-left-color: #22c55e; }
.toast.warning { border-left-color: #f59e0b; }
.toast.message { border-left-color: #38bdf8; }
@keyframes slideInNotify {
  from { opacity: 0; transform: translateX(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Centro global de avisos */
.notify-center-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.notify-center-btn,
.notify-permission-btn,
.notify-sound-btn {
  width: 40px;
  height: 40px;
  border: 1px solid #cdd9e5;
  background: #fff;
  color: #1f2933;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  font-size: 18px;
}
.notify-permission-btn { color: #64748b; }
.notify-sound-btn { color: #64748b; }
.notify-permission-btn.enabled {
  color: #15803d;
  border-color: #86c89a;
  background: #eefbf1;
}
.notify-sound-btn.enabled {
  color: #15803d;
  border-color: #86c89a;
  background: #eefbf1;
}
.notify-permission-btn.push-limited {
  color: #9a3412;
  border-color: #f59e0b;
  background: #fff7ed;
}
.notification-attention .notify-center-btn {
  color: #fff;
  border-color: #dc2626;
  background: #dc2626;
  animation: notifyUrgent 0.9s ease-in-out infinite;
}
.notify-center-btn.has-alerts {
  color: #9a3412;
  border-color: #f59e0b;
  background: #fff7ed;
  animation: notifyPulse 1.8s ease-in-out infinite;
}
.notify-center-badge {
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 21px;
  height: 21px;
  padding: 0 5px;
  border-radius: 999px;
  background: #dc2626;
  color: #fff;
  border: 2px solid #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 17px;
  text-align: center;
}
.notify-center-panel {
  position: absolute;
  top: calc(100% + 9px);
  right: 0;
  width: min(430px, calc(100vw - 24px));
  max-height: min(620px, calc(100vh - 100px));
  overflow: hidden;
  display: none;
  background: #fff;
  border: 1px solid #cdd9e5;
  border-radius: 8px;
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.22);
  z-index: 1800;
}
.notify-center-panel.open { display: block; }
.notify-center-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  border-bottom: 1px solid #e5edf4;
}
.notify-center-head div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.notify-center-head span { color: #64748b; font-size: 12px; }
.notify-center-head button {
  border: 0;
  background: transparent;
  color: #126579;
  font-weight: 700;
  cursor: pointer;
}
.notify-center-list { max-height: 520px; overflow-y: auto; }
.notify-center-item {
  display: flex;
  gap: 11px;
  padding: 13px 14px;
  border-bottom: 1px solid #edf2f7;
  color: #1f2933;
  text-decoration: none;
}
.notify-center-item:hover { background: #f8fafc; }
.notify-center-item.unread { background: #f0f9ff; }
.notify-center-item.unread.assignment { border-left: 4px solid #15803d; }
.notify-center-item.unread.message { border-left: 4px solid #0284c7; }
.notify-center-item.unread.warning { border-left: 4px solid #d97706; }
.notify-center-icon {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: #e8f4f7;
  color: #126579;
}
.notify-center-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.notify-center-copy strong { font-size: 14px; }
.notify-center-copy span { color: #475569; font-size: 13px; line-height: 1.35; }
.notify-center-copy time { color: #7c8a9a; font-size: 11px; }
.notify-center-empty { padding: 24px; color: #64748b; text-align: center; }
@keyframes notifyPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245,158,11,0); }
  50% { box-shadow: 0 0 0 5px rgba(245,158,11,0.18); }
}
@keyframes notifyUrgent {
  0%, 100% { transform:scale(1); box-shadow:0 0 0 0 rgba(220,38,38,0); }
  50% { transform:scale(1.08); box-shadow:0 0 0 7px rgba(220,38,38,.2); }
}

/* ── Filters bar ──────────────────────────────────────────── */
.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.filters select, .filters input {
  flex: 1;
  min-width: 120px;
  padding: 8px 10px;
  font-size: 13px;
}

/* ── Detail view ──────────────────────────────────────────── */
.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--bg);
  font-size: 14px;
}
.detail-row:last-child { border-bottom: none; }
.detail-key   { color: var(--muted); }
.detail-value { font-weight: 600; text-align: right; }

.firma-img {
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
}

.foto-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}
.foto-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 480px) {
  .nav-grid { grid-template-columns: repeat(2, 1fr); }
  .familia-grid { grid-template-columns: 1fr; }
  .btn-row { flex-direction: column; }
  .orden-matricula { font-size: 18px; }
}

/* ── Footer corporativo ──────────────────────────────────── */
.app-footer {
  background: #136074;
  color: #fff;
  padding: 20px 24px;
  margin-top: 48px;
  text-align: center;
}
.app-footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}
.app-footer-logo {
  height: 32px;
  filter: brightness(0) invert(1);
  opacity: 0.88;
}
.app-footer-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
}
.app-footer-label { display: none;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  opacity: 0.72;
  font-weight: 600;
}
.app-footer-copy {
  font-size: 12px;
  font-weight: 500;
  opacity: 0.9;
}
