/* ==========================================================================
   AGENTES REMOTOS // herramienta de Cortex
   Mismo lenguaje visual que el dashboard: negro, verde fosforo, monoespaciado.
   ========================================================================== */

:root {
  --bg: #030604;
  --panel: rgba(7, 16, 10, 0.92);
  --panel-2: #0a140d;
  --border: rgba(57, 255, 136, 0.22);
  --border-strong: rgba(57, 255, 136, 0.5);
  --text: #d9ffe8;
  --muted: #74a389;
  --accent: #39ff88;
  --accent-2: #18a859;
  --danger: #ff4d5e;
  --ok: #39ff88;
  --radius: 2px;
  --font: "JetBrains Mono", "Cascadia Code", "SFMono-Regular", Consolas,
    "Liberation Mono", monospace;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

/* El canvas del navegador tambien pinta: sin esto, en la PWA de iOS la
   franja del home indicator (safe-area inferior) se ve negra. */
html {
  background-color: var(--bg);
}

body {
  margin: 0;
  min-height: 100dvh;
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 15% -10%, rgba(57, 255, 136, 0.1), transparent 42%),
    radial-gradient(circle at 100% 10%, rgba(57, 255, 136, 0.05), transparent 38%),
    linear-gradient(rgba(57, 255, 136, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(57, 255, 136, 0.035) 1px, transparent 1px);
  background-size: auto, auto, 44px 44px, 44px 44px;
  background-repeat: no-repeat, no-repeat, repeat, repeat;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.16) 0,
    rgba(0, 0, 0, 0.16) 1px,
    transparent 1px,
    transparent 3px
  );
  opacity: 0.3;
  mix-blend-mode: multiply;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 11px;
}

/* ---------------------------- Login ---------------------------- */

.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
  z-index: 1;
}

.card {
  background: linear-gradient(180deg, rgba(8, 20, 12, 0.96), rgba(3, 8, 5, 0.98));
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 0 28px rgba(57, 255, 136, 0.12);
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 28px;
  position: relative;
}

.login-card::before,
.login-card::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid var(--accent);
}

.login-card::before {
  top: -2px;
  left: -2px;
  border-right: 0;
  border-bottom: 0;
}

.login-card::after {
  right: -2px;
  bottom: -2px;
  border-left: 0;
  border-top: 0;
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 24px;
  letter-spacing: 0.12em;
  color: var(--accent);
  text-shadow: 0 0 16px rgba(57, 255, 136, 0.45);
}

.login-card p {
  margin: 0 0 20px;
}

form {
  display: grid;
  gap: 6px;
}

label {
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-top: 10px;
}

input,
textarea,
select,
button {
  font: inherit;
  color: inherit;
}

input,
textarea,
select {
  width: 100%;
  background: #020503;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--green-bright, var(--text));
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(57, 255, 136, 0.16),
    inset 0 0 10px rgba(57, 255, 136, 0.06);
}

button {
  cursor: pointer;
  border: 1px solid var(--accent);
  background: rgba(57, 255, 136, 0.12);
  color: var(--accent);
  border-radius: var(--radius);
  padding: 11px 16px;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

button:hover:not(:disabled) {
  background: var(--accent);
  color: #021006;
  box-shadow: 0 0 20px rgba(57, 255, 136, 0.3);
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#login-button {
  margin-top: 18px;
}

button.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
  font-weight: 600;
  padding: 8px 12px;
}

button.ghost:hover:not(:disabled) {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(57, 255, 136, 0.08);
  box-shadow: none;
}

button.icon-button {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 16px;
  line-height: 1;
}

.error {
  margin: 8px 0 0;
  min-height: 20px;
  color: var(--danger);
  font-size: 12px;
}

/* --------------------------- App shell -------------------------- */

.app-shell {
  height: 100vh;
  height: 100dvh;
  max-width: 1100px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right))
    calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
  position: relative;
  z-index: 1;
}

/* En el chat no se muestra el banner: solo en el dashboard. */
.app-shell.chat-mode {
  grid-template-rows: 1fr;
}

.app-shell.chat-mode .topbar {
  display: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: linear-gradient(180deg, rgba(8, 18, 11, 0.92), rgba(4, 9, 6, 0.94));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  backdrop-filter: blur(6px);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.cortex-home {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-decoration: none;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.cortex-home:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(57, 255, 136, 0.08);
}

#deepseek-balance {
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

#notify-button.active {
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 14px rgba(57, 255, 136, 0.2);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 0;
  background: var(--muted);
  box-shadow: 0 0 0 3px rgba(116, 163, 137, 0.12);
}

.dot.ok {
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(57, 255, 136, 0.16), 0 0 10px rgba(57, 255, 136, 0.5);
}

.dot.bad {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(255, 77, 94, 0.16), 0 0 10px rgba(255, 77, 94, 0.5);
}

/* --------------------------- Proyectos -------------------------- */

.projects-view {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
}

.projects-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.projects-head h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  text-shadow: 0 0 14px rgba(57, 255, 136, 0.3);
}

.projects-head p {
  margin: 2px 0 0;
}

#project-search {
  width: 240px;
  max-width: 100%;
}

.projects-list {
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 2px 2px 12px;
}

.projects-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.projects-section-title {
  margin: 0;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
  align-content: start;
}

