/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:        #2563eb;
  --primary-dark:   #1d4ed8;
  --primary-light:  #eff6ff;
  --secondary:      #f97316;
  --secondary-light:#fff7ed;
  --success:        #16a34a;
  --success-light:  #f0fdf4;
  --warning:        #d97706;
  --warning-light:  #fffbeb;
  --danger:         #dc2626;
  --danger-light:   #fef2f2;
  --text:           #1e293b;
  --text-muted:     #64748b;
  --border:         #e2e8f0;
  --bg:             #f8fafc;
  --white:          #ffffff;
  --sidebar-bg:     #0f172a;
  --sidebar-w:      248px;
  --radius:         8px;
  --shadow:         0 1px 3px rgba(0,0,0,.1);
  --shadow-md:      0 4px 12px rgba(0,0,0,.1);
  --shadow-lg:      0 10px 24px rgba(0,0,0,.12);
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ============================================================
   LAYOUT
   ============================================================ */
.app-container {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: var(--bg);
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-icon { font-size: 24px; }
.brand-name {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.3px;
}

.obra-selector-wrap {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.obra-label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: rgba(255,255,255,.4);
  margin-bottom: 6px;
}
.obra-row { display: flex; gap: 6px; align-items: center; }
.obra-select {
  flex: 1;
  background: rgba(255,255,255,.08);
  color: #fff;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: var(--radius);
  padding: 6px 8px;
  font-size: 13px;
  cursor: pointer;
  min-width: 0;
}
.obra-select option { background: #1e293b; color: #fff; }
.btn-new-obra {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  width: 30px;
  height: 30px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s;
}
.btn-new-obra:hover { background: var(--primary-dark); }

.sidebar-nav {
  padding: 8px 8px;
  flex: 1;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius);
  color: rgba(255,255,255,.6);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  margin-bottom: 2px;
}
.nav-item:hover {
  background: rgba(255,255,255,.07);
  color: rgba(255,255,255,.9);
}
.nav-item.active {
  background: var(--primary);
  color: #fff;
}
.nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.btn-sidebar-action {
  background: rgba(255,255,255,.07);
  color: rgba(255,255,255,.65);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: var(--radius);
  padding: 7px 12px;
  font-size: 12px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: all .15s;
  display: block;
}
.btn-sidebar-action:hover {
  background: rgba(255,255,255,.12);
  color: #fff;
}

/* ============================================================
   TYPOGRAPHY & HEADINGS
   ============================================================ */
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-title { font-size: 20px; font-weight: 700; color: var(--text); }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
  flex-wrap: wrap;
}
.card-title { font-size: 14px; font-weight: 600; color: var(--text); }
.card-body { padding: 16px 18px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.stat-icon { font-size: 22px; float: right; margin-top: -2px; }

/* ============================================================
   TABLES
   ============================================================ */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
thead th {
  background: var(--bg);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
tbody td {
  padding: 10px 14px;
  vertical-align: middle;
}
td.actions { white-space: nowrap; text-align: right; }

/* ============================================================
   FORMS
   ============================================================ */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1 / -1; }
label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
input, select, textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 14px;
  color: var(--text);
  background: var(--white);
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
textarea { resize: vertical; min-height: 80px; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all .15s;
  white-space: nowrap;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }

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

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }

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

