/* ============================================================
   Lexicon 101 — Batch Chat (premium UI)
   Used in both the student and teacher portals via batch-chat.js.
   Colours flow through CSS variables so the student dark-mode
   override (student-login.html) keeps working.
   ============================================================ */

.lex-chat-widget {
  --chat-bg: #eef3f9;
  --chat-panel: #ffffff;
  --chat-line: rgba(16, 38, 74, 0.10);
  --chat-text: #102444;
  --chat-muted: #6a7e9c;
  --chat-accent: #1ea7b8;
  --chat-accent-2: #2f7fe0;
  --chat-ok: #2d68b2;
  color: var(--chat-text);
  -webkit-font-smoothing: antialiased;
}

.lex-chat-widget.lex-chat-light {
  --chat-bg: #eef3f9;
  --chat-panel: #ffffff;
  --chat-line: rgba(16, 38, 74, 0.10);
  --chat-text: #102444;
  --chat-muted: #6a7e9c;
  --chat-accent: #1ea7b8;
  --chat-accent-2: #2f7fe0;
  --chat-ok: #2d68b2;
}

/* ---------- header ---------- */
.lex-chat-head {
  display: flex;
  justify-content: space-between;
  gap: 0.7rem;
  align-items: center;
  margin-bottom: 0.95rem;
}

.lex-chat-title-wrap { position: relative; min-width: 0; }

.lex-chat-title-button {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: 0;
  background: transparent;
  color: var(--chat-text);
  padding: 0;
  font: inherit;
  font-size: 1.18rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.2;
  text-align: left;
  cursor: pointer;
}
.lex-chat-title-button:disabled { cursor: default; opacity: 0.85; }
.lex-chat-title-button[aria-expanded="true"] .lex-chat-caret { transform: rotate(180deg); }

.lex-chat-caret {
  display: inline-grid;
  place-items: center;
  width: 1.4rem;
  height: 1.4rem;
  border: 1px solid var(--chat-line);
  border-radius: 999px;
  color: var(--chat-accent);
  font-size: 0.7rem;
  transition: transform 0.18s ease;
}

.lex-chat-title { font-size: 1.05rem; font-weight: 800; color: var(--chat-text); line-height: 1.2; }

.lex-chat-sub {
  margin-top: 0.28rem;
  color: var(--chat-muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.lex-chat-refresh {
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
  border: 1px solid var(--chat-line);
  border-radius: 999px;
  background: var(--chat-panel);
  color: var(--chat-muted);
  min-height: 2.1rem;
  padding: 0.34rem 0.85rem;
  font: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}
.lex-chat-refresh:hover {
  color: var(--chat-accent);
  border-color: color-mix(in srgb, var(--chat-accent) 45%, var(--chat-line));
  box-shadow: 0 4px 14px rgba(16, 38, 74, 0.06);
}

/* ---------- room dropdown ---------- */
.lex-chat-dropdown {
  position: absolute;
  top: calc(100% + 0.55rem);
  left: 0;
  z-index: 20;
  display: grid;
  gap: 0.3rem;
  width: min(360px, 82vw);
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--chat-line);
  border-radius: 16px;
  padding: 0.45rem;
  background: var(--chat-panel);
  box-shadow: 0 22px 55px rgba(16, 38, 74, 0.18);
}
.lex-chat-dropdown[hidden] { display: none; }

.lex-chat-dropdown-item {
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--chat-text);
  padding: 0.58rem 0.66rem;
  text-align: left;
  font: inherit;
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease;
}
.lex-chat-dropdown-item:hover,
.lex-chat-dropdown-item.active {
  border-color: color-mix(in srgb, var(--chat-accent) 32%, transparent);
  background: color-mix(in srgb, var(--chat-accent) 12%, transparent);
}
.lex-chat-dropdown-item strong,
.lex-chat-dropdown-item span { display: block; }
.lex-chat-dropdown-item strong { font-size: 0.84rem; font-weight: 800; }
.lex-chat-dropdown-item span { margin-top: 0.16rem; color: var(--chat-muted); font-size: 0.7rem; }

/* ---------- layout ---------- */
.lex-chat-shell {
  display: grid;
  grid-template-columns: minmax(150px, 0.4fr) minmax(0, 1fr);
  gap: 0.85rem;
  min-height: 420px;
}

.lex-chat-rooms {
  display: grid;
  align-content: start;
  gap: 0.4rem;
  max-height: 520px;
  overflow-y: auto;
  padding: 0.4rem;
  border: 1px solid var(--chat-line);
  border-radius: 16px;
  background: var(--chat-bg);
}

