/* klar chat — full-viewport, standalone (no shell sidebar). Needs theme.css.
   Adapted from the Control Room design's klar app. */
html, body { height: 100%; }
body { display: flex; overflow: hidden; }
.icon, .kic { display: block; flex-shrink: 0; }

.klar { flex: 1; min-height: 0; display: grid; grid-template-columns: 72px 248px minmax(0, 1fr) 240px; background: var(--bg); width: 100%; }
.klar.no-members { grid-template-columns: 72px 248px minmax(0, 1fr); }
.klar.no-members .k-members { display: none; }

/* server rail */
.k-rail { background: var(--bg); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px 0; overflow-y: auto; }
.k-srv { position: relative; width: 46px; height: 46px; flex-shrink: 0; border: none; cursor: pointer; display: grid; place-items: center;
  font-family: "Chakra Petch", sans-serif; font-weight: 700; font-size: 15px; color: #fff;
  background: linear-gradient(225deg, transparent 0 9px, var(--c, #8b3fe0) 9px); transition: transform .12s ease, filter .12s ease; }
.k-srv:hover { transform: translateY(-1px); filter: brightness(1.08); }
.k-srv::before { content: ""; position: absolute; left: -13px; top: 50%; width: 4px; height: 0; background: var(--ink); transform: translateY(-50%); transition: height .15s ease; }
.k-srv:hover::before { height: 14px; }
.k-srv.on::before { height: 32px; background: var(--hue); }
.k-srv.home { --c: var(--surface-2); color: var(--ink); }
.k-srv.add { --c: transparent; color: var(--ink-soft); border: 1px dashed var(--line); }
.k-srv.add:hover { color: var(--hue); border-color: var(--hue); }
.k-rail-sep { width: 28px; height: 2px; background: var(--line); flex-shrink: 0; }

/* channel side */
.k-side { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.k-side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 10px 0 16px; height: 52px; flex-shrink: 0; border-bottom: 1px solid var(--line);
  font-family: "Chakra Petch", sans-serif; font-weight: 700; font-size: 15px; background: linear-gradient(225deg, var(--hue) 0 10px, transparent 10px); }
.k-side-head span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.k-side-list { flex: 1; overflow-y: auto; padding: 8px 8px 12px; }
.k-cat { display: flex; justify-content: space-between; align-items: center; margin: 14px 6px 4px 8px; font-family: "IBM Plex Mono", monospace; font-size: 10.5px; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-faint); }
.k-ch { width: 100%; display: flex; align-items: center; gap: 8px; background: none; border: none; color: var(--ink-soft); cursor: pointer; padding: 7px 8px; font-size: 14px; text-align: left; }
.k-ch span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.k-ch .kic { width: 16px; height: 16px; color: var(--ink-faint); }
.k-ch:hover { background: var(--surface-2); color: var(--ink); }
.k-ch.on { background: var(--surface-2); color: var(--ink); font-weight: 600; box-shadow: inset 2px 0 0 var(--hue); }
.k-ch .k-chdel { visibility: hidden; }
.k-ch:hover .k-chdel { visibility: visible; }
.k-empty { color: var(--ink-faint); font-size: 12.5px; padding: 10px 8px; line-height: 1.5; }
.k-ibtn { width: 30px; height: 30px; display: grid; place-items: center; background: none; border: none; color: var(--ink-soft); cursor: pointer; padding: 0; flex-shrink: 0; }
.k-ibtn:hover { background: var(--surface-2); color: var(--ink); }
.k-ibtn.sm { width: 20px; height: 20px; } .k-ibtn.sm .kic { width: 14px; height: 14px; }
.k-ibtn.danger:hover { color: var(--danger); }

/* avatars + presence */
.k-av { --c: #8b3fe0; width: 32px; height: 32px; flex-shrink: 0; display: inline-grid; place-items: center; color: #fff;
  font-family: "Chakra Petch", sans-serif; font-weight: 700; font-size: 13px; background: linear-gradient(225deg, transparent 0 6px, var(--c) 6px); }
.k-av.sm { width: 24px; height: 24px; font-size: 10px; background: linear-gradient(225deg, transparent 0 5px, var(--c) 5px); }
.k-avwrap { position: relative; display: inline-flex; flex-shrink: 0; }
.k-dot { position: absolute; right: -3px; bottom: -3px; width: 11px; height: 11px; border: 2px solid var(--surface); background: var(--ink-faint); }
.k-dot.on { background: #2fb36a; }

.k-me { display: flex; align-items: center; gap: 2px; padding: 8px; border-top: 1px solid var(--line); background: var(--bg); }
.k-me-id { flex: 1; min-width: 0; display: flex; align-items: center; gap: 9px; background: none; border: none; padding: 4px; color: var(--ink); text-align: left; }
.k-me-txt { min-width: 0; }
.k-me-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.k-me-sub { font-size: 11px; color: var(--ink-faint); }

/* main column */
.k-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.k-head { height: 52px; flex-shrink: 0; display: flex; align-items: center; gap: 10px; padding: 0 12px 0 18px; border-bottom: 1px solid var(--line); }
.k-head-t { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; overflow: hidden; white-space: nowrap; }
.k-head-t b { font-family: "Chakra Petch", sans-serif; font-size: 16px; }
.k-head-t .kic { color: var(--ink-faint); }
.k-burger { display: none; }
.k-msgs { flex: 1; overflow-y: auto; padding: 12px 0 8px; }
.k-start { padding: 24px 20px 16px; border-bottom: 1px solid var(--line); margin: 0 18px 12px; }
.k-start-mark { width: 54px; height: 54px; display: grid; place-items: center; color: #fff; background: linear-gradient(225deg, transparent 0 11px, var(--hue) 11px); margin-bottom: 12px; }
.k-start-mark .kic { width: 26px; height: 26px; }
.k-start h3 { font-family: "Chakra Petch", sans-serif; font-size: 20px; margin: 0 0 4px; }
.k-start p { margin: 0; color: var(--ink-soft); font-size: 13.5px; }
.k-msg { position: relative; display: grid; grid-template-columns: 40px minmax(0, 1fr); column-gap: 14px; padding: 6px 18px 2px; }
.k-msg.cont { padding-top: 1px; }
.k-msg:hover { background: var(--surface); }
.k-msg-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 1px; }
.k-msg-head b { font-size: 14px; }
.k-msg-time { font-size: 11px; color: var(--ink-faint); font-family: "IBM Plex Mono", monospace; }
.k-msg-body { font-size: 14.5px; line-height: 1.5; overflow-wrap: anywhere; white-space: pre-wrap; }
.k-edited { font-size: 10.5px; color: var(--ink-faint); margin-left: 6px; }
.k-msg-acts { position: absolute; right: 16px; top: -12px; display: none; background: var(--surface); border: 1px solid var(--line); box-shadow: 0 6px 16px -8px rgba(0, 0, 0, .4); }
.k-msg:hover .k-msg-acts, .k-msg:focus-within .k-msg-acts { display: flex; }
.k-msg-acts button { background: none; border: none; color: var(--ink-soft); font-size: 12px; padding: 5px 10px; cursor: pointer; }
.k-msg-acts button:hover { background: var(--surface-2); color: var(--ink); }
.k-editbox { width: 100%; font-size: 14px; }
.k-typing { height: 20px; padding: 0 20px; font-size: 11.5px; color: var(--ink-soft); font-style: italic; }
.k-compose { display: flex; align-items: flex-end; gap: 8px; margin: 0 16px 16px; padding: 8px 8px 8px 14px; background: var(--surface); border: 1px solid var(--line); }
.k-compose:focus-within { border-color: var(--hue); }
.k-compose textarea { flex: 1; border: none; background: none; padding: 6px 0; resize: none; font-size: 14.5px; line-height: 1.45; max-height: 200px; outline: none; width: 100%; }
.k-send { width: 38px; height: 38px; display: grid; place-items: center; border: none; cursor: pointer; color: #fff; background: linear-gradient(225deg, transparent 0 7px, var(--hue) 7px); }
.k-send:disabled { opacity: .4; cursor: not-allowed; }
.k-blank { flex: 1; display: grid; place-items: center; padding: 24px; }
.k-blank-in { max-width: 380px; text-align: center; }
.k-blank-in h3 { font-family: "Chakra Petch", sans-serif; font-size: 22px; margin: 0 0 6px; }
.k-blank-in p { color: var(--ink-soft); font-size: 13.5px; line-height: 1.55; margin: 0 0 16px; }

/* members */
.k-members { background: var(--surface); border-left: 1px solid var(--line); overflow-y: auto; padding: 14px 8px; }
.k-mem-cat { font-family: "IBM Plex Mono", monospace; font-size: 10.5px; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-faint); margin: 4px 8px 6px; }
.k-mem { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.k-mem:hover { background: var(--surface-2); }
.k-mem.off { opacity: .5; }
.k-mem-name { font-size: 13.5px; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.k-crown { font-family: "IBM Plex Mono", monospace; font-size: 9.5px; color: var(--hue); border: 1px solid var(--hue); padding: 0 4px; margin-left: 4px; }

/* buttons reused from theme.css (.btn). small helpers */
.k-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* modal (local copy so klar needs no shell.js) */
dialog.modal { width: 92vw; max-width: 460px; padding: 0; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); }
dialog.modal::backdrop { background: rgba(0, 0, 0, .45); }
.modalhead { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modalhead h3 { margin: 0; font-family: "Chakra Petch", sans-serif; font-size: 16px; }
.modalbody { padding: 18px; }
.modalfoot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--line); }
.iconbtn { background: none; border: none; color: var(--ink-faint); font-size: 18px; line-height: 1; cursor: pointer; padding: 4px; }
.code { font-family: "IBM Plex Mono", monospace; font-size: 18px; letter-spacing: .2em; padding: 6px 12px; background: var(--surface-2); border: 1px solid var(--line); display: inline-block; }
.formerr { margin-top: 12px; padding: 9px 11px; border: 1px solid var(--danger); color: var(--danger); font-size: 12.5px; }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 40; transform: translateX(-50%); padding: 9px 14px; background: var(--ink); color: var(--bg); font: 12px "IBM Plex Mono", monospace; opacity: 0; pointer-events: none; transition: opacity .2s; }
.toast.show { opacity: 1; }

/* full-page gate (auth / no access) */
.gate { flex: 1; display: grid; place-items: center; padding: 32px; text-align: center; }
.gate .in { max-width: 400px; }
.gate h1 { font-family: "Chakra Petch", sans-serif; font-size: 22px; margin: 0 0 8px; }
.gate p { color: var(--ink-soft); font-size: 13.5px; line-height: 1.6; margin: 0 0 16px; }

@media (max-width: 1100px) { .klar { grid-template-columns: 72px 248px minmax(0, 1fr); } .k-members { display: none; } }
@media (max-width: 760px) {
  .klar, .klar.no-members { grid-template-columns: 64px minmax(0, 1fr); }
  .k-srv { width: 42px; height: 42px; }
  .k-rail { position: relative; z-index: 11; }
  .k-side { position: absolute; left: 64px; top: 0; bottom: 0; width: min(280px, calc(100vw - 64px)); z-index: 10; transform: translateX(calc(-100% - 64px)); visibility: hidden; transition: transform .2s ease, visibility 0s linear .2s; box-shadow: 12px 0 30px -10px rgba(0, 0, 0, .5); }
  .klar.side-open .k-side { transform: none; visibility: visible; transition: transform .2s ease; }
  .k-burger { display: grid; }
  .k-head { padding-left: 8px; }
}
@media (prefers-reduced-motion: reduce) { .k-srv, .k-side { transition: none; } }
