/* DR-Chat web client. Delta design tokens; system fonts only (no network fetches). */
:root {
  --delta-blue: #0066CC;
  --delta-navy: #1A1A2E;
  --delta-teal: #00C9A7;
  --delta-red: #E53E3E;
  --delta-orange: #DD6B20;
  --delta-green: #38A169;
  --bg: #F7F8FA;
  --surface: #FFFFFF;
  --border: #E2E8F0;
  --text: #1A202C;
  --muted: #718096;
  --side-bg: #1A1A2E;
  --side-text: #E2E8F0;
  --side-muted: #A0AEC0;
  --side-hover: #26264A;
  --link: #0066CC;
  --self: #EEF5FF;
  --alert-bg: #FFF5F5;
  --status-bg: #FFFAF0;
  --checkin-bg: #F0FFF4;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1020; --surface: #17182B; --border: #2A2C45; --text: #E2E8F0; --muted: #A0AEC0;
    --side-bg: #0B0C18; --side-hover: #1E2038; --link: #63B3ED; --self: #1B2340;
    --alert-bg: #3B1D1D; --status-bg: #3A2A12; --checkin-bg: #163024;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0F1020; --surface: #17182B; --border: #2A2C45; --text: #E2E8F0; --muted: #A0AEC0;
  --side-bg: #0B0C18; --side-hover: #1E2038; --link: #63B3ED; --self: #1B2340;
  --alert-bg: #3B1D1D; --status-bg: #3A2A12; --checkin-bg: #163024;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--link); }
.muted { color: var(--muted); }
h1, h2, h3 { margin: 0; }

button.primary {
  background: var(--delta-blue); color: #fff; border: 0; border-radius: 8px;
  padding: 0 16px; min-height: 44px; font-weight: 600;
}
button.primary:hover { filter: brightness(1.08); }
button.primary:disabled { opacity: .6; cursor: progress; }
.link-btn { background: none; border: 0; color: var(--link); padding: 4px 6px; min-height: 32px; }
.icon-btn {
  background: none; border: 1px solid transparent; border-radius: 8px; color: inherit;
  min-width: 44px; min-height: 44px; padding: 0 8px;
}
.icon-btn:hover { border-color: var(--border); }
input, textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
  min-height: 44px; width: 100%;
}
input:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--delta-blue); outline-offset: 1px; }

