/* ============================================================
   Asistent virtual — Colegiul Medicilor Iași (widget WordPress)
   Extras din web/index.html. Variabilele si box-sizing sunt SCOPATE
   la #chat-root, ca sa nu afecteze tema site-ului gazda.
   ============================================================ */

#chat-root {
  /* Primar — albastru institutional profund #00438A */
  --petrol-900: #002a57;
  --petrol-800: #003670;
  --petrol-700: #00438A;
  --petrol-600: #0b54a3;
  --petrol-500: #2a70c0;
  --petrol-100: #cdddf1;
  --petrol-050: #eaf2fb;

  /* Accent cald — teracota (CTA / actiuni) */
  --accent-600: #c2622f;
  --accent-500: #d97642;
  --accent-100: #f7e3d6;

  /* Neutre calde */
  --bg:        #f4f1ec;
  --surface:   #fbfaf7;
  --surface-2: #f0ece4;
  --line:      #e6ded1;

  /* Text */
  --ink-900: #1a2b30;
  --ink-700: #3c4a4f;
  --ink-500: #6b7679;
  --ink-300: #9aa3a5;

  /* Stare */
  --online: #2f9e6f;

  /* Forme */
  --r-lg: 22px;
  --r-md: 16px;
  --r-sm: 11px;
  --r-bubble: 18px;

  /* Umbre stratificate */
  --shadow-fab: 0 6px 16px rgba(0,40,87,.30), 0 2px 6px rgba(0,40,87,.20);
  --shadow-panel:
    0 1px 1px rgba(0,40,87,.05),
    0 8px 18px rgba(0,40,87,.12),
    0 28px 56px rgba(0,40,87,.20);
  --shadow-card: 0 1px 2px rgba(0,40,87,.07), 0 4px 10px rgba(0,40,87,.07);

  --ease: cubic-bezier(.22,.61,.36,1);

  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* box-sizing doar pentru elementele widget-ului (nu global pe site). */
#chat-root, #chat-root *, .fab-wrap, .fab-wrap *, .panel, .panel * { box-sizing: border-box; }

/* ============================================================
   FAB — buton flotant
   ============================================================ */
.fab-wrap {
  position: fixed;
  right: clamp(18px, 3vw, 30px);
  bottom: clamp(18px, 3vw, 30px);
  z-index: 9999;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}
.fab {
  position: relative;
  min-width: 64px; height: 64px;
  border-radius: 32px;
  border: none;
  background: var(--petrol-700);
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center;
  box-shadow: var(--shadow-fab);
  transition: transform .25s var(--ease), background .2s var(--ease), box-shadow .25s var(--ease);
}
.fab:hover { background: var(--petrol-600); transform: translateY(-2px); }
.fab:active { transform: translateY(0) scale(.98); }
.fab svg { width: 28px; height: 28px; transition: transform .35s var(--ease); }
.fab.is-open svg { transform: rotate(90deg) scale(.9); }

.fab-ico {
  flex: 0 0 64px;
  display: grid; place-items: center;
  height: 64px;
}

.fab-label {
  max-width: 0;
  opacity: 0;
  overflow: hidden;
  white-space: nowrap;
  font-size: 14.5px; font-weight: 600; letter-spacing: .1px;
  padding-left: 20px; padding-right: 2px;
  transition: max-width .4s var(--ease), opacity .25s var(--ease),
              padding .4s var(--ease);
}
.fab-wrap:hover .fab-label,
.fab:focus-visible .fab-label {
  max-width: 240px;
  opacity: 1;
}

.fab-pulse {
  position: absolute; inset: 0;
  width: 64px;
  border-radius: 50%;
  background: var(--petrol-700);
  opacity: .5;
  z-index: -1;
  animation: fab-pulse 2.8s var(--ease) infinite;
}
.fab-wrap:hover .fab-pulse { animation: none; opacity: 0; }
@keyframes fab-pulse {
  0%   { transform: scale(1);   opacity: .45; }
  70%  { transform: scale(1.7); opacity: 0; }
  100% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .fab-label { transition: opacity .2s linear; }
}