.btn-sm {
  padding: 5px 11px;
  font-size: 12.5px;
}
.btn-icon-sm {
  padding: 5px 8px;
  font-size: 12px;
  border-radius: 6px;
}

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

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .03em;
  white-space: nowrap;
}
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger  { background: var(--danger-light);  color: var(--danger); }
.badge-neutral { background: #f1f5f9; color: var(--text-muted); }
.badge-secondary { background: var(--secondary-light); color: var(--secondary); }

/* ============================================================
   PROGRESS BAR
   ============================================================ */
.progress-bar-wrap {
  background: var(--border);
  border-radius: 20px;
  height: 8px;
  overflow: hidden;
  min-width: 80px;
}
.progress-bar-fill {
  height: 100%;
  border-radius: 20px;
  background: var(--primary);
  transition: width .3s;
}
.progress-bar-fill.success { background: var(--success); }
.progress-bar-fill.warning { background: var(--warning); }
.progress-bar-fill.danger  { background: var(--danger); }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
  backdrop-filter: blur(2px);
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--white);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal.modal-lg { max-width: 800px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h2 { font-size: 16px; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 6px;
  transition: all .15s;
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
}

/* ============================================================
   TOAST
   ============================================================ */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
}
.toast {
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 13.5px;
  box-shadow: var(--shadow-md);
  animation: slideIn .25s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 340px;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
.toast.warning { background: var(--warning); }
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ============================================================
   DASHBOARD
   ============================================================ */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 16px;
}
@media (max-width: 900px) { .dashboard-grid { grid-template-columns: 1fr; } }

.obra-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  font-size: 13px;
}
.obra-info-item { display: flex; flex-direction: column; gap: 2px; }
.obra-info-label { font-size: 11px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; }
.obra-info-value { font-weight: 500; }

.list-items { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--bg);
  gap: 10px;
}
.list-item-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.list-item-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item-sub  { font-size: 12px; color: var(--text-muted); }

/* ============================================================
   PRESUPUESTO
   ============================================================ */
.presupuesto-totales {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.total-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.total-card.highlight { border-color: var(--primary); background: var(--primary-light); }
.total-card.danger-card { border-color: var(--danger); background: var(--danger-light); }
.total-card .lbl { font-size: 11px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; margin-bottom: 4px; }
.total-card .val { font-size: 20px; font-weight: 700; }

.filter-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.filter-row select, .filter-row input {
  padding: 7px 10px;
  font-size: 13px;
  max-width: 200px;
}

/* ============================================================
   PLANNING / GANTT
   ============================================================ */
/* Toolbar de escala (Día / Semana / Mes) */
.gantt-toolbar { display: flex; align-items: center; gap: 10px; padding: 12px 16px 6px; flex-wrap: wrap; }
.gantt-toolbar-lbl { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 5px; }
.gantt-toolbar-lbl svg.lucide { width: 14px; height: 14px; }
.gantt-scale-group { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.gantt-scale-btn {
  border: none; background: var(--white); color: var(--text-muted);
  font-family: inherit; font-size: 12px; font-weight: 600; padding: 5px 14px; cursor: pointer;
  border-right: 1px solid var(--border);
}
.gantt-scale-btn:last-child { border-right: none; }
.gantt-scale-btn.active { background: var(--primary); color: #fff; }
.gantt-toolbar-hint {
  font-size: 11px;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
}
.gantt-toolbar-hint svg.lucide { width: 13px; height: 13px; }
@media (max-width: 700px) { .gantt-toolbar-hint { display: none; } }

/* Layout en píxeles: columna de nombres fija + timeline scrollable */
.gantt2 { display: flex; align-items: flex-start; border-top: 1px solid var(--border); }
.gantt2-names { flex: 0 0 auto; width: 190px; border-right: 2px solid var(--border); background: var(--white); }
.gantt2-names-head {
  height: 38px; display: flex; align-items: center; padding: 0 12px;
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  background: #1e293b; color: rgba(255,255,255,.8);
}
.gantt2-name {
  height: 46px; padding: 5px 12px; border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; justify-content: center; gap: 2px; overflow: hidden;
}
.gantt2-name-t { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gantt2-name-d { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gantt2-name.is-active { background: rgba(220,38,38,.05); box-shadow: inset 3px 0 0 var(--danger); }

.gantt2-scroll { flex: 1 1 auto; overflow-x: auto; overflow-y: hidden; }
.gantt2-canvas { position: relative; }
.gantt2-ticks { display: flex; height: 38px; background: #1e293b; }
.gantt2-tick {
  flex: 0 0 auto; box-sizing: border-box;
  border-right: 1px solid rgba(255,255,255,.12);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: rgba(255,255,255,.75); overflow: hidden;
}
.gantt2-tick.wk { background: rgba(255,255,255,.05); }
.gantt2-tick .t-dow { font-size: 9px; text-transform: uppercase; opacity: .65; line-height: 1.1; }
.gantt2-tick .t-day { font-size: 11px; font-weight: 600; white-space: nowrap; line-height: 1.2; }
.gantt2-body { position: relative; }
.gantt2-row { position: relative; height: 46px; border-bottom: 1px solid var(--border); }
.gantt2-row.is-active { background: rgba(220,38,38,.04); }
.gantt2-row:hover { background: rgba(37,99,235,.04); }

.gantt-bar {
  position: absolute;
  top: 10px;
  height: 26px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 500;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: filter .15s;
  box-shadow: var(--shadow);
}
.gantt-bar:hover { filter: brightness(1.1); }
.gantt-bar.pendiente   { background: var(--text-muted); }
.gantt-bar.en-curso    { background: var(--primary); }
.gantt-bar.completada  { background: var(--success); }
.gantt-bar.bloqueada   { background: var(--danger); }
.gantt-bar.programada  { background: var(--primary); }
.gantt-bar.cancelada   { background: var(--danger); }

/* Línea "ahora" viva (avanza con la hora del día) */
.gantt-now-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--danger);
  pointer-events: none;
  z-index: 5;
  transition: left .6s ease;
}
.gantt-now-line::before {
  content: '';
  position: absolute;
  top: 30px; left: 50%;
  transform: translateX(-50%);
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--danger);
}
.gantt-now-label {
  position: absolute;
  top: 3px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 6px;
  white-space: nowrap;
  z-index: 6;
}
.gantt-now-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0 16px 12px;
  padding: 8px 12px;
  background: var(--danger-light);
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  font-size: 12px;
  color: #b91c1c;
}
.gantt-now-banner svg.lucide { width: 15px; height: 15px; color: var(--danger); }
.gantt-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--danger);
  margin-right: 6px;
  vertical-align: middle;
  animation: gantt-pulse 1.6s ease-in-out infinite;
}
@keyframes gantt-pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* ============================================================
   MODAL DE DETALLES (tareas / reuniones)
   ============================================================ */
