/* TheoryPrac public chat — scoped under .tpc-* */
.tpc-page { max-width: 880px; margin: 0 auto; padding: 12px; }

.tpc-wrap {
  --bg: #ffffff; --surface: #f3f6f4; --line: #e1e8e4; --text: #1b2420; --muted: #66726c;
  --accent: #00703c; --accent-ink: #ffffff; --mine: #00703c; --mine-ink: #ffffff;
  --other: #eef2f0; --warn: #fff4d6; --warn-ink: #5c4300; --danger: #c62828; --focus: #2563eb;
  position: relative; display: flex; flex-direction: column; overflow: hidden;
  height: calc(100dvh - 150px); min-height: 460px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 14px;
  font-family: 'Vazirmatn', system-ui, sans-serif; direction: rtl;
}
[data-bs-theme="dark"] .tpc-wrap {
  --bg: #16191a; --surface: #1d2123; --line: #2a3033; --text: #e8ecea; --muted: #96a29c;
  --accent: #3ba776; --accent-ink: #0c1a13; --mine: #0f5a38; --mine-ink: #f1f7f4;
  --other: #23292b; --warn: #3a3317; --warn-ink: #f1e2a8; --danger: #ef7a7a; --focus: #60a5fa;
}
@media (min-width: 1200px) { .tpc-wrap { height: calc(100dvh - 210px); } }

.tpc-wrap [hidden] { display: none !important; }
.tpc-wrap button, .tpc-wrap textarea, .tpc-wrap input, .tpc-wrap select { font-family: inherit; font-size: 0.9rem; color: inherit; }
.tpc-wrap :focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* header */
.tpc-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface); flex-shrink: 0; }
.tpc-title { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.tpc-title strong { font-size: 1rem; font-weight: 800; }
.tpc-online { font-size: 0.78rem; color: var(--muted); white-space: nowrap; }
.tpc-tools { display: flex; gap: 4px; }
.tpc-tool { display: inline-flex; align-items: center; gap: 5px; border: 0; background: transparent; padding: 6px 9px; border-radius: 8px; cursor: pointer; font-size: 0.8rem; color: var(--muted); }
.tpc-tool:hover { background: var(--line); color: var(--text); }
.tpc-tool.on { color: var(--accent); }
@media (max-width: 575.98px) { .tpc-tool span { display: none; } .tpc-tool { padding: 8px 10px; font-size: 1rem; } }

/* staff panel */
.tpc-staff { display: grid; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--surface); flex-shrink: 0; }
.tpc-staff input[type="text"], .tpc-staff select { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.tpc-staff-row { display: flex; align-items: center; gap: 10px; justify-content: space-between; font-size: 0.85rem; }
.tpc-staff-row select { width: auto; }
.tpc-staff-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.tpc-link { font-size: 0.82rem; color: var(--accent); }

/* pinned + banner + status */
.tpc-pin { display: flex; align-items: center; gap: 8px; padding: 7px 14px; background: var(--surface); border-bottom: 1px solid var(--line); flex-shrink: 0; font-size: 0.82rem; }
.tpc-pin i { color: var(--accent); }
.tpc-pin-text { flex: 1; min-width: 0; border: 0; background: none; text-align: right; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tpc-pin-x { border: 0; background: none; font-size: 1.2rem; line-height: 1; cursor: pointer; color: var(--muted); }
.tpc-banner { padding: 8px 14px; background: var(--warn); color: var(--warn-ink); font-size: 0.82rem; flex-shrink: 0; }
.tpc-status { padding: 6px 14px; font-size: 0.78rem; color: var(--muted); text-align: center; flex-shrink: 0; }
.tpc-status.err { color: var(--danger); }

/* messages */
.tpc-list { flex: 1; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 6px; overscroll-behavior: contain; }
.tpc-msg { display: flex; flex-direction: column; align-items: flex-start; position: relative; max-width: 100%; }
.tpc-msg.mine { align-items: flex-end; }
.tpc-bubble { position: relative; max-width: min(82%, 520px); padding: 7px 11px 6px; border-radius: 14px; border-top-right-radius: 4px; background: var(--other); touch-action: pan-y; transition: transform .15s ease; }
.tpc-msg.mine .tpc-bubble { background: var(--mine); color: var(--mine-ink); border-top-right-radius: 14px; border-top-left-radius: 4px; }
@media (pointer: coarse) { .tpc-bubble { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; } }
.tpc-msg.flash .tpc-bubble { box-shadow: 0 0 0 2px var(--accent); }

.tpc-name { display: flex; align-items: center; gap: 6px; font-size: 0.75rem; font-weight: 800; color: var(--accent); margin-bottom: 2px; }
.tpc-role { font-size: 0.66rem; font-weight: 700; padding: 1px 6px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); }
.tpc-role.admin { background: var(--danger); color: #fff; }
.tpc-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.92rem; line-height: 1.7; }
.tpc-time { font-size: 0.66rem; opacity: .65; margin-top: 1px; text-align: left; }
.tpc-quote { display: grid; gap: 1px; margin-bottom: 4px; padding: 4px 8px; border-right: 3px solid var(--accent); background: rgba(0,0,0,.06); border-radius: 6px; font-size: 0.76rem; cursor: pointer; }
[data-bs-theme="dark"] .tpc-quote { background: rgba(255,255,255,.07); }
.tpc-msg.mine .tpc-quote { border-right-color: var(--mine-ink); background: rgba(255,255,255,.14); }
.tpc-quote span { opacity: .8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tpc-reacts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.tpc-reacts:empty { display: none; }
.tpc-chip { display: inline-flex; align-items: center; gap: 3px; padding: 1px 7px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); color: var(--text); font-size: 0.74rem; cursor: pointer; }
.tpc-chip.mine { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--bg)); }

