/* ============ LOGIN ============ */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0969da 0%, #033d8b 100%);
  padding: 20px;
}
.login-screen[hidden] { display: none; }
.login-card {
  background: #fff;
  padding: 36px 32px;
  border-radius: 12px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
}
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 24px; }
.login-brand .logo { font-size: 32px; }
.login-brand h1 { margin: 0; font-size: 22px; }
.login-submit { width: 100%; padding: 10px; margin-top: 8px; }
.login-error { margin: 12px 0 0; padding: 10px; background: #ffe5e5; color: #cf222e; border-radius: 6px; font-size: 13px; }
.login-hint { margin-top: 16px; font-size: 12px; color: #888; text-align: center; }
.login-hint code { background: #f6f8fa; padding: 1px 6px; border-radius: 3px; font-size: 11px; }
.current-user { font-size: 13px; color: #57606a; }

/* Reset minimal + tipografía */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  font-size: 14px;
  color: #1a1a1a;
  background: #f4f6f8;
}

/* ============ TOPBAR ============ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: #ffffff;
  border-bottom: 1px solid #e1e4e8;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand .logo { font-size: 22px; }
.brand strong { font-size: 16px; }
.env {
  font-size: 11px;
  background: #fff8c5;
  border: 1px solid #d4a72c;
  color: #7d4e00;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 8px;
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-select { padding: 4px 8px; border: 1px solid #d0d7de; border-radius: 6px; font-size: 13px; }
.api-status { font-size: 11px; color: #888; padding: 4px 8px; border-radius: 12px; }
.api-status.ok    { background: #dcffe4; color: #1a7f37; }
.api-status.error { background: #ffe5e5; color: #cf222e; }

/* ============ TABS ============ */
.tabs {
  display: flex;
  background: #ffffff;
  border-bottom: 1px solid #e1e4e8;
  padding: 0 20px;
}
.tab {
  background: none;
  border: none;
  padding: 12px 20px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: #57606a;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.tab:hover { color: #0969da; }
.tab.active { color: #0969da; border-bottom-color: #0969da; }

/* ============ MAIN / PANELES ============ */
.main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.panel.hidden { display: none; }
.panel-title { margin: 0; font-size: 16px; font-weight: 600; }

/* ============ TOOLBAR ============ */
.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.toolbar input[type="search"],
.toolbar select {
  padding: 8px 12px;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  font-size: 14px;
  min-width: 200px;
  background: #fff;
}
.toolbar input[type="search"]:focus,
.toolbar select:focus { outline: 2px solid #0969da; outline-offset: -1px; border-color: transparent; }

/* ============ BOTONES ============ */
.btn {
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn.primary { background: #0969da; color: white; border-color: #0969da; }
.btn.primary:hover { background: #0860c4; }
.btn.ghost { background: transparent; color: #57606a; border-color: #d0d7de; }
.btn.ghost:hover { background: #f6f8fa; }
.btn.danger { background: #cf222e; color: white; border-color: #cf222e; }
.btn.small { padding: 4px 10px; font-size: 12px; }

/* ============ LISTAS / CARDS ============ */
.list { display: flex; flex-direction: column; gap: 8px; }
.loading, .empty {
  padding: 30px;
  text-align: center;
  color: #57606a;
  background: #fff;
  border-radius: 8px;
  border: 1px dashed #d0d7de;
}
.card {
  background: #fff;
  border: 1px solid #e1e4e8;
  border-radius: 8px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.card:hover {
  border-color: #0969da;
  box-shadow: 0 1px 4px rgba(9, 105, 218, 0.15);
}
.card-codigo {
  font-weight: 700;
  color: #0969da;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  font-size: 13px;
  min-width: 90px;
}
.card-titular { font-weight: 500; flex: 1; }
.card-meta { color: #57606a; font-size: 12px; }

/* ============ ESTADO BADGES ============ */
.estado-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}
.estado-PARA_ESTUDIO              { background: #fff8c5; color: #7d4e00; }
.estado-ESTUDIOS_REALIZADOS       { background: #ddf4ff; color: #0969da; }
.estado-ESTUDIOS_ENVIADOS         { background: #c8e1ff; color: #0550ae; }
.estado-ESTUDIOS_RECEPCION_CONFIRMADA { background: #b6e3ff; color: #033d8b; }
.estado-STANDBY                   { background: #eaeef2; color: #57606a; }
.estado-DESCARTADA                { background: #ffe5e5; color: #cf222e; }
.estado-ACEPTADA_CON_AYUDA        { background: #dafbe1; color: #1a7f37; }
.estado-ACEPTADA_SIN_AYUDA        { background: #aceebb; color: #116329; }
.estado-OBRA_FINALIZADA           { background: #4ac26b; color: white; }

/* ============ MODAL ============ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 50px 20px;
  z-index: 100;
  overflow-y: auto;
}
.modal.hidden { display: none; }
.modal-content {
  background: #fff;
  border-radius: 8px;
  padding: 24px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}
.modal-content.wide { max-width: 720px; }
.modal-content h2 { margin: 0 0 16px 0; font-size: 18px; }
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ============ FORMS ============ */
form label {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  color: #57606a;
}
form input[type="text"],
form input[type="email"],
form input[type="password"],
form input[type="number"],
form input[type="search"],
form input:not([type]),
form select,
form textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 12px;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: #1a1a1a;
}
form input:focus, form select:focus, form textarea:focus {
  outline: 2px solid #0969da;
  outline-offset: -1px;
  border-color: transparent;
}
.checkbox {
  display: flex !important;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.checkbox input { width: auto; margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; margin-bottom: 12px; }

/* ============ DETALLE PROYECTO ============ */
.detalle-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  border-bottom: 1px solid #e1e4e8;
  padding-bottom: 12px;
}
.detalle-header h2 {
  margin: 0;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  color: #0969da;
  font-size: 22px;
}
.detalle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px 18px;
  margin-bottom: 16px;
}
.detalle-grid .field {
  font-size: 12px;
  color: #57606a;
}
.detalle-grid .field strong {
  display: block;
  font-weight: 500;
  font-size: 13px;
  color: #1a1a1a;
  margin-top: 2px;
}
.transiciones {
  background: #f6f8fa;
  padding: 12px;
  border-radius: 6px;
  margin-top: 12px;
}
.transiciones h3 { margin: 0 0 8px 0; font-size: 13px; color: #57606a; font-weight: 500; }
.transiciones-buttons { display: flex; gap: 6px; flex-wrap: wrap; }

/* ============ DETALLE: tabs internas ============ */
.detalle-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid #e1e4e8;
  margin: 0 0 16px 0;
}
.detalle-tab {
  background: none;
  border: none;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: #57606a;
  border-bottom: 2px solid transparent;
}
.detalle-tab:hover { color: #0969da; }
.detalle-tab.active { color: #0969da; border-bottom-color: #0969da; }
.detalle-tab .count {
  display: inline-block;
  background: #eaeef2;
  color: #57606a;
  border-radius: 10px;
  padding: 1px 7px;
  margin-left: 4px;
  font-size: 11px;
  font-weight: 600;
}
.detalle-tab.active .count { background: #ddf4ff; color: #0969da; }
.detalle-pane[hidden] { display: none; }

/* ============ TIMELINE comentarios ============ */
.comment-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.comment {
  background: #f6f8fa;
  border-left: 3px solid #d0d7de;
  border-radius: 4px;
  padding: 8px 12px;
}
.comment.tipo-llamada    { border-left-color: #0969da; }
.comment.tipo-email      { border-left-color: #6e40c9; }
.comment.tipo-whatsapp   { border-left-color: #1a7f37; }
.comment.tipo-visita     { border-left-color: #d4a72c; }
.comment.tipo-reunion    { border-left-color: #bf3989; }
.comment.tipo-sistema    { border-left-color: #57606a; background: #eaeef2; font-style: italic; }
.comment-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
  font-size: 12px;
}
.comment-author { font-weight: 600; color: #1a1a1a; }
.comment-tipo {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #57606a;
  margin-left: 6px;
}
.comment-fecha { color: #888; }
.comment-text { font-size: 14px; white-space: pre-wrap; }

.comment-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #fff;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  padding: 10px;
}
.comment-form textarea { width: 100%; min-height: 60px; resize: vertical; }
.comment-form-row { display: flex; gap: 8px; align-items: center; justify-content: space-between; }

/* ============ LISTA tareas ============ */
.task-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.task {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid #e1e4e8;
  border-radius: 6px;
}
.task.done { opacity: 0.55; }
.task.done .task-text { text-decoration: line-through; }
.task-checkbox { width: 18px; height: 18px; cursor: pointer; flex-shrink: 0; }
.task-text { flex: 1; font-size: 14px; }
.task-meta { font-size: 11px; color: #888; }
.task-prio-muy_alta { color: #cf222e; font-weight: 600; }
.task-prio-alta     { color: #d4a72c; font-weight: 500; }
.task-prio-media    { color: #57606a; }
.task-prio-baja     { color: #888; }
.task-delete {
  background: none;
  border: none;
  color: #888;
  cursor: pointer;
  padding: 0 4px;
  font-size: 16px;
}
.task-delete:hover { color: #cf222e; }

.task-form {
  display: flex;
  gap: 8px;
  align-items: stretch;
  background: #fff;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  padding: 8px;
}
.task-form input { flex: 1; }
.task-form select { min-width: auto; }

/* ============ HISTORIAL (eventos_log) ============ */
.event-list { display: flex; flex-direction: column; gap: 4px; }
.event {
  display: flex;
  gap: 12px;
  padding: 8px 10px;
  font-size: 13px;
  border-bottom: 1px solid #f0f3f6;
}
.event:last-child { border-bottom: none; }
.event-fecha { color: #888; min-width: 130px; font-size: 12px; }
.event-tipo { font-weight: 600; min-width: 110px; }
.event-detalle { flex: 1; color: #57606a; font-size: 12px; }
.event-actor { color: #57606a; font-size: 12px; }

/* ============ TAB BADGE (en topbar de tabs) ============ */
.tab-badge {
  display: inline-block;
  background: #cf222e;
  color: white;
  border-radius: 10px;
  padding: 1px 7px;
  margin-left: 4px;
  font-size: 11px;
  font-weight: 600;
  vertical-align: top;
  line-height: 16px;
}
.tab-badge[hidden] { display: none; }

/* ============ TOGGLE Lista / Kanban ============ */
.view-toggle {
  display: inline-flex;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
  margin-left: auto;
}
.view-btn {
  background: #fff;
  border: none;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 16px;
  color: #57606a;
}
.view-btn:hover { background: #f6f8fa; }
.view-btn.active { background: #0969da; color: white; }

/* ============ KANBAN ============ */
.kanban {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 12px;
  /* permitir scroll horizontal si hay muchas columnas */
}
.kanban[hidden] { display: none; }
.kanban-col {
  flex: 0 0 270px;
  background: #f0f3f6;
  border-radius: 8px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 200px);
}
.kanban-col-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  padding: 4px 6px;
}
.kanban-col-head h3 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #57606a;
}
.kanban-col-count {
  font-size: 11px;
  color: #888;
  background: #fff;
  padding: 1px 7px;
  border-radius: 10px;
  font-weight: 500;
}
.kanban-col-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  flex: 1;
  min-height: 60px;
}
.kanban-col.drag-over {
  background: #ddf4ff;
  outline: 2px dashed #0969da;
  outline-offset: -4px;
}
.kanban-card {
  background: #fff;
  border-radius: 6px;
  padding: 8px 10px;
  border: 1px solid #e1e4e8;
  cursor: grab;
  transition: box-shadow 0.15s, transform 0.05s;
  font-size: 13px;
}
.kanban-card:hover { box-shadow: 0 2px 6px rgba(0,0,0,0.08); }
.kanban-card.dragging { opacity: 0.45; transform: rotate(1.5deg); cursor: grabbing; }
.kanban-card .codigo { font-family: 'SF Mono', Monaco, Consolas, monospace; color: #0969da; font-weight: 600; font-size: 11px; }
.kanban-card .titular { font-weight: 500; margin: 4px 0 2px; line-height: 1.25; }
.kanban-card .meta { color: #57606a; font-size: 11px; }
.kanban-card .tags { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.kanban-card .activity-badge { font-size: 10px; padding: 1px 5px; }

/* ============ MIS TAREAS ============ */
.mt-group { margin-bottom: 18px; }
.mt-group-head {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #57606a;
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid #e1e4e8;
}
.mt-group-head a { color: #0969da; text-decoration: none; }
.mt-group-head a:hover { text-decoration: underline; }
.mt-task {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid #e1e4e8;
  border-radius: 6px;
  margin-bottom: 4px;
}
.mt-task.done { opacity: 0.55; }
.mt-task.done .mt-task-text { text-decoration: line-through; }
.mt-task.overdue {
  border-left: 3px solid #cf222e;
}
.mt-task.due-soon {
  border-left: 3px solid #d4a72c;
}
.mt-task-text { flex: 1; font-size: 14px; }
.mt-task-meta { font-size: 11px; color: #57606a; }
.mt-task-meta.overdue { color: #cf222e; font-weight: 500; }

/* ============ Badges en tarjeta lista ============ */
.activity-badges { display: flex; gap: 6px; }
.activity-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 11px;
  background: #f6f8fa;
  color: #57606a;
}
.activity-badge.has-tareas { background: #fff8c5; color: #7d4e00; font-weight: 500; }
.activity-badge.has-comentarios { background: #ddf4ff; color: #0969da; }

/* ============ RESPONSIVE ============ */
@media (max-width: 600px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar input[type="search"], .toolbar select { min-width: 0; }
  .card { flex-wrap: wrap; }
  .modal { padding: 10px; }
}