.detalle-grid { display: flex; flex-direction: column; gap: 2px; margin-bottom: 16px; }
.detalle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.detalle-lbl {
  color: var(--text-muted);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 7px;
}
.detalle-lbl svg.lucide { width: 15px; height: 15px; }
.detalle-progreso {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.detalle-desc { font-size: 13px; }
.detalle-desc p { color: var(--text); }
.detalle-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chip {
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 500;
}

/* Colores de barra Gantt para reuniones */
.gantt-bar.programada { background: var(--primary); }
.gantt-bar.cancelada  { background: var(--danger); }

/* Lista de checks (asistentes a reuniones, etc.) */
.check-list {
  max-height: 190px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.check-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 2px;
  font-size: 13px;
  font-weight: 400;
  text-transform: none;
  color: var(--text);
  cursor: pointer;
}
.check-item input { width: auto; margin: 0; }

/* ============================================================
   AUTOPROGRAMAR (catálogo de tareas)
   ============================================================ */
.auto-list {
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 4px;
}
.auto-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-weight: 400;
  text-transform: none;
  transition: background .12s;
}
.auto-item:last-child { border-bottom: none; }
.auto-item:hover { background: var(--bg); }
.auto-item.sel { background: var(--primary-light); }
.auto-item input { width: auto; margin: 0; flex-shrink: 0; }
.auto-item-main { display: flex; flex-direction: column; gap: 1px; flex: 1; min-width: 0; }
.auto-item-name { font-size: 13.5px; font-weight: 600; color: var(--text); }
.auto-item-cat { font-size: 11px; color: var(--text-muted); }
.auto-item-dur {
  font-size: 11px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-light);
  padding: 2px 8px;
  border-radius: 12px;
  white-space: nowrap;
  flex-shrink: 0;
}
.auto-config {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 4px;
}
.auto-preview {
  font-size: 13px;
  color: var(--text);
  background: var(--white);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-top: 4px;
}
.auto-preview svg.lucide { width: 15px; height: 15px; vertical-align: -2px; color: var(--primary); }