.lex-chat-room {
  position: relative;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--chat-text);
  padding: 0.6rem 0.7rem;
  text-align: left;
  cursor: pointer;
  font: inherit;
  transition: background 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease;
}
.lex-chat-room:hover { background: var(--chat-panel); }
.lex-chat-room.active {
  background: var(--chat-panel);
  border-color: color-mix(in srgb, var(--chat-accent) 30%, var(--chat-line));
  box-shadow: 0 6px 18px rgba(16, 38, 74, 0.07);
}
.lex-chat-room.active::before {
  content: "";
  position: absolute;
  left: 0; top: 18%; bottom: 18%;
  width: 3px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--chat-accent), var(--chat-accent-2));
}
.lex-chat-room-code { display: block; font-size: 0.86rem; font-weight: 800; word-break: break-word; }
.lex-chat-room-meta {
  display: block;
  margin-top: 0.2rem;
  color: var(--chat-muted);
  font-size: 0.68rem;
  line-height: 1.35;
}

/* ---------- conversation panel ---------- */
.lex-chat-panel {
  display: grid;
  grid-template-rows: auto minmax(220px, 1fr) auto;
  min-width: 0;
  border: 1px solid var(--chat-line);
  border-radius: 18px;
  background: var(--chat-panel);
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(16, 38, 74, 0.06);
}

.lex-chat-active-head {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--chat-line);
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--chat-accent) 12%, transparent), transparent 60%),
    var(--chat-panel);
}
.lex-chat-active-title { color: var(--chat-text); font-weight: 800; font-size: 0.98rem; letter-spacing: -0.01em; }
.lex-chat-participants {
  margin-top: 0.3rem;
  color: var(--chat-muted);
  font-size: 0.72rem;
  line-height: 1.45;
}

.lex-chat-messages {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 1rem;
  max-height: 440px;
  overflow-y: auto;
  background:
    radial-gradient(120% 100% at 100% 0%, color-mix(in srgb, var(--chat-accent) 6%, transparent), transparent 55%),
    var(--chat-bg);
  scroll-behavior: smooth;
}

.lex-chat-empty {
  margin: auto;
  text-align: center;
  color: var(--chat-muted);
  font-size: 0.84rem;
  line-height: 1.5;
  padding: 1.4rem;
}

/* ---------- message rows ---------- */
.lex-chat-row {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  max-width: 86%;
}
.lex-chat-row.own {
  flex-direction: row-reverse;
  margin-left: auto;
}

