/* Koigram look: a layout familiar to Teams users (top bar, app rail, list
   pane, conversation with message cards), with Koigram's own colours. */

:root {
  --chrome: #ebebeb;        /* top bar and app rail */
  --pane: #f5f5f5;          /* list pane */
  --canvas: #f5f5f5;        /* conversation background */
  --surface: #ffffff;       /* cards, header, dialogs */
  --surface-2: #f0f0f0;     /* hover, code, quotes */
  --selected: #ffffff;      /* selected list item */
  --own: #e3ecf6;           /* the user's own messages */
  --text: #242424;
  --muted: #616161;
  --border: #e0e0e0;
  --accent: #2f5d8a;
  --accent-hover: #264d73;
  --accent-soft: #e3ecf6;
  --accent-text: #ffffff;
  --badge: #c4314b;
  --error: #b3261e;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.12);
  --shadow-pop: 0 8px 28px rgb(0 0 0 / 0.18);
  --radius: 6px;
  --rail: 68px;
  --list: 320px;
  --top: 48px;
  color-scheme: light;
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;
  font-size: 14px;
  line-height: 1.43;

  /* Avatar colours: background and initials. */
  --av-0: #dbe8f6; --av-0-t: #1d4f7c;
  --av-1: #fde7e9; --av-1-t: #a4262c;
  --av-2: #e0f2e9; --av-2-t: #0b6a3b;
  --av-3: #fff4ce; --av-3-t: #7a5a00;
  --av-4: #f1e6fa; --av-4-t: #6b2a8a;
  --av-5: #dff6f6; --av-5-t: #006666;
  --av-6: #fbe7dc; --av-6-t: #8a3c0a;
  --av-7: #e8eaf8; --av-7-t: #3b4594;
}

@media (prefers-color-scheme: dark) {
  :root {
    --chrome: #141414;
    --pane: #1c1c1c;
    --canvas: #1f1f1f;
    --surface: #2b2b2b;
    --surface-2: #333333;
    --selected: #2e2e2e;
    --own: #263a52;
    --text: #e8e8e8;
    --muted: #adadad;
    --border: #3a3a3a;
    --accent: #7fa7d1;
    --accent-hover: #9bbbdc;
    --accent-soft: #24364d;
    --accent-text: #0d1520;
    --badge: #e5546a;
    --error: #f2b8b5;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.5);
    --shadow-pop: 0 8px 28px rgb(0 0 0 / 0.6);
    color-scheme: dark;

    --av-0: #1f3a57; --av-0-t: #b7d4f2;
    --av-1: #4a2326; --av-1-t: #f4b6bb;
    --av-2: #1c3d2c; --av-2-t: #a6e3c4;
    --av-3: #45391a; --av-3-t: #f3dd94;
    --av-4: #3b2a4a; --av-4-t: #dcbdf2;
    --av-5: #173f40; --av-5-t: #9fe3e3;
    --av-6: #4a2d1d; --av-6-t: #f4c3a6;
    --av-7: #2c3158; --av-7-t: #c3c9f5;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--canvas); color: var(--text); }
kg-app { display: block; height: 100%; }
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); }
.error { color: var(--error); }
.brand { color: var(--muted); font-size: 0.85rem; }
[hidden] { display: none !important; }

