@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700;900&display=swap');

:root {
  --bg:         #f0f2f5;
  --card:       #ffffff;
  --primary:    #0048d4;
  --primary-10: rgba(0, 72, 212, 0.10);
  --primary-30: rgba(0, 72, 212, 0.30);
  --border:     #d8dde8;
  --text:       #1a1d2e;
  --muted:      #6b7280;
  --danger:     #dc2626;
  --danger-10:  rgba(220, 38, 38, 0.10);
  --success:    #16a34a;
  --success-10: rgba(22, 163, 74, 0.10);
  --warning:    #d97706;
  --warning-10: rgba(217, 119, 6, 0.10);
  --radius:     14px;
  --radius-sm:  8px;
  --shadow:     0 2px 10px rgba(0, 0, 0, 0.07);
  --shadow-lg:  0 4px 24px rgba(0, 0, 0, 0.12);
  --header-h:   56px;
  --nav-h:      60px;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg:         #0f1117;
  --card:       #1a1d2e;
  --primary:    #4d8bff;
  --primary-10: rgba(77, 139, 255, 0.10);
  --primary-30: rgba(77, 139, 255, 0.30);
  --border:     #2a2d3e;
  --text:       #e8eaf0;
  --muted:      #9ca3af;
  --danger:     #ef4444;
  --danger-10:  rgba(239, 68, 68, 0.10);
  --success:    #22c55e;
  --success-10: rgba(34, 197, 94, 0.10);
  --warning:    #f59e0b;
  --warning-10: rgba(245, 158, 11, 0.10);
  --shadow:     0 2px 10px rgba(0, 0, 0, 0.30);
  --shadow-lg:  0 4px 24px rgba(0, 0, 0, 0.50);
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior: none;
  transition: background var(--transition), color var(--transition);
}

a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font-family: 'DM Sans', sans-serif; font-size: inherit; }

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  z-index: 100;
  box-shadow: 0 2px 16px rgba(0, 72, 212, 0.3);
}

.app-header .logo { font-size: 1.4rem; font-weight: 900; letter-spacing: -1px; flex: 1; }
.app-header .logo span { color: #7eb8ff; }

.app-header .header-links { display: flex; gap: 8px; }

.app-header .header-link {
  color: rgba(255,255,255,0.8);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background var(--transition);
}

.app-header .header-link:hover { background: rgba(255,255,255,0.15); color: #fff; }

.app-content {
  flex: 1;
  padding-top: var(--header-h);
  padding-bottom: var(--nav-h);
  overflow-y: auto;
}

.wrap { max-width: 680px; margin: 0 auto; padding: 16px 14px 24px; }

.app-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--muted);
  transition: color var(--transition);
  min-width: 40px;
  min-height: 44px;
  justify-content: center;
  background: none;
  border: none;
}

.nav-item.active { color: var(--primary); }
.nav-item svg { width: 20px; height: 20px; }
.nav-item span { font-size: 0.62rem; font-weight: 600; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 20px 18px;
  margin-bottom: 14px;
}

.card h3 {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--primary);
  margin-bottom: 14px;
}

.card-row { display: flex; gap: 12px; margin-bottom: 14px; }
.card-row .card { flex: 1; margin-bottom: 0; text-align: center; }

.f { margin-bottom: 14px; position: relative; }

label {
  display: block;
  font-size: 0.73rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 5px;
}

input, select, textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  color: var(--text);
  background: var(--card);
  outline: none;
  -webkit-appearance: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

/* Selects con listas largas (ej. selector de tecnico): texto mas pequeno para
   que la lista desplegable ocupe menos en movil */
.sel-tec-compacto, .sel-tec-compacto option { font-size: 0.8rem; }

