/* FieldTech - Mobile-first Design System */
/* Fuente principal: Urbanist (moderna, técnica, legible) */
@import url('https://fonts.googleapis.com/css2?family=Urbanist:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;600&display=swap');

/* ── VARIABLES ────────────────────────────────────────────── */
:root {
  --bg:        #0a0e1a;
  --bg2:       #111827;
  --bg3:       #1a2235;
  --border:    rgba(255,255,255,.08);
  --text:      #f0f4ff;
  --text2:     #8b9ab7;
  --text3:     #4a5568;
  --primary:   #3b82f6;
  --primary-d: #2563eb;
  --primary-g: linear-gradient(135deg, #3b82f6, #6366f1);
  --success:   #10b981;
  --warning:   #f59e0b;
  --danger:    #ef4444;
  --urgente:   #dc2626;
  --alta:      #f97316;
  --media:     #f59e0b;
  --baja:      #10b981;
  --radius:    12px;
  --radius-sm: 8px;
  --shadow:    0 4px 20px rgba(0,0,0,.4);
  --shadow-sm: 0 2px 8px rgba(0,0,0,.3);
  --nav-h:     64px;
  --transition: .2s ease;
}

/* ── RESET ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Urbanist', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; border: none; background: none; }
input, select, textarea {
  font-family: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .75rem 1rem;
  width: 100%;
  outline: none;
  transition: border-color var(--transition);
  -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
select option { background: var(--bg2); }
textarea { resize: vertical; min-height: 80px; }
img { max-width: 100%; display: block; }

/* ── LAYOUT ───────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}
.page {
  display: none;
  flex: 1;
  flex-direction: column;
  padding-bottom: calc(var(--nav-h) + 8px);
  min-height: 100dvh;
  animation: fadeIn .2s ease;
}
.page.active { display: flex; }
@keyframes fadeIn { from { opacity:0; transform:translateY(4px); } to { opacity:1; transform:none; } }

.page-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10,14,26,.95);
  backdrop-filter: blur(12px);
  padding: 1rem 1rem .75rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .75rem;
}
.page-title {
  font-size: 1.1rem;
  font-weight: 700;
  flex: 1;
}
.page-content {
  flex: 1;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

/* ── BOTTOM NAV ───────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 200;
  height: var(--nav-h);
  background: rgba(17,24,39,.97);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: stretch;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text3);
  font-size: .65rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  transition: color var(--transition);
  position: relative;
  padding: .5rem;
  -webkit-tap-highlight-color: transparent;
}
.nav-item svg { width: 22px; height: 22px; transition: transform var(--transition); }
.nav-item.active { color: var(--primary); }
.nav-item.active svg { transform: translateY(-2px); }
.nav-item .badge {
  position: absolute;
  top: 8px; right: calc(50% - 18px);
  background: var(--danger);
  color: #fff;
  font-size: .6rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ── AUTH PAGES ───────────────────────────────────────────── */
#page-login, #page-register {
  justify-content: center;
  align-items: center;
  padding: 2rem 1.5rem;
  background: var(--bg);
  gap: 0;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2rem 1.5rem;
  box-shadow: var(--shadow);
}
.auth-logo {
  text-align: center;
  margin-bottom: 2rem;
}
.auth-logo .logo-icon {
  width: 60px; height: 60px;
  background: var(--primary-g);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
  font-size: 2rem;
}
.auth-logo h1 { font-size: 1.6rem; font-weight: 800; }
.auth-logo p { color: var(--text2); font-size: .9rem; margin-top: .25rem; }

/* ── FORMS ────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: .5rem; }
.form-group label { font-size: .85rem; font-weight: 600; color: var(--text2); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.form-stack { display: flex; flex-direction: column; gap: .75rem; }

/* ── BUTTONS ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .875rem 1.5rem;
  border-radius: var(--radius-sm);
  font-size: .95rem;
  font-weight: 700;
  transition: all var(--transition);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  min-height: 48px;
}
.btn-primary { background: var(--primary-g); color: #fff; }
.btn-primary:active { opacity: .85; transform: scale(.98); }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { color: var(--text2); padding: .5rem; min-height: 36px; }
.btn-block { width: 100%; }
.btn-sm { padding: .5rem .875rem; font-size: .85rem; min-height: 36px; }
.btn svg { width: 18px; height: 18px; flex-shrink: 0; }

/* ── CARDS ────────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}
.card-body { padding: 1rem; }
.card-title { font-size: .95rem; font-weight: 700; }

/* ── TICKET CARD ──────────────────────────────────────────── */
.ticket-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  cursor: pointer;
  transition: border-color var(--transition), transform var(--transition);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
}
.ticket-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  border-radius: 4px 0 0 4px;
}
.ticket-card.urgente::before { background: var(--urgente); }
.ticket-card.alta::before    { background: var(--alta); }
.ticket-card.media::before   { background: var(--media); }
.ticket-card.baja::before    { background: var(--baja); }
.ticket-card:active { transform: scale(.985); border-color: var(--primary); }

