/* =====================================================================
   Gemminis — estética cartográfica / survey
   Fraunces (display) · Hanken Grotesk (UI) · JetBrains Mono (datos)
   ===================================================================== */
:root {
  --paper:      #f1ece1;
  --surface:    #fbf8f1;
  --surface-2:  #f6f1e6;
  --ink:        #1b1a15;
  --ink-soft:   #5b5749;
  --ink-faint:  #8a8472;
  --line:       #d9d0bd;
  --line-soft:  #e6decd;
  --emerald:    #1a6049;
  --emerald-deep: #0f4636;
  --emerald-tint:#e4ece4;
  --orange:     #c5532a;
  --orange-tint:#f3e3d6;

  --font-display: "Fraunces", Georgia, serif;
  --font-ui: "Hanken Grotesk", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --radius: 14px;
  --shadow: 0 1px 2px rgba(27,26,21,.04), 0 8px 24px -12px rgba(27,26,21,.18);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  position: relative;
  overflow: hidden;
}
.hidden { display: none !important; }

/* Texturas de fondo ------------------------------------------------- */
.paper-grid {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(27,26,21,.035) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(27,26,21,.035) 1px, transparent 1px);
  background-size: 30px 30px;
  -webkit-mask-image: radial-gradient(ellipse 80% 70% at 50% 40%, #000 55%, transparent 100%);
          mask-image: radial-gradient(ellipse 80% 70% at 50% 40%, #000 55%, transparent 100%);
}
.grain {
  position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: .5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.045'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
}
.screen { position: relative; z-index: 1; min-height: 100vh; }

/* Tipografía base --------------------------------------------------- */
.display { font-family: var(--font-display); font-weight: 500; letter-spacing: -.02em; }
.eyebrow, .corner, .tenant-label, .brand, .user-name, .tool-tag, .chip,
.btn-ghost, .composer-note {
  font-family: var(--font-mono);
}

/* Botones ----------------------------------------------------------- */
.btn-primary {
  font-family: var(--font-mono); font-size: 13px; font-weight: 500; letter-spacing: .02em;
  background: var(--emerald); color: #f4efe4; border: 0; border-radius: 10px;
  padding: 12px 20px; cursor: pointer;
  transition: transform .15s ease, background .15s ease, box-shadow .15s ease;
  box-shadow: 0 6px 16px -8px rgba(26,96,73,.6);
}
.btn-primary:hover { background: var(--emerald-deep); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-ghost {
  font-size: 12px; letter-spacing: .03em; color: var(--ink-soft);
  background: transparent; border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 12px; cursor: pointer; transition: all .15s ease;
}
.btn-ghost:hover { border-color: var(--emerald); color: var(--emerald); background: var(--surface); }

/* Esquinas decorativas (login) -------------------------------------- */
.corner {
  position: fixed; z-index: 2; font-size: 10.5px; letter-spacing: .14em;
  color: var(--ink-faint); text-transform: uppercase;
}
.corner.tl { top: 22px; left: 26px; }
.corner.br { bottom: 22px; right: 26px; }

/* LOGIN ------------------------------------------------------------- */
.login-screen { display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 440px; text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px; padding: 44px 42px 40px;
  box-shadow: var(--shadow);
  position: relative;
}
.login-card > * { animation: rise .6s cubic-bezier(.2,.7,.2,1) both; }
.login-card .mark { animation-delay: .02s; }
.login-card .eyebrow { animation-delay: .08s; }
.login-card .display { animation-delay: .14s; }
.login-card .lede { animation-delay: .20s; }
.login-card .btn-primary { animation-delay: .26s; }
.mark { font-size: 26px; color: var(--emerald); margin-bottom: 18px; }
.eyebrow { font-size: 11px; letter-spacing: .22em; text-transform: uppercase; color: var(--orange); margin: 0 0 10px; }
.login-card .display { font-size: clamp(44px, 7vw, 60px); line-height: .95; margin: 0 0 18px; color: var(--ink); }
.lede { font-size: 15px; line-height: 1.6; color: var(--ink-soft); margin: 0 0 28px; max-width: 36ch; }
.login-error { font-family: var(--font-mono); font-size: 12px; color: var(--orange); margin-top: 14px; }
.request-access {
  display: inline-block; margin: 22px 0 14px; font-size: 14px; font-weight: 600;
  color: var(--emerald); text-decoration: none; letter-spacing: .01em;
  border-bottom: 1px solid var(--emerald); padding-bottom: 2px;
  transition: color .15s ease, border-color .15s ease, transform .15s ease;
}
.request-access:hover { color: var(--emerald-deep); border-color: var(--emerald-deep); transform: translateX(2px); }

/* CHAT shell -------------------------------------------------------- */
.chat-screen { display: flex; flex-direction: column; height: 100vh; }
.chat-header {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 14px 22px; border-bottom: 1px solid var(--line);
  background: rgba(251,248,241,.82); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: baseline; gap: 8px; font-size: 13px; }
.brand-mark { color: var(--emerald); font-size: 14px; }
.brand-name { font-weight: 700; letter-spacing: .18em; color: var(--ink); }
.brand-sub { color: var(--ink-faint); font-size: 11px; letter-spacing: .06em; }
.header-right { display: flex; align-items: center; gap: 12px; }
.user-name { font-size: 12px; color: var(--ink-soft); }
.tenant-select { display: flex; align-items: center; gap: 7px; }
.tenant-label { font-size: 10.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-faint); }
.tenant-select select {
  font-family: var(--font-mono); font-size: 12px; color: var(--emerald); font-weight: 500;
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px;
  background: var(--surface); cursor: pointer;
}
.tenant-select select:focus { outline: none; border-color: var(--emerald); }

/* Mensajes ---------------------------------------------------------- */
.messages {
  flex: 1; overflow-y: auto; padding: 32px 0 20px;
  display: flex; flex-direction: column; gap: 22px; scroll-behavior: smooth;
}
.msg {
  display: flex; gap: 13px; width: 100%; max-width: 800px; margin: 0 auto; padding: 0 26px;
  animation: rise .35s cubic-bezier(.2,.7,.2,1) both;
}
.msg-user { justify-content: flex-end; }
.msg-user .bubble {
  background: var(--emerald); color: #f3efe4; padding: 11px 16px;
  border-radius: 16px 16px 5px 16px; max-width: 78%; line-height: 1.5;
  box-shadow: 0 6px 18px -10px rgba(26,96,73,.55);
}
.msg-avatar {
  flex: 0 0 auto; width: 32px; height: 32px; border-radius: 9px;
  background: var(--emerald); color: #f3efe4; font-family: var(--font-display);
  font-size: 17px; display: flex; align-items: center; justify-content: center;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
}
.msg-col { display: flex; flex-direction: column; gap: 9px; min-width: 0; max-width: 78%; }
.msg-assistant .bubble {
  background: var(--surface); border: 1px solid var(--line);
  padding: 14px 17px; border-radius: 5px 16px 16px 16px; line-height: 1.62;
  box-shadow: var(--shadow); font-size: 15px;
}
.bubble :first-child { margin-top: 0; } .bubble :last-child { margin-bottom: 0; }
.bubble p { margin: 0 0 10px; }
.bubble ul, .bubble ol { margin: 8px 0; padding-left: 20px; }
.bubble li { margin: 4px 0; }
.bubble strong { color: var(--ink); font-weight: 700; }
.bubble a {
  color: var(--orange); text-decoration: underline; text-underline-offset: 3px;
  text-decoration-thickness: 1.5px; font-weight: 500;
}
.bubble a:hover { color: var(--emerald); }
.bubble code {
  font-family: var(--font-mono); font-size: 12.5px; background: var(--surface-2);
  border: 1px solid var(--line-soft); padding: 1px 5px; border-radius: 5px;
}
.bubble pre {
  background: #1f1d17; color: #efe9da; padding: 14px 16px; border-radius: 10px;
  overflow-x: auto; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.5;
}
.bubble pre code { background: none; border: 0; padding: 0; color: inherit; }
.bubble-error { border-color: var(--orange) !important; color: var(--orange); background: var(--orange-tint) !important; }

/* Indicador "pensando" --------------------------------------------- */
.thinking { display: flex; gap: 6px; padding: 8px 2px; }
.thinking span { width: 7px; height: 7px; border-radius: 50%; background: var(--emerald); animation: blink 1.3s infinite both; }
.thinking span:nth-child(2) { animation-delay: .22s; }
.thinking span:nth-child(3) { animation-delay: .44s; }

/* Etiqueta de tool en curso ---------------------------------------- */
.tool-tag {
  font-size: 11.5px; letter-spacing: .03em; color: var(--emerald);
  background: var(--emerald-tint); border: 1px solid #cfe0d2;
  padding: 5px 12px; border-radius: 999px; align-self: flex-start;
  display: inline-flex; align-items: center; gap: 7px;
}
.tool-tag::before { content: "●"; font-size: 8px; animation: blink 1s infinite; }

/* Chips de sugerencia (field tags) --------------------------------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 2px; }
.chip {
  font-size: 12px; letter-spacing: .01em; color: var(--ink-soft);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 7px 14px; cursor: pointer; text-align: left;
  transition: all .15s ease;
}
.chip:hover { border-color: var(--emerald); color: var(--emerald); transform: translateY(-1px); box-shadow: var(--shadow); }

/* Composer ---------------------------------------------------------- */
.composer { border-top: 1px solid var(--line); background: rgba(251,248,241,.82); backdrop-filter: blur(8px); padding: 14px 26px 10px; }
.chat-form { display: flex; gap: 10px; align-items: flex-end; max-width: 800px; margin: 0 auto; width: 100%; }
.chat-form textarea {
  flex: 1; resize: none; font-family: var(--font-ui); font-size: 15px; line-height: 1.5;
  color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 13px; padding: 12px 15px; max-height: 168px; transition: border-color .15s ease, box-shadow .15s ease;
}
.chat-form textarea::placeholder { color: var(--ink-faint); }
.chat-form textarea:focus { outline: none; border-color: var(--emerald); box-shadow: 0 0 0 3px rgba(26,96,73,.1); }
.btn-primary.send { padding: 0; width: 46px; height: 46px; border-radius: 12px; font-size: 19px; display: flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.composer-note { font-size: 10.5px; letter-spacing: .04em; color: var(--ink-faint); text-align: center; margin: 9px 0 0; }

/* Animaciones ------------------------------------------------------- */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }

/* Scrollbar --------------------------------------------------------- */
.messages::-webkit-scrollbar { width: 10px; }
.messages::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; border: 3px solid var(--paper); }

/* M6: avisos de sistema (hilo restaurado, reset de sesión) y reintento */
.msg-notice {
  align-self: center; text-align: center; font-size: 12px; color: var(--ink-soft, #888);
  padding: 4px 12px; margin: 6px 0; border: 1px dashed var(--line, #ddd); border-radius: 999px;
}
.chip-retry { margin-top: 6px; align-self: flex-start; }
