:root {
  --bg: #0b0d12;
  --surface: #161922;
  --surface-2: #1e212b;
  --border: #2a2e3b;
  --text: #e2e8f0;
  --text-2: #94a3b8;
  --accent: #4ade80;
  --accent-dim: #22c55e;
  --danger: #f87171;
  --warning: #fbbf24;
  --info: #60a5fa;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
  background: var(--bg);
  padding-bottom: 72px;
}

/* SCREENS */
.screen {
  display: none;
  min-height: 100vh;
}
.screen.active { display: block; }

/* LOGIN */
.login-box {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.logo { text-align: center; margin-bottom: 32px; }
.logo h1 {
  font-size: 2.6rem;
  font-weight: 900;
  letter-spacing: 4px;
  color: var(--accent);
}
.logo p { color: var(--text-2); margin-top: 6px; font-size: 0.95rem; }

.field { margin-bottom: 18px; }
.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color .15s;
  font-family: inherit;
}
.field input:focus,
.field textarea:focus,
.field select:focus { border-color: var(--accent); }

.btn-primary {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #052e16;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform .08s, opacity .2s;
}
.btn-primary:active { transform: scale(0.98); opacity: 0.92; }

.btn-danger {
  width: 100%;
  padding: 14px;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  background: rgba(248,113,113,0.1);
  color: var(--danger);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform .08s;
}
.btn-danger:active { transform: scale(0.98); }

.btn-accent {
  width: 100%;
  padding: 14px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: rgba(74,222,128,0.1);
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform .08s;
}
.btn-accent:active { transform: scale(0.98); }

.btn-ghost {
  padding: 12px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-2);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-large {
  padding: 20px;
  font-size: 1.1rem;
}

.error-msg {
  margin-top: 12px;
  color: var(--danger);
  font-size: 0.9rem;
  text-align: center;
  min-height: 1.2em;
}

.success-msg {
  margin-top: 12px;
  color: var(--accent);
  font-size: 0.9rem;
  text-align: center;
  min-height: 1.2em;
}

.login-actions {
  text-align: center;
  margin-top: 16px;
}

.btn-link {
  background: none;
  border: none;
  color: var(--text-2);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 12px;
  transition: color .15s;
}
.btn-link:hover, .btn-link:focus { color: var(--accent); }

.role-select {
  display: flex;
  gap: 12px;
}

.role-option {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-2);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}

.role-option input[type="radio"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

.role-option:has(input[type="radio"]:checked) {
  border-color: var(--accent);
  background: rgba(74,222,128,0.08);
  color: var(--accent);
}

/* PAGE HEADER */
.page-header {
  padding: 24px 20px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}
.page-header h2 {
  font-size: 1.4rem;
  font-weight: 700;
}
.page-header .sub {
  color: var(--text-2);
  font-size: 0.85rem;
  margin-top: 2px;
}

/* PAGE BODY */
.page-body {
  padding: 16px 20px 24px;
}

.section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-2);
  margin: 20px 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* STATS */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 8px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 14px;
  text-align: center;
}
.stat-value {
  display: block;
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--accent);
}
.stat-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-2);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* LIST ITEMS */
.list-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.list-item .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.list-item .title {
  font-weight: 600;
  font-size: 0.95rem;
}
.list-item .meta {
  font-size: 0.8rem;
  color: var(--text-2);
}

/* BADGES */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-pendiente { background: rgba(251,191,36,0.15); color: var(--warning); }
.badge-en_progreso { background: rgba(96,165,250,0.15); color: var(--info); }
.badge-completada { background: rgba(74,222,128,0.15); color: var(--accent); }
.badge-cancelada { background: rgba(248,113,113,0.15); color: var(--danger); }
.badge-entrada { background: rgba(74,222,128,0.15); color: var(--accent); }
.badge-salida { background: rgba(248,113,113,0.15); color: var(--danger); }

/* FICHAR */
.fichar-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
}
.fichar-time {
  font-size: 3.2rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 2px;
}
.fichar-date {
  color: var(--text-2);
  font-size: 0.95rem;
  margin-bottom: 16px;
}
.fichar-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.95rem;
  font-weight: 700;
}
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-2);
  display: inline-block;
}
.fichar-status.dentro .status-dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.fichar-status.fuera .status-dot { background: var(--danger); box-shadow: 0 0 8px var(--danger); }
.fichar-gps {
  font-size: 0.8rem;
  color: var(--text-2);
  margin-bottom: 8px;
}
.fichar-gps-warn {
  font-size: 0.85rem;
  color: var(--warning);
  font-weight: 600;
  margin-bottom: 12px;
}
.fichar-actions {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}
.fichar-actions .btn-large {
  padding: 22px 10px;
  font-size: 1.15rem;
  font-weight: 700;
}
.fichar-msg {
  min-height: 1.4em;
  font-size: 0.9rem;
  color: var(--text-2);
}
.fichar-msg.ok { color: var(--accent); }
.fichar-msg.err { color: var(--danger); }
.fichar-last {
  margin-top: 16px;
  text-align: left;
}