.ticket-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: .5rem;
}
.ticket-card-title {
  font-size: .95rem;
  font-weight: 700;
  line-height: 1.3;
  flex: 1;
}
.ticket-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-top: .5rem;
}
.ticket-card-meta span {
  font-size: .75rem;
  color: var(--text2);
  display: flex;
  align-items: center;
  gap: 3px;
}
.ticket-card-meta svg { width: 12px; height: 12px; }

/* ── BADGES / CHIPS ───────────────────────────────────────── */
.badge-status {
  font-size: .7rem;
  font-weight: 700;
  padding: .25rem .6rem;
  border-radius: 20px;
  white-space: nowrap;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.badge-status.pendiente  { background: rgba(251,191,36,.15); color: #fbbf24; }
.badge-status.en_proceso { background: rgba(59,130,246,.15); color: #60a5fa; }
.badge-status.completado { background: rgba(16,185,129,.15); color: #34d399; }
.badge-status.reagendado { background: rgba(168,85,247,.15); color: #c084fc; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: .75rem;
  padding: .25rem .625rem;
  border-radius: 20px;
  background: var(--bg3);
  color: var(--text2);
  border: 1px solid var(--border);
}

/* ── MAP ──────────────────────────────────────────────────── */
#map-container {
  position: relative;
  height: calc(100dvh - var(--nav-h));
  overflow: hidden;
}
#map {
  width: 100%;
  height: 100%;
}
.map-controls {
  position: absolute;
  top: 1rem; left: 50%;
  transform: translateX(-50%);
  z-index: 400;
  display: flex;
  gap: .5rem;
  background: rgba(17,24,39,.92);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 40px;
  padding: .4rem;
  max-width: calc(100vw - 2rem);
  overflow-x: auto;
  scrollbar-width: none;
}
.map-controls::-webkit-scrollbar { display: none; }
.map-view-btn {
  padding: .4rem .875rem;
  border-radius: 30px;
  font-size: .8rem;
  font-weight: 700;
  color: var(--text2);
  white-space: nowrap;
  transition: all var(--transition);
  background: transparent;
}
.map-view-btn.active {
  background: var(--primary);
  color: #fff;
}
.map-fab {
  position: absolute;
  bottom: 1.5rem; right: 1rem;
  z-index: 400;
  background: var(--primary-g);
  color: #fff;
  width: 52px; height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(59,130,246,.5);
  transition: transform var(--transition);
}
.map-fab:active { transform: scale(.92); }
.map-fab svg { width: 24px; height: 24px; }
.map-filter-bar {
  position: absolute;
  bottom: 1.5rem; left: 1rem;
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.map-filter-btn {
  background: rgba(17,24,39,.92);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .5rem .875rem;
  border-radius: 8px;
  font-size: .8rem;
  font-weight: 600;
}

/* Leaflet popup override */
.leaflet-popup-content-wrapper {
  background: var(--bg2);
  color: var(--text);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.leaflet-popup-tip { background: var(--bg2); }
.leaflet-popup-content { margin: .75rem 1rem; font-family: 'Urbanist', sans-serif; }
.popup-title { font-weight: 700; font-size: .95rem; margin-bottom: .4rem; }
.popup-meta { font-size: .8rem; color: var(--text2); margin-bottom: .5rem; }

/* ── MODAL ────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 500;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}
.modal {
  background: var(--bg2);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 92dvh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  padding-bottom: env(safe-area-inset-bottom, 1rem);
}
.modal-overlay.open .modal {
  transform: translateY(0);
}
.modal-handle {
  width: 36px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: .75rem auto .25rem;
}
.modal-header {
  padding: .75rem 1rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-size: 1.1rem; font-weight: 800; }
.modal-body { padding: 0 1rem 1rem; }

/* ── STATS ────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .25rem;
}
.stat-card .stat-value {
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1;
  font-family: 'JetBrains Mono', monospace;
}
.stat-card .stat-label { font-size: .75rem; color: var(--text2); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.stat-card .stat-icon { font-size: 1.5rem; margin-bottom: .25rem; }

/* ── TECNICO CARD ─────────────────────────────────────────── */
.tecnico-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: .875rem;
  cursor: pointer;
  transition: border-color var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.tecnico-card:active { border-color: var(--primary); }
.avatar {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: var(--primary-g);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
  color: #fff;
  flex-shrink: 0;
}
.tecnico-info { flex: 1; min-width: 0; }
.tecnico-name { font-weight: 700; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tecnico-meta { font-size: .8rem; color: var(--text2); }

/* ── LIST ITEMS ───────────────────────────────────────────── */
.list-item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .875rem 1rem;
  display: flex;
  align-items: center;
  gap: .75rem;
}
.list-item-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1rem;
}
.list-item-content { flex: 1; min-width: 0; }
.list-item-title { font-weight: 600; font-size: .9rem; }
.list-item-sub { font-size: .78rem; color: var(--text2); margin-top: 2px; }
.list-item-actions { display: flex; gap: .5rem; }

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

#toast-container {
  position: fixed;
  top: 1rem; left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  width: min(calc(100vw - 2rem), 360px);
}
.toast {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .875rem 1rem;
  font-size: .9rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: toastIn .25s ease;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.toast.success { border-color: var(--success); }
.toast.error   { border-color: var(--danger); }
.toast.info    { border-color: var(--primary); }
@keyframes toastIn { from { opacity:0; transform:translateY(-10px); } }

/* ── PHOTO GRID ───────────────────────────────────────────── */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .5rem;
}
.photo-thumb {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--border);
}
.photo-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
}