/* Icons */
.icon-svg { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon-svg .fill { fill: currentColor; stroke: none; }

/* Buttons and fields */
button {
  font: inherit;
  padding: 6px 14px;
  min-height: 32px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
}
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button:disabled { opacity: 0.6; cursor: default; }
button.link { border: 0; padding: 0; min-height: 0; color: var(--accent); background: none; font-weight: 400; }
button.link:hover { text-decoration: underline; }
button.icon {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--muted);
  font-weight: 400;
}
button.icon:hover { background: var(--surface-2); color: var(--accent); }
button.icon.emoji { font-size: 1.1rem; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

input, textarea, select {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-color: var(--muted);
  border-radius: 4px;
  padding: 6px 10px;
  width: 100%;
}
input:focus, textarea:focus { outline: none; border-bottom: 2px solid var(--accent); padding-bottom: 5px; }
textarea { resize: none; }

/* Avatars */
.avatar {
  --size: 32px;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  font-size: calc(var(--size) * 0.38);
  font-weight: 600;
  letter-spacing: 0.02em;
  user-select: none;
}
.avatar.square { border-radius: calc(var(--size) * 0.22); }
.av-0 { background: var(--av-0); color: var(--av-0-t); }
.av-1 { background: var(--av-1); color: var(--av-1-t); }
.av-2 { background: var(--av-2); color: var(--av-2-t); }
.av-3 { background: var(--av-3); color: var(--av-3-t); }
.av-4 { background: var(--av-4); color: var(--av-4-t); }
.av-5 { background: var(--av-5); color: var(--av-5-t); }
.av-6 { background: var(--av-6); color: var(--av-6-t); }
.av-7 { background: var(--av-7); color: var(--av-7-t); }

/* Login page */
.center { min-height: 100%; display: grid; place-items: center; padding: 16px; background: var(--chrome); }
.card {
  width: min(420px, 100%);
  padding: 32px;
  background: var(--surface);
  border-radius: 8px;
  box-shadow: var(--shadow-pop);
}
.card header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card h1 { font-size: 1.5rem; font-weight: 600; }

/* Application shell: top bar, app rail, list pane, conversation. */
.shell {
  display: grid;
  grid-template-columns: var(--rail) var(--list) minmax(0, 1fr);
  grid-template-rows: var(--top) minmax(0, 1fr);
  grid-template-areas: "top top top" "rail pane main";
  height: 100%;
  background: var(--chrome);
}

.topbar {
  grid-area: top;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(200px, 560px) minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  background: var(--chrome);
}
.topbar-org { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-org .logo { border-radius: 6px; }
.org-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 10px;
  background: var(--surface);
  border-radius: 4px;
  color: var(--muted);
  box-shadow: var(--shadow);
}
.topbar-search:focus-within { outline: 2px solid var(--accent); }
.topbar-search input { border: 0; padding: 0; background: none; height: 100%; }
.topbar-search input:focus { border: 0; padding: 0; }
.topbar-right { display: flex; align-items: center; justify-content: flex-end; gap: 10px; min-width: 0; }
.topbar-bell {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 2px 10px;
  border-radius: 14px;
  border: 0;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.85rem;
  white-space: nowrap;
}
.topbar-bell.denied { background: none; color: var(--muted); cursor: default; font-weight: 400; }
button.me { padding: 0; min-height: 0; border: 0; border-radius: 50%; background: none; }
button.me:hover { background: none; filter: brightness(0.95); }
.connection { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }
.connection.offline { color: var(--error); }

.rail {
  grid-area: rail;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  padding: 4px 0;
  background: var(--chrome);
}
.rail-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 56px;
  padding: 8px 0 6px;
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 400;
}
.rail-item:hover { background: none; color: var(--accent); }
.rail-item[aria-current="page"] { color: var(--accent); font-weight: 600; }
.rail-item[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: 0;
  top: 12px;
  bottom: 12px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.rail-icon { position: relative; display: inline-grid; place-items: center; }
.rail-badge {
  position: absolute;
  top: -6px;
  left: 14px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--badge);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  border: 2px solid var(--chrome);
  box-sizing: content-box;
}

