:root {
  --navy: #0c2238;
  --ink: #1b2733;
  --muted: #626d78;
  --line: #dfe4e9;
  --line-strong: #c8d1d9;
  --bg: #f4f6f8;
  --white: #ffffff;
  --blue: #1f5f9e;
  --blue-soft: #eef4fa;
  --red: #9b2c2c;
  --red-soft: #fdf0f0;
  --green: #246b4b;
  --green-soft: #edf7f1;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
a:hover { color: var(--blue); }
p { margin: 0 0 1rem; }
h1, h2, h3 { margin: 0; color: var(--navy); line-height: 1.18; letter-spacing: -0.02em; }
h1 { font-size: clamp(1.8rem, 3.4vw, 2.6rem); font-weight: 650; }
h2 { font-size: 1.3rem; font-weight: 650; }

:focus-visible { outline: 3px solid rgba(31, 95, 158, 0.5); outline-offset: 3px; }

.app-header { background: var(--navy); color: rgba(255, 255, 255, 0.8); }
.app-header-inner {
  display: flex; align-items: center; justify-content: space-between; gap: 2rem;
  width: min(calc(100% - 2.5rem), 1100px); margin-inline: auto; min-height: 4.4rem;
}
.brand { color: #fff; font-size: 1.02rem; font-weight: 700; }
.brand .amp { color: #d0aa6b; }
.brand-sub {
  margin-left: 0.45rem; padding: 0.12rem 0.4rem; border: 1px solid rgba(255,255,255,0.3);
  color: rgba(255,255,255,0.66); font-size: 0.6rem; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase;
}
.signout {
  padding: 0.45rem 0.75rem; border: 1px solid rgba(255,255,255,0.3); background: transparent;
  color: #fff; font: inherit; font-size: 0.82rem; cursor: pointer;
}
.signout:hover { background: rgba(255,255,255,0.08); }

.app-main { padding-block: 2.5rem 5rem; }
.app-content { width: min(calc(100% - 2.5rem), 1100px); margin-inline: auto; }
.eyebrow {
  margin: 0 0 0.6rem; color: var(--blue); font-size: 0.68rem; font-weight: 700;
  letter-spacing: 0.16em; text-transform: uppercase;
}
.muted { color: var(--muted); }
.page-head { margin-bottom: 2rem; }
.page-head p:last-child { margin-top: 0.5rem; }

.button {
  display: inline-flex; align-items: center; justify-content: center; min-height: 2.75rem;
  padding: 0.65rem 1.15rem; border: 1px solid var(--blue); background: var(--blue);
  color: #fff; font: inherit; font-size: 0.9rem; font-weight: 650; cursor: pointer;
}
.button:hover { background: #174a7c; border-color: #174a7c; color: #fff; }

.alert { margin-bottom: 1.3rem; padding: 0.85rem 1rem; border: 1px solid; font-size: 0.92rem; }
.alert-error { border-color: #e3b8b8; background: var(--red-soft); color: var(--red); }
.alert-notice { border-color: #b9d8c6; background: var(--green-soft); color: var(--green); }

.login-wrap { display: grid; place-items: center; min-height: 100vh; padding: 1.5rem; }
.login-card {
  width: min(100%, 26rem); padding: 2.2rem; background: var(--white);
  border: 1px solid var(--line); border-top: 4px solid var(--navy);
}
.login-card h1 { margin-bottom: 0.5rem; }
.login-card > .muted { font-size: 0.92rem; }
.login-card .alert { margin-top: 1.2rem; }
.login-form { display: grid; gap: 0.55rem; margin-top: 1.5rem; }
.login-form label, .reply-form label {
  color: var(--navy); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
}
.login-form input, .reply-form textarea {
  width: 100%; padding: 0.7rem 0.8rem; border: 1px solid var(--line-strong);
  border-radius: 0; background: #fff; color: var(--ink); font: inherit;
}
.login-form input:focus, .reply-form textarea:focus {
  border-color: var(--blue); outline: 3px solid rgba(31, 95, 158, 0.15); outline-offset: 0;
}
.login-form .button { margin-top: 0.8rem; }

.thread-list { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.thread-list li { border-bottom: 1px solid var(--line); }
.thread-row {
  display: grid; grid-template-columns: minmax(0, 1fr) 13.5rem; gap: 2rem;
  padding: 1.15rem 0.4rem; background: transparent;
}
.thread-row:hover { background: var(--white); color: inherit; }
.thread-main { display: grid; gap: 0.2rem; min-width: 0; }
.thread-subject { color: var(--navy); font-weight: 650; }
.thread-applicant { color: var(--ink); font-size: 0.9rem; }
.thread-preview { color: var(--muted); font-size: 0.86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-side { display: grid; justify-items: end; align-content: start; gap: 0.28rem; font-size: 0.78rem; }
.thread-to, .thread-date, .thread-count { color: var(--muted); }
.reference {
  padding: 0.18rem 0.42rem; border: 1px solid #c7d8e8; background: var(--blue-soft);
  color: var(--blue); font-size: 0.68rem; font-weight: 700; letter-spacing: 0.08em;
}
.reference-muted { border-color: var(--line); background: #f0f2f4; color: var(--muted); }

.empty {
  padding: 3rem 2rem; background: var(--white); border: 1px solid var(--line); text-align: center;
}
.empty h1, .empty h2 { margin-bottom: 0.7rem; }
.empty .button { margin-top: 0.7rem; }

.back-link { display: inline-block; margin-bottom: 1.5rem; color: var(--muted); font-size: 0.86rem; font-weight: 600; }
.thread-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 2rem;
  padding-bottom: 1.5rem; margin-bottom: 1.5rem; border-bottom: 1px solid var(--line);
}
.thread-head h1 { max-width: 26ch; }
.thread-details { margin: 0.7rem 0 0; color: var(--muted); font-size: 0.9rem; }
.thread-head-side { display: grid; justify-items: end; gap: 0.4rem; font-size: 0.8rem; }

.messages { display: grid; gap: 1rem; }
.message {
  padding: 1.2rem 1.3rem; background: var(--white); border: 1px solid var(--line);
}
.message-out { background: var(--blue-soft); border-color: #cbdbea; }
.message-head { display: flex; align-items: center; flex-wrap: wrap; gap: 0.6rem; padding-bottom: 0.7rem; margin-bottom: 0.8rem; border-bottom: 1px solid rgba(0,0,0,0.08); }
.message-person { font-size: 0.86rem; }
.message-head time { margin-left: auto; color: var(--muted); font-size: 0.78rem; }
.badge { padding: 0.16rem 0.42rem; font-size: 0.62rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; }
.badge-in { background: #eef1f4; color: var(--muted); }
.badge-out { background: #dcebf7; color: var(--blue); }
.message-text {
  margin: 0; white-space: pre-wrap; overflow-wrap: anywhere;
  font-family: var(--sans); font-size: 0.93rem; line-height: 1.6;
}
.message-html { width: 100%; height: 26rem; border: 1px solid var(--line); background: #fff; }
.attachments { margin-top: 1rem; padding-top: 0.8rem; border-top: 1px solid rgba(0,0,0,0.08); }
.attachments-title { margin: 0 0 0.4rem; color: var(--muted); font-size: 0.68rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; }
.attachments ul { margin: 0; padding: 0; list-style: none; }
.attachments li { margin-bottom: 0.3rem; font-size: 0.88rem; }
.attachments a { color: var(--blue); text-decoration: underline; text-underline-offset: 2px; }
.attachment-size { margin-left: 0.4rem; color: var(--muted); font-size: 0.76rem; }
.raw-link { display: inline-block; margin-top: 0.8rem; color: var(--muted); font-size: 0.78rem; text-decoration: underline; }

.reply-panel { margin-top: 2rem; padding: 1.6rem; background: var(--white); border: 1px solid var(--line); border-top: 3px solid var(--navy); }
.reply-panel h2 { margin-bottom: 0.4rem; }
.reply-panel > .muted { font-size: 0.88rem; }
.reply-form { display: grid; gap: 0.5rem; margin-top: 1.1rem; }
.reply-form textarea { resize: vertical; min-height: 10rem; }
.form-actions { display: flex; justify-content: flex-end; margin-top: 0.5rem; }

@media (max-width: 820px) {
  .thread-row { grid-template-columns: 1fr; gap: 0.6rem; }
  .thread-side { display: flex; flex-wrap: wrap; justify-content: flex-start; gap: 0.5rem 0.8rem; }
  .thread-head { flex-direction: column; gap: 1rem; }
  .thread-head-side { justify-items: start; }
}

@media (max-width: 600px) {
  .app-header-inner { align-items: flex-start; flex-direction: column; gap: 0.5rem; padding-block: 0.9rem; }
  .app-main { padding-block: 1.5rem 3rem; }
  .app-content { width: min(calc(100% - 1.5rem), 1100px); }
  .thread-side { display: flex; }
  .message { padding: 1rem; }
  .message-head time { width: 100%; margin-left: 0; }
}
