:root {
    --brand: #2563eb;
    --border: #e4e7ec;
    --muted: #667085;
    --bg: #f9fafb;
    --text: #101828;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

/* ---- chrome ---------------------------------------------------------------- */

.topbar {
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand { font-weight: 700; font-size: 16px; color: var(--text); text-decoration: none; }

.nav { display: flex; align-items: center; gap: 18px; }
.nav a { color: var(--muted); text-decoration: none; font-weight: 500; }
.nav a:hover { color: var(--text); }
.nav .who { color: var(--muted); font-size: 13px; }

.main { max-width: 1040px; margin: 0 auto; padding: 24px; }

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 18px;
}
.page-header h1 { margin: 2px 0; font-size: 22px; }

.filters { display: flex; gap: 8px; }

/* ---- flashes --------------------------------------------------------------- */

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; font-weight: 500; }
.flash-ok { background: #ecfdf3; color: #027a48; border: 1px solid #abefc6; }
.flash-err { background: #fef3f2; color: #b42318; border: 1px solid #fecdca; }

/* ---- tables ---------------------------------------------------------------- */

.tbl { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--border); background: #fcfcfd; }
.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl a { color: var(--brand); text-decoration: none; font-weight: 500; }
.tbl a:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.empty { background: #fff; border: 1px dashed var(--border); border-radius: 8px; padding: 40px; text-align: center; color: var(--muted); }

.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
.snippet { font-size: 12px; background: #f2f4f7; padding: 3px 6px; border-radius: 4px; word-break: break-all; }

/* ---- badges ---------------------------------------------------------------- */

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-open { background: #eff8ff; color: #175cd3; }
.badge-pending { background: #fffaeb; color: #b54708; }
.badge-resolved { background: #ecfdf3; color: #027a48; }
.badge-closed { background: #f2f4f7; color: #475467; }

/* ---- cards / forms --------------------------------------------------------- */

.card { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 24px; }
.card-narrow { max-width: 400px; margin: 60px auto; }
.card h1 { margin: 0 0 18px; font-size: 20px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.field input, .field textarea, select, textarea {
    width: 100%; padding: 9px 11px; border: 1px solid #d0d5dd; border-radius: 6px;
    font-size: 14px; font-family: inherit; color: var(--text); background: #fff;
}
select { width: auto; padding-right: 28px; }
.field input:focus, .field textarea:focus, textarea:focus, select:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
.field input[readonly] { background: #f9fafb; color: var(--muted); }
.color-input { height: 38px; padding: 3px; width: 80px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.err { color: #b42318; font-size: 13px; }

.btn {
    display: inline-block; padding: 9px 14px; border-radius: 6px; border: 1px solid #d0d5dd;
    background: #fff; color: var(--text); font-size: 14px; font-weight: 600;
    cursor: pointer; text-decoration: none; font-family: inherit;
}
.btn:hover { background: #f9fafb; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { filter: brightness(1.06); background: var(--brand); }
.btn-sm { padding: 5px 10px; font-size: 13px; }

/* ---- thread ---------------------------------------------------------------- */

.thread { display: grid; gap: 12px; margin-bottom: 20px; }

.msg { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; }
.msg-in { border-left: 3px solid #98a2b3; }
.msg-out { border-left: 3px solid var(--brand); background: #fcfcff; }
.msg-hdr { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; font-size: 13px; }
.msg-body { white-space: pre-wrap; }

.reply-form { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 16px; }
.reply-form label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.reply-form textarea { margin-bottom: 10px; resize: vertical; }

.status-form select { min-width: 120px; }

/* ---- public reply page ----------------------------------------------------- */

.public-wrap { max-width: 640px; margin: 40px auto; padding: 0 16px; }
.public-card { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 24px; }
.public-card.center { text-align: center; padding: 48px 24px; }
.public-card h1 { font-size: 20px; margin: 4px 0 16px; }
.public-hdr { border-bottom: 1px solid var(--border); padding-bottom: 14px; margin-bottom: 18px; }

/* ---- reply page: refresh bar + live updates ------------------------------- */

.thread-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
    font-size: 13px;
}
.thread-bar .btn { flex: none; }

/* New messages arriving via polling get a brief highlight so they aren't missed. */
.msg-new {
    animation: msg-arrive 4s ease-out;
}
@keyframes msg-arrive {
    0%   { background: #fffaeb; border-color: #fec84b; }
    100% { background: inherit; border-color: var(--border); }
}

@media (prefers-reduced-motion: reduce) {
    .msg-new { animation: none; box-shadow: inset 3px 0 0 #fec84b; }
}

/* ---- attachments ------------------------------------------------------------ */

.attachments { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.attachment {
    display: inline-flex; align-items: center; gap: 8px; max-width: 100%;
    padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px;
    background: #fff; color: var(--text); text-decoration: none; font-size: 13px;
}
a.attachment:hover { border-color: var(--brand); }
.attachment-type {
    font-size: 10px; font-weight: 700; letter-spacing: .04em; padding: 2px 5px;
    border-radius: 4px; background: #f2f4f7; color: #475467;
}
.attachment-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.attachments.pending { margin: 0 0 10px; }

.attach-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.attach-btn { cursor: pointer; }
.hint-inline { font-size: 12px; }
.reply-form .err { margin-bottom: 10px; }

.visually-hidden {
    position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
/* The input stays keyboard-reachable; show its focus on the visible button. */
.attach-row:focus-within .attach-btn { outline: 2px solid var(--brand); outline-offset: 2px; }
