:root {
  --navy: #2a4e68; --navy-dark: #1d3a50; --navy-soft: #e4ecf2;
  --cream: #f7efe5; --paper: #fffcf7; --ink: #1c2833; --muted: #566370;
  --line: #ddd5c4; --accent: #9c4221; --accent-soft: #f6e4d8; --ok: #2f6b3f;
  --radius: 14px;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: var(--sans); font-size: 1rem; line-height: 1.5; color: var(--ink); background: var(--cream); overscroll-behavior: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
:focus-visible { outline: 3px solid #e0a100; outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
#app { height: 100%; }

.btn { border: 0; border-radius: 10px; padding: 10px 16px; background: var(--navy); color: #fff; font-weight: 600; cursor: pointer; min-height: 44px; }
.btn:hover { background: var(--navy-dark); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: transparent; color: var(--navy); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--navy-soft); }
.btn.danger { background: var(--accent); }
.btn { white-space: nowrap; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.field { display: block; margin: 0 0 14px; }
.field > span { display: block; font-weight: 600; margin-bottom: 4px; font-size: .95rem; }
.field input, .field select, .field textarea { width: 100%; padding: 10px 12px; border: 1px solid #b9b19f; border-radius: 10px; background: #fff; min-height: 44px; }
.hint { color: var(--muted); font-size: .9rem; margin: 4px 0 0; }
.error { color: #8a1c1c; background: #fbe9e7; border-radius: 10px; padding: 8px 12px; margin: 0 0 12px; }
.notice { background: var(--navy-soft); border-radius: 10px; padding: 10px 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* sign-in and centred cards */
.center { min-height: 100%; display: grid; place-items: center; padding: 20px 16px; }
.card { width: min(100%, 420px); background: var(--paper); border: 1px solid var(--line); border-radius: 18px; padding: 26px 22px; box-shadow: 0 6px 24px rgba(29,58,80,.08); }
.card h1 { font-size: 1.35rem; margin: 10px 0 4px; color: var(--navy); text-align: center; }
.card .sub { text-align: center; color: var(--muted); margin: 0 0 20px; }
.card .logo { height: 84px; width: auto; margin: 0 auto; }
.card .btn { width: 100%; }
.lock-note { margin-top: 16px; font-size: .85rem; color: var(--muted); text-align: center; }

/* main layout */
.shell { height: 100%; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 10px; background: var(--paper); border-bottom: 3px solid var(--navy); padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
.topbar img { height: 38px; width: auto; }
.topbar h1 { margin: 0; font-size: 1.05rem; color: var(--navy); line-height: 1.2; }
.topbar .who { font-size: .8rem; color: var(--muted); }
.tabs { display: flex; gap: 4px; }
.tab { border: 0; background: transparent; padding: 8px 12px; border-radius: 8px; font-weight: 600; color: var(--navy); cursor: pointer; min-height: 40px; }
.tab[aria-current="page"] { background: var(--navy-soft); }
.main { flex: 1; min-height: 0; display: flex; }
.sidebar { width: 320px; flex: none; background: var(--paper); border-right: 1px solid var(--line); overflow-y: auto; }
.convo { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.facility-item { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: transparent; padding: 12px 14px; cursor: pointer; min-height: 64px; }
.facility-item:hover, .facility-item[aria-current="true"] { background: var(--navy-soft); }
.facility-item .name { font-weight: 700; display: block; }
.facility-item .prev { display: block; color: var(--muted); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.facility-item .meta { min-width: 0; flex: 1; }
.badge { background: var(--accent); color: #fff; border-radius: 999px; padding: 1px 8px; font-size: .8rem; font-weight: 700; min-width: 22px; text-align: center; }
.convo-head { padding: 10px 14px; background: var(--paper); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.convo-head h2 { margin: 0; font-size: 1.05rem; color: var(--navy); }
.back { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 8px; overscroll-behavior: contain; }
.empty { margin: auto; color: var(--muted); text-align: center; padding: 20px; }
.msg { max-width: min(78%, 560px); padding: 8px 12px; border-radius: 16px; background: var(--paper); border: 1px solid var(--line); align-self: flex-start; overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.mine { align-self: flex-end; background: var(--navy); color: #fff; border-color: var(--navy); }
.msg .by { display: block; font-size: .78rem; font-weight: 700; opacity: .8; margin-bottom: 2px; white-space: normal; }
.msg .at { display: block; font-size: .72rem; opacity: .7; margin-top: 2px; text-align: right; white-space: normal; }
.msg.urgent { border-color: var(--accent); box-shadow: inset 4px 0 0 var(--accent); }
.msg.mine.urgent { box-shadow: inset 4px 0 0 #f2b48f; }
.day { align-self: center; font-size: .78rem; color: var(--muted); margin: 6px 0; }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 10px; padding-bottom: max(8px, env(safe-area-inset-bottom)); background: var(--paper); border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; max-height: 140px; min-height: 44px; border: 1px solid #b9b19f; border-radius: 12px; padding: 10px 12px; background: #fff; }
.composer .urg { display: flex; align-items: center; gap: 4px; font-size: .85rem; color: var(--accent); font-weight: 600; white-space: nowrap; }
.composer-note { padding: 0 12px 4px; font-size: .78rem; color: var(--muted); background: var(--paper); }
.conn { background: #fff4d6; color: #5c4400; text-align: center; font-size: .85rem; padding: 4px; }

/* admin */
.admin { flex: 1; overflow-y: auto; padding: 16px; width: min(100%, 960px); margin-inline: auto; }
.admin h2 { color: var(--navy); margin: 18px 0 8px; font-size: 1.15rem; }
.table-wrap { overflow-x: auto; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--navy-soft); color: var(--navy-dark); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.pill { display: inline-block; padding: 0 8px; border-radius: 999px; background: var(--navy-soft); font-size: .78rem; font-weight: 700; color: var(--navy-dark); }
.pill.off { background: #eee; color: #666; }

dialog { border: 0; border-radius: 16px; padding: 22px; width: min(92vw, 440px); background: var(--paper); color: var(--ink); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(20,30,40,.55); }
dialog h2 { margin: 0 0 12px; color: var(--navy); font-size: 1.2rem; }
.temp { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.3rem; background: var(--navy-soft); border-radius: 10px; padding: 12px; text-align: center; letter-spacing: .04em; user-select: all; }
.secret { font-family: ui-monospace, Menlo, Consolas, monospace; word-break: break-all; background: var(--navy-soft); padding: 8px; border-radius: 8px; user-select: all; }
.checkrow { display: flex; gap: 10px; align-items: flex-start; margin: 0 0 14px; }
.checkrow input { width: 22px; height: 22px; margin-top: 2px; }

@media (max-width: 760px) {
  .sidebar { width: 100%; border-right: 0; }
  .main[data-view="thread"] .sidebar { display: none; }
  .main[data-view="list"] .convo { display: none; }
  .back { display: inline-flex; }
  .msg { max-width: 88%; }
  .topbar .who { display: none; }
}

/* attachments */
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 10px 0; background: var(--paper); }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--navy-soft); border-radius: 999px; padding: 2px 4px 2px 12px; font-size: .85rem; max-width: 100%; }
.chip.bad { background: #fbe9e7; color: #8a1c1c; }
.chip-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-state { color: var(--muted); font-size: .78rem; }
.chip.bad .chip-state { color: #8a1c1c; }
.chip-x { border: 0; background: transparent; font-size: 1.2rem; line-height: 1; cursor: pointer; min-width: 32px; min-height: 32px; border-radius: 50%; }
.files { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; white-space: normal; }
.photo img { max-width: min(260px, 100%); max-height: 260px; border-radius: 10px; border: 1px solid rgba(0,0,0,.15); background: #fff; }
.pdf { display: flex; align-items: center; gap: 8px; text-decoration: none; background: rgba(255,255,255,.85); color: var(--navy-dark); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.pdf-icon { background: var(--accent); color: #fff; font-weight: 800; font-size: .7rem; padding: 4px 6px; border-radius: 6px; }
.pdf-name { font-weight: 600; overflow-wrap: anywhere; }
.pdf-size { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.attach { min-width: 44px; padding-inline: 12px; }
@media (max-width: 760px) {
  .composer { flex-wrap: wrap; }
  .composer textarea { order: -1; flex: 1 1 100%; }
  .composer .urg { margin-left: auto; }
}