/* BOTTOM NAV */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 480px;
  margin: 0 auto;
  background: rgba(22,25,34,0.95);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 60px;
  z-index: 100;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 100%;
  color: var(--text-2);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  border: none;
  background: none;
  transition: color .15s;
}
.nav-item.active { color: var(--accent); }
.nav-item svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

/* MODAL */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal.active { display: flex; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
}
.modal-box {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 420px;
  z-index: 1;
}
.modal-box h3 { margin-bottom: 16px; }
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.modal-actions button { flex: 1; }

/* CONFIRM MODAL */
.modal-confirm-box {
  text-align: center;
  padding: 28px 24px;
}
.confirm-msg {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.5;
  margin: 0;
}
#btn-confirm-ok {
  transition: opacity .2s, transform .08s;
}
#btn-confirm-ok:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* DASHBOARD ACTIONS */
.dash-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 16px;
}
.dash-action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 18px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform .08s, border-color .15s, background .15s;
}
.dash-action-btn:active { transform: scale(0.97); }
.dash-action-btn:hover, .dash-action-btn:focus {
  border-color: var(--accent);
  background: var(--surface-2);
}
.dash-action-btn svg {
  width: 26px;
  height: 26px;
  fill: currentColor;
  color: var(--accent);
}

/* DASHBOARD SIMPLE STATS */
.dash-simple-stats {
  margin-top: 20px;
}
.simple-bar-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}
.simple-bar-row {
  display: grid;
  grid-template-columns: 90px 1fr 36px;
  align-items: center;
  gap: 10px;
}
.simple-bar-label {
  font-size: 0.8rem;
  color: var(--text-2);
}
.simple-bar {
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.simple-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width .4s ease;
}
.simple-bar-num {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* DASH PROGRESS */
.dash-progress {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 16px;
}
.dash-progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.dash-progress-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.dash-progress-pct {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent);
}
.dash-progress-bar {
  height: 10px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.dash-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width .4s ease;
}

/* SEGMENTED TABS */
.segmented {
  display: flex;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 16px;
}
.seg-btn {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-2);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.seg-btn.active {
  background: var(--surface-2);
  color: var(--text);
}

/* INCIDENCIA BADGES */
.badge-abierta { background: rgba(251,191,36,0.15); color: var(--warning); }
.badge-en_revision { background: rgba(96,165,250,0.15); color: var(--info); }
.badge-resuelta { background: rgba(74,222,128,0.15); color: var(--accent); }
.badge-cerrada { background: rgba(148,163,184,0.15); color: var(--text-2); }

/* PRIORIDAD BADGES */
.badge-baja { background: rgba(148,163,184,0.15); color: var(--text-2); }
.badge-media { background: rgba(251,191,36,0.15); color: var(--warning); }
.badge-alta { background: rgba(248,113,113,0.15); color: var(--danger); }
.badge-critica { background: rgba(248,113,113,0.25); color: var(--danger); border: 1px solid rgba(248,113,113,0.3); }

/* TIMELINE */
.timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding-left: 8px;
  border-left: 2px solid var(--border);
  margin-left: 8px;
}
.timeline-item {
  position: relative;
  padding: 10px 0 14px 16px;
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: -13px;
  top: 14px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
}
.timeline-item.pendiente::before { background: var(--warning); }
.timeline-item.abierta::before { background: var(--danger); }
.timeline-item.completada::before, .timeline-item.resuelta::before, .timeline-item.cerrada::before { background: var(--accent); }
.timeline-date {
  font-size: 0.75rem;
  color: var(--text-2);
  margin-bottom: 2px;
}
.timeline-title {
  font-size: 0.9rem;
  font-weight: 600;
}
.timeline-meta {
  font-size: 0.8rem;
  color: var(--text-2);
  margin-top: 2px;
}

/* EMPTY */
.empty {
  text-align: center;
  color: var(--text-2);
  padding: 40px 20px;
  font-size: 0.95rem;
}

/* SCROLLBAR */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
