/* Intercom: the teacher's panel (admin: recorder, call card, history) and the listening indicator (display). */

/* ---------- admin panel ---------- */
.intercom-panel { margin-bottom: 18px; }
.intercom-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.intercom-heading h2 { display: flex; align-items: center; gap: 10px; margin: 6px 0 8px; }
.intercom-heading .hint { max-width: 66ch; margin: 0; font-size: 13.5px; line-height: 1.6; }
.intercom-kicker { color: var(--ink-3, #707c74); font-size: 11px; font-weight: 800; letter-spacing: .16em; }
.intercom-badge { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 700; color: var(--ink-2, #52635a); background: var(--surface-2, #f3f5f1); border: 1px solid var(--line-2, #d5ddd1); }
.intercom-badge i { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--ink-3, #9aa59d); }
.intercom-badge.is-live { color: var(--green-700, #2d5746); background: var(--accent-soft, #e8f0e6); }
.intercom-badge.is-live i { background: #1f9d55; box-shadow: 0 0 0 4px rgba(31, 157, 85, .2); }
.intercom-badge.is-warn { color: var(--warn, #b7791f); border-color: var(--warn, #b7791f); }
.intercom-badge.is-warn i { background: var(--warn, #b7791f); }

/* two cards side by side, one under the other on narrow screens */
.intercom-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); gap: 16px; margin-top: 20px; align-items: stretch; }
.ic-card { display: flex; flex-direction: column; gap: 18px; min-width: 0; padding: 20px; border-radius: var(--radius, 22px); background: var(--surface-2, #f3f5f1); border: 1px solid var(--line, #e4e8e1); }
.ic-card-head { display: flex; align-items: center; gap: 14px; }
.ic-card-icon { flex: none; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 14px; color: var(--accent, #2d5746); background: var(--accent-soft, #e8f0e6); }
.ic-card-head h3 { margin: 0; font-size: 16px; line-height: 1.3; }
.ic-card-sub { margin: 2px 0 0; font-size: 13px; line-height: 1.45; color: var(--ink-3, #707c74); }

/* recorder */
.intercom-stage { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.intercom-button {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  flex: none; width: 148px; height: 148px; border: 0; border-radius: 50%; cursor: pointer;
  font: inherit; font-weight: 800; letter-spacing: .12em; font-size: 14px;
  color: var(--accent-ink, #fff); background: var(--accent, #2d5746);
  box-shadow: 0 22px 44px -20px var(--accent, #2d5746); transition: transform .12s ease, background .2s ease;
}
.intercom-button .i { width: 38px; height: 38px; stroke-width: 1.8; }
.intercom-button:hover:not(:disabled) { transform: scale(1.025); }
.intercom-button:active:not(:disabled) { transform: scale(.97); }
.intercom-button:disabled { cursor: not-allowed; opacity: .55; }
.intercom-button.is-busy:disabled { cursor: progress; opacity: .7; }
.intercom-button:focus-visible { outline: 3px solid var(--focus, #a0b89d); outline-offset: 5px; }
.intercom-ring { position: absolute; inset: -10px; border-radius: 50%; border: 2px solid var(--accent, #2d5746); opacity: 0; pointer-events: none; }
.intercom-button.is-recording { background: var(--danger, #d4443f); box-shadow: 0 22px 44px -20px var(--danger, #d4443f); }
.intercom-button.is-recording .intercom-ring { border-color: var(--danger, #d4443f); animation: intercom-pulse 1.5s ease-out infinite; }
@keyframes intercom-pulse { 0% { transform: scale(.96); opacity: .75; } 100% { transform: scale(1.22); opacity: 0; } }

.intercom-readout { flex: 1; min-width: 200px; display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.intercom-timer { font-family: var(--display, var(--font)); font-size: 30px; line-height: 1.1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; color: var(--ink-3, #707c74); }
.intercom-timer.is-live { color: var(--danger, #d4443f); }
.intercom-status { margin: 0; font-size: 14.5px; line-height: 1.55; color: var(--ink-2, #52635a); }
.intercom-status.is-error { color: var(--danger, #d4443f); font-weight: 700; }

/* live microphone level while recording */
.intercom-meter { display: flex; align-items: stretch; gap: 3px; width: 100%; max-width: 300px; height: 26px; }
.intercom-meter[hidden] { display: none; }
.intercom-meter i { flex: 1; min-width: 0; border-radius: 3px; background: var(--line-2, #d5ddd1); }
.intercom-meter i.on { background: var(--accent, #2d5746); }
.intercom-meter i.on:nth-child(n+17) { background: var(--warn, #b7791f); }
.intercom-meter i.on:nth-child(n+22) { background: var(--danger, #d4443f); }
.intercom-silent { margin: 0; font-size: 13px; font-weight: 700; color: var(--warn, #b7791f); }

/* listen back before sending */
.intercom-review { padding: 14px 16px; border-radius: 16px; background: var(--surface, #fff); border: 1px solid var(--accent, #2d5746); box-shadow: 0 0 0 3px var(--accent-soft, #e8f0e6); }
.intercom-review-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.intercom-review-time { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--ink-3, #707c74); }
.intercom-review-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.intercom-options { display: flex; align-items: center; justify-content: space-between; gap: 10px 18px; flex-wrap: wrap; padding-top: 16px; border-top: 1px dashed var(--line-2, #d5ddd1); }
.intercom-options .btn { height: auto; min-height: 36px; padding-top: 7px; padding-bottom: 7px; white-space: normal; text-align: left; line-height: 1.3; }
.intercom-options .btn.is-playing { color: var(--accent-ink, #fff); background: var(--accent, #2d5746); border-color: var(--accent, #2d5746); }
.ic-switch { position: relative; display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-size: 14px; font-weight: 700; color: var(--ink-2, #52635a); }
.ic-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.ic-switch-track { position: relative; flex: none; width: 46px; height: 28px; border-radius: 999px; background: var(--line-2, #d5ddd1); border: 1px solid var(--line-2, #d5ddd1); transition: background .2s ease; }
.ic-switch-track i { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--ink-3, #707c74); transition: transform .2s ease, background .2s ease; }
.ic-switch input:checked + .ic-switch-track { background: var(--accent, #2d5746); border-color: var(--accent, #2d5746); }
.ic-switch input:checked + .ic-switch-track i { transform: translateX(18px); background: var(--accent-ink, #fff); }
.ic-switch input:focus-visible + .ic-switch-track { outline: 3px solid var(--focus, #a0b89d); outline-offset: 3px; }
.ic-switch input:disabled + .ic-switch-track { opacity: .5; }

.intercom-warn { display: flex; align-items: flex-start; gap: 10px; margin: 0; padding: 10px 14px; border-radius: 14px; font-size: 13.5px; font-weight: 600; line-height: 1.5; color: var(--ink, #24372e); background: var(--surface, #fff); border: 1px solid var(--warn, #b7791f); }
.intercom-warn[hidden] { display: none; }
.intercom-warn .i { margin-top: 2px; color: var(--warn, #b7791f); }

/* history */
.intercom-recent-wrap { margin-top: 24px; }
.intercom-recent-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.intercom-recent-head h3 { margin: 0; font-size: 15px; }
.intercom-recent { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
.intercom-item { display: flex; align-items: center; justify-content: space-between; gap: 10px 14px; flex-wrap: wrap; padding: 10px 14px; border-radius: 14px; background: var(--surface-2, #f3f5f1); border: 1px solid var(--line, #e4e8e1); font-variant-numeric: tabular-nums; }
.intercom-item-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.intercom-item-when { font-size: 14px; font-weight: 800; color: var(--ink, #24372e); }
.intercom-item-meta { font-size: 12.5px; font-weight: 600; color: var(--ink-3, #707c74); }
.intercom-item-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.intercom-empty { display: flex; align-items: center; gap: 14px; padding: 18px; border-radius: 14px; border: 1px dashed var(--line-2, #d5ddd1); color: var(--ink-3, #707c74); font-size: 14px; line-height: 1.5; }
.intercom-empty .i { flex: none; box-sizing: content-box; padding: 10px; border-radius: 50%; color: var(--accent, #2d5746); background: var(--accent-soft, #e8f0e6); }

.intercom-how { margin: 18px 0 4px; font-size: 14px; color: var(--ink-2, #52635a); }
.intercom-how summary { cursor: pointer; font-weight: 700; padding: 6px 0; }
.intercom-how summary:focus-visible { outline: 3px solid var(--focus, #a0b89d); outline-offset: 3px; border-radius: 6px; }
.intercom-how ol { margin: 10px 0 0; padding-left: 20px; line-height: 1.7; }

/* ---------- display indicator ----------
   Only a WARNING shows (sound locked, album code needed, connection lost); idle listening has no pill at all. It sits at the TOP
   centre, under the site header, so it can never cover a toolbar; while the whiteboard is immersive it is not shown in any state
   (the whole screen belongs to the board). */
.intercom-pill {
  position: fixed; z-index: 10040; left: 50%; top: calc(max(8px, env(safe-area-inset-top)) + 84px); bottom: auto; transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 10px; width: max-content; max-width: min(92vw, 520px); padding: 10px 16px; border-radius: 999px;
  font: 700 13px/1.35 var(--font, system-ui, sans-serif); color: var(--ink, #24372e); cursor: default;
  background: var(--surface, #fff); border: 1px solid var(--line-2, #d5ddd1); box-shadow: 0 14px 34px -14px rgba(8, 40, 24, .45);
}
.intercom-pill[hidden] { display: none; }
body.board-immersive .intercom-pill { display: none !important; }
body[data-tab="board"] .intercom-pill[data-state="playing"] { display: none !important; }
.intercom-pill i { flex: none; width: 10px; height: 10px; border-radius: 50%; background: #1f9d55; box-shadow: 0 0 0 4px rgba(31, 157, 85, .18); }
.intercom-pill[data-state="warn"] { cursor: pointer; border-color: var(--warn, #b7791f); }
.intercom-pill[data-state="warn"] i { background: var(--warn, #b7791f); box-shadow: 0 0 0 4px rgba(183, 121, 31, .2); }
.intercom-pill[data-state="off"] i { background: var(--ink-3, #9aa59d); box-shadow: none; }
.intercom-pill[data-state="off"], .intercom-pill[data-state="playing"] { pointer-events: none; }   /* nothing to tap: never steal a tap from the page under it */
.intercom-pill[data-state="playing"] { color: var(--accent-ink, #fff); background: var(--accent, #2d5746); border-color: var(--accent, #2d5746); }
.intercom-pill[data-state="playing"] i { background: #fff; box-shadow: 0 0 0 4px rgba(255, 255, 255, .25); animation: intercom-blink 1s ease-in-out infinite; }
@keyframes intercom-blink { 50% { opacity: .35; } }

@media (max-width: 720px) {
  .intercom-pill { top: calc(max(8px, env(safe-area-inset-top)) + 66px); padding: 7px 13px; gap: 8px; font-size: 12px; line-height: 1.3; }
}
@media (max-width: 560px) {
  .ic-card { padding: 16px; gap: 16px; }
  .intercom-stage { justify-content: center; text-align: center; }
  .intercom-readout { align-items: center; }
  .intercom-button { width: 132px; height: 132px; }
  .intercom-review-actions .btn { flex: 1 1 100%; }
  .intercom-options { flex-direction: column; align-items: stretch; }
  .intercom-options .btn { width: 100%; }
  .intercom-item { align-items: stretch; }
  .intercom-item-actions .btn { flex: 1 1 auto; }
}
@media (prefers-reduced-motion: reduce) {
  .intercom-button, .intercom-button.is-recording .intercom-ring, .intercom-pill[data-state="playing"] i, .ic-switch-track, .ic-switch-track i { animation: none; transition: none; }
}
