:root {
  --red: #c2161a;
  --red-soft: #fdecec;
  --bg: #f3f4f6;
  --border: #e5e7eb;
  --text: #1f2937;
  --muted: #9ca3af;
  --green: #16a34a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
button { cursor: pointer; font-family: inherit; }

/* ===== Login ===== */
.login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
  padding: 32px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-card h1 { color: var(--red); margin: 0; text-align: center; }
.login-sub { text-align: center; color: var(--muted); margin: 0 0 8px; }
.login-card input {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
}
.login-card button {
  background: var(--red);
  color: #fff;
  border: 0;
  padding: 12px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
}
.login-error { color: var(--red); font-size: 13px; text-align: center; min-height: 16px; }

/* ===== App shell ===== */
.app { max-width: 1200px; margin: 0 auto; background: #fff; min-height: 100vh; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 22px; }
.topbar-right { display: flex; align-items: center; gap: 14px; color: var(--muted); }
.link-btn { background: none; border: 0; color: var(--red); font-size: 14px; }
.me-company {
  background: var(--red-soft); color: var(--red);
  font-weight: 700; font-size: 12px;
  padding: 4px 10px; border-radius: 20px;
}

.tabs { display: flex; border-bottom: 1px solid var(--border); }
.tab {
  flex: 1;
  background: none;
  border: 0;
  padding: 16px;
  font-size: 15px;
  color: var(--muted);
  border-bottom: 3px solid transparent;
}
.tab.active { color: var(--red); font-weight: 600; border-bottom-color: var(--red); }

/* ===== Split layout ===== */
.split { display: flex; min-height: calc(100vh - 120px); }
.list-pane {
  width: 420px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.detail-pane { flex: 1; display: flex; flex-direction: column; }

.company-filter {
  padding: 14px 16px 0;
  font-size: 14px;
  color: #374151;
}
.company-filter label { display: flex; align-items: center; gap: 8px; }
.company-filter select {
  flex: 1;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
}
.company-chip {
  background: #eef2ff; color: #3730a3;
  font-weight: 700; font-size: 11px;
  padding: 4px 10px; border-radius: 20px;
}
.list-controls { display: flex; gap: 10px; padding: 16px; }
.list-controls input {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
}
.primary {
  background: var(--red);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 0 18px;
  font-weight: 600;
  white-space: nowrap;
}
.only-pending {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  color: #374151;
}

/* ===== Task list ===== */
.task-list { overflow-y: auto; flex: 1; }
.task-item {
  display: flex;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.task-item:hover { background: #fafafa; }
.task-item.active { background: var(--red-soft); }
.task-icon {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 15px;
}
.task-icon.completada { background: #dcfce7; }
.task-icon.pendiente, .task-icon.en_progreso { background: #fef3c7; }
.task-body { flex: 1; min-width: 0; }
.task-title { font-weight: 600; line-height: 1.3; }
.task-item.completada .task-title { color: var(--muted); }
.task-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ===== Detail ===== */
.detail-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  padding: 40px;
  text-align: center;
}
.detail { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.detail-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 24px 6px;
}
.detail-head h2 { margin: 0; font-size: 20px; flex: 1; }
.back-btn {
  background: none; border: 0; color: var(--red);
  font-size: 26px; line-height: 1; display: none;
}
.edit-btn {
  background: #fff; border: 1px solid var(--border);
  border-radius: 8px; width: 38px; height: 38px; color: var(--red); font-size: 16px;
}
.detail-meta { display: flex; align-items: center; gap: 10px; padding: 4px 24px; }
.tag {
  background: var(--red-soft);
  color: var(--red);
  font-weight: 700;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 20px;
  letter-spacing: 0.3px;
}
.status-select {
  border: 0;
  background: #fef3c7;
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 13px;
  color: #92400e;
  font-weight: 600;
}
.detail-created { padding: 6px 24px 16px; color: var(--muted); font-size: 13px; border-bottom: 1px solid var(--border); }

/* ===== Avances feed ===== */
.avances { flex: 1; overflow-y: auto; padding: 20px 24px; display: flex; flex-direction: column; gap: 14px; }
.avances-empty { color: var(--muted); text-align: center; margin: auto; }
.avance {
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}
.avance-meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; display: flex; justify-content: space-between; gap: 8px; }
.avance-author { font-weight: 600; color: #374151; }
.avance-text { white-space: pre-wrap; line-height: 1.4; }
.avance img { max-width: 100%; border-radius: 8px; margin-top: 8px; display: block; }

/* ===== Avance form ===== */
.avance-form {
  display: flex;
  gap: 10px;
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  align-items: center;
}
.photo-btn {
  width: 46px; height: 46px;
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; cursor: pointer; flex-shrink: 0;
}
.avance-form input[type="text"] {
  flex: 1;
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
}
.send-btn {
  background: var(--red);
  color: #fff;
  border: 0;
  width: 52px; height: 46px;
  border-radius: 10px;
  font-size: 20px;
  flex-shrink: 0;
}
.photo-preview { padding: 0 24px 12px; font-size: 13px; color: var(--green); }

/* ===== Bitácora ===== */
.bitacora-list { padding: 16px 24px; display: flex; flex-direction: column; gap: 10px; }
.bita-item {
  display: flex; gap: 12px;
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}
.bita-icon { font-size: 18px; }
.bita-body { flex: 1; }
.bita-title { font-weight: 600; }
.bita-detail { color: #4b5563; font-size: 14px; margin-top: 2px; }
.bita-time { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* ===== Admin panel ===== */
.admin-panel { padding: 20px 24px; display: flex; flex-direction: column; gap: 28px; }
.admin-section { max-width: 760px; }
.admin-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.admin-head h3 { margin: 0; }
.primary.small { padding: 8px 14px; font-size: 14px; border-radius: 8px; }
.admin-list { display: flex; flex-direction: column; gap: 8px; }
.admin-row {
  display: flex; align-items: center; gap: 12px;
  background: #f9fafb; border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px;
}
.admin-row .grow { flex: 1; min-width: 0; }
.admin-row .row-title { font-weight: 600; }
.admin-row .row-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.badge {
  font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 20px;
}
.badge.admin { background: #fef3c7; color: #92400e; }
.badge.client { background: #dcfce7; color: #166534; }
.icon-btn {
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  width: 34px; height: 34px; font-size: 14px;
}
.icon-btn.del { color: var(--red); border-color: #fecaca; }

/* ===== Modal ===== */
.modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 50;
}
.modal-card {
  background: #fff; border-radius: 14px; padding: 24px;
  width: 100%; max-width: 420px;
  display: flex; flex-direction: column; gap: 14px;
}
.modal-card h3 { margin: 0; }
.modal-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: #374151; }
.modal-card label input {
  padding: 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
.modal-actions { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.modal-actions .spacer { flex: 1; }
.danger { background: #fff; color: var(--red); border: 1px solid var(--red); border-radius: 8px; padding: 9px 14px; }
.modal-actions .primary { padding: 10px 18px; border-radius: 8px; }

/* ===== Responsive ===== */
@media (max-width: 760px) {
  .split { flex-direction: column; min-height: 0; }
  .list-pane { width: 100%; border-right: 0; }
  .detail-pane { display: none; }
  .app.show-detail .list-pane { display: none; }
  .app.show-detail .detail-pane { display: flex; }
  .back-btn { display: block !important; }
  .edit-btn { width: 34px; height: 34px; }
}