/* List pane */
.pane {
  grid-area: pane;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--pane);
  border-top-left-radius: 8px;
  overflow: hidden;
}
kg-room-list, kg-activity { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 56px;
  padding: 8px 12px 8px 20px;
}
.pane-header h2 { font-size: 1.15rem; font-weight: 700; }
.pane-actions { display: flex; gap: 2px; }
.pane-scroll { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.pane-empty { padding: 24px 12px; text-align: center; color: var(--muted); }
.pane-empty p { margin: 0 0 12px; }
.pane-note { padding: 8px 12px; margin: 0; }
.list-title { font-size: 0.8rem; font-weight: 600; color: var(--muted); margin: 10px 12px 4px; }
.rooms, .teams, .channels-list { list-style: none; margin: 0; padding: 0; }

.room-item, .activity-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  column-gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 52px;
  padding: 8px 12px;
  border: 0;
  border-radius: 4px;
  background: none;
  text-align: left;
  font-weight: 400;
}
.room-item > .avatar, .activity-item > .avatar { grid-row: 1 / 3; }
.room-item:hover, .activity-item:hover, .channel-item:hover { background: var(--surface-2); }
.room-item[aria-current="true"], .activity-item[aria-current="true"], .channel-item[aria-current="true"] {
  background: var(--selected);
  box-shadow: var(--shadow);
}
.room-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-time { font-size: 0.75rem; color: var(--muted); justify-self: end; }
.room-preview {
  grid-column: 2;
  font-size: 0.85rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.unread .room-name, .unread .room-preview { font-weight: 700; color: var(--text); }
.badge {
  grid-column: 3;
  grid-row: 2;
  justify-self: end;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--badge);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
}
.badge.highlight::before { content: "@"; margin-right: 1px; }

/* Teams and channels */
.team { margin-bottom: 2px; }
.team-header { display: flex; align-items: center; border-radius: 4px; }
.team-header:hover { background: var(--surface-2); }
.team-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 6px 4px 6px 6px;
  border: 0;
  background: none;
  text-align: left;
}
.team-toggle:hover { background: none; }
.team-toggle .badge { margin-left: auto; }
.chevron { display: inline-grid; place-items: center; width: 16px; color: var(--muted); }
.team-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.team-more { opacity: 0; }
.team-header:hover .team-more, .team-more:focus-visible { opacity: 1; }
.channel-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 32px;
  padding: 4px 12px 4px 66px;
  border: 0;
  border-radius: 4px;
  background: none;
  text-align: left;
  font-weight: 400;
}
.channel-item .room-name { flex: 1; }
.channel-item .badge { grid-column: auto; grid-row: auto; }
.channel-item.browse { color: var(--accent); }

