/* ATEP Chat. Mobile first: one pane at a time on a phone, list and conversation side by side on a wide screen.
   No inline styles (the page runs under a strict CSP); the few dynamic sizes are set through CSSOM in the script. */
:root {
  --bg: #080d12;
  --panel: #0f1822;
  --panel2: #142130;
  --line: #243646;
  --text: #dbe7f1;
  --muted: #93a8ba;
  --accent: #4cc9f0;
  --ok: #5ee38b;
  --bad: #ff6b6b;
  --warn: #ffc857;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  --out1: #1d3a52;
  --out2: #16293b;
  --in: #172636;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; height: 100%; }
body { margin: 0; height: 100%; background: radial-gradient(900px 500px at 50% -10%, #10202e 0%, var(--bg) 62%) var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
a { color: var(--accent); }
code { font: 0.9em var(--mono); background: #0a131b; padding: 0.1em 0.35em; border-radius: 5px; color: #bfe6f9; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
button, input, textarea { font: inherit; color: var(--text); }
button { cursor: pointer; touch-action: manipulation; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---- start and unlock screens ---- */
.screen { min-height: 100%; padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); }
.center { display: grid; place-items: center; }
.panel { background: linear-gradient(180deg, var(--panel2), var(--panel)); border: 1px solid var(--line); border-radius: 18px; padding: 18px 18px 20px; width: 100%; }
.narrow { max-width: 30rem; padding: 28px 22px 24px; }
.brand { text-align: center; margin: 0.2rem 0 0.9rem; }
/* The JPEG has a near-black background: "lighten" keeps whichever is brighter per pixel, so the card shows through and no dark box sits around the wordmark. */
.wordmark { display: block; margin: 0 auto; width: min(100%, 14rem); height: auto; mix-blend-mode: lighten; }
.wm-sub { display: flex; align-items: center; justify-content: center; gap: 0.8rem; margin: 0.15rem 0 0; color: #8fb3c9; font-size: 0.8rem; font-weight: 600; letter-spacing: 0.4em; text-transform: uppercase; }
.wm-sub::before, .wm-sub::after { content: ""; width: 2rem; height: 1px; background: linear-gradient(90deg, transparent, #2c4358); }
.wm-sub::after { transform: scaleX(-1); }
.wm-sub span { margin-right: -0.4em; } /* the last letter-space would push the word off centre */
.panel .lead { text-align: center; }
.h1 { margin: 0; font-size: 1.5rem; }
h2 { margin: 0; }
.lead { color: var(--muted); margin: 8px 0 10px; }
.notes { color: #c9d6e2; font-size: 0.93rem; padding-left: 1.1rem; margin: 0 0 14px; }
.notes li { margin: 0.3rem 0; }
.form { display: grid; gap: 12px; position: relative; }
/* The hidden username field (it lets a password manager file the password): out of sight, and never wide enough to scroll the page. */
input.sr[type="text"] { width: 1px; height: 1px; min-height: 0; padding: 0; border: 0; opacity: 0; pointer-events: none; }
.field { display: grid; gap: 4px; }
.field > span { font-weight: 600; font-size: 0.95rem; }
.field small, .fine, .muted { color: var(--muted); font-size: 0.88rem; }
input[type="password"], input[type="text"], textarea { width: 100%; background: #0a131b; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; min-height: 48px; }
/* The file picker: a themed button and a file-name area over the native input (kept for forms and assistive technology). */
.field, .form, .sheetbody > *, .tabs { min-width: 0; } /* let long content (file names) shrink inside a grid instead of widening the card */
.filepick { min-width: 0; max-width: 100%; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 58px; padding: 8px; background: #0a131b; border: 1px dashed #2c4358; border-radius: 14px; transition: border-color 0.15s, background 0.15s, box-shadow 0.15s; }
.filepick:hover, .filepick.drag { border-color: var(--accent); background: #0c1822; }
.filepick.drag { box-shadow: 0 0 0 3px rgba(76, 201, 240, 0.25); }
.filepick.has-file { border-style: solid; border-color: #1d4a35; }
.filebtn { flex: none; min-height: 42px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--accent); background: linear-gradient(180deg, #1d3a52, #16293b); color: var(--text); font-weight: 600; transition: box-shadow 0.15s, filter 0.15s; }
.filebtn:hover { box-shadow: 0 0 18px -4px rgba(76, 201, 240, 0.75); filter: brightness(1.12); }
.filename { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 0.92rem; }
.filepick.has-file .filename { color: var(--text); }
.filepick.has-file .filename::before { content: "\2713  "; color: var(--ok); font-weight: 700; }
.err { color: var(--bad); margin: 0; font-size: 0.93rem; }
.primary { background: linear-gradient(180deg, #1d3a52, #16293b); border: 1px solid var(--accent); border-radius: 12px; padding: 12px 16px; min-height: 48px; }
.primary.big { min-height: 54px; font-weight: 600; font-size: 1.05rem; box-shadow: 0 0 34px -14px rgba(76, 201, 240, 0.9); }
.primary:disabled { opacity: 0.55; cursor: progress; }
.fine.center-text { text-align: center; }
.linkish { background: none; border: 0; padding: 6px 0; color: var(--accent); text-decoration: underline; }

/* ---- the app ---- */
.app { height: 100dvh; display: grid; grid-template-columns: 1fr; grid-template-rows: 1fr; max-width: 70rem; margin: 0 auto; }
.pane { min-height: 0; display: flex; flex-direction: column; background: var(--bg); }
.app[data-view="list"] .thread { display: none; }
.app[data-view="thread"] .list { display: none; }
.bar { flex: none; display: flex; align-items: center; gap: 6px; padding: max(8px, env(safe-area-inset-top)) 10px 8px 14px; background: linear-gradient(180deg, #121f2c, #0e1822); border-bottom: 1px solid var(--line); min-height: 58px; }
.title { flex: 1; font-size: 1.35rem; }
.icon { flex: none; width: 44px; height: 44px; padding: 0; display: grid; place-items: center; background: transparent; border: 0; border-radius: 50%; font-size: 1.5rem; line-height: 1; color: var(--text); }
.icon svg { display: block; }
.icon:hover { background: #162433; }

.searchbar { flex: none; padding: 8px 12px; background: #0b141d; border-bottom: 1px solid #14212d; }
.searchbar input { width: 100%; min-height: 40px; padding: 8px 14px; border-radius: 20px; background: #0a131b; border: 1px solid var(--line); -webkit-appearance: none; appearance: none; }
.searchbar input::-webkit-search-cancel-button { filter: invert(0.8); cursor: pointer; }
.contacts:empty { display: none; }
.nomatch { padding: 18px 16px; display: grid; gap: 10px; justify-items: start; }
.nomatch p { margin: 0; overflow-wrap: anywhere; }
.nomatch[hidden] { display: none; }
.contacts { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.contact { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 14px; min-height: 68px; background: none; border: 0; border-bottom: 1px solid #14212d; text-align: left; }
.contact:hover, .contact[aria-current="true"] { background: #101c28; }
.avatar { flex: none; width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #06131b; letter-spacing: 0.02em; }
.avatar.small { width: 32px; height: 32px; font-size: 0.85rem; }
.av-0 { background: #4cc9f0; } .av-1 { background: #8ae234; } .av-2 { background: #c792ea; } .av-3 { background: #ffb454; }
.av-4 { background: #ff7fbf; } .av-5 { background: #5ee38b; } .av-6 { background: #7aa2ff; } .av-7 { background: #ffd166; }
.ctext { flex: 1; min-width: 0; display: grid; gap: 1px; }
.crow { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.cname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctime { color: var(--muted); font-size: 0.78rem; flex: none; }
.cprev { color: var(--muted); font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { flex: none; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--accent); color: #04101a; font-size: 0.8rem; font-weight: 700; display: grid; place-items: center; }
.pad { padding: 16px; }

.thread { position: relative; }
.empty { flex: 1; display: none; place-items: center; color: var(--muted); padding: 24px; text-align: center; }
#thread-live { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.back { font-size: 1.4rem; }
.who { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; background: none; border: 0; text-align: left; padding: 2px 4px; border-radius: 12px; }
.whotext { display: grid; min-width: 0; }
.name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub { color: var(--muted); font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* The chat background (set in Settings) sits behind the messages, under a soft dark tint so the text stays readable. */
.messages.has-wall .day, .messages.has-wall .note { background: rgba(8, 13, 18, 0.72); padding: 3px 12px; border-radius: 999px; }
.messages.has-wall .meta { color: #cbd7e2; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8); }
.messages { list-style: none; margin: 0; padding: 12px 12px 6px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; -webkit-overflow-scrolling: touch; }
.day { align-self: center; color: var(--muted); font-size: 0.78rem; padding: 6px 0 2px; }
.msg { max-width: min(82%, 34rem); display: grid; gap: 3px; }
.msg.out { align-self: flex-end; }
.msg.in { align-self: flex-start; }
.bubble { padding: 9px 13px; border-radius: 18px; white-space: pre-wrap; overflow-wrap: anywhere; }
.out .bubble { background: linear-gradient(180deg, var(--out1), var(--out2)); border-bottom-right-radius: 5px; border: 1px solid rgba(76, 201, 240, 0.45); box-shadow: 0 4px 14px -10px rgba(0, 0, 0, 0.8); }
.in .bubble { background: var(--in); border: 1px solid #20344a; border-bottom-left-radius: 5px; }
.meta { font-size: 0.74rem; color: var(--muted); padding: 0 6px; display: flex; gap: 8px; flex-wrap: wrap; }
.out .meta { justify-content: flex-end; }
.ok { color: var(--ok); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; padding: 2px 0 4px; }
.chip { min-height: 38px; padding: 6px 12px; border-radius: 999px; background: #112232; border: 1px solid #2c4358; font-size: 0.85rem; }
.chip:hover { border-color: var(--accent); }
.note { align-self: center; max-width: 92%; text-align: center; font-size: 0.82rem; color: var(--warn); background: #1c1a12; border: 1px solid #4a3d18; border-radius: 12px; padding: 6px 12px; }

.composer { flex: none; display: flex; align-items: flex-end; gap: 12px; padding: 12px 16px max(14px, env(safe-area-inset-bottom)); background: #0e1822; border-top: 1px solid var(--line); }
.composer textarea { flex: 1; min-width: 0; resize: none; min-height: 44px; max-height: 9rem; border-radius: 22px; padding: 10px 18px; line-height: 1.35; }
/* The focus ring stays inside the gap to the neighbouring buttons instead of crowding them. */
.composer textarea:focus-visible { outline-offset: 0; outline-width: 2px; }
.composer .icon, .composer .send { margin-bottom: 0; }
.send { flex: none; width: 46px; height: 46px; border-radius: 50%; border: 0; background: linear-gradient(180deg, #2a9cc7, #1d6f94); font-size: 1.2rem; display: grid; place-items: center; box-shadow: 0 0 18px -6px rgba(76, 201, 240, 0.9); }
.send:disabled { opacity: 0.5; }

/* ---- sheets ---- */
.sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.backdrop { position: absolute; inset: 0; background: rgba(2, 6, 10, 0.66); }
.sheet .card { position: relative; width: 100%; max-width: 34rem; max-height: 90dvh; overflow-y: auto; background: linear-gradient(180deg, var(--panel2), var(--panel)); border: 1px solid var(--line); border-radius: 20px 20px 0 0; padding: 6px 16px max(16px, env(safe-area-inset-bottom)); }
.sheethead { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--panel2); padding: 8px 0; }
.sheethead h2 { margin: 0; font-size: 1.15rem; }
.sheetbody { display: grid; gap: 12px; padding-bottom: 6px; }
.sheetbody p { margin: 0; }
/* An Agent ID is 57 characters: it always fits on one line. The box is a size container and the text scales to its width (a monospace character is about 0.6em wide); the whole ID is still selected and copied. */
.idbox { container-type: inline-size; background: #0a131b; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; user-select: all; margin: 0; }
.idtext { display: block; white-space: nowrap; overflow: hidden; font: 600 min(1rem, 0.78rem) / 1.6 var(--mono); font-size: min(1rem, calc(100cqw / 36.5)); color: #bfefff; }
/* Only when the one-line text would drop below about 9.5px (a narrow phone) does the ID wrap to two readable lines instead. */
@container (max-width: 345px) { .idtext { white-space: normal; overflow-wrap: anywhere; word-break: break-all; font-size: 0.8rem; } }
.idbox .p { color: var(--muted); font-weight: 400; }
.row { display: grid; gap: 8px; grid-template-columns: 1fr; }
/* The profile's key buttons: two by two at every width (a lone last one spans the row). */
.row.pair { grid-template-columns: 1fr 1fr; }
.row.pair > :last-child:nth-child(odd) { grid-column: 1 / -1; }
.btn { min-height: 48px; padding: 10px 14px; background: #162433; border: 1px solid #2c4358; border-radius: 12px; }
.btn:hover { border-color: var(--accent); }
.btn.danger { border-color: #5a2a2e; color: #ffb4b4; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tab { min-height: 44px; border-radius: 12px; background: #0e1822; border: 1px solid var(--line); }
.tab[aria-selected="true"] { border-color: var(--accent); background: #12293a; }
textarea.big { min-height: 7rem; border-radius: 12px; font-family: var(--mono); font-size: 0.8rem; }

.toast { position: fixed; left: 50%; top: max(12px, env(safe-area-inset-top)); transform: translateX(-50%); z-index: 30; max-width: min(92vw, 30rem); margin: 0; padding: 10px 16px; background: #10202e; border: 1px solid var(--accent); border-radius: 14px; box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.8); }

/* ---- wide screens: list and conversation side by side ---- */
@media (min-width: 52rem) {
  .app { grid-template-columns: 22rem 1fr; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .app[data-view="list"] .thread, .app[data-view="thread"] .list { display: flex; }
  .list { border-right: 1px solid var(--line); }
  .back { display: none; }
  .empty { display: grid; }
  .thread.has-chat .empty { display: none; }
  .sheet { align-items: center; }
  .sheet .card { border-radius: 20px; }
  .row { grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); }
  .row.pair { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: no-preference) {
  .msg { animation: rise 0.18s ease-out; }
  .sheet .card { animation: sheet 0.2s ease-out; }
  @keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
  @keyframes sheet { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
}

/* ---- settings ---- */
.setting { display: grid; gap: 14px; min-width: 0; }
.setting h3 { margin: 0; font-size: 1.05rem; }
.setting p { margin: 0; }
.setting .head { display: grid; gap: 4px; }
.wallprev { height: 9.5rem; border-radius: 14px; border: 1px solid var(--line); background-color: #0a131b; background-repeat: no-repeat; background-position: center; display: grid; place-items: center; color: var(--muted); font-size: 0.9rem; overflow: hidden; }
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (min-width: 32rem) { .modes { grid-template-columns: repeat(5, 1fr); } }
.mode { min-width: 0; min-height: 42px; padding: 8px 10px; border-radius: 12px; background: #0e1822; border: 1px solid var(--line); }
.mode:hover { border-color: var(--accent); }
.mode[aria-pressed="true"] { border-color: var(--accent); background: #12293a; box-shadow: 0 0 0 1px rgba(76, 201, 240, 0.35); }
.mode:disabled { opacity: 0.45; cursor: not-allowed; }
.modehint { min-height: 2.6em; }

/* ---- the window background (Settings): a fixed layer behind everything, with the panels made see-through so it shows ---- */
.window-bg { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
.screen, .app { position: relative; z-index: 1; }
body.has-window .pane { background: rgba(8, 13, 18, 0.58); }
body.has-window .bar { background: linear-gradient(180deg, rgba(18, 31, 44, 0.84), rgba(14, 24, 34, 0.84)); }
body.has-window .searchbar { background: rgba(11, 20, 29, 0.72); }
body.has-window .composer { background: rgba(14, 24, 34, 0.84); }
body.has-window .contact:hover, body.has-window .contact[aria-current="true"] { background: rgba(16, 28, 40, 0.85); }
body.has-window .contact { border-bottom-color: rgba(36, 54, 70, 0.6); }
body.has-window .empty { color: #cbd7e2; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8); }
.sheetbody { gap: 18px; }
.setting + .setting { padding-top: 18px; border-top: 1px solid var(--line); }

/* The hosted copy adds the atep.dev site footer; the chat is an app screen, so it shows none. */
body .atep-site-foot { display: none; }