.fab-badge {
  position: absolute;
  top: -2px; right: -2px;
  min-width: 20px; height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--accent-500);
  color: #fff;
  font-size: 11.5px; font-weight: 700;
  display: grid; place-items: center;
  border: 2px solid var(--bg);
  box-shadow: 0 1px 3px rgba(0,0,0,.18);
}

/* ============================================================
   Panou de chat
   ============================================================ */
.panel {
  position: fixed;
  right: clamp(18px, 3vw, 30px);
  bottom: calc(clamp(18px, 3vw, 30px) + 64px + 16px);
  width: min(384px, calc(100vw - 36px));
  height: min(600px, calc(100vh - 130px));
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  transform-origin: bottom right;
  border: 1px solid rgba(0,40,87,.07);
  opacity: 1;
  transform: translateY(0) scale(1);
  transition: opacity .4s var(--ease), transform .42s var(--ease);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}
.panel.is-hidden {
  opacity: 0;
  transform: translateY(16px) scale(.92);
  pointer-events: none;
}

/* Header */
.panel-header {
  background:
    linear-gradient(150deg, var(--petrol-700) 0%, var(--petrol-800) 100%);
  color: #fff;
  padding: 16px 16px 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.ph-logo {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: rgba(255,255,255,.14);
  border: 1.5px solid rgba(255,255,255,.28);
  display: grid; place-items: center;
  font-weight: 700; font-size: 14px; letter-spacing: .03em;
  flex-shrink: 0;
}
.ph-meta { flex: 1; min-width: 0; line-height: 1.3; }
.ph-title { font-size: 15.5px; font-weight: 600; }
.ph-sub {
  font-size: 12px; color: rgba(255,255,255,.72);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ph-status {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; color: rgba(255,255,255,.85);
  margin-top: 3px;
}
.ph-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--online);
  box-shadow: 0 0 0 0 rgba(47,158,111,.6);
  animation: status-pulse 2.4s ease-out infinite;
}
@keyframes status-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(47,158,111,.55); }
  70%  { box-shadow: 0 0 0 6px rgba(47,158,111,0); }
  100% { box-shadow: 0 0 0 0 rgba(47,158,111,0); }
}
.ph-actions { display: flex; gap: 2px; flex-shrink: 0; }
.ph-btn {
  width: 34px; height: 34px;
  border: none; background: transparent;
  color: rgba(255,255,255,.85);
  border-radius: 9px;
  cursor: pointer;
  display: grid; place-items: center;
  transition: background .18s var(--ease), color .18s var(--ease);
}
.ph-btn:hover { background: rgba(255,255,255,.16); color: #fff; }
.ph-btn svg { width: 18px; height: 18px; }

/* Zona de mesaje */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  background:
    radial-gradient(100% 60% at 50% 0%, var(--petrol-050) 0%, transparent 70%),
    var(--surface);
}
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: rgba(0,40,87,.18); border-radius: 8px; }
.messages::-webkit-scrollbar-track { background: transparent; }

/* Rand mesaj */
.row { display: flex; flex-direction: column; max-width: 100%; animation: msg-in .34s var(--ease) both; }
.row.bot  { align-items: flex-start; }
.row.user { align-items: flex-end; }
@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.bubble {
  max-width: 84%;
  padding: 11px 14px;
  font-size: 14.5px;
  line-height: 1.5;
  position: relative;
  box-shadow: var(--shadow-card);
  word-wrap: break-word;
}
.bubble.bot {
  background: var(--surface-2);
  color: var(--ink-900);
  border-radius: var(--r-bubble) var(--r-bubble) var(--r-bubble) 5px;
}
.bubble.user {
  background: var(--petrol-700);
  color: #fff;
  border-radius: var(--r-bubble) var(--r-bubble) 5px var(--r-bubble);
}
.bubble b { font-weight: 600; }
.bubble .b-list { margin: 6px 0 0; padding-left: 18px; }
.bubble .b-list li { margin: 2px 0; }