/* ============================================================
   USUARIOS Y PERMISOS
   ============================================================ */
.user-info {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  margin-bottom: 8px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 8px;
  color: #fff;
  font-size: 12px;
  line-height: 1.3;
}
.user-info svg.lucide { width: 24px; height: 24px; color: rgba(255,255,255,.7); flex-shrink: 0; }
.perm-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
.perm-item {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.perm-item .badge { flex-shrink: 0; }
table code { background: var(--bg); padding: 1px 6px; border-radius: 4px; font-size: 12px; }

/* Rejilla de permisos por sección */
.perm-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
}
.perm-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 4px;
  flex-wrap: wrap;
}
.perm-row-name { font-size: 13px; font-weight: 600; }
.perm-seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.perm-opt {
  font-size: 11.5px;
  padding: 5px 11px;
  cursor: pointer;
  color: var(--text-muted);
  border-right: 1px solid var(--border);
  background: var(--white);
  text-transform: none;
  font-weight: 600;
  user-select: none;
}
.perm-opt:last-child { border-right: none; }
.perm-opt input { display: none; }
.perm-opt.editar:has(input:checked)  { background: var(--success); color: #fff; }
.perm-opt.ver:has(input:checked)     { background: var(--primary); color: #fff; }
.perm-opt.ocultar:has(input:checked) { background: var(--text-muted); color: #fff; }

/* ============================================================
   SPLASH / PANTALLA DE CARGA
   ============================================================ */
.splash {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  transition: opacity .4s ease;
}
.splash.hide { opacity: 0; pointer-events: none; }
.splash-logo {
  width: 92px; height: 92px;
  border-radius: 22px;
  box-shadow: 0 12px 34px rgba(0,0,0,.45);
  animation: splash-pop .5s ease;
}
@keyframes splash-pop { from { transform: scale(.82); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.splash-name { color: #fff; font-size: 24px; font-weight: 800; letter-spacing: -.5px; margin-top: 4px; }
.splash-sub { color: rgba(255,255,255,.55); font-size: 13px; margin-top: -6px; }
.splash-bar {
  width: 170px; height: 4px;
  background: rgba(255,255,255,.12);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 10px;
}
.splash-bar-fill {
  height: 100%; width: 40%;
  background: var(--primary);
  border-radius: 4px;
  animation: splash-load 1.1s ease-in-out infinite;
}
@keyframes splash-load { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }

/* Iconos de marca (imagen del icono de la app) */
.login-logo-img {
  width: 72px; height: 72px;
  border-radius: 18px;
  box-shadow: var(--shadow-md);
  margin: 0 auto 12px;
  display: block;
}
.brand-img { width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0; }

/* ============================================================
   ZONA SEGURA SUPERIOR (notch / barra de estado — iPhone PWA)
   ============================================================ */
#safeTop {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: env(safe-area-inset-top, 0px);
  background: #fff;
  z-index: 10000;
  pointer-events: none;
}
/* El contenido del menú y de los overlays arranca bajo la banda */
.sidebar { padding-top: env(safe-area-inset-top, 0px); }
.splash { padding-top: env(safe-area-inset-top, 0px); }
.login-overlay { padding-top: env(safe-area-inset-top, 0px); }

/* ============================================================
   EQUIPOS
   ============================================================ */
.workers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}
.worker-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  position: relative;
}
.worker-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 10px;
}
.worker-name { font-size: 15px; font-weight: 600; }
.worker-role { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.worker-info { font-size: 12.5px; color: var(--text-muted); margin-bottom: 4px; }
.worker-actions {
  display: flex;
  gap: 6px;
  margin-top: 12px;
}
.worker-inactive { opacity: .55; }

/* Carpetas / grupos de equipo */
.folder-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-left: 4px solid var(--folder-color, var(--primary));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  overflow: hidden;
}
.folder-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--folder-color, var(--primary)) 7%, var(--white));
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.folder-head-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.folder-ic {
  width: 38px; height: 38px;
  border-radius: 9px;
  background: var(--folder-color, var(--primary));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.folder-ic svg.lucide { width: 20px; height: 20px; }
.folder-name { font-size: 15px; font-weight: 700; }
.folder-sub { font-size: 12px; color: var(--text-muted); }
.folder-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.folder-body { padding: 16px; }
.folder-body svg.lucide { width: 14px; height: 14px; vertical-align: -2px; }

/* Selector de color */
.color-picker { display: flex; gap: 10px; flex-wrap: wrap; }
.color-dot {
  width: 30px; height: 30px;
  border-radius: 50%;
  cursor: pointer;
  position: relative;
  box-shadow: 0 0 0 2px var(--white), 0 0 0 2px var(--border);
  transition: transform .12s;
}
.color-dot:hover { transform: scale(1.1); }
.color-dot input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.color-dot:has(input:checked) { box-shadow: 0 0 0 2px var(--white), 0 0 0 4px var(--text); }

/* ============================================================
   MATERIALES
   ============================================================ */
.stock-alert {
  background: var(--warning-light);
  border: 1px solid #fcd34d;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  color: #92400e;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ============================================================
   DOCUMENTOS
   ============================================================ */
.doc-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 18px;
}
.doc-tab {
  padding: 8px 16px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  color: var(--text-muted);
  border-radius: 6px 6px 0 0;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  transition: all .15s;
}
.doc-tab:hover { color: var(--primary); }
.doc-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.diario-entry {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.diario-entry-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.diario-date { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.diario-title { font-size: 14px; font-weight: 600; }
.diario-content { font-size: 13px; color: var(--text-muted); }

.incidencia-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-left: 4px solid var(--text-muted);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
}
.incidencia-card.alta   { border-left-color: var(--danger); }
.incidencia-card.media  { border-left-color: var(--warning); }
.incidencia-card.baja   { border-left-color: var(--success); }

.checklist-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
}
.checklist-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--primary);
}
.checklist-text { flex: 1; font-size: 13.5px; }
.checklist-text.done {
  text-decoration: line-through;
  color: var(--text-muted);
}

