/* Member portal: sign in and private chat. Builds on styles.css. */
.portal-body { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.portal-main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.pv[hidden] { display: none !important; }
.center { text-align: center; padding: 60px 0; }
.portal-user { display: flex; align-items: center; gap: 12px; }
.portal-user[hidden] { display: none; }
.portal-user-name { color: var(--muted); font-weight: 600; font-size: .92rem; }
.portal-home[hidden] { display: none; }

/* Auth */
.auth { flex: 1; display: grid; place-items: center; padding: 40px 16px 60px; }
.auth-card { width: min(440px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 32px 28px; }
.auth-logo { margin: 0 auto 14px; }
.auth-card h1 { font-size: 1.7rem; text-align: center; margin-bottom: 6px; }
.auth-card > .muted { text-align: center; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px; padding: 4px; margin: 20px 0 20px; }
.tabs button { border: 0; background: none; color: var(--muted); font: 600 .95rem var(--sans); padding: 10px; border-radius: 999px; cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--mint); color: var(--mint-ink); }
.help { color: var(--muted); font-size: .88rem; margin-top: 14px; }
form[hidden] { display: none; }

/* Chat layout */
.chat-app { flex: none; display: grid; grid-template-columns: 340px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); height: calc(100dvh - 71px); min-height: 0; }
.inbox { border-right: 1px solid var(--line); background: var(--bg-2); display: flex; flex-direction: column; min-height: 0; overflow-y: auto; }
.inbox-head { padding: 22px 20px 10px; }
.inbox-title { font-size: 1.5rem; margin: 0; }
.inbox-sub { margin: 4px 0 0; font-size: .9rem; }
.start-chat { padding: 6px 20px 14px; border-bottom: 1px solid var(--line); }
.start-chat[hidden] { display: none; }
.start-chat .label { font-size: .75rem; color: var(--mint); text-transform: uppercase; letter-spacing: .1em; font-weight: 700; margin-bottom: 8px; }
.start-list { display: flex; flex-wrap: wrap; gap: 8px; }
.convo-list { list-style: none; margin: 0; padding: 6px 8px 20px; }
.inbox-empty { padding: 10px 20px; font-size: .92rem; }
.convo { position: relative; width: 100%; display: flex; gap: 12px; align-items: center; text-align: left; border: 0; background: none; color: var(--text); padding: 12px; border-radius: 12px; cursor: pointer; font: inherit; }
.convo:hover { background: var(--panel); }
.convo[aria-current="true"] { background: var(--panel-2); }
.avatar { flex: none; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: rgba(108, 189, 161, .14); border: 1px solid rgba(108, 189, 161, .4); color: var(--mint); font: 900 .9rem var(--serif); }
.convo-text { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.convo-top { display: flex; justify-content: space-between; gap: 8px; }
.convo-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convo-time { color: var(--muted); font-size: .78rem; flex: none; }
.convo-last { color: var(--muted); font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.has-unread .convo-last { color: var(--text); font-weight: 600; }
.unread { position: absolute; right: 12px; bottom: 12px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; background: var(--mint); color: var(--mint-ink); font-size: .75rem; font-weight: 800; display: grid; place-items: center; }
.has-unread .convo-last { padding-right: 30px; }

/* Thread */
.thread { display: flex; flex-direction: column; min-height: 0; background: var(--bg); position: relative; }
.thread-empty { display: none; }
.thread[data-empty="true"] > :not(.thread-empty) { display: none !important; }
.thread[data-empty="true"] .thread-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; opacity: .85; }
.thread-head { display: flex; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--bg-2); }
.thread-back { display: none; width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 50%; background: var(--panel); color: var(--text); font-size: 1.5rem; line-height: 1; cursor: pointer; flex: none; }
.thread-who { min-width: 0; flex: 1; }
.thread-name { font-family: var(--sans); font-size: 1.1rem; font-weight: 700; margin: 0; }
.thread-meta { margin: 0; font-size: .85rem; overflow-wrap: anywhere; }
.thread-reset[hidden] { display: none; }
.thread-reset-box { padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.thread-reset-box[hidden] { display: none; }
.thread-reset-box p { margin: 0 0 8px; font-size: .92rem; }
.thread-reset-box input { width: 100%; font: .85rem ui-monospace, Menlo, monospace; color: var(--text); background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.reset-row { display: flex; gap: 8px; margin-top: 10px; }

.messages { list-style: none; margin: 0; padding: 20px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; overscroll-behavior: contain; }
.messages .day { align-self: center; color: var(--muted); font-size: .78rem; font-weight: 600; margin: 12px 0 4px; text-transform: uppercase; letter-spacing: .06em; }
.messages .intro { align-self: center; text-align: center; max-width: 420px; margin: auto 0; font-size: .92rem; }
.msg { display: flex; flex-direction: column; max-width: min(75%, 560px); }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.theirs { align-self: flex-start; align-items: flex-start; }
.bubble { padding: 10px 14px; border-radius: 18px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }
.mine .bubble { background: var(--mint); color: var(--mint-ink); border-bottom-right-radius: 6px; }
.theirs .bubble { background: var(--panel-2); color: var(--text); border-bottom-left-radius: 6px; }
.msg time { font-size: .72rem; color: var(--muted); margin: 3px 6px 0; }
.seen { font-size: .72rem; color: var(--mint); margin: 0 6px; }

.composer { display: flex; align-items: flex-end; gap: 10px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--bg-2); }
.composer textarea { flex: 1; resize: none; font: 1rem/1.4 var(--sans); color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 11px 16px; max-height: 160px; }
.composer textarea:focus { outline: none; border-color: var(--mint); }
.composer .btn { width: 46px; padding: 0; flex: none; }
.composer-msg { margin: 0; padding: 0 16px; }
.composer-msg:empty { display: none; }
.composer-msg:not(:empty) { padding-bottom: 10px; background: var(--bg-2); }

@media (max-width: 860px) {
  .chat-app { grid-template-columns: 1fr; }
  .inbox { border-right: 0; }
  .thread { display: none; }
  .thread-open .inbox { display: none; }
  .thread-open .thread { display: flex; }
  .thread-back { display: block; }
  .portal-user-name { display: none; }
  .msg { max-width: 85%; }
  .thread-head { padding: 10px 12px; }
  .messages { padding: 14px 12px; }
}
@media (max-width: 480px) {
  .auth-card { padding: 24px 18px; }
  .thread-reset { font-size: .8rem; padding: 0 12px; }
}

/* Pending approval */
.pending-card { text-align: center; }
.pending-card p { color: #cfd6d3; }
.pending-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 18px; }

/* Coaches: members */
.inbox-head { position: relative; }
.members-btn { position: absolute; right: 16px; top: 22px; display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font: 600 .88rem var(--sans); padding: 8px 14px; border-radius: 999px; cursor: pointer; }
.members-btn:hover, .members-btn[aria-pressed="true"] { border-color: var(--mint); color: var(--mint); }
.members-btn[hidden] { display: none; }
.members-count { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--mint); color: var(--mint-ink); font-size: .72rem; font-weight: 800; display: grid; place-items: center; }
.members-count[hidden] { display: none; }
.members { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.members[hidden], .thread[hidden] { display: none !important; }
.members-body { flex: 1; overflow-y: auto; padding: 8px 20px 40px; }
.members-body h3 { font-size: 1rem; margin: 22px 0 6px; }
.members-body h3 .count { color: var(--muted); font-weight: 500; }
.small { font-size: .82rem; }
.members-body > .small { margin: 0 0 10px; }
.member-search { width: 100%; max-width: 360px; margin: 4px 0 10px; font: 1rem var(--sans); color: var(--text); background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; }
.member-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.member { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 14px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
[data-list="pending"] .member { border-color: rgba(108, 189, 161, .55); }
.member-info { display: flex; flex-direction: column; min-width: 0; }
.member-info .muted { overflow-wrap: anywhere; font-size: .88rem; }
.member-actions { display: flex; gap: 8px; flex: none; }
.member-empty { padding: 6px 2px; font-size: .9rem; }
@media (max-width: 860px) {
  .members { display: none; }
  .thread-open .members:not([hidden]) { display: flex; }
  .member { flex-direction: column; align-items: stretch; }
  .member-actions .btn { flex: 1; }
  .members-body { padding: 4px 12px 40px; }
}

/* Coaches: add an existing member */
.add-member { margin: 14px 0 4px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); padding: 0 16px; }
.add-member summary { list-style: none; cursor: pointer; padding: 14px 0; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.add-member summary::-webkit-details-marker { display: none; }
.add-member .plus { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--mint); color: var(--mint-ink); font-weight: 800; font-size: 1.2rem; line-height: 1; transition: transform .15s; }
.add-member[open] .plus { transform: rotate(45deg); }
.add-member > .small { margin: -4px 0 12px; }
.add-member-form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; gap: 10px; align-items: end; padding-bottom: 14px; }
.add-member-form .field { margin: 0; }
.add-member-form .btn { min-height: 46px; }
.add-member-msg { margin: -4px 0 14px; }
.add-member-msg:empty { display: none; }
.invite-box { margin-top: 12px; padding: 16px; border: 2px solid var(--mint); border-radius: 12px; background: rgba(108, 189, 161, .08); }
.invite-box[hidden] { display: none; }
.invite-box p { margin: 0 0 6px; }
.invite-box input { width: 100%; margin-top: 4px; font: .85rem ui-monospace, Menlo, monospace; color: var(--text); background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.invite-box .reset-row { flex-wrap: wrap; }
.invite-tag { align-self: flex-start; margin-top: 6px; font-size: .75rem; font-weight: 700; color: #f4d35e; background: rgba(244, 211, 94, .12); border: 1px solid rgba(244, 211, 94, .4); border-radius: 999px; padding: 2px 8px; }
@media (max-width: 1100px) { .add-member-form { grid-template-columns: 1fr 1fr; } .add-member-form .btn { grid-column: 1 / -1; } }
@media (max-width: 860px) { .add-member-form { grid-template-columns: 1fr; } }
