/* ─── Project View (two-column layout) ──────────────────────────────────── */
.project-view {
  display: none;
  gap: 20px;
  min-height: calc(100vh - 80px);
  min-height: calc(100dvh - 80px);
}
.project-view.visible {
  display: flex;
}

/* Toggle de sidebar (oculto en desktop, visible en móvil) */
.sidebar-toggle { display: none; }

.project-sidebar {
  width: 40%;
  min-width: 300px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

/* ─── Sidebar cards ─────────────────────────────────────────────────────── */
.sidebar-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}
.sidebar-card h3 {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
}
.sidebar-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 4px;
}
.sidebar-url {
  font-size: 0.8rem;
  color: var(--accent);
  text-decoration: none;
  word-break: break-all;
}
.sidebar-url:hover { text-decoration: underline; }

/* Score bars */
.score-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.score-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  width: 90px;
  flex-shrink: 0;
}
.score-bar {
  flex: 1;
  height: 8px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
}
.score-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
}
.score-value {
  font-size: 0.8rem;
  font-weight: 600;
  width: 32px;
  text-align: right;
  flex-shrink: 0;
}

/* Lock badges */
.lock-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.lock-badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 500;
}
.lock-badge-req { background: #22c55e18; color: var(--green); border: 1px solid #22c55e33; }
.lock-badge-forb { background: #ef444418; color: var(--red); border: 1px solid #ef444433; }

.btn-back {
  padding: 8px 16px;
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.15s;
  width: 100%;
}
.btn-back:hover { color: var(--text); border-color: var(--accent); }

/* ─── Chat header ───────────────────────────────────────────────────────── */
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
}
.mode-select {
  font-size: 0.8rem;
  padding: 4px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
}

/* ─── Messages area ─────────────────────────────────────────────────────── */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: calc(100vh - 280px);
  height: calc(100dvh - 280px);
}

.msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.88rem;
  line-height: 1.5;
  word-break: break-word;
}
.message-user {
  align-self: flex-end;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.06);
}
.message-assistant {
  align-self: flex-start;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.04);
}
.message-action-plan {
  align-self: flex-start;
  background: rgba(234,179,8,0.06);
  border: 1px solid rgba(234,179,8,0.2);
  border-left: 3px solid var(--yellow);
  max-width: 90%;
}
.message-action-result {
  align-self: flex-start;
  max-width: 90%;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
}
.message-action-result.success {
  background: rgba(34,197,94,0.06);
  border: 1px solid rgba(34,197,94,0.2);
  border-left: 3px solid var(--green);
}
.message-action-result.failed {
  background: rgba(239,68,68,0.06);
  border: 1px solid rgba(239,68,68,0.2);
  border-left: 3px solid var(--red);
}

.plan-type {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--yellow);
  margin-bottom: 6px;
}
.plan-files {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 6px 0;
}
.plan-impact {
  display: inline-block;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
  margin-bottom: 8px;
}
.impact-low { background: #22c55e22; color: var(--green); }
.impact-medium { background: #eab30822; color: var(--yellow); }
.impact-high { background: #ef444422; color: var(--red); }

.btn-apply {
  padding: 6px 14px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-apply:hover { opacity: 0.85; }
.btn-apply:disabled { opacity: 0.4; cursor: not-allowed; }

.msg-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--text-muted);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 6px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.running-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--yellow);
  padding: 8px 14px;
  background: rgba(234,179,8,0.06);
  border-radius: 8px;
  align-self: flex-start;
}

/* ─── Input composer ────────────────────────────────────────────────────── */
.chat-composer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.composer-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.chat-textarea {
  flex: 1;
  resize: none;
  min-height: 38px;
  max-height: 90px;
  padding: 8px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.88rem;
  font-family: inherit;
  line-height: 1.4;
  overflow-y: auto;
}
.chat-textarea:focus { border-color: var(--accent); outline: none; }

.btn-send, .btn-attach {
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: opacity 0.15s;
  flex-shrink: 0;
}
.btn-send { background: var(--accent); color: #fff; }
.btn-send:hover { opacity: 0.85; }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-attach { background: var(--surface2); color: var(--text-muted); border: 1px solid var(--border); }
.btn-attach:hover { color: var(--text); border-color: var(--accent); }

/* Attachment preview */
.attachment-preview {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 0.8rem;
}
.attachment-preview.visible { display: flex; }
.attachment-preview img {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  object-fit: cover;
}
.attachment-name { color: var(--text-muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-remove {
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 2px 4px;
}
.attachment-remove:hover { color: var(--red); }

/* Quick actions */
.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 16px 4px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.quick-action-btn {
  font-size: 0.75rem;
  padding: 4px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}
.quick-action-btn:hover { color: var(--accent); border-color: var(--accent); }

/* ─── Responsive (fases 1, 5, 6) ────────────────────────────────────────── */
@media (max-width: 768px) {
  .project-view.visible { flex-direction: column; }
  .project-sidebar { width: 100%; min-width: 0; }

  /* Sidebar colapsable: toggle visible y sidebar-content oculto por defecto */
  .sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 10px 14px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    min-height: 44px;
  }
  .sidebar-toggle-arrow { transition: transform 0.2s; }
  .project-sidebar.sidebar-open .sidebar-toggle-arrow { transform: rotate(180deg); }
  .project-sidebar > .sidebar-content { display: none; }
  .project-sidebar.sidebar-open > .sidebar-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  /* Chat ocupa lo que pueda sin calc() fijo: flex + altura mínima */
  .messages-area { flex: 1; min-height: 320px; height: auto; }

  /* Sidebar cards más compactos; score-label no bloquea */
  .sidebar-card { padding: 12px; }
  .score-label { width: auto; min-width: 60px; flex-shrink: 1; font-size: 0.78rem; }

  /* Composer: safe-area + tap targets 44px + fuente 16px (evita zoom iOS) */
  .chat-composer {
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  }
  .chat-textarea { min-height: 44px; font-size: 16px; }
  .btn-send, .btn-attach { min-height: 44px; padding: 10px 16px; }

  /* Quick-actions con tap targets más grandes */
  .quick-actions { gap: 8px; padding: 10px 14px 6px; }
  .quick-action-btn { padding: 8px 14px; font-size: 0.82rem; min-height: 36px; }

  /* Botones volver / eliminar */
  .btn-back { min-height: 44px; padding: 12px 16px; font-size: 0.9rem; }
}