/* ============================================================
   MISC UTILITIES
   ============================================================ */
/* ============================================================
   LOGIN
   ============================================================ */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--sidebar-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 24px;
}
.login-overlay.hidden { display: none; }

.login-box {
  background: #1e293b;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 24px 48px rgba(0,0,0,.4);
}
.login-logo { font-size: 48px; text-align: center; margin-bottom: 10px; }
.login-title {
  text-align: center;
  color: #fff;
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 4px;
}
.login-subtitle {
  text-align: center;
  color: rgba(255,255,255,.4);
  font-size: 14px;
  margin-bottom: 28px;
}
.login-box label { color: rgba(255,255,255,.5); }
.login-box input {
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.12);
  color: #fff;
  font-size: 15px;
  padding: 10px 12px;
}
.login-box input::placeholder { color: rgba(255,255,255,.25); }
.login-box input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.2);
}
.login-error {
  background: rgba(220,38,38,.15);
  border: 1px solid rgba(220,38,38,.3);
  color: #f87171;
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 10px;
}

/* ============================================================
   HAMBURGER + MOBILE SIDEBAR
   ============================================================ */
.menu-toggle {
  display: none;
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 14px);
  left: calc(env(safe-area-inset-left, 0px) + 12px);
  z-index: 600;
  background: var(--sidebar-bg);
  color: rgba(255,255,255,.8);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 8px;
  width: 40px;
  height: 40px;
  font-size: 18px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 499;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.visible { display: block; }