/* ── Dropdown de tecnico propio (sustituye el <select> nativo en movil) ── */
.seltec { position: relative; }
.seltec-input {
  width: 100%; padding: 11px 13px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); font-size: .88rem; color: var(--text);
  background: var(--card); display: flex; align-items: center; justify-content: space-between;
  gap: 8px; cursor: pointer; user-select: none;
}
.seltec-input.placeholder { color: var(--muted); }
.seltec-input .arrow { color: var(--muted); font-size: .7rem; transition: transform .15s; flex-shrink: 0; }
.seltec-input.open .arrow { transform: rotate(180deg); }
.seltec-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.seltec-panel {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 50;
  background: var(--card); border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); max-height: 320px; display: flex; flex-direction: column;
  overflow: hidden;
}
.seltec-panel.hidden { display: none; }
.seltec-search { padding: 8px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.seltec-search input {
  width: 100%; padding: 8px 10px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: .82rem; background: var(--bg); color: var(--text); outline: none;
}
.seltec-list { overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.seltec-group-label {
  font-size: .68rem; font-weight: 700; color: var(--primary); text-transform: uppercase;
  letter-spacing: .04em; padding: 8px 12px 4px;
}
.seltec-opt {
  padding: 9px 12px; font-size: .82rem; cursor: pointer; display: flex; align-items: center;
  justify-content: space-between; gap: 8px;
}
.seltec-opt:hover { background: var(--primary-10); }
.seltec-opt .mat { font-size: .68rem; color: var(--muted); flex-shrink: 0; }
.seltec-empty { padding: 16px; text-align: center; font-size: .8rem; color: var(--muted); }

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-10);
}

input.err, select.err, textarea.err {
  border-color: var(--danger);
  background: var(--danger-10);
}

input[readonly], input:disabled, select:disabled {
  background: var(--bg);
  color: var(--muted);
  cursor: not-allowed;
}

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

.g2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.g3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 10px; }
.g4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 8px; }

@media (max-width: 480px) {
  .g2 { grid-template-columns: 1fr; }
  .g3 { grid-template-columns: 1fr; }
  .g4 { grid-template-columns: 1fr 1fr; }
}

.radio-group { display: flex; gap: 8px; flex-wrap: wrap; }

.radio-opt { flex: 1; min-width: 80px; position: relative; }

.radio-opt input[type="radio"] { position: absolute; opacity: 0; width: 0; height: 0; }

.radio-opt label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  background: var(--card);
  transition: all 0.15s;
  min-height: 44px;
}

.radio-opt input:checked + label {
  border-color: var(--primary);
  background: var(--primary-10);
  color: var(--primary);
  font-weight: 700;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.toggle-row:last-child { border-bottom: none; }
.toggle-label { font-size: 0.9rem; font-weight: 500; }

.toggle { position: relative; width: 44px; height: 26px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 26px;
  cursor: pointer;
  transition: background var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 20px; height: 20px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  min-height: 44px;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  width: 100%;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 700;
  padding: 14px;
}

.btn-primary:hover { background: #003aab; }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1.5px solid var(--border);
}

.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }

.btn-danger {
  background: var(--danger-10);
  color: var(--danger);
  border: 1.5px solid var(--danger);
}

.btn-ghost {
  background: none;
  color: var(--muted);
  border: 1.5px solid var(--border);
  padding: 6px 12px;
  font-size: 0.78rem;
}

.btn-ghost:hover { border-color: var(--danger); color: var(--danger); }

.btn-icon {
  width: 44px; height: 44px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1.5px solid var(--border);
  color: var(--muted);
  flex-shrink: 0;
}

.btn-icon:hover { border-color: var(--primary); color: var(--primary); }

.btn-fab {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px);
  right: 16px;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  font-size: 1.6rem;
  cursor: pointer;
  box-shadow: 0 4px 20px var(--primary-30);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition), box-shadow var(--transition);
  z-index: 90;
}

.btn-fab:active { transform: scale(0.92); }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-primary  { background: var(--primary-10); color: var(--primary); }
.badge-success  { background: var(--success-10); color: var(--success); }
.badge-danger   { background: var(--danger-10);  color: var(--danger); }
.badge-warning  { background: var(--warning-10); color: var(--warning); }
.badge-muted    { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }

.item-list { display: flex; flex-direction: column; gap: 10px; }

.item-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.item-card:active { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-10); }
.item-card-body { flex: 1; min-width: 0; }
.item-card-title { font-size: 0.92rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-card-meta { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }

.item-card-icon {
  width: 42px; height: 42px;
  border-radius: 10px;
  background: var(--primary-10);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ac-wrap { position: relative; }

.ac-list {
  position: absolute;
  top: 100%; left: 0; right: 0;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  max-height: 180px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: var(--shadow-lg);
  display: none;
}

.ac-item { padding: 10px 13px; font-size: 0.88rem; cursor: pointer; border-bottom: 1px solid var(--border); }
.ac-item:last-child { border-bottom: none; }
.ac-item:hover { background: var(--primary-10); color: var(--primary); }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1200;
  display: flex;
  align-items: flex-end;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--card);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px 16px 32px;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.34, 1.1, 0.64, 1);
}

