:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --side: #1b1d22;
  --side-fg: #d7d9de;
  --side-muted: #8a8f99;
  --side-hover: #2a2d34;
  --fg: #1d1f24;
  --muted: #6b7079;
  --line: #e4e2dd;
  --accent: #e8a33d;
  --accent-fg: #14161a;
  --danger: #c2412d;
  --ok: #2f9e5b;
  --name-l: 38%;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --panel: #1b1d22;
    --side: #101215;
    --side-hover: #22252b;
    --fg: #e6e7ea;
    --muted: #979ca6;
    --line: #2b2e35;
    --name-l: 70%;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
a { color: var(--accent); }
.muted { color: var(--muted); }

/* ---------- auth cards ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 28px 24px; display: grid; gap: 14px;
  box-shadow: 0 10px 30px rgb(0 0 0 / .06);
}
.card h1 { margin: 0; font-size: 22px; }
.card p { margin: 0; }
.logo { width: 48px; height: 48px; }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
input, textarea, select {
  font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
button[type=submit], .btn {
  background: var(--accent); color: var(--accent-fg); border: 0; border-radius: 8px;
  padding: 10px 16px; font-weight: 650;
}
button[type=submit]:hover, .btn:hover { filter: brightness(1.05); }
.btn.secondary { background: transparent; color: var(--fg); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid currentColor; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.error { color: var(--danger); min-height: 1em; font-size: 14px; }
.error:empty { display: none; }
.fine { font-size: 12px; color: var(--muted); text-align: center; }
.link { background: none; border: 0; color: var(--side-muted); text-decoration: underline; padding: 0; }

/* ---------- chat layout ---------- */
.app { display: grid; grid-template-columns: 260px 1fr; height: 100dvh; }
.sidebar {
  background: var(--side); color: var(--side-fg); display: flex; flex-direction: column; min-height: 0;
}
.side-head { display: flex; align-items: center; gap: 10px; padding: 16px; border-bottom: 1px solid rgb(255 255 255 / .06); }
.logo-sm { width: 28px; height: 28px; }
.sidebar nav { flex: 1; overflow-y: auto; padding: 8px; }
.sidebar h2 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--side-muted);
  margin: 16px 8px 6px; display: flex; align-items: center; gap: 6px;
}
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.chan {
  width: 100%; display: flex; align-items: center; gap: 6px; background: none; border: 0;
  color: var(--side-fg); padding: 7px 10px; border-radius: 6px; text-align: left;
}
.chan:hover { background: var(--side-hover); }
.chan.active { background: var(--accent); color: var(--accent-fg); font-weight: 600; }
.chan .hash { opacity: .6; }
.chan-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--danger); color: #fff; border-radius: 99px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
.pill { background: var(--side-hover); color: var(--side-fg); border-radius: 99px; padding: 0 7px; font-size: 11px; }
.online li { padding: 4px 10px; display: flex; align-items: center; gap: 8px; font-size: 14px; }
.online li::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.online li.me { color: #fff; }
.side-foot {
  padding: 12px 16px; border-top: 1px solid rgb(255 255 255 / .06); font-size: 13px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px; color: var(--side-muted);
}
.side-foot strong { color: var(--side-fg); }

.room { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--panel); }
.room-head {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line);
  padding-top: max(12px, env(safe-area-inset-top));
}
.room-title { flex: 1; min-width: 0; }
.room-title h1 { margin: 0; font-size: 17px; }
.room-title p { margin: 0; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { display: none; background: none; border: 1px solid var(--line); border-radius: 8px; color: var(--fg); padding: 4px 10px; font-size: 18px; }
.status { color: var(--danger); font-size: 12px; }
.status.ok { color: var(--ok); }
.day-banner {
  font-size: 12px; text-align: center; color: var(--muted); padding: 6px 16px;
  background: color-mix(in srgb, var(--accent) 12%, transparent); border-bottom: 1px solid var(--line);
}

.messages { flex: 1; overflow-y: auto; list-style: none; margin: 0; padding: 12px 0; overscroll-behavior: contain; }
.msg { padding: 6px 16px 2px; }
.msg.grouped { padding-top: 0; }
.msg:hover { background: color-mix(in srgb, var(--fg) 3%, transparent); }
.msg-head { display: flex; align-items: baseline; gap: 8px; }
.who { font-weight: 700; }
.when { font-size: 12px; color: var(--muted); }
.dept {
  font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 99px; white-space: nowrap;
  color: var(--muted); border: 1px solid var(--line);
}
.dept:empty { display: none; }
.sidebar .dept { color: var(--side-muted); border-color: rgb(255 255 255 / .12); }
.online-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hint { font-weight: 400; font-size: 12px; }
.body { white-space: pre-wrap; overflow-wrap: anywhere; }
.empty { color: var(--muted); text-align: center; padding: 40px 16px; }

.typing { font-size: 12px; color: var(--muted); padding: 0 16px; min-height: 18px; }
.composer {
  display: flex; gap: 8px; padding: 8px 16px 12px; padding-bottom: max(12px, env(safe-area-inset-bottom));
  align-items: flex-end;
}
.composer textarea { resize: none; max-height: 160px; line-height: 1.4; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translate(-50%, 20px); opacity: 0;
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 99px; font-size: 14px;
  transition: .2s; pointer-events: none; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.scrim { display: none; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(280px, 85vw); z-index: 20;
    transform: translateX(-100%); transition: transform .2s;
  }
  .nav-open .sidebar { transform: none; }
  .nav-open .scrim { display: block; position: fixed; inset: 0; background: rgb(0 0 0 / .4); z-index: 10; }
  .icon-btn { display: block; }
  .composer textarea { font-size: 16px; } /* prevent iOS zoom */
}

/* ---------- admin ---------- */
.admin { max-width: 1100px; margin: 0 auto; padding: 16px; }
.admin-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.admin-head h1 { margin: 0; font-size: 20px; flex: 1; }
.public-url {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; padding: 10px 14px;
  border: 1px solid var(--accent); border-radius: var(--radius); background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.public-url a { font-weight: 600; overflow-wrap: anywhere; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button {
  background: none; border: 0; padding: 10px 14px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs button.active { color: var(--fg); border-color: var(--accent); font-weight: 600; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.backlog { display: grid; grid-template-columns: 200px 1fr; gap: 16px; }
.days { list-style: none; margin: 0; padding: 0; max-height: 70vh; overflow-y: auto; }
.days button {
  width: 100%; display: flex; justify-content: space-between; background: none; border: 0; color: var(--fg);
  padding: 8px 10px; border-radius: 6px; text-align: left;
}
.days button:hover { background: var(--bg); }
.days button.active { background: var(--accent); color: var(--accent-fg); font-weight: 600; }
.days .today { font-size: 11px; opacity: .8; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar select, .toolbar input { width: auto; flex: 1; min-width: 140px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
td.body { min-width: 200px; }
tr.deleted td { opacity: .5; text-decoration: line-through; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--bg); border: 1px solid var(--line); }
.form-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.form-row label { flex: 1; min-width: 160px; }
.settings { display: grid; gap: 20px; max-width: 520px; }
.settings section { display: grid; gap: 10px; }
.settings h3 { margin: 0; font-size: 15px; }
.table-wrap { overflow-x: auto; }

@media (max-width: 760px) {
  .backlog { grid-template-columns: 1fr; }
  .days { display: flex; overflow-x: auto; max-height: none; gap: 4px; }
  .days button { white-space: nowrap; gap: 8px; }
}
