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

:root {
  --bg:          #f4f7f5;
  --surface:     #ffffff;
  --card:        #ffffff;
  --border:      #e2ebd8;
  --border-light:#cfdcc2;
  --primary:     #1f8f4c;
  --primary-dim: #e8f6ed;
  --gold:        #a37d10;
  --gold-dim:    #fcf7e6;
  --red:         #d32f2f;
  --blue:        #1976d2;
  --text:        #18281e;
  --text-muted:  #526c5b;
  --text-dim:    #8aa293;
  --shadow:      0 2px 12px rgba(24, 40, 30, 0.05);
  --radius:      12px;
  --radius-sm:   8px;
}

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

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  font-size: 14px;
}

/* ── Sidebar ── */
.sidebar {
  width: 260px;
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-logo {
  padding: 28px 24px 20px;
  border-bottom: 1px solid var(--border);
}

.logo-icon { font-size: 28px; margin-bottom: 6px; display: block; }

.logo-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: .3px;
  line-height: 1.2;
}

.logo-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.sidebar-nav {
  padding: 16px 12px;
  flex: 1;
  overflow-y: auto;
}

.nav-section {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 12px 12px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-muted);
  font-weight: 500;
  transition: all .18s;
  margin-bottom: 2px;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--primary-dim); color: var(--primary); }

.nav-icon { font-size: 16px; width: 20px; text-align: center; }

.nav-badge {
  margin-left: auto;
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 20px;
  padding: 1px 6px;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .6; }
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
}

/* ── Main content ── */
.main {
  margin-left: 260px;
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title { font-size: 18px; font-weight: 600; }
.topbar-sub   { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--primary);
  animation: pulse 2s infinite;
  display: inline-block;
  margin-right: 6px;
}

.content { padding: 28px; flex: 1; }

/* ── Cards / Stats ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color .2s;
}

.stat-card:hover { border-color: var(--border-light); }

.stat-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
}

.stat-value.green  { color: var(--primary); }
.stat-value.gold   { color: var(--gold); }
.stat-value.red    { color: var(--red); }
.stat-value.blue   { color: var(--blue); }

.stat-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ── Tables ── */
.table-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}

.table-title {
  font-size: 14px;
  font-weight: 600;
}

.table-filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-select, .filter-input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 6px 10px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}

.filter-select:focus, .filter-input:focus { border-color: var(--primary); }

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  padding: 10px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .6px;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 13px;
}

tr:last-child td { border-bottom: none; }

tbody tr { transition: background .12s; }
tbody tr:hover { background: rgba(24, 40, 30, .02); }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-green    { background: rgba(52,208,104,.15); color: var(--primary); }
.badge-gold     { background: rgba(200,168,75,.15);  color: var(--gold); }
.badge-red      { background: rgba(224,82,82,.15);   color: var(--red); }
.badge-blue     { background: rgba(91,156,246,.15);  color: var(--blue); }
.badge-muted    { background: rgba(90,128,104,.12);  color: var(--text-muted); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: all .15s;
}

.btn-primary   { background: var(--primary); color: #071209; }
.btn-primary:hover { filter: brightness(1.1); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover { border-color: var(--border-light); color: var(--text); }

.btn-danger { background: rgba(224,82,82,.15); color: var(--red); border: 1px solid rgba(224,82,82,.3); }
.btn-danger:hover { background: rgba(224,82,82,.25); }

.btn-sm { padding: 4px 10px; font-size: 11px; }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp .2s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-title { font-size: 16px; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
}
.modal-close:hover { color: var(--text); }

.modal-body { padding: 20px 24px; }
.modal-footer { padding: 0 24px 20px; display: flex; justify-content: flex-end; gap: 8px; }

/* Modal con header/footer fijos y body scrollable — para móvil y tablas anchas.
   Scoped: solo afecta modales que lleven la clase .modal--scroll. */
.modal.modal--scroll {
  display: flex;
  flex-direction: column;
  overflow: hidden;            /* el scroll lo maneja el body, no el modal entero */
  height: -webkit-fit-content; /* WebView Android: da altura definitiva al flex container */
  height: fit-content;         /* shrink to content — max-height de .modal lo techa */
}
.modal.modal--scroll .modal-header,
.modal.modal--scroll .modal-footer {
  flex: 0 0 auto;              /* fijos, siempre visibles */
}
.modal.modal--scroll .modal-body {
  flex: 1 1 auto;
  min-height: 0;              /* clave: permite encoger y scrollear dentro del flex */
  overflow-y: auto;
  overflow-x: auto;          /* contiene la tabla ancha → arregla "la línea" */
}

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 500; color: var(--text-muted); margin-bottom: 6px; }

.form-input, .form-select, .form-textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 12px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}

.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--primary); }

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

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Chat view ── */
.chat-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 400px;
  overflow-y: auto;
  padding: 4px;
}

.chat-msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13px;
  line-height: 1.5;
}

.chat-msg.user {
  background: var(--primary-dim);
  color: var(--primary);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.chat-msg.model {
  background: var(--surface);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}

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

/* ── Loading ── */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
  font-size: 13px;
}