/* desktop hover buttons (hidden until the pointer is over a message) */
.tpc-hover { display: none; position: absolute; top: 4px; gap: 2px; padding: 2px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
.tpc-msg:not(.mine) .tpc-hover { left: 4px; }
.tpc-msg.mine .tpc-hover { right: 4px; }
.tpc-hover button { border: 0; background: none; padding: 2px 7px; border-radius: 6px; cursor: pointer; color: var(--muted); font-size: 0.95rem; }
.tpc-hover button:hover { background: var(--surface); color: var(--text); }
@media (hover: hover) and (pointer: fine) { .tpc-msg:hover .tpc-hover { display: flex; } }

.tpc-new { position: absolute; bottom: 86px; left: 50%; transform: translateX(-50%); z-index: 5; border: 0; border-radius: 999px; padding: 6px 14px; background: var(--accent); color: var(--accent-ink); font-size: 0.8rem; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.2); }

/* reply bar + composer */
.tpc-reply { display: flex; align-items: center; gap: 8px; padding: 6px 14px; border-top: 1px solid var(--line); background: var(--surface); font-size: 0.8rem; flex-shrink: 0; }
.tpc-reply-body { flex: 1; min-width: 0; display: grid; border-right: 3px solid var(--accent); padding-right: 8px; }
.tpc-reply-body span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tpc-reply button { border: 0; background: none; font-size: 1.3rem; line-height: 1; cursor: pointer; color: var(--muted); }

.tpc-compose { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); background: var(--bg); flex-shrink: 0; }
.tpc-compose textarea { flex: 1; resize: none; max-height: 120px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); line-height: 1.6; }
.tpc-compose textarea:disabled { opacity: .6; }
.tpc-send { width: 42px; height: 42px; flex-shrink: 0; border: 0; border-radius: 50%; background: var(--accent); color: var(--accent-ink); cursor: pointer; font-size: 1.05rem; }
.tpc-send i { display: inline-block; transform: scaleX(-1); }
.tpc-send:disabled { opacity: .45; cursor: not-allowed; }
.tpc-count { position: absolute; bottom: 58px; left: 62px; font-size: 0.7rem; color: var(--muted); pointer-events: none; }