@media (max-width: 768px) {
  /* ── Mostrar hamburguesa ── */
  .menu-toggle {
    display: flex;
    width: 48px;
    height: 48px;
    font-size: 22px;
    top: calc(env(safe-area-inset-top, 0px) + 14px);
    left: calc(env(safe-area-inset-left, 0px) + 12px);
  }
  /* Ocultar la hamburguesa mientras el menú está abierto */
  body.sidebar-open .menu-toggle { display: none; }

  /* ── Sidebar deslizante ── */
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 500;
    transform: translateX(-100%);
    transition: transform .28s cubic-bezier(.4,0,.2,1);
    box-shadow: 4px 0 32px rgba(0,0,0,.5);
    width: 260px;
    min-width: 260px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar.open { transform: translateX(0); }

  /* Nav items más grandes para dedos */
  .nav-item {
    padding: 13px 14px;
    font-size: 15px;
    margin-bottom: 4px;
    min-height: 48px;
  }
  .nav-icon { font-size: 18px; width: 24px; }

  /* Sidebar footer botones más grandes */
  .btn-sidebar-action {
    padding: 11px 14px;
    font-size: 13.5px;
    min-height: 44px;
  }

  /* ── Contenido principal ── */
  .main-content {
    margin-left: 0 !important;
    padding: calc(64px + env(safe-area-inset-top, 0px)) 12px calc(24px + env(safe-area-inset-bottom, 0px));
    overflow-x: hidden;
  }

  .app-container { flex-direction: column; }

  /* ── Grids responsive ── */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .workers-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .presupuesto-totales { grid-template-columns: repeat(2, 1fr); }

  .page-header { flex-direction: column; align-items: flex-start; }
  .page-title { font-size: 17px; }

  /* ── Tablas ── */
  table { font-size: 12px; }
  thead th, tbody td { padding: 8px 8px; }
  td.actions { display: flex; gap: 4px; justify-content: flex-end; }

  /* ── Gantt ── */
  .gantt2-names { width: 130px; }
  .gantt2-name-t { font-size: 12px; }

  /* ── Modal centrado (NO bottom-sheet — mal para formularios con teclado) ── */
  .modal-overlay {
    align-items: center;
    padding: 16px;
  }
  .modal {
    max-width: 100%;
    max-height: 88vh;
    border-radius: 16px;
  }
  .modal-header {
    padding: 14px 16px;
    position: sticky;
    top: 0;
    background: var(--white);
    z-index: 1;
  }
  /* Botón cerrar modal: target grande */
  .modal-close {
    width: 44px;
    height: 44px;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--bg);
    color: var(--text);
  }
  .modal-footer {
    padding: 12px 16px;
    position: sticky;
    bottom: 0;
    background: var(--white);
    z-index: 1;
  }
  /* Botones en el footer del modal: full width en móvil */
  .modal-footer .btn {
    flex: 1;
    justify-content: center;
    min-height: 44px;
  }

  /* ── Botones generales más grandes ── */
  .btn { min-height: 40px; }
  .btn-sm, .btn-icon-sm { min-height: 36px; min-width: 36px; }

  /* ── Card headers ── */
  .card-header { flex-wrap: wrap; gap: 8px; }
  .card-body { padding: 12px 14px; }

  /* ── Ocultar columnas no esenciales en tablas ── */
  .table-wrap { -webkit-overflow-scrolling: touch; }
}

/* ============================================================
   GITHUB SYNC STATUS
   ============================================================ */