.overlay.open .modal { transform: translateY(0); }
.modal-handle { width: 40px; height: 4px; background: var(--border); border-radius: 4px; margin: 0 auto 20px; }
.modal-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 20px; }

#toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 12px);
  left: 50%;
  right: auto;
  transform: translateX(-50%) translateY(200px);
  background: var(--text);
  color: var(--bg);
  padding: 11px 20px;
  border-radius: 30px;
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 9999;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  white-space: normal;
  word-wrap: break-word;
  max-width: calc(100vw - 32px);
  width: auto;
  text-align: center;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
}

#toast.show    { transform: translateX(-50%) translateY(0); }
#toast.ok      { background: var(--success); color: #fff; }
#toast.err     { background: var(--danger);  color: #fff; }
#toast.warning { background: var(--warning); color: #fff; }

.aviso {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.55;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  margin-bottom: 14px;
  border-left: 3px solid var(--primary);
}

.empty-state { text-align: center; padding: 48px 24px; color: var(--muted); }
.empty-state svg { width: 48px; height: 48px; margin: 0 auto 12px; opacity: 0.4; }
.empty-state p { font-size: 0.9rem; font-weight: 500; }

.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 32px auto;
}

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

.firma-box {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  position: relative;
  overflow: hidden;
  touch-action: none;
}

.firma-canvas { display: block; width: 100%; height: 160px; cursor: crosshair; }

.firma-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  color: var(--border);
  pointer-events: none;
  font-weight: 500;
}

.text-muted   { color: var(--muted); }
.text-primary { color: var(--primary); }
.text-danger  { color: var(--danger); }
.text-success { color: var(--success); }
.text-sm      { font-size: 0.78rem; }
.text-center  { text-align: center; }
.fw-bold      { font-weight: 700; }
.mt-8         { margin-top: 8px; }
.mt-16        { margin-top: 16px; }
.mb-8         { margin-bottom: 8px; }
.mb-16        { margin-bottom: 16px; }
.gap-8        { gap: 8px; }
.flex         { display: flex; }
.flex-center  { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.w-100        { width: 100%; }

.divider { height: 1px; background: var(--border); margin: 16px 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
/* Pedidos - checkbox custom */
.pedido-chk-icon {
  width: 26px !important;
  height: 26px !important;
  border-radius: 8px !important;
  border: 2px solid var(--border) !important;
  flex-shrink: 0 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  font-size: 16px !important;
  font-weight: 900 !important;
  cursor: pointer !important;
  background: transparent !important;
  padding: 0 !important;
  transition: all .15s !important;
}
.pedido-chk-icon.activo {
  background: var(--primary) !important;
  border-color: var(--primary) !important;
  color: #fff !important;
}

/* Parte de postes - radio buttons nativos */
.pp-form input[type="radio"] {
    -webkit-appearance: radio !important;
    appearance: radio !important;
    width: 16px !important;
    height: 16px !important;
    accent-color: #0048d4;
}

/* Parte de postes - restaurar apariencia nativa de radio buttons */
.pp-form input[type="radio"] {
    -webkit-appearance: radio !important;
    appearance: radio !important;
    width: 16px !important;
    height: 16px !important;
    padding: 0 !important;
    border: none !important;
    background: none !important;
    accent-color: #0048d4;
}

/* Parte de postes - radio buttons */
.pp-form input[type="radio"] {
    -webkit-appearance: radio !important;
    appearance: radio !important;
    width: 16px !important;
    height: 16px !important;
    min-width: 16px !important;
    padding: 0 !important;
    border: none !important;
    background: none !important;
    accent-color: #0048d4;
    cursor: pointer;
    flex-shrink: 0;
}

/* Tickets - checkboxes nativos en formularios de ticket */
.tck-form input[type="checkbox"] {
    -webkit-appearance: checkbox !important;
    appearance: checkbox !important;
    width: 18px !important;
    height: 18px !important;
    min-width: 18px !important;
    padding: 0 !important;
    border: none !important;
    background: none !important;
    accent-color: #0048d4;
    cursor: pointer;
    flex-shrink: 0;
}

/* Fix: modal CTO sobre mapa Leaflet */
#dw3-modal-cto-det,
#dw3-modal-cto-edit,
#dw3-modal-cto-del { z-index: 99999 !important; }