/* gates + modal */
.tpc-gate { position: absolute; inset: 0; z-index: 20; overflow-y: auto; padding: 16px; background: var(--bg); }
.tpc-gate.tpc-modal { background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; }
.tpc-card { width: 100%; max-width: 560px; margin: 0 auto; padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); }
.tpc-card h2 { font-size: 1.1rem; font-weight: 800; margin: 0 0 6px; }
.tpc-card h3 { font-size: 0.92rem; font-weight: 800; margin: 14px 0 4px; }
.tpc-card p, .tpc-card li { font-size: 0.86rem; line-height: 1.9; }
.tpc-card ul { padding-right: 18px; margin: 0; }
.tpc-card hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0 4px; }
.tpc-card textarea { width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); margin: 6px 0 10px; }
.tpc-file { display: grid; gap: 4px; font-size: 0.8rem; color: var(--muted); margin-bottom: 8px; }
.tpc-checkrow { display: flex; gap: 8px; align-items: center; margin: 14px 0 12px; font-size: 0.86rem; font-weight: 600; }
.tpc-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.tpc-msgline { min-height: 1.2em; font-size: 0.8rem; color: var(--danger); margin: 6px 0; }
.tpc-msgline.ok { color: var(--accent); }
.tpc-ts { margin: 8px 0; min-height: 4px; }
.tpc-btn { display: inline-block; padding: 9px 16px; border: 1px solid var(--accent); border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 0.86rem; text-decoration: none; cursor: pointer; }
.tpc-btn.ghost { background: transparent; color: var(--accent); }
.tpc-btn:disabled { opacity: .45; cursor: not-allowed; }

/* action sheet (long-press / right-click) */
.tpc-sheet-back { position: absolute; inset: 0; z-index: 30; background: rgba(0,0,0,.35); }
.tpc-sheet { position: absolute; z-index: 31; right: 0; left: 0; bottom: 0; padding: 12px 12px 16px; border-radius: 16px 16px 0 0; background: var(--bg); border-top: 1px solid var(--line); display: grid; gap: 4px; max-width: 560px; margin: 0 auto; animation: tpc-up .16s ease-out; }
@keyframes tpc-up { from { transform: translateY(24px); opacity: .4; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .tpc-sheet { animation: none; } .tpc-bubble { transition: none; } }
.tpc-sheet-react { display: flex; justify-content: center; gap: 10px; padding: 4px 0 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.tpc-sheet-react button { width: 46px; height: 46px; border: 1px solid var(--line); border-radius: 50%; background: var(--surface); font-size: 1.4rem; cursor: pointer; }
.tpc-sheet-react button.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, var(--bg)); }
.tpc-act { display: block; width: 100%; padding: 11px 10px; border: 0; border-radius: 10px; background: none; text-align: right; font-size: 0.92rem; cursor: pointer; }
.tpc-act:hover { background: var(--surface); }
.tpc-act.danger { color: var(--danger); }
.tpc-ban { display: grid; gap: 6px; padding: 6px 4px 0; font-size: 0.8rem; color: var(--muted); }
.tpc-ban div { display: flex; gap: 6px; flex-wrap: wrap; }
.tpc-ban button { padding: 6px 11px; border: 1px solid var(--danger); border-radius: 999px; background: none; color: var(--danger); cursor: pointer; font-size: 0.8rem; }
/* layout swap: my messages on the right, others on the left, send button on the right */
.tpc-msg { align-items: flex-end; }
.tpc-msg.mine { align-items: flex-start; }
.tpc-bubble { border-top-right-radius: 14px; border-top-left-radius: 4px; }
.tpc-msg.mine .tpc-bubble { border-top-left-radius: 14px; border-top-right-radius: 4px; }
.tpc-msg:not(.mine) .tpc-hover { left: auto; right: 4px; }
.tpc-msg.mine .tpc-hover { right: auto; left: 4px; }
.tpc-compose { flex-direction: row-reverse; }
.tpc-count { left: auto; right: 62px; }