.sync-status {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: var(--radius);
  font-size: 12px;
  min-height: 28px;
  transition: all .2s;
  color: rgba(255,255,255,.5);
}
.sync-status:empty { display: none; }
.sync-ok      { color: #4ade80; background: rgba(74,222,128,.1); }
.sync-error   { color: #f87171; background: rgba(248,113,113,.1); }
.sync-syncing { color: #93c5fd; background: rgba(147,197,253,.1); }
@keyframes spin { to { transform: rotate(360deg); } }
.sync-syncing .spin { display: inline-block; animation: spin 1s linear infinite; }

/* ============================================================
   MISC UTILITIES
   ============================================================ */
.hidden { display: none !important; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary); }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-12 { margin-bottom: 12px; }
.flex  { display: flex; }
.flex-col { flex-direction: column; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

.no-obra-msg {
  text-align: center;
  padding: 80px 24px;
}
.no-obra-msg .big-icon { font-size: 56px; margin-bottom: 16px; }
.no-obra-msg h2 { font-size: 20px; margin-bottom: 8px; }
.no-obra-msg p { color: var(--text-muted); margin-bottom: 20px; }

/* ============================================================
   ICONOS LUCIDE — tamaños por contexto
   ============================================================ */
svg.lucide {
  width: 18px; height: 18px;
  stroke-width: 2;
  vertical-align: -3px;
  flex-shrink: 0;
}
.btn svg.lucide { width: 16px; height: 16px; vertical-align: -2px; }
.btn-sm svg.lucide, .btn-icon-sm svg.lucide { width: 15px; height: 15px; }
.nav-icon svg.lucide { width: 18px; height: 18px; vertical-align: -4px; }
.brand-icon svg.lucide { width: 22px; height: 22px; vertical-align: -5px; color: var(--primary); }
.login-logo svg.lucide { width: 48px; height: 48px; vertical-align: middle; }
.menu-toggle svg.lucide { width: 22px; height: 22px; vertical-align: -5px; }
.modal-close svg.lucide { width: 18px; height: 18px; }
.empty-state .empty-icon svg.lucide { width: 40px; height: 40px; }
.no-obra-msg .big-icon svg.lucide { width: 56px; height: 56px; color: var(--primary); }
.card-title svg.lucide, .page-title svg.lucide { width: 18px; height: 18px; vertical-align: -3px; color: var(--text-muted); }
.page-subtitle svg.lucide { width: 14px; height: 14px; vertical-align: -2px; }
.btn-sidebar-action svg.lucide { width: 16px; height: 16px; vertical-align: -3px; }
.sync-status .spin svg.lucide { width: 13px; height: 13px; }
.toast-ic svg.lucide { width: 17px; height: 17px; vertical-align: -3px; }

/* ============================================================
   DASHBOARD — resumen + casillas grandes
   ============================================================ */
.dash-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}
.dash-meta-item {
  flex: 1;
  min-width: 140px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.dash-meta-lbl {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
}
.dash-meta-lbl svg.lucide { width: 13px; height: 13px; vertical-align: middle; }
.dash-meta-val { font-size: 15px; }

.dash-tiles {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
@media (min-width: 720px)  { .dash-tiles { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1280px) { .dash-tiles { grid-template-columns: repeat(4, 1fr); } }

.dash-tile {
  text-align: left;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 142px;
  box-shadow: var(--shadow);
  font-family: inherit;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.dash-tile:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: #cbd5e1; }
.dash-tile:active { transform: translateY(0); }
.dash-tile-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.dash-tile-ic {
  width: 42px; height: 42px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}
.dash-tile-ic svg.lucide { width: 22px; height: 22px; vertical-align: middle; }
.dash-tile-arrow { color: var(--text-muted); }
.dash-tile-badge { color: var(--danger); display: flex; }
.dash-tile-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  font-weight: 700;
}
.dash-tile-main {
  font-size: 25px;
  font-weight: 700;
  line-height: 1.15;
  color: var(--text);
  word-break: break-word;
}
.dash-tile-main.is-text { font-size: 16px; }
.dash-tile-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: auto;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.tile-blue   .dash-tile-ic { background: #2563eb; }
.tile-green  .dash-tile-ic { background: #16a34a; }
.tile-purple .dash-tile-ic { background: #7c3aed; }
.tile-teal   .dash-tile-ic { background: #0d9488; }
.tile-orange .dash-tile-ic { background: #ea580c; }
.tile-red    .dash-tile-ic { background: #dc2626; }
.tile-slate  .dash-tile-ic { background: #64748b; }
