/* Minimal chat UI — themed per tenant via --accent from /theme.css */
:root {
    --accent: #7c5cff;
    --bg: #f5f6f8;
    --fg: #1c1e24;
    --card: #ffffff;
    --muted: #6b7280;
    --line: #e5e7eb;
    --radius: 12px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
    color: var(--fg);
    background: var(--bg);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.5rem; margin: 0 0 .5rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.status { min-height: 1.2em; margin: .5rem 0 0; font-size: .9rem; }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.5rem;
}

/* ---------- landing / login ---------- */
.page-landing main, .page-login main {
    max-width: 30rem;
    margin: 8vh auto;
}

form label { display: block; margin: .75rem 0; font-size: .9rem; }
input, textarea {
    display: block;
    width: 100%;
    margin-top: .25rem;
    padding: .55rem .7rem;
    font: inherit;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }

button {
    font: inherit;
    padding: .55rem 1.1rem;
    border: 0;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
}
button:disabled { opacity: .5; cursor: default; }
button.ghost {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--line);
}

.hp-field { position: absolute; left: -9999px; top: -9999px; }
.admin-login { margin-top: 1.5rem; }
.admin-login summary { color: var(--muted); cursor: pointer; font-size: .85rem; }

/* ---------- app shell ---------- */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .6rem 1rem;
    background: var(--card);
    border-bottom: 1px solid var(--line);
}
.topbar .brand { font-weight: 600; color: var(--fg); }
.topbar nav { display: flex; gap: .75rem; align-items: center; }

.app-main { max-width: 46rem; margin: 1.25rem auto; padding: 0 1rem; }

/* ---------- conversation list ---------- */
.conv-list { list-style: none; margin: 0; padding: 0; }
.conv-list .empty { padding: .75rem 0; }
.conv-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    grid-template-areas: "title when badge" "sub when badge";
    gap: 0 .6rem;
    padding: .65rem .4rem;
    border-bottom: 1px solid var(--line);
    color: var(--fg);
    border-radius: 6px;
}
.conv-row:hover { background: var(--bg); text-decoration: none; }
.conv-row.closed { opacity: .6; }
.conv-title { grid-area: title; font-weight: 550; }
.conv-sub { grid-area: sub; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 28rem; }
.conv-when { grid-area: when; align-self: center; }
.badge {
    grid-area: badge;
    align-self: center;
    background: var(--accent);
    color: #fff;
    font-size: .75rem;
    border-radius: 99px;
    padding: .1rem .5rem;
    min-width: 1.4rem;
    text-align: center;
}
.tag {
    grid-area: badge;
    align-self: center;
    font-size: .7rem;
    color: var(--muted);
    border: 1px solid var(--line);
    border-radius: 99px;
    padding: .05rem .5rem;
}

/* ---------- thread ---------- */
.thread-card { display: flex; flex-direction: column; height: calc(100vh - 8rem); padding: 0; }
.thread-head {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--line);
}
.thread-title { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-box { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}
.msg { max-width: 75%; padding: .5rem .75rem; border-radius: var(--radius); }
.msg .meta { font-size: .72rem; color: var(--muted); margin-bottom: .15rem; }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.mine {
    align-self: flex-end;
    background: var(--accent);
    color: #fff;
}
.msg.mine .meta { color: rgba(255, 255, 255, .75); }
.msg.theirs { align-self: flex-start; background: var(--bg); }
.msg.system {
    align-self: center;
    font-size: .8rem;
    color: var(--muted);
    background: transparent;
    padding: .15rem .5rem;
}
.msg.pending { opacity: .6; }
.msg.failed { outline: 2px solid #e11d48; opacity: .8; }

.new-pill {
    position: absolute;
    bottom: 4.5rem;
    left: 50%;
    transform: translateX(-50%);
    font-size: .8rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, .15);
}
.new-pill.hidden { display: none; }

.composer {
    display: flex;
    gap: .5rem;
    padding: .75rem;
    border-top: 1px solid var(--line);
}
.composer textarea { resize: none; max-height: 200px; margin: 0; flex: 1; }
.composer button { align-self: flex-end; }