/* ── UPLOAD ZONE ──────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text2);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.upload-zone:hover { border-color: var(--primary); background: rgba(59,130,246,.05); }
.upload-zone svg { width: 36px; height: 36px; margin: 0 auto .75rem; opacity: .5; }
.upload-zone p { font-size: .9rem; font-weight: 500; }

/* ── FILTER BAR ───────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: .5rem;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: .25rem;
}
.filter-bar::-webkit-scrollbar { display: none; }
.filter-chip {
  padding: .4rem .875rem;
  border-radius: 20px;
  font-size: .8rem;
  font-weight: 700;
  color: var(--text2);
  background: var(--bg2);
  border: 1px solid var(--border);
  white-space: nowrap;
  transition: all var(--transition);
  flex-shrink: 0;
}
.filter-chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── DIVIDER ──────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: .5rem 0; }

/* ── EMPTY STATE ──────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text2);
}
.empty-state svg { width: 48px; height: 48px; opacity: .3; margin: 0 auto 1rem; }
.empty-state p { font-size: .95rem; }

/* ── SECTION HEADER ───────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .75rem;
}
.section-title { font-size: .8rem; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: .06em; }

/* ── UTILITIES ────────────────────────────────────────────── */
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-muted   { color: var(--text2); }
.text-sm      { font-size: .85rem; }
.text-xs      { font-size: .75rem; }
.font-mono    { font-family: 'JetBrains Mono', monospace; }
.fw-bold      { font-weight: 700; }
.fw-800       { font-weight: 800; }
.mt-1  { margin-top: .5rem; }
.mt-2  { margin-top: 1rem; }
.mb-1  { margin-bottom: .5rem; }
.mb-2  { margin-bottom: 1rem; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-1 { gap: .5rem; }
.gap-2 { gap: 1rem; }
.flex-1 { flex: 1; }
.hidden { display: none !important; }

/* ── RESPONSIVE DESKTOP ───────────────────────────────────── */
@media (min-width: 768px) {
  .page-content { max-width: 720px; margin: 0 auto; padding: 1.5rem; }
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .bottom-nav { max-width: 480px; left: 50%; transform: translateX(-50%); border-radius: 20px 20px 0 0; }
  .modal { border-radius: 20px; align-self: center; margin: 1rem; }
  .modal-overlay { align-items: center; }
}

/* ── PWA / SAFE AREA ──────────────────────────────────────── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .bottom-nav { padding-bottom: env(safe-area-inset-bottom); height: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
}