.project-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 120px;
  padding: 14px;
  text-align: left;
  font-weight: 500;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(57, 255, 136, 0.05), transparent 55%),
    rgba(2, 7, 4, 0.72);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
}

.project-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 22px rgba(57, 255, 136, 0.18);
  transform: translateY(-1px);
}

.project-card:active {
  transform: none;
}

.project-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.fav-toggle {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: 17px;
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0;
}

.fav-toggle:hover:not(:disabled) {
  color: #ffcf5c;
  background: rgba(255, 207, 92, 0.08);
  box-shadow: none;
}

.fav-toggle.active {
  color: #ffcf5c;
}

.project-top {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding-right: 28px;
}

.project-avatar {
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(57, 255, 136, 0.08);
  color: var(--accent);
  font-weight: 700;
  font-size: 13px;
  text-shadow: 0 0 10px rgba(57, 255, 136, 0.5);
}

.project-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-meta {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 11px;
  color: var(--muted);
}

.project-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ok);
}

.project-badge .ping {
  width: 7px;
  height: 7px;
  border-radius: 0;
  background: var(--ok);
  box-shadow: 0 0 8px rgba(57, 255, 136, 0.7);
  animation: pulse 1.2s infinite ease-in-out;
}

.projects-empty {
  grid-column: 1 / -1;
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
}

/* ----------------------------- Chat ----------------------------- */

.chat-view {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: linear-gradient(180deg, rgba(8, 18, 11, 0.92), rgba(4, 9, 6, 0.94));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
}

.chat-title {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1 1 160px;
}

.chat-title strong {
  color: var(--accent);
  letter-spacing: 0.04em;
}

.chat-title strong,
.chat-title span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.chat-actions select {
  width: auto;
  max-width: 240px;
  padding: 7px 10px;
  font-size: 12px;
}

#agent-select {
  max-width: 140px;
  font-weight: 700;
  color: var(--accent);
}

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 8px 2px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.empty {
  margin: auto;
  max-width: 440px;
  text-align: center;
  color: var(--muted);
  padding: 32px 16px;
}

.row {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  gap: 4px;
}

.row.user {
  align-self: flex-end;
  align-items: flex-end;
}

.row.assistant {
  align-self: flex-start;
}

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.row.user .bubble {
  background: linear-gradient(180deg, rgba(27, 74, 44, 0.85), rgba(10, 35, 20, 0.9));
  border-color: rgba(57, 255, 136, 0.4);
}

.row.assistant .bubble {
  background: rgba(4, 10, 6, 0.9);
}

.role {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  padding: 0 4px;
}

.tools {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}

.tool {
  font-size: 11px;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 5px 9px;
  overflow-wrap: anywhere;
}

.tool b {
  color: var(--text);
  font-weight: 600;
}

.working {
  align-self: flex-start;
  color: var(--accent);
  font-size: 11px;
  letter-spacing: 0.08em;
  padding: 6px 12px;
  border-radius: var(--radius);
  background: rgba(57, 255, 136, 0.06);
  border: 1px solid var(--border);
}

.working::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 8px;
  border-radius: 0;
  background: var(--accent);
  animation: pulse 1s infinite ease-in-out;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.25;
    transform: scale(0.8);
  }
  50% {
    opacity: 1;
    transform: scale(1.15);
  }
}

/* --------------------------- Composer --------------------------- */

.composer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: linear-gradient(180deg, rgba(8, 18, 11, 0.92), rgba(4, 9, 6, 0.94));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
}

.composer-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.composer textarea {
  resize: none;
  max-height: 220px;
  min-height: 46px;
  border: none;
  background: transparent;
  padding: 8px;
  color: var(--text);
}

.composer textarea:focus {
  box-shadow: none;
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

#attach-button {
  width: 44px;
  height: 44px;
  font-size: 17px;
}

#send-button {
  height: 44px;
  min-width: 92px;
}

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

.attachment-thumb {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--panel-2);
}

.attachment-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.attachment-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.75);
  color: var(--danger);
  font-size: 12px;
  line-height: 1;
  letter-spacing: 0;
}

.attachment-remove:hover:not(:disabled) {
  background: var(--danger);
  color: #120306;
  box-shadow: none;
}

/* --------------------------- Responsive -------------------------- */

@media (max-width: 640px) {
  .app-shell {
    padding: calc(10px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right))
      calc(10px + env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left));
    gap: 8px;
  }

  .row {
    max-width: 96%;
  }

  .chat-actions {
    gap: 6px;
  }

  .chat-actions select {
    max-width: 150px;
  }

  #agent-select {
    max-width: 100px;
  }

  .projects-grid {
    grid-template-columns: 1fr;
    gap: 9px;
  }

  .project-card {
    min-height: 96px;
    padding: 12px;
  }

  #project-search {
    width: 100%;
  }

  /* Evita el zoom automatico de iOS al enfocar un campo */
  input,
  textarea,
  select {
    font-size: 16px;
  }
}

@media (display-mode: standalone) {
  body {
    user-select: none;
  }

  input,
  textarea,
  select,
  .bubble {
    user-select: text;
  }
}

@media (prefers-reduced-motion: reduce) {
  .project-badge .ping,
  .working::after {
    animation: none;
  }
}
