:root {
  --red: #e4022e;
  --navy: #002c41;
  --ivory: #f6f5ee;
  --ink: #16232b;
  --muted: #5d6b73;
  --line: #dedbd0;
  --card: #ffffff;
  --late: #fdecef;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Montserrat, system-ui, -apple-system, Segoe UI, sans-serif;
  background: var(--ivory);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}
h1 { font-size: 1.25rem; margin: 0 0 .25rem; color: var(--navy); }
h2 { font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 .75rem; }
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.top {
  background: var(--navy); color: #fff; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 600; }
.brand img { background: #fff; border-radius: 4px; padding: 3px 5px; height: 29px; width: auto; }
main { max-width: 1200px; margin: 0 auto; padding: 16px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.narrow { max-width: 380px; margin: 10vh auto; display: grid; gap: 10px; }
label { font-weight: 600; font-size: .9rem; }
input, textarea {
  font: inherit; width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
textarea { resize: vertical; line-height: 1.55; }
input:focus, textarea:focus, button:focus-visible { outline: 3px solid rgba(228, 2, 46, .25); outline-offset: 1px; border-color: var(--red); }

.btn { border: 0; border-radius: 8px; padding: 10px 16px; font-weight: 600; }
.btn.primary { background: var(--red); color: #fff; }
.btn.primary:hover { background: #c40027; }
.btn.secondary { background: #fff; color: var(--navy); border: 2px solid var(--navy); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn[disabled] { opacity: .55; cursor: progress; }
.link { background: none; border: 0; color: var(--navy); padding: 4px 0; font-weight: 600; }
.link.light { color: #fff; }
.link.small { font-size: .8rem; font-weight: 500; color: var(--muted); text-decoration: underline; }
.error { color: var(--red); margin: 0; font-weight: 600; }
.subtle { color: var(--muted); font-size: .85rem; margin: 0; }

.tabs { display: flex; gap: 6px; border-bottom: 2px solid var(--line); margin-bottom: 12px; }
.tab { background: none; border: 0; padding: 10px 14px; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -2px; }
.tab.active { color: var(--navy); border-bottom-color: var(--red); }
.count { display: inline-block; min-width: 1.6em; padding: 0 .45em; border-radius: 99px; background: var(--red); color: #fff; font-size: .8rem; text-align: center; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.row-item {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; background: #fff; border: 1px solid var(--line);
  border-left: 5px solid var(--navy); border-radius: var(--radius); padding: 12px 14px; cursor: pointer;
}
.row-item:hover { border-color: var(--navy); }
.row-item.late { border-left-color: var(--red); background: var(--late); }
.row-item .who { font-weight: 700; color: var(--navy); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-item .subj { grid-column: 1 / -1; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-item .meta { display: flex; gap: 8px; align-items: center; justify-self: end; }
.row-item .wait { font-size: .85rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
.row-item.late .wait { color: var(--red); }
.row-item .extra { grid-column: 1 / -1; font-size: .8rem; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.list-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 24px; }

.chip { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: .75rem; font-weight: 700; white-space: nowrap; background: #e8eef1; color: var(--navy); }
.chip.Complaint { background: #fde0e6; color: #9c0020; }
.chip.Cancellation { background: #002c41; color: #fff; }
.chip.Refund { background: #fff0cc; color: #6b4a00; }
.chip.Freeze { background: #dcefff; color: #0b4c7a; }
.chip.Payment { background: #fff4d6; color: #6b4a00; }
.chip.Joining { background: #dff5e6; color: #1b5e33; }
.chip.Access { background: #ece6ff; color: #45308f; }
.chip.Injury.clinic { background: #e2f4f4; color: #0e5959; }
.chip.Personal.training { background: #f3e8d8; color: #6a4214; }
.chip.Sent { background: #dff5e6; color: #1b5e33; }
.chip.Rejected { background: #eceae3; color: #5d6b73; }
.chip.Replied { background: #dcefff; color: #0b4c7a; }

.item-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin: 8px 0 16px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.thread { max-height: 75vh; overflow: auto; }
.msg { border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; background: var(--ivory); border: 1px solid var(--line); }
.msg.out { background: #eef3f5; }
.msg .mhead { font-size: .8rem; color: var(--muted); margin-bottom: 6px; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.msg .mhead strong { color: var(--navy); }
.msg .mbody { white-space: pre-wrap; word-break: break-word; }
.msg details { margin-top: 6px; font-size: .8rem; color: var(--muted); }
.msg details pre { white-space: pre-wrap; font-family: inherit; }
.notes { background: #fff7e0; border: 1px solid #f0d98a; border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; font-size: .9rem; }
.notes ul { margin: 4px 0 0 18px; padding: 0; }
.signoff { font-family: inherit; white-space: pre-line; color: var(--muted); font-size: .9rem; margin: 10px 0 0; padding: 10px 12px; border-left: 3px solid var(--line); }
.signoff img { display: block; margin: 4px 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; align-items: center; }
.rewrite { margin-top: 12px; display: grid; gap: 8px; }
.row { display: flex; gap: 12px; align-items: center; }

.group { margin-top: 20px; }
.group h2 { color: var(--navy); }

dialog { border: 0; border-radius: 12px; padding: 20px; width: min(760px, 94vw); }
dialog::backdrop { background: rgba(0, 44, 65, .55); }
.preview-meta { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: .9rem; }
.preview-meta dt { font-weight: 700; color: var(--navy); }
.preview-meta dd { margin: 0; word-break: break-all; }
#confirm-send { width: min(460px, 92vw); }
.confirm-text { font-size: 1.05rem; font-weight: 600; color: var(--navy); margin: 0 0 16px; overflow-wrap: anywhere; }
#pv-frame { width: 100%; height: 50vh; border: 1px solid var(--line); border-radius: 8px; margin: 12px 0; background: #fff; }

.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 8px; display: flex; gap: 12px; align-items: center; z-index: 20; max-width: calc(100vw - 32px); }
.toast button { background: none; border: 0; color: #fff; text-decoration: underline; font-weight: 700; }

@media (max-width: 820px) {
  .split { grid-template-columns: 1fr; }
  .thread { max-height: none; }
  .brand span { display: none; }
  .actions .btn { flex: 1 1 auto; }
}