/* ── Section header ── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.section-title { font-size: 20px; font-weight: 700; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ── Tabs ── */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Módulo: Reportes Diarios / Bitácoras ── */
.bitacora-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 20px;
}

.ref-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  min-width: 0;
}

.bitacora-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bitacora-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.bitacora-actividades {
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.image-upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s;
  background: var(--surface);
}

.image-upload-zone:hover,
.image-upload-zone.drag-over {
  border-color: var(--primary);
  background: rgba(31, 143, 76, 0.04);
  color: var(--text);
  transform: scale(1.01);
}

.preview-thumbnails {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.thumbnail-wrapper {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border-light);
}

.thumbnail-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumbnail-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  background: rgba(224, 82, 82, 0.9);
  color: white;
  border: none;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.bitacora-gallery {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.bitacora-img {
  width: 120px;
  height: 90px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: transform 0.2s;
}

.bitacora-img:hover {
  transform: scale(1.05);
}

/* ── Módulo: Producción ── */
.production-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.prod-summary-card {
  background: linear-gradient(135deg, rgba(52, 208, 104, 0.05), rgba(91, 156, 246, 0.02));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}

.prod-element-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  font-size: 13px;
}

/* ── Módulo: Materiales ── */
.inventory-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.inventory-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  text-align: center;
}

.inventory-qty {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  margin-top: 4px;
}

/* ── Menu Button & Overlay ── */
.menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 24px;
  cursor: pointer;
  padding: 8px;
  align-items: center;
  justify-content: center;
  outline: none;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(4, 8, 5, 0.6);
  backdrop-filter: blur(4px);
  z-index: 99;
}

.sidebar-overlay.open {
  display: block;
}

/* ── Dashboard Tables Grid ── */
.dashboard-tables-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 4px;
}

/* ── Responsive ── */
@media (max-width: 860px) {
  .menu-btn {
    display: inline-flex;
  }
  
  .sidebar {
    left: -260px;
    transition: left 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    width: 260px;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.7);
  }
  .sidebar.open {
    left: 0;
  }
  
  .main {
    margin-left: 0 !important;
  }

  .topbar {
    padding: 12px 16px;
  }
  
  .content {
    padding: 16px;
  }

  .dashboard-tables-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  /* Planilla de Asistencia responsiva con Grid Areas */
  .attendance-row {
    grid-template-columns: repeat(3, 1fr) 90px !important;
    grid-template-areas:
      "info info info info"
      "btn1 btn2 btn3 hours" !important;
    gap: 12px 6px !important;
    padding: 12px 14px !important;
  }
  .worker-info {
    grid-area: info !important;
  }
  .att-btn.att-presente {
    grid-area: btn1 !important;
  }
  .att-btn.att-ausente {
    grid-area: btn2 !important;
  }
  .att-btn.att-permiso {
    grid-area: btn3 !important;
  }
  .att-hours {
    grid-area: hours !important;
    justify-content: flex-end !important;
    width: auto !important;
  }
  .att-hours input {
    width: 50px !important;
    padding: 4px !important;
  }

  /* Tablas responsivas con scroll horizontal */
  .table-card {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .table-card table {
    min-width: 650px;
  }

  /* Formularios responsivos */
  .form-row {
    grid-template-columns: 1fr !important;
    gap: 8px;
  }
  .form-grid {
    grid-template-columns: 1fr !important;
    gap: 8px;
  }

  /* Escala y penalizaciones responsivas */
  .escala-container {
    grid-template-columns: 1fr !important;
    gap: 16px;
  }
  
  .blue-bar {
    padding: 12px 16px;
    gap: 10px;
  }
  .blue-bar .bono-rate {
    margin-left: 0;
    width: 100%;
    margin-top: 4px;
  }
  .topbar .btn {
    display: none !important;
  }

  /* Modales responsivos en móvil */
  .modal-overlay {
    padding: 10px;
    align-items: flex-start;
    padding-top: 40px;
  }
  .modal {
    max-width: 100%;
    max-height: 85vh;
    width: 100%;
    border-radius: 12px;
  }
  .modal-header {
    padding: 14px 16px;
    font-size: 1rem;
  }
  .modal-body {
    padding: 14px 16px;
  }
  .modal-footer {
    padding: 10px 16px;
  }
}

/* Frappe Gantt Customizations for MS Project Style */
.gantt-summary .bar {
  fill: #2c3e50 !important;
}
.gantt-summary .bar-progress {
  fill: #1a252f !important;
}
.gantt-summary .bar-label {
  fill: white !important;
  font-weight: bold;
}
.gantt-milestone .bar, .gantt-milestone .bar-progress {
  fill: #f39c12 !important;
  transform: rotate(45deg);
  transform-origin: center;
}
.gantt-milestone .bar-label {
  fill: #333 !important;
  font-weight: bold;
  transform: translateY(-10px);
}
.critical-path .bar, .critical-path .bar-progress {
  fill: #e74c3c !important;
}
.critical-path .bar-progress {
  fill: #c0392b !important;
}

/* Filas clickeables en tablas */
.clickable-row { cursor: pointer; transition: background 0.2s; -webkit-tap-highlight-color: rgba(52, 211, 153, 0.2); user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.clickable-row:hover, .clickable-row:active { background: rgba(0, 122, 255, 0.08); }