/* Activity */
.chips { display: flex; gap: 6px; padding: 0 20px 8px; }
.chip {
  min-height: 28px;
  padding: 2px 12px;
  border-radius: 14px;
  font-weight: 400;
  background: var(--surface);
}
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.activity-item { align-items: start; min-height: 64px; }
.activity-text { display: flex; flex-direction: column; min-width: 0; grid-row: 1 / 3; }
.activity-title, .activity-room, .activity-snippet { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity-room { font-size: 0.8rem; color: var(--muted); }
.activity-snippet { font-size: 0.85rem; color: var(--muted); }
.activity-item.unread .activity-snippet { color: var(--text); }
.activity-item .room-time { grid-column: 3; grid-row: 1; }
.activity-item.unread::after {
  content: "";
  grid-column: 3;
  grid-row: 2;
  justify-self: end;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

/* Pop-up menus and pickers */
.menu-label { display: flex; flex-direction: column; align-items: flex-start; text-align: left; }
.menu {
  position: fixed;
  z-index: 10;
  display: flex;
  flex-direction: column;
  min-width: 220px;
  padding: 4px 0;
  background: var(--surface);
  border-radius: 6px;
  box-shadow: var(--shadow-pop);
}
.menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: 0;
  padding: 6px 14px;
  text-align: left;
  font-weight: 400;
  background: none;
}
.menu button:hover { background: var(--surface-2); }
.menu button.danger { color: var(--error); }
.menu .icon-space { width: 18px; }
.menu-info { display: flex; flex-direction: column; padding: 8px 14px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
/* People suggested after "@" in the composer */
.mention-list { width: 320px; max-width: calc(100vw - 16px); max-height: 300px; overflow-y: auto; }
.mention-option { display: flex; align-items: center; gap: 10px; padding: 6px 14px; cursor: pointer; }
.mention-option[aria-selected="true"] { background: var(--surface-2); }
.mention-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mention-id { font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.reaction-picker {
  position: fixed;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  padding: 6px;
  background: var(--surface);
  border-radius: 8px;
  box-shadow: var(--shadow-pop);
}

/* Conversation */
kg-room-view {
  grid-area: main;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--canvas);
  border-left: 1px solid var(--border);
}
.room-header {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 8px 12px 8px 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
  z-index: 1;
}
.room-header:empty { display: none; }
.room-title { flex: 1; min-width: 0; }
.room-title h1 { font-size: 1.05rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topic { margin: 0; font-size: 0.8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-actions { display: flex; align-items: center; gap: 2px; }
.header-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 10px;
  border: 0;
  background: none;
  color: var(--muted);
}
.header-button:hover { color: var(--accent); }
.back { display: none !important; }

.room-body { flex: 1; display: flex; flex-direction: row; min-height: 0; }
.room-main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.placeholder { margin: auto; padding: 24px; text-align: center; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.placeholder h2 { font-size: 1.25rem; color: var(--text); margin-top: 8px; }
.placeholder p { margin: 0; }
.placeholder-logo { border-radius: 16px; opacity: 0.9; }
.placeholder.invite { color: var(--text); }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.placeholder .actions { justify-content: center; }

kg-timeline { flex: 1; overflow-y: auto; padding: 16px 24px 8px; }
.timeline-list { display: flex; flex-direction: column; max-width: 1100px; margin: 0 auto; }
.timeline-note { text-align: center; color: var(--muted); font-size: 0.8rem; margin: 8px 0; }
.day { display: flex; align-items: center; gap: 12px; margin: 20px 0 8px; color: var(--muted); font-size: 0.8rem; }
.day::before, .day::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

/* Messages: other people's on the left with an avatar, the user's own on
   the right in a tinted card. */
.message {
  /* Off-screen messages are not laid out or painted: long rooms stay fast. */
  content-visibility: auto;
  contain-intrinsic-size: auto 56px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 14px;
}
.message.grouped { margin-top: 3px; }
/* The hovered message is on screen anyway: lift the paint containment so
   its toolbar can show above it. */
.message:hover, .message:focus-within { content-visibility: visible; }
.message.own { justify-content: flex-end; }
.avatar-space { width: 32px; flex: none; }
.message-main { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; max-width: min(78%, 760px); }
.message.own .message-main { align-items: flex-end; }
.bubble {
  position: relative;
  min-width: 80px;
  max-width: 100%;
  padding: 7px 14px 9px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.message.own .bubble { background: var(--own); box-shadow: none; }
.bubble header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 2px; }
.sender { font-weight: 600; font-size: 0.85rem; }
.bubble time { font-size: 0.75rem; color: var(--muted); }
.body { white-space: pre-wrap; overflow-wrap: anywhere; }
.body.html { white-space: normal; }
.body.html p, .body.html ul, .body.html ol, .body.html pre, .body.html blockquote { margin: 4px 0; }
.body.html > :first-child { margin-top: 0; }
.body.html > :last-child { margin-bottom: 0; }
.body a { color: var(--accent); }
/* A person mentioned in a message; the user's own name stands out. */
.mention { padding: 0 4px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.mention.me { background: var(--accent); color: var(--accent-text); }
.message.mentions-me .bubble { box-shadow: inset 3px 0 0 var(--accent), var(--shadow); }
.body code { background: var(--surface-2); padding: 1px 4px; border-radius: 4px; font-size: 0.9em; }
.message.own .body code, .message.own .body pre { background: color-mix(in srgb, var(--own) 60%, var(--surface)); }
.body pre { background: var(--surface-2); padding: 8px 10px; border-radius: 4px; overflow-x: auto; }
.body pre code { background: none; padding: 0; }
.body blockquote { border-left: 3px solid var(--border); margin: 4px 0; padding: 2px 10px; color: var(--muted); }
.reply-quote {
  display: flex;
  flex-direction: column;
  margin: 4px 0 6px;
  padding: 4px 10px;
  border-left: 3px solid var(--accent);
  border-radius: 2px;
  background: var(--surface-2);
  font-size: 0.85rem;
  color: var(--muted);
}
.message.own .reply-quote { background: color-mix(in srgb, var(--own) 50%, var(--surface)); }
.reply-quote strong { color: var(--text); font-weight: 600; }
.reply-quote span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message.redacted .body { font-style: italic; }
.edited { font-size: 0.75rem; color: var(--muted); }
.message.sending .bubble { opacity: 0.65; }
.status { display: inline-flex; align-items: center; gap: 4px; margin-top: 2px; font-size: 0.75rem; color: var(--muted); }
.status.error { color: var(--error); }

.media { margin-top: 4px; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.media img { display: block; max-width: 100%; height: auto; border-radius: 4px; background: var(--surface-2); }
.media video { max-width: min(480px, 100%); border-radius: 4px; }
.media.player button { display: inline-flex; align-items: center; gap: 6px; }
.media progress, .file progress { width: 200px; }
button.image { padding: 0; min-height: 0; border: 0; background: none; }
.file {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
  padding: 8px 8px 8px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  width: min(360px, 100%);
  background: var(--surface);
}
.file-icon { display: inline-grid; color: var(--accent); }
.file-info { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.file-meta { font-size: 0.8rem; }
.lightbox { border: 0; padding: 0; background: transparent; max-width: 95vw; max-height: 95vh; }
.lightbox::backdrop { background: rgb(0 0 0 / 0.85); }
.lightbox img { display: block; max-width: 95vw; max-height: 85vh; object-fit: contain; }
.lightbox-actions { display: flex; gap: 8px; justify-content: center; margin-top: 8px; }
.drop-target { outline: 3px dashed var(--accent); outline-offset: -6px; }

.message-actions {
  display: none;
  position: absolute;
  top: -20px;
  left: 8px;
  gap: 0;
  padding: 2px;
  background: var(--surface);
  border-radius: 6px;
  box-shadow: var(--shadow-pop);
  z-index: 2;
}
.message.own .message-actions { left: auto; right: 8px; }
.bubble:hover .message-actions, .message:focus-within .message-actions { display: flex; }
.message-actions button.icon { width: 30px; height: 30px; }

.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 400;
  background: var(--surface);
  box-shadow: var(--shadow);
  border: 1px solid transparent;
}
.reaction .count { font-size: 0.75rem; color: var(--muted); }
.reaction.mine { background: var(--accent-soft); border-color: var(--accent); }
.thread-summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  min-height: 26px;
  padding: 0 6px;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 0.85rem;
}

.typing { min-height: 1.6em; padding: 0 24px; font-size: 0.8rem; color: var(--muted); }

/* Composer */
kg-composer { display: block; padding: 0 24px 16px; }
.composer-box {
  display: flex;
  flex-direction: column;
  max-width: 1100px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: 6px;
  box-shadow: var(--shadow);
  border-bottom: 2px solid transparent;
}
.composer-box:focus-within { border-bottom-color: var(--accent); }
.composer-box textarea {
  border: 0;
  padding: 10px 14px 4px;
  min-height: 40px;
  max-height: 200px;
  background: none;
}
.composer-box textarea:focus { border: 0; padding-bottom: 4px; }
.composer-tools { display: flex; align-items: center; gap: 2px; padding: 2px 6px 4px; }
.composer-hint { flex: 1; text-align: right; padding-right: 8px; font-size: 0.75rem; color: var(--muted); opacity: 0; transition: opacity 0.15s; }
.composer-box:focus-within .composer-hint { opacity: 1; }
button.send {
  margin-left: auto;
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 32px;
  min-height: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
}
button.send:hover { background: var(--accent-soft); }
.composer-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin: 8px 10px 0;
  padding: 4px 4px 4px 10px;
  border-left: 3px solid var(--accent);
  background: var(--surface-2);
  border-radius: 2px;
  font-size: 0.85rem;
  color: var(--muted);
}
.composer-bar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer-bar strong { color: var(--text); }

/* Thread panel */
kg-thread {
  display: flex;
  flex-direction: column;
  width: min(440px, 45%);
  border-left: 1px solid var(--border);
  background: var(--canvas);
  min-height: 0;
}
.thread-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 48px;
  padding: 6px 8px 6px 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.thread-header h2 { display: flex; align-items: center; gap: 8px; font-size: 1rem; }
.thread-list { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; }
kg-thread kg-composer { padding: 0 12px 12px; }
kg-thread .message-main { max-width: 85%; }

/* Search results */
kg-room-view.searching > :not(kg-search) { display: none; }
kg-search { flex: 1; overflow-y: auto; padding: 16px 24px; }
.search-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; max-width: 900px; margin: 0 auto 12px; }
.search-header h1 { font-size: 1.2rem; }
.search-header p { margin: 4px 0 0; }
.search-results { list-style: none; padding: 0; margin: 0 auto; max-width: 900px; }
.search-result { padding: 10px 14px; border-radius: 6px; margin-bottom: 8px; background: var(--surface); box-shadow: var(--shadow); }
.search-meta { font-size: 0.85rem; color: var(--muted); }
.search-meta strong { color: var(--text); }
.search-text { margin: 6px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
mark { background: color-mix(in srgb, var(--accent) 30%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.actions.left { justify-content: flex-start; margin-top: 4px; }
.actions.left button { padding: 2px 10px; font-size: 0.85rem; }
.search-context { margin-top: 8px; padding: 8px 10px; border-left: 3px solid var(--border); font-size: 0.9rem; }
.search-context p { margin: 4px 0; }
.search-context p.current { background: var(--accent-soft); border-radius: 4px; padding: 2px 4px; }
.more { display: block; margin: 8px auto; }
.center-text { text-align: center; }
.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  background: var(--text);
  color: var(--canvas);
  padding: 10px 16px;
  border-radius: 6px;
  max-width: calc(100% - 32px);
  box-shadow: var(--shadow-pop);
}

/* Dialogs */
.dialog {
  width: min(480px, calc(100% - 32px));
  border: 0;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 24px;
  box-shadow: var(--shadow-pop);
}
.dialog::backdrop { background: rgb(0 0 0 / 0.4); }
.dialog h2 { font-size: 1.25rem; font-weight: 700; margin-bottom: 16px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field > span { font-weight: 600; font-size: 0.9rem; }
.check { display: flex; gap: 8px; align-items: center; font-size: 0.9rem; }
.check input { width: auto; }
.people { list-style: none; padding: 0; margin: 12px 0 0; max-height: 50vh; overflow-y: auto; }
.person { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; text-align: left; font-weight: 400; padding: 6px 8px; }
.member-name { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.member-name small { font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; }
.dialog input[type="search"] { margin-bottom: 6px; }
.members { list-style: none; padding: 0; margin: 0; max-height: 50vh; overflow-y: auto; }
.members li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.channels { list-style: none; padding: 0; margin: 0; max-height: 55vh; overflow-y: auto; }
.channels li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.channel-info { display: flex; flex-direction: column; min-width: 0; }

/* Administration */
kg-admin { display: none; }
.shell.admin-open .pane, .shell.admin-open kg-room-view { display: none; }
.shell.admin-open kg-admin {
  grid-column: 2 / 4;
  grid-row: 2;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 0;
}
.admin-nav { background: var(--pane); border-top-left-radius: 8px; padding: 0 8px; }
.admin-nav .pane-header { padding-left: 12px; }
.admin-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 6px 12px;
  border: 0;
  border-radius: 4px;
  background: none;
  text-align: left;
  font-weight: 400;
  color: var(--text);
}
.admin-nav-item:hover { background: var(--surface-2); }
.admin-nav-item[aria-current="page"] { background: var(--selected); box-shadow: var(--shadow); font-weight: 600; }
.admin-nav-item[aria-current="page"] .icon-svg { color: var(--accent); }
.admin-page { overflow-y: auto; background: var(--canvas); border-left: 1px solid var(--border); padding: 24px 32px; min-width: 0; }
.admin-page > * { max-width: 1100px; margin-left: auto; margin-right: auto; }
.admin-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; }
.admin-header button { white-space: nowrap; }
.admin-header h1 { font-size: 1.4rem; font-weight: 700; }
.admin-header p { margin: 4px 0 0; }
.admin-toolbar { margin-bottom: 12px; }
.admin-toolbar input { max-width: 360px; background: var(--surface); }
.table-wrap { background: var(--surface); border-radius: 6px; box-shadow: var(--shadow); overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th { text-align: left; font-size: 0.8rem; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.admin-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.admin-table td.grow { white-space: normal; width: 100%; }
.admin-table tr:last-child td { border-bottom: 0; }
.admin-table tbody tr:hover { background: var(--surface-2); }
.admin-table tr.disabled .person-cell { opacity: 0.6; }
.person-cell { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.actions-cell { width: 48px; text-align: right; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 0.8rem; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.tag.accent, .tag.on { background: var(--accent-soft); color: var(--accent); }
.tag.pending { background: color-mix(in srgb, #c19c00 18%, transparent); color: var(--text); }
.tag.off { background: color-mix(in srgb, var(--error) 15%, transparent); color: var(--error); }
.admin-actions { display: flex; gap: 8px; }
.admin-actions button, .admin-header > button { white-space: nowrap; }
.admin-subtitle { font-size: 1rem; font-weight: 700; margin: 24px 0 8px; }
.admin-card { background: var(--surface); border-radius: 6px; box-shadow: var(--shadow); padding: 16px 20px; }
.admin-card .field { max-width: 520px; }
.admin-note { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; margin: 0 0 16px; border-radius: 6px; background: var(--accent-soft); color: var(--text); }
.admin-note .icon-svg { color: var(--accent); margin-top: 1px; }
p.admin-note.muted { background: none; padding: 8px 0; color: var(--muted); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 10px 24px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; }
.option { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 4px; cursor: pointer; }
.option:hover { background: var(--surface-2); }
.option input { width: auto; margin-top: 3px; }
.option span { display: flex; flex-direction: column; }
.days-input { display: flex; align-items: center; gap: 8px; }
.days-input input { width: 120px; }
.admin-table td.wrap { white-space: normal; min-width: 180px; }
.person[aria-selected="true"] { background: var(--accent-soft); }
.howto { margin: 0 0 12px; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; }
.admin-subtitle.first { margin-top: 0; }
.import-counts { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.import-preview .table-wrap { max-height: 50vh; overflow-y: auto; }
kg-admin-team-import .member-name small { white-space: normal; overflow-wrap: anywhere; }
kg-admin-team-import td.grow { min-width: 220px; vertical-align: top; }
.import-skipped { margin: 12px 0; }
.import-skipped summary { cursor: pointer; color: var(--muted); }
.import-skipped ul { margin: 8px 0 0; padding-left: 18px; font-size: 0.9rem; }
.import-confirm { margin-top: 16px; }
/* The Teams connector's report. */
.report-periods { padding: 0; margin-bottom: 12px; flex-wrap: wrap; }
.report-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.report-card { background: var(--surface); border-radius: 6px; box-shadow: var(--shadow); padding: 12px 16px; display: flex; flex-direction: column; gap: 2px; }
.report-card strong { font-size: 1.6rem; font-weight: 700; }
.report-person { display: flex; flex-direction: column; }
.report-note { margin-top: 12px; font-size: 0.85rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice { border: 0; padding: 0; margin: 0 0 14px; display: flex; flex-direction: column; gap: 6px; }
.choice legend { font-weight: 600; font-size: 0.9rem; margin-bottom: 4px; padding: 0; }
.copy-row { display: flex; gap: 8px; margin: 12px 0; }
.password-value { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1rem; }

/* Narrow windows: a smaller list. */
@media (max-width: 1000px) {
  :root { --list: 280px; }
  .topbar { grid-template-columns: auto minmax(0, 1fr) auto; }
  .composer-hint { display: none; }
}

/* Phones: the rail moves to the bottom, as in the mobile apps, and the open
   conversation takes the whole screen. */
@media (max-width: 720px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--top) minmax(0, 1fr) auto;
    grid-template-areas: "top" "pane" "rail";
  }
  .shell.room-open { grid-template-rows: minmax(0, 1fr); grid-template-areas: "main"; }
  .shell.room-open .topbar, .shell.room-open .rail, .shell.room-open .pane { display: none; }
  .shell:not(.room-open) kg-room-view { display: none; }
  .topbar { grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; }
  .org-name, .topbar-bell span { display: none; }
  .rail { flex-direction: row; justify-content: space-around; padding: 0 0 env(safe-area-inset-bottom); border-top: 1px solid var(--border); }
  .rail-item { flex: 1; min-height: 54px; }
  .rail-item[aria-current="page"]::before { left: 30%; right: 30%; top: 0; bottom: auto; width: auto; height: 3px; border-radius: 0 0 3px 3px; }
  .pane { border-radius: 0; }
  kg-room-view { border-left: 0; }
  .back { display: inline-grid !important; }
  .room-header { padding: 6px 6px 6px 4px; gap: 6px; }
  .header-button span { display: none; }
  kg-timeline { padding: 12px 10px 8px; }
  kg-composer { padding: 0 8px 8px; }
  .message-main { max-width: 88%; }
  kg-thread { position: fixed; inset: 0; width: 100%; z-index: 5; border: 0; }
  .message-actions { top: auto; bottom: calc(100% + 4px); }
  .team-more { opacity: 1; }
  .shell.admin-open kg-admin { grid-area: pane; display: flex; flex-direction: column; }
  .admin-nav { border-radius: 0; }
  .admin-nav .rooms { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 6px; }
  .admin-page { padding: 16px 12px; border-left: 0; flex: 1; }
  .admin-header { flex-direction: column; }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .facts { grid-template-columns: 1fr; gap: 2px; }
  .facts dd { margin-bottom: 8px; }
}

/* Teams archive (phase 4.2) */
.dialog.archive-dialog { width: min(1100px, calc(100% - 32px)); height: min(800px, calc(100% - 32px)); padding: 0; }
kg-teams-archive { display: flex; flex-direction: column; height: 100%; }
.archive-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.archive-header h2 { margin: 0; }
.archive-header p { margin: 4px 0 0; }
.archive-body { display: grid; grid-template-columns: 320px 1fr; flex: 1; min-height: 0; }
.archive-nav { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-right: 1px solid var(--border); min-height: 0; }
.archive-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.archive-item { display: flex; gap: 10px; align-items: flex-start; width: 100%; border: 0; background: none; text-align: left; font-weight: 400; padding: 8px; border-radius: 6px; }
.archive-item[aria-current="true"], .archive-item:hover { background: var(--surface-2); }
.archive-empty { padding: 8px; }
.archive-messages { overflow-y: auto; padding: 12px 20px 20px; min-height: 0; }
.archive-title { display: flex; align-items: center; gap: 8px; position: sticky; top: -12px; background: var(--surface); padding: 8px 0; z-index: 1; }
.archive-title h3 { margin: 0; font-size: 1.05rem; }
.archive-title button.archive-back { display: none; }
kg-teams-archive > p.error { margin: 8px 20px 0; }
.archive-more { display: block; margin: 8px auto; }
.archive-message { padding: 8px 0; border-bottom: 1px solid var(--border); }
.archive-message header { font-size: 0.9rem; }
.archive-reply { font-size: 0.85rem; margin: 2px 0; }
.archive-image { max-width: min(360px, 100%); max-height: 300px; border-radius: 6px; display: block; margin: 4px 0; }
.archive-files { list-style: none; padding: 0; margin: 4px 0 0; font-size: 0.9rem; }
.archive-controls { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; margin: 12px 0; }
.archive-controls .field { margin: 0; min-width: 240px; }
@media (max-width: 720px) {
  .dialog.archive-dialog { width: 100%; height: 100%; max-width: none; max-height: none; border-radius: 0; }
  .archive-body { grid-template-columns: 1fr; }
  .archive-body[data-open="true"] .archive-nav { display: none; }
  .archive-body[data-open="false"] .archive-messages { display: none; }
  .archive-nav { border-right: 0; }
  .archive-title button.archive-back { display: grid; }
}