.timestamp {
  font-size: 10.5px;
  color: var(--ink-300);
  margin: 4px 4px 0;
}
.row.user .timestamp { color: var(--ink-300); }

/* Surse */
.sources {
  display: flex; flex-direction: column; gap: 7px;
  margin-top: 9px; max-width: 84%;
}
.sources-label {
  font-size: 11px; font-weight: 600; letter-spacing: .04em;
  color: var(--ink-500); text-transform: uppercase;
  display: flex; align-items: center; gap: 5px;
}
.source-card {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 9px 11px;
  transition: border-color .18s var(--ease), transform .18s var(--ease), box-shadow .18s var(--ease);
}
.source-card:hover {
  border-color: var(--petrol-500);
  transform: translateX(2px);
  box-shadow: var(--shadow-card);
}
.source-ico {
  width: 30px; height: 30px; flex-shrink: 0;
  border-radius: 8px;
  background: var(--petrol-050);
  color: var(--petrol-600);
  display: grid; place-items: center;
}
.source-ico svg { width: 16px; height: 16px; }
.source-text { min-width: 0; line-height: 1.35; }
.source-title {
  font-size: 13px; font-weight: 600; color: var(--ink-900);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.source-dom { font-size: 11.5px; color: var(--ink-500); }
.source-rel {
  margin-left: auto; flex-shrink: 0;
  font-size: 11px; font-weight: 600; color: var(--petrol-600);
}

/* Quick-reply chips */
.chips {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 10px; max-width: 92%;
}
.chip {
  border: 1.5px solid var(--petrol-100);
  background: var(--surface);
  color: var(--petrol-700);
  font-size: 13px; font-weight: 500;
  font-family: inherit;
  padding: 8px 13px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .18s var(--ease), border-color .18s var(--ease), transform .12s var(--ease);
}
.chip:hover { background: var(--petrol-050); border-color: var(--petrol-500); }
.chip:active { transform: scale(.96); }
.chip:disabled { opacity: .45; cursor: default; }

/* Indicator „se scrie..." */
.typing {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--surface-2);
  border-radius: var(--r-bubble) var(--r-bubble) var(--r-bubble) 5px;
  padding: 14px 16px;
  box-shadow: var(--shadow-card);
}
.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ink-300);
  animation: typing-bounce 1.3s var(--ease) infinite;
}
.typing span:nth-child(2) { animation-delay: .18s; }
.typing span:nth-child(3) { animation-delay: .36s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* Card de fallback — secretariat */
.fallback {
  max-width: 92%;
  background: var(--accent-100);
  border: 1px solid #ecc9b3;
  border-radius: var(--r-md);
  padding: 14px;
  box-shadow: var(--shadow-card);
}
.fb-head { display: flex; align-items: center; gap: 9px; margin-bottom: 4px; }
.fb-ico {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent-500); color: #fff;
  display: grid; place-items: center; flex-shrink: 0;
}
.fb-ico svg { width: 17px; height: 17px; }
.fb-title { font-size: 14px; font-weight: 700; color: var(--accent-600); }
.fb-intro { font-size: 13.5px; line-height: 1.5; color: var(--ink-700); margin: 6px 0 12px; }
.fb-rows { display: flex; flex-direction: column; gap: 9px; margin-bottom: 13px; }
.fb-row { display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; color: var(--ink-900); }
.fb-row svg { width: 15px; height: 15px; color: var(--accent-600); margin-top: 2px; flex-shrink: 0; }
.fb-row .k { color: var(--ink-500); }
.fb-actions { display: flex; gap: 8px; }
.fb-btn {
  flex: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  text-decoration: none;
  font-size: 13.5px; font-weight: 600; font-family: inherit;
  padding: 9px 12px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .18s var(--ease), transform .12s var(--ease), border-color .18s;
}
.fb-btn svg { width: 15px; height: 15px; }
.fb-btn.primary { background: var(--accent-500); color: #fff; }
.fb-btn.primary:hover { background: var(--accent-600); }
.fb-btn.ghost { background: var(--surface); color: var(--accent-600); border-color: #ecc9b3; }
.fb-btn.ghost:hover { background: #fff; }
.fb-btn:active { transform: scale(.97); }

/* Zona de input */
.composer { flex-shrink: 0; border-top: 1px solid var(--line); background: var(--surface); padding: 12px 14px 10px; }
.composer-row {
  display: flex; align-items: flex-end; gap: 9px;
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 6px 6px 6px 14px;
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
.composer-row:focus-within {
  border-color: var(--petrol-500);
  box-shadow: 0 0 0 3px var(--petrol-050);
}
.composer textarea {
  flex: 1;
  border: none; outline: none; resize: none;
  background: transparent;
  font-family: inherit; font-size: 14.5px; color: var(--ink-900);
  line-height: 1.4; max-height: 96px;
  padding: 7px 0;
}
.composer textarea::placeholder { color: var(--ink-300); }
.send-btn {
  width: 40px; height: 40px; flex-shrink: 0;
  border: none; border-radius: 11px;
  background: var(--accent-500); color: #fff;
  cursor: pointer;
  display: grid; place-items: center;
  transition: background .18s var(--ease), transform .12s var(--ease), opacity .18s;
}
.send-btn:hover:not(:disabled) { background: var(--accent-600); }
.send-btn:active:not(:disabled) { transform: scale(.92); }
.send-btn:disabled { background: var(--surface-2); color: var(--ink-300); cursor: default; }
.send-btn svg { width: 19px; height: 19px; }

.composer-note {
  font-size: 11px; color: var(--ink-500);
  text-align: center; line-height: 1.4;
  margin: 9px 4px 2px;
}

/* Focus vizibil — scopat la widget (nu altereaza focus-ul site-ului gazda) */
#chat-root :focus-visible, .panel :focus-visible, .fab-wrap :focus-visible {
  outline: 2px solid var(--accent-500); outline-offset: 2px; border-radius: 4px;
}
.fab:focus-visible { outline-offset: 4px; }

/* Responsive — mobil full-screen */
@media (max-width: 480px) {
  .panel {
    right: 0; bottom: 0; top: 0; left: 0;
    width: 100%; height: 100%;
    max-height: 100%;
    border-radius: 0;
    border: none;
  }
  .panel.is-hidden { transform: translateY(24px); }
}

/* prefers-reduced-motion — scopat la widget */
@media (prefers-reduced-motion: reduce) {
  .panel, .panel *, .fab-wrap, .fab-wrap * {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  .panel.is-hidden, .panel { transition: none; }
}

/* tablete / ecrane medii */
@media (min-width: 481px) and (max-width: 640px) {
  .panel { height: min(640px, calc(100vh - 110px)); }
}

/* ecrane scunde (telefon in landscape) -> full-screen */
@media (max-height: 560px) {
  .panel { right: 0; left: 0; top: 0; bottom: 0; width: 100%; height: 100%; max-height: 100%; border-radius: 0; border: none; }
  .panel.is-hidden { transform: translateY(24px); }
  .composer-note { display: none; }
}

/* ecrane foarte mari (>=1600px) */
@media (min-width: 1600px) {
  .panel { width: 420px; height: min(680px, calc(100vh - 140px)); }
  .fab { width: 68px; height: 68px; }
}

/* randare raspuns (paragrafe + liste + linkuri) */
.bubble .b-p { margin: 0; }
.bubble .b-p + .b-p { margin-top: 8px; }
.bubble .b-p + .b-list, .bubble .b-list + .b-p { margin-top: 6px; }
.bubble a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.bubble.user a { color: #fff; }