.lex-chat-avatar {
  flex: 0 0 auto;
  width: 2.1rem;
  height: 2.1rem;
  margin-top: 1.25rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  box-shadow: 0 4px 12px rgba(16, 38, 74, 0.18);
  background: linear-gradient(135deg, #6b7fa8, #41557d);
}
.lex-chat-avatar[data-role="teacher"] { background: linear-gradient(135deg, var(--chat-accent), var(--chat-accent-2)); }
.lex-chat-avatar[data-role="student"] { background: linear-gradient(135deg, #7c8db0, #4a5d86); }
.lex-chat-avatar[data-role="team"] { background: linear-gradient(135deg, #e6a93a, #d9772f); }

.lex-chat-bubble-wrap { min-width: 0; display: flex; flex-direction: column; }
.lex-chat-row.own .lex-chat-bubble-wrap { align-items: flex-end; }

.lex-chat-message-top {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0 0.2rem 0.28rem;
  font-size: 0.7rem;
}
.lex-chat-row.own .lex-chat-message-top { flex-direction: row-reverse; }

.lex-chat-sender { color: var(--chat-text); font-weight: 800; font-size: 0.76rem; }

.lex-chat-role {
  text-transform: capitalize;
  font-weight: 700;
  font-size: 0.62rem;
  letter-spacing: 0.02em;
  padding: 0.08rem 0.46rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--chat-accent) 14%, transparent);
  color: color-mix(in srgb, var(--chat-accent) 75%, var(--chat-text));
}
.lex-chat-role[data-role="teacher"] { background: rgba(30, 167, 184, 0.16); color: #0f7c89; }
.lex-chat-role[data-role="student"] { background: rgba(91, 109, 138, 0.16); color: #4a5d86; }
.lex-chat-role[data-role="team"] { background: rgba(217, 119, 47, 0.16); color: #b4621f; }

.lex-chat-time { color: var(--chat-muted); font-size: 0.66rem; font-weight: 600; }

.lex-chat-bubble {
  border-radius: 4px 16px 16px 16px;
  padding: 0.62rem 0.8rem;
  background: var(--chat-panel);
  border: 1px solid var(--chat-line);
  box-shadow: 0 4px 14px rgba(16, 38, 74, 0.05);
  max-width: 100%;
}
.lex-chat-row.own .lex-chat-bubble {
  border-radius: 16px 4px 16px 16px;
  border-color: transparent;
  background: linear-gradient(135deg, var(--chat-accent), var(--chat-accent-2));
  color: #fff;
  box-shadow: 0 8px 20px color-mix(in srgb, var(--chat-accent) 30%, transparent);
}

.lex-chat-text {
  color: inherit;
  font-size: 0.86rem;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ---------- attachments ---------- */
.lex-chat-attachments { display: grid; gap: 0.45rem; margin-top: 0.55rem; }
.lex-chat-attachment {
  display: block;
  border: 1px solid var(--chat-line);
  border-radius: 12px;
  overflow: hidden;
  background: color-mix(in srgb, var(--chat-text) 6%, transparent);
  color: inherit;
  text-decoration: none;
}
.lex-chat-row.own .lex-chat-attachment { border-color: rgba(255, 255, 255, 0.35); background: rgba(255, 255, 255, 0.14); }
.lex-chat-attachment img,
.lex-chat-attachment video {
  display: block;
  width: 100%;
  max-height: 240px;
  object-fit: cover;
  background: #0a1b34;
}
.lex-chat-file-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.58rem 0.66rem;
  color: inherit;
  font-size: 0.78rem;
  font-weight: 700;
}
.lex-chat-file-size { color: var(--chat-muted); font-size: 0.68rem; font-weight: 600; }
.lex-chat-row.own .lex-chat-file-size { color: rgba(255, 255, 255, 0.8); }

/* ---------- composer ---------- */
.lex-chat-form {
  display: block;
  padding: 0.7rem;
  border-top: 1px solid var(--chat-line);
  background: var(--chat-panel);
}

.lex-chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 0.45rem;
  border: 1px solid var(--chat-line);
  border-radius: 18px;
  padding: 0.32rem 0.32rem 0.32rem 0.4rem;
  background: var(--chat-bg);
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}
.lex-chat-composer:focus-within {
  border-color: color-mix(in srgb, var(--chat-accent) 55%, var(--chat-line));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--chat-accent) 16%, transparent);
}

.lex-chat-attach {
  position: relative;
  flex: 0 0 auto;
  width: 2.3rem;
  height: 2.3rem;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: var(--chat-muted);
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease;
}
.lex-chat-attach:hover { background: color-mix(in srgb, var(--chat-accent) 12%, transparent); color: var(--chat-accent); }
.lex-chat-file-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.lex-chat-textarea {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 2.3rem;
  max-height: 150px;
  resize: none;
  border: 0;
  background: transparent;
  color: var(--chat-text);
  padding: 0.55rem 0.2rem;
  font: inherit;
  font-size: 0.88rem;
  line-height: 1.45;
  outline: none;
}
.lex-chat-textarea::placeholder { color: var(--chat-muted); }

.lex-chat-send {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--chat-accent), var(--chat-accent-2));
  color: #fff;
  height: 2.3rem;
  padding: 0 0.95rem;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--chat-accent) 32%, transparent);
  transition: transform 0.12s ease, box-shadow 0.16s ease, opacity 0.16s ease;
}
.lex-chat-send svg { display: block; }
.lex-chat-send:hover { transform: translateY(-1px); box-shadow: 0 10px 22px color-mix(in srgb, var(--chat-accent) 38%, transparent); }
.lex-chat-send:active { transform: translateY(0); }
.lex-chat-send:disabled { opacity: 0.6; cursor: default; transform: none; box-shadow: none; }

.lex-chat-hint {
  margin: 0.5rem 0.3rem 0.1rem;
  color: var(--chat-muted);
  font-size: 0.68rem;
  line-height: 1.4;
}
.lex-chat-hint strong { color: var(--chat-text); font-weight: 700; }

.lex-chat-file-list { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.55rem; }
.lex-chat-selected-file {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  max-width: 100%;
  border: 1px solid var(--chat-line);
  border-radius: 999px;
  padding: 0.28rem 0.55rem;
  color: var(--chat-text);
  background: color-mix(in srgb, var(--chat-accent) 10%, transparent);
  font-size: 0.7rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}
.lex-chat-selected-file small { color: var(--chat-muted); font-size: 0.62rem; font-weight: 700; }

/* ---------- status banners ---------- */
.lex-chat-status {
  display: none;
  margin-bottom: 0.7rem;
  border-radius: 12px;
  padding: 0.6rem 0.72rem;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.45;
}
.lex-chat-status.ok,
.lex-chat-status.warn,
.lex-chat-status.error { display: block; }
.lex-chat-status.ok { color: var(--chat-ok); border: 1px solid rgba(45, 104, 178, 0.28); background: rgba(45, 104, 178, 0.08); }
.lex-chat-status.warn { color: #b07d09; border: 1px solid rgba(250, 204, 21, 0.32); background: rgba(250, 204, 21, 0.10); }
.lex-chat-status.error { color: #c23b3b; border: 1px solid rgba(248, 113, 113, 0.34); background: rgba(248, 113, 113, 0.10); }

/* ---------- responsive ---------- */
@media (max-width: 720px) {
  .lex-chat-shell { grid-template-columns: 1fr; }
  .lex-chat-rooms {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    max-height: none;
  }
  .lex-chat-room { min-width: 150px; }
  .lex-chat-room.active::before { display: none; }
  .lex-chat-row { max-width: 94%; }
}