/* ---- login ---- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; display: flex; flex-direction: column; gap: 8px;
  box-shadow: 0 6px 24px rgba(0,0,0,.06);
}
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.brand h1 { font-size: 22px; }
.brand p { margin: 0; }
.login-card label { font-weight: 600; margin-top: 6px; }
.login-card button { margin-top: 12px; }
.error { color: var(--delta-red); font-weight: 600; margin: 4px 0 0; }
.fine { color: var(--muted); font-size: 12px; margin: 6px 0 0; }

/* ---- app layout ---- */
.app { display: grid; grid-template-columns: 260px 1fr; height: 100%; }
.sidebar {
  background: var(--side-bg); color: var(--side-text); display: flex; flex-direction: column; min-height: 0;
}
.sidebar-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; font-weight: 700; font-size: 16px; }
.sidebar-title { flex: 1; }
.convs { flex: 1; overflow-y: auto; padding: 4px 8px; }
.convs h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--side-muted); margin: 14px 8px 6px; }
.convs ul { list-style: none; margin: 0; padding: 0; }
.convs li button {
  width: 100%; display: flex; align-items: center; gap: 8px; text-align: left; background: none; border: 0;
  color: var(--side-text); padding: 8px 10px; border-radius: 8px; min-height: 40px;
}
.convs li button:hover { background: var(--side-hover); }
.convs li button.active { background: var(--delta-blue); color: #fff; }
.convs li button.unread { font-weight: 700; }
.conv-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--delta-teal); color: var(--delta-navy); border-radius: 999px; padding: 0 7px; font-size: 12px; font-weight: 700; }
.badge.mention { background: var(--delta-red); color: #fff; }
.join-form { display: flex; gap: 6px; padding: 8px 12px; }
.join-form input { background: var(--side-hover); border-color: transparent; color: var(--side-text); min-height: 40px; }
.join-form button { background: var(--side-hover); border: 0; color: var(--side-text); border-radius: 8px; padding: 0 12px; }
.sidebar-foot {
  display: flex; align-items: center; gap: 6px; padding: 8px 12px 12px; border-top: 1px solid #2A2C45; flex-wrap: wrap;
}
.sidebar-foot .link-btn { color: var(--side-muted); }
.me { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: #4A5568; color: #fff; }
.pill.ok { background: var(--delta-green); }
.pill.warn { background: var(--delta-orange); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); }
.topbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.title { flex: 1; min-width: 0; }
.title h2 { font-size: 17px; }
.topic { margin: 0; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.banner { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.banner-alert { background: var(--alert-bg); border-left: 5px solid var(--delta-red); }
.banner-alert strong { color: var(--delta-red); }
.banner-status { background: var(--status-bg); border-left: 5px solid var(--delta-orange); }
.banner-status strong { color: var(--delta-orange); }
.banner-checkin { background: var(--checkin-bg); border-left: 5px solid var(--delta-green); }
.banner-checkin input { flex: 1; min-width: 160px; }
#broadcast-text, #status-text, #checkin-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }

.content { flex: 1; display: flex; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 8px 0; }
.load-older { display: block; margin: 4px auto 8px; }
.msg-list { list-style: none; margin: 0; padding: 0; }
.msg { display: grid; grid-template-columns: 44px auto 1fr; gap: 0 8px; padding: 3px 14px; align-items: baseline; }
.msg:hover { background: var(--bg); }
.msg time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.msg .nick { font-weight: 700; white-space: nowrap; }
.msg .text { overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.self { background: var(--self); }
.msg.notice .text { font-style: italic; }
.msg.action .text { font-style: italic; }
.msg.system { color: var(--muted); font-size: 13px; }
.msg.system .nick { font-weight: 400; }
.msg.mention { border-left: 4px solid var(--delta-orange); padding-left: 10px; }
.msg.bot .nick { color: var(--delta-orange); }
.day { text-align: center; color: var(--muted); font-size: 12px; margin: 10px 0 4px; }
.day span { background: var(--surface); padding: 0 10px; }
.day::before { content: ""; display: block; border-top: 1px solid var(--border); position: relative; top: .8em; z-index: 0; }
.day span { position: relative; z-index: 1; }

.nick-c0 { color: #0066CC; } .nick-c1 { color: #2F855A; } .nick-c2 { color: #B7791F; } .nick-c3 { color: #9F7AEA; }
.nick-c4 { color: #C53030; } .nick-c5 { color: #2B6CB0; } .nick-c6 { color: #00A389; } .nick-c7 { color: #D53F8C; }

.members { width: 200px; border-left: 1px solid var(--border); overflow-y: auto; padding: 10px 12px; }
.members h3 { font-size: 12px; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.members ul { list-style: none; margin: 0; padding: 0; }
.members li { padding: 3px 0; }

.composer { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); }
.composer textarea { resize: none; max-height: 160px; }

.only-mobile { display: none; }
.scrim { display: none; }

@media (max-width: 1023px) {
  .app { grid-template-columns: 1fr; }
  .only-mobile { display: inline-block; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 20;
    transform: translateX(-100%); transition: transform .2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 10; }
  .members { position: fixed; right: 0; top: 0; bottom: 0; z-index: 15; background: var(--surface); width: min(240px, 70vw); }
  .msg { grid-template-columns: 44px auto 1fr; padding: 3px 10px; }
}
@media (max-width: 640px) {
  .banner-checkin #checkin-text { flex-basis: 100%; }
  .banner-checkin input { min-width: 0; }
}
@media (max-width: 480px) {
  .msg { grid-template-columns: 40px 1fr; }
  .msg .text { grid-column: 1 / -1; }
  .composer button { padding: 0 12px; }
}

/* ---- panels (Users, Help) ---- */
dialog.panel {
  width: min(680px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
dialog.panel[open] { display: flex; flex-direction: column; }
dialog.panel::backdrop { background: rgba(0,0,0,.45); }
.panel-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px 10px 18px; border-bottom: 1px solid var(--border); }
.panel-head h2 { flex: 1; font-size: 18px; }
.panel-body { overflow-y: auto; padding: 14px 18px 18px; }
.panel-sub { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 6px; }

.adduser label[for] { font-weight: 600; display: block; margin-bottom: 6px; }
.adduser-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.adduser-row input:not([type]) { flex: 1; min-width: 160px; width: auto; }
.check { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; }
.check input { width: 18px; min-height: 18px; height: 18px; padding: 0; }
.result { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--checkin-bg); border-left: 5px solid var(--delta-green); }
.result.err { background: var(--alert-bg); border-left-color: var(--delta-red); }
.result p { margin: 0; overflow-wrap: anywhere; }
.result .fine { margin-top: 6px; }
.secret-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.secret-row code { font: 700 16px/1.3 ui-monospace, "Cascadia Mono", Consolas, monospace; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; overflow-wrap: anywhere; flex: 1; min-width: 0; }
.secret-row button, .users-list button { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; min-height: 36px; padding: 0 10px; }
.secret-row button:hover, .users-list button:hover { border-color: var(--delta-blue); }

.users-list { list-style: none; margin: 0; padding: 0; }
.users-list li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.users-list .u-name { font-weight: 700; min-width: 110px; overflow-wrap: anywhere; }
.users-list .u-tags { flex: 1; display: flex; gap: 4px; flex-wrap: wrap; }
.users-list .u-acts { display: flex; gap: 6px; flex-wrap: wrap; }
.users-list button.confirm { border-color: var(--delta-red); color: var(--delta-red); font-weight: 600; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); color: var(--muted); }
.tag.admin { color: var(--delta-blue); border-color: var(--delta-blue); }
.tag.disabled { color: var(--muted); text-decoration: line-through; }
.tag.locked { color: #fff; background: var(--delta-red); border-color: var(--delta-red); }

.help section + section { margin-top: 18px; }
.help h3 { font-size: 15px; margin-bottom: 6px; }
.help ul { margin: 0; padding-left: 20px; }
.help li { margin: 4px 0; }
.help p { margin: 4px 0; }
.help code, .cmds code { font: 13px ui-monospace, "Cascadia Mono", Consolas, monospace; background: var(--bg); border-radius: 4px; padding: 1px 4px; overflow-wrap: anywhere; }
.cmds { border-collapse: collapse; width: 100%; margin: 4px 0 8px; }
.cmds td { padding: 4px 8px 4px 0; vertical-align: top; border-top: 1px solid var(--border); }
.cmds td:first-child { white-space: nowrap; width: 1%; }
.t-alert { color: var(--delta-red); }
.t-status { color: var(--delta-orange); }
.t-checkin { color: var(--delta-green); }
@media (max-width: 480px) {
  .cmds, .cmds tbody, .cmds tr, .cmds td { display: block; width: auto; }
  .cmds tr { border-top: 1px solid var(--border); padding: 4px 0; }
  .cmds td { border-top: 0; padding: 1px 0; }
  .cmds td:first-child { white-space: normal; width: auto; }
  .users-list .u-name { min-width: 0; flex-basis: 100%; }
}
