:root {
  --bg: #12151a;
  --panel: #1a1f26;
  --panel-2: #222834;
  --border: #2b323d;
  --sidebar: #0e1116;
  --sidebar-hi: #1c222b;
  --text: #e5e8ee;
  --muted: #8f9aa8;
  --accent: #d98b76;
  --accent-deep: #b0654f;
  --accent-soft: rgba(217, 139, 118, .16);
  --parella: #7fb3ff;
  --parella-bg: #1e2c42;
  --coach: #e3b45e;
  --coach-bg: #362a12;
  --danger: #e2837a;
  --radius: 14px;
  font-size: 16px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: "Segoe UI", system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); line-height: 1.65; }
.hidden { display: none !important; }
button { cursor: pointer; font: inherit; }
input, select, textarea { font: inherit; color: var(--text); }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background: radial-gradient(1100px 600px at 20% -10%, #1e2230 0%, var(--bg) 55%),
              radial-gradient(900px 500px at 110% 110%, #2a2026 0%, transparent 60%); }
.auth-card { background: var(--panel); border: 1px solid var(--border); border-radius: 20px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, .5); padding: 36px 40px; width: 100%; max-width: 560px; }
.auth-brand { text-align: center; margin-bottom: 20px; }
.logo img { width: 64px; height: 64px; display: inline-block; }
.logo.small { display: inline-flex; align-items: center; }
.logo.small img { width: 26px; height: 26px; }
.linklike i { width: 1.3em; text-align: center; color: #fff; }
.linklike.danger i, .chat-head .linklike i { color: inherit; }
.auth-brand h1 { margin: 6px 0 2px; font-size: 26px; }
.tagline { color: var(--muted); margin: 0; }
.auth-card h2 { font-size: 19px; margin: 18px 0 10px; }
.auth-card label { display: block; margin: 10px 0; font-size: 14px; color: var(--muted); }
.auth-card input { display: block; width: 100%; margin-top: 4px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--panel-2); }
.auth-card input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.reg-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.reg-cols fieldset { border: 1px solid var(--border); border-radius: 12px; padding: 4px 14px 12px; }
.reg-cols legend { font-size: 13px; color: var(--accent); font-weight: 600; padding: 0 6px; }
.btn { border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  border-radius: 10px; padding: 10px 18px; }
.btn:hover { background: #2a3532; }
.btn.primary { background: #c26a52; border-color: #c26a52; color: #fff; }
.btn.primary:hover { background: #a85643; border-color: #a85643; }
#loginForm .btn.primary, #registerForm .btn.primary, #forgotForm .btn.primary, #resetForm .btn.primary { width: 100%; margin-top: 12px; }
.switch { text-align: center; font-size: 14px; color: var(--muted); }
.switch a { color: var(--accent); }
.msg { text-align: center; min-height: 1.2em; font-size: 14px; color: var(--danger); }
.msg.ok { color: var(--accent); }
.hint { font-size: 13px; color: var(--muted); }
.privacy-note { font-size: 12.5px; color: var(--muted); text-align: center; border-top: 1px solid var(--border); padding-top: 14px; }

/* ---------- layout ---------- */
.app { display: flex; height: 100vh; }
.sidebar { width: 280px; min-width: 280px; background: var(--sidebar); color: #cfd9d5;
  display: flex; flex-direction: column; border-right: 1px solid #191e25; }
.sb-head { display: flex; align-items: center; gap: 10px; padding: 18px 18px 10px; font-weight: 600;
  color: inherit; text-decoration: none; }
.sb-title { color: #e8eeeb; }
.new-topic { margin: 10px 14px; background: var(--sidebar-hi); color: #fff; border: 1px solid #2b323d; text-align: left; }
.new-topic:hover { background: #263431; }
.topic-list { flex: 1; overflow-y: auto; padding: 6px 8px; }
.topic-item { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 10px; cursor: pointer;
  font-size: 14.5px; color: #b9c6c1; margin-bottom: 2px; }
.topic-item:hover { background: var(--sidebar-hi); }
.topic-item.active { background: var(--sidebar-hi); color: #fff; }
.topic-item .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 9px; height: 9px; min-width: 9px; border-radius: 50%; display: inline-block; }
.dot.normal { background: #d98b76; }
.dot.mediacio { background: #e0b352; }
.dot.simulacio { background: #7fb3ff; }
.sb-foot { padding: 12px 16px; border-top: 1px solid #1c222b; font-size: 14px; }
.sb-foot .linklike { display: inline-block; padding: 8px 0; }
.sb-tools-toggle { display: block; width: 100%; text-align: left; font-weight: 600; color: #e5e8ee; }
.sb-tools-toggle i { transition: transform .15s; }
.sb-tools { padding-left: 6px; }
.userbox { display: flex; justify-content: space-between; margin-top: 8px; color: #8da09a; }
.linklike { background: none; border: none; color: #b9c6c1; padding: 4px 0; }
.linklike:hover { color: #fff; }
.linklike.danger:hover { color: var(--danger); }
.sb-del { font-size: 11.5px; color: #6b7683; margin-top: 6px; }
.sb-del:hover { color: var(--danger); }
.danger-btn { background: #7a2f26; border-color: #7a2f26; color: #fff; }
.danger-btn:hover { background: #93392e; }

/* selector d'idioma compacte */
.lang-mini { display: flex; gap: 4px; justify-content: flex-end; }
.lang-mini button { background: none; border: 1px solid transparent; color: var(--muted);
  border-radius: 8px; padding: 3px 8px; font-size: 12.5px; font-weight: 600; cursor: pointer; }
.lang-mini button.active { border-color: var(--border); background: var(--panel-2); color: var(--text); }
.sb-tools .lang-mini, .sb-foot .lang-mini { justify-content: flex-start; margin: 6px 0; }

/* bloc de parella (vinculació) */
.couple-box { display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin-bottom: 8px;
  border-radius: 8px; background: var(--sidebar-hi); border: 1px solid #262d37; }
.couple-box img { width: 26px; height: 26px; }
.couple-box b { display: block; font-size: 13.5px; color: #e5e8ee; line-height: 1.25; }
.couple-box small { display: block; font-size: 11.5px; color: var(--muted); }
.welcome-couple { color: var(--muted); font-size: 14.5px; background: var(--panel);
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 10px; padding: 10px 14px; }

/* indicador de saldo */
.saldo { padding: 6px 10px; margin-bottom: 8px; border-radius: 8px; font-size: 13.5px;
  background: var(--sidebar-hi); color: #b9c1cc; border: 1px solid #262d37; }
.saldo.inf { color: var(--accent); border-color: rgba(217, 139, 118, .35); }
.saldo.inf b { font-size: 15px; margin-right: 4px; }
.saldo.low { color: var(--danger); border-color: rgba(226, 131, 122, .4); }
.saldo-add { font-size: 12px; color: var(--accent) !important; padding: 0 0 0 4px; }
.badge-promo { display: inline-block; font-size: 11.5px; font-weight: 700; letter-spacing: .02em;
  background: var(--accent-soft); color: var(--accent); border: 1px solid rgba(217, 139, 118, .45);
  border-radius: 20px; padding: 3px 10px; margin-left: 8px; vertical-align: middle; white-space: nowrap; }
.rc-presets { display: flex; gap: 8px; margin: 12px 0 4px; }
.rc-presets .btn { flex: 1; padding: 8px 0; text-align: center; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.welcome { max-width: 760px; margin: 8vh auto; padding: 0 28px; }
.welcome h2 { font-size: 28px; }
.mode-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-top: 18px; }
.mode-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; font-size: 14px; }
.mode-card b { display: inline-block; margin-left: 6px; }
.mode-card p { color: var(--muted); margin: 8px 0 0; }

/* ---------- chat ---------- */
.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 14px 24px; background: var(--panel);
  border-bottom: 1px solid var(--border); font-weight: 600; }
.chat-head #chatTitle { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head .linklike { color: var(--muted); }
.chat-head .linklike:hover { color: var(--danger); }
.mode-badge { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 20px;
  background: var(--accent-soft); color: var(--accent); }
.mode-badge.simulacio { background: var(--parella-bg); color: var(--parella); }
.mode-badge.mediacio { background: var(--coach-bg); color: var(--coach); }

.messages { flex: 1; overflow-y: auto; padding: 26px 0; }
.mrow { max-width: 780px; margin: 0 auto 18px; padding: 0 24px; display: flex; }
.bubble { padding: 12px 16px; border-radius: var(--radius); line-height: 1.7; font-size: 15.5px;
  white-space: normal; overflow-wrap: break-word; max-width: 88%; }
.mrow.user { justify-content: flex-end; }
.mrow.user .bubble { background: var(--accent-deep); color: #fff; border-bottom-right-radius: 4px; }
.mrow.assistant .bubble { background: var(--panel); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble p { margin: 0 0 12px; } .bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 6px 0; padding-left: 22px; }
.bubble h1, .bubble h2, .bubble h3 { font-size: 1.05em; margin: 12px 0 6px; }
.bubble code { background: var(--panel-2); border-radius: 4px; padding: 1px 5px; font-size: .9em; }

/* simulació: veu de la parella i coach */
.seg-parella { background: var(--parella-bg); border-left: 4px solid var(--parella); color: #cfe0f8;
  padding: 10px 14px; border-radius: 8px; margin: 10px 0; }
.seg-parella .seg-label { display: block; font-size: 11.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--parella); margin-bottom: 4px; }
.seg-coach { background: var(--coach-bg); border-left: 4px solid var(--coach); color: #ecd9ae;
  padding: 10px 14px; border-radius: 8px; margin: 10px 0; font-size: 14.5px; }
.seg-coach .seg-label { display: block; font-size: 11.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--coach); margin-bottom: 4px; }

.typing { color: var(--muted); font-style: italic; }

/* sessió conjunta */
.mode-badge.conjunta { background: rgba(217, 139, 118, .16); color: var(--accent); }
.joint-intro { max-width: 780px; margin: 0 auto 18px; padding: 0 24px; color: var(--muted); font-size: 13.5px; text-align: center; }
.mrow.partner { justify-content: flex-start; }
.mrow.partner .bubble { background: #1e2c42; border: 1px solid #2c4258; border-bottom-left-radius: 4px; }
.autor-label { display: block; font-size: 11.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: #7db6d9; margin-bottom: 4px; }

/* botó comparteix (apareix en passar el ratolí per la bombolla) */
.bubble { position: relative; }
.share-btn { position: absolute; top: -10px; right: -8px; border: 1px solid var(--border);
  background: var(--panel-2); border-radius: 50%; width: 28px; height: 28px; font-size: 13px;
  line-height: 1; opacity: 0; transition: opacity .15s; padding: 0; }
.bubble:hover .share-btn { opacity: 1; }
.share-btn:disabled { opacity: 1; color: var(--accent); border-color: var(--accent); }

/* termòmetre */
.termo-input { display: flex; align-items: center; gap: 14px; margin: 10px 0; }
.termo-input input[type=range] { flex: 1; accent-color: var(--accent); }
.termo-num { font-size: 26px; font-weight: 700; color: var(--accent); min-width: 38px; text-align: center; }
.termo-chart { margin-top: 12px; }
.termo-chart svg { width: 100%; height: auto; }
.tc-grid { stroke: var(--border); stroke-width: 1; }
.tc-lbl { fill: var(--muted); font-size: 11px; text-anchor: end; }
.tc-line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.tc-dot { fill: var(--accent); }

/* indicador "està pensant": tres punts saltant */
.typing-dots { display: inline-flex; gap: 5px; align-items: flex-end; padding: 4px 2px; }
.typing-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
  opacity: .4; animation: tp-bounce 1.2s ease-in-out infinite; }
.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes tp-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .35; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* cursor parpellejant mentre l'agent escriu */
.caret { display: inline-block; width: 2px; height: 1em; background: var(--accent);
  margin-left: 2px; vertical-align: -0.15em; animation: caret-blink 1s steps(1) infinite; }
@keyframes caret-blink { 50% { opacity: 0; } }

.composer { display: flex; gap: 10px; max-width: 780px; width: 100%; margin: 0 auto; padding: 8px 24px 4px; }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; background: var(--panel-2); max-height: 180px; }
.composer textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.composer textarea::placeholder { color: var(--muted); }
.composer .btn { align-self: flex-end; }
.disclaimer { text-align: center; font-size: 11.5px; color: var(--muted); margin: 6px 0 10px; }

/* ---------- modals ---------- */
.modal { position: fixed; inset: 0; background: rgba(5, 8, 7, .65); display: flex; align-items: center;
  justify-content: center; z-index: 50; }
.modal-card { background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 24px 26px; width: 100%; max-width: 420px; box-shadow: 0 18px 60px rgba(0, 0, 0, .6); }
.modal-card.wide { max-width: 640px; max-height: 80vh; overflow-y: auto; }
.modal-card h3 { margin: 0 0 12px; }
.modal-card label { display: block; margin: 10px 0; font-size: 14px; color: var(--muted); }
.modal-card input, .modal-card select { display: block; width: 100%; margin-top: 4px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--panel-2); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.md-view { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 18px; font-size: 14.5px; line-height: 1.65; }

/* scrollbars discrets */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2b323d; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #3a4350; }
::-webkit-scrollbar-track { background: transparent; }

/* consentiment RGPD al registre */
.consent { display: flex; gap: 10px; align-items: flex-start; font-size: 12.5px !important;
  line-height: 1.45; margin-top: 14px !important; }
.consent input { width: auto !important; display: inline-block !important; margin-top: 2px !important; }
.consent a { color: var(--accent); }

/* banner de verificació d'email */
.verify-banner { background: var(--coach-bg); color: var(--coach); font-size: 13.5px;
  padding: 8px 16px; text-align: center; border-bottom: 1px solid #4a3a17; }
.verify-banner .linklike { color: var(--coach); text-decoration: underline; margin-left: 8px; }

/* botó de menú (només mòbil) i backdrop */
.menu-btn { display: none; position: fixed; top: 12px; left: 12px; z-index: 45;
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; width: 42px; height: 42px; font-size: 19px; }
.sb-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 39; }

@media (max-width: 760px) {
  .sidebar { position: fixed; z-index: 40; height: 100%; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .reg-cols { grid-template-columns: 1fr; }
  .menu-btn { display: block; }
  .chat-head { padding-left: 64px; }
  .welcome { margin-top: 70px; }
}

/* espai compartit: control del que surt de l'espai privat */
.compartit-list { max-height: 60vh; overflow-y: auto; padding-right: 4px; }
.cm-grup { margin: 18px 0 8px; font-size: 12px; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.cm-grup:first-child { margin-top: 4px; }
.cm-card { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 10px; }
.cm-card.empty { border-style: dashed; }
.cm-card > b { font-size: 14.5px; }
.cm-desc { font-size: 12.5px; color: var(--muted); line-height: 1.5; margin: 4px 0 10px; }
.cm-text { width: 100%; resize: vertical; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); padding: 10px 12px; font-size: 14px; line-height: 1.6; }
.cm-text:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.cm-text::placeholder { color: var(--muted); }
.cm-acts { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.cm-ro { background: var(--bg); }
.cm-none { color: var(--muted); font-style: italic; margin: 0; }
