:root {
  --navy: #17448b;
  --navy-dark: #0e2f52;
  --navy-light: #eef4fb;
  --green: #2e7d47;
  --ink: #1f2937;
  --line: #e4e1db;
  --paper: #fbfaf7;
  --white: #fff;
  --radius: 12px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, .brand, .chan-name { font-family: "Plus Jakarta Sans", Inter, sans-serif; }
.muted { color: #6b7280; font-size: 12.5px; }
button { font-family: inherit; cursor: pointer; }
a { color: var(--navy); }

#app { display: grid; grid-template-columns: 264px 1fr; height: 100vh; height: 100dvh; }
#app.thread-open { grid-template-columns: 264px 1fr 360px; }

/* ---------------------------------------------------------------- sidebar */
#sidebar {
  background: var(--navy-dark);
  color: #e9eef7;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.side-head { display: flex; gap: 10px; align-items: center; padding: 16px 16px 12px; }
.side-head img { border-radius: 7px; }
.brand { font-weight: 800; font-size: 15px; letter-spacing: .01em; }
.tag { font-size: 11px; color: #9fb3d1; letter-spacing: .04em; text-transform: uppercase; }
.search-wrap { padding: 0 12px 10px; position: relative; }
.search-wrap input {
  width: 100%; padding: 9px 11px; border-radius: 9px; border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.08); color: #fff; font: inherit; font-size: 13px;
}
.search-wrap input::placeholder { color: #93a6c4; }
#searchResults {
  position: absolute; left: 12px; right: 12px; top: 44px; z-index: 20;
  background: #fff; color: var(--ink); border-radius: 10px; box-shadow: 0 18px 40px -18px rgba(14,47,82,.6);
  max-height: 320px; overflow: auto; border: 1px solid var(--line);
}
#searchResults .hit { padding: 9px 11px; border-bottom: 1px solid #f0eee9; cursor: pointer; font-size: 13px; }
#searchResults .hit:last-child { border-bottom: 0; }
#searchResults .hit b { color: var(--navy); }
#searchResults .hit small { color: #6b7280; display: block; font-size: 11.5px; }

.side-body { flex: 1; overflow: auto; padding: 4px 8px 12px; min-height: 0; }
.side-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; color: #8ba2c4;
  padding: 10px 8px 4px; font-weight: 600;
}
.chan {
  display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: 8px;
  color: #dbe5f4; cursor: pointer; font-size: 13.5px; line-height: 1.25;
}
.chan:hover { background: rgba(255,255,255,.07); }
.chan.active { background: var(--navy); color: #fff; }
.chan .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chan .hash { opacity: .55; font-weight: 600; }
.badge {
  background: var(--green); color: #fff; border-radius: 999px; font-size: 11px;
  padding: 1px 7px; font-weight: 600;
}
.badge.quiet { background: rgba(255,255,255,.18); }
.person { display: flex; align-items: center; gap: 8px; padding: 6px 9px; border-radius: 8px; font-size: 13px; color: #dbe5f4; cursor: pointer; }
.person:hover { background: rgba(255,255,255,.07); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: #5b6d86; display: inline-block; }
.dot.on { background: #4ade80; box-shadow: 0 0 0 3px rgba(74,222,128,.16); }

.side-foot {
  border-top: 1px solid rgba(255,255,255,.1); padding: 12px 14px; display: flex;
  align-items: center; justify-content: space-between; gap: 8px;
}
.me { display: flex; gap: 9px; align-items: center; font-size: 13px; }
.me-dot { background: #4ade80; }
.signout { color: #9fb3d1; font-size: 12px; text-decoration: none; }
.signout:hover { color: #fff; }

/* ------------------------------------------------------------------- main */
#main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--white); }
#chanHead {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--white);
}
.chan-name { font-size: 16px; font-weight: 700; color: var(--navy-dark); }
.head-right { display: flex; align-items: center; gap: 8px; }
.presence { font-size: 12px; color: var(--green); font-weight: 600; }
.ghost {
  background: #fff; border: 1px solid var(--line); color: var(--navy); border-radius: 8px;
  padding: 6px 10px; font-size: 12.5px; font-weight: 600;
}
.ghost:hover { border-color: var(--navy); }

.scroll { flex: 1; overflow-y: auto; min-height: 0; }
#messages { padding: 18px 20px 8px; }

.msg { display: grid; grid-template-columns: 34px 1fr; gap: 10px; padding: 9px 6px; border-radius: 10px; }
.msg:hover { background: #fcfbf9; }
.msg.mentioned { background: #f1f7f3; box-shadow: inset 3px 0 0 var(--green); }
.avatar {
  width: 34px; height: 34px; border-radius: 9px; background: var(--navy-light); color: var(--navy);
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.avatar.g { background: #eaf3ed; color: var(--green); }
.msg-head { display: flex; align-items: baseline; gap: 8px; }
.msg-author { font-weight: 600; color: var(--navy-dark); font-size: 13.5px; }
.msg-time { font-size: 11.5px; color: #9aa1ac; }
.msg-body { white-space: pre-wrap; word-wrap: break-word; font-size: 14.5px; }
.msg-body code { background: #f2f1ec; padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.msg-body pre { background: #0e2f52; color: #e9eef7; padding: 10px 12px; border-radius: 9px; overflow-x: auto; font-size: 12.5px; }
.msg-body .mention { background: #e6f0ea; color: var(--green); border-radius: 5px; padding: 0 3px; font-weight: 600; }
.msg-body a { color: var(--navy); }
.msg.deleted .msg-body { color: #9aa1ac; font-style: italic; }
.msg-actions { opacity: 0; display: flex; gap: 4px; margin-left: auto; transition: opacity .12s; }
.msg:hover .msg-actions { opacity: 1; }
.msg-actions button {
  border: 1px solid var(--line); background: #fff; border-radius: 7px; font-size: 11.5px;
  padding: 3px 7px; color: #4b5563;
}
.msg-actions button:hover { color: var(--navy); border-color: var(--navy); }
.replies { margin-top: 5px; font-size: 12px; color: var(--navy); cursor: pointer; font-weight: 600; }
.reactions { display: flex; gap: 5px; margin-top: 5px; flex-wrap: wrap; }
.reactions span {
  background: var(--navy-light); border-radius: 999px; padding: 1px 8px; font-size: 12px;
  border: 1px solid #dbe6f5;
}
.pin-flag { font-size: 11px; color: var(--green); font-weight: 600; }

.empty { padding: 60px 24px; text-align: center; }
.empty h2 { color: var(--navy-dark); font-size: 18px; margin: 0 0 6px; }

.typing { height: 20px; padding: 0 22px; font-size: 12px; color: var(--green); }

.composer { display: flex; gap: 10px; padding: 12px 16px 16px; border-top: 1px solid var(--line); align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  font: inherit; font-size: 14px; max-height: 180px; min-height: 42px; background: #fff; color: var(--ink);
}
.composer textarea:focus { outline: 2px solid rgba(23,68,139,.18); border-color: var(--navy); }
.send {
  background: var(--navy); color: #fff; border: 0; border-radius: 10px; padding: 11px 16px;
  font-weight: 600; font-size: 13.5px;
}
.send:hover { background: var(--navy-dark); }

/* ----------------------------------------------------------------- thread */
#thread { border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: #fff; }
.thread-head { display: flex; justify-content: space-between; align-items: center; padding: 13px 16px; border-bottom: 1px solid var(--line); font-weight: 700; color: var(--navy-dark); font-size: 14px; }
#threadMessages { padding: 14px 14px 6px; }
#thread .msg { grid-template-columns: 28px 1fr; }
#thread .avatar { width: 28px; height: 28px; font-size: 11.5px; }

/* ------------------------------------------------------------------ sheet */
#sheet { position: fixed; inset: 0; background: rgba(14,47,82,.45); display: grid; place-items: center; z-index: 60; }
.sheet-card { background: #fff; border-radius: 16px; padding: 20px 22px; width: min(420px, 92vw); max-height: 80vh; overflow: auto; box-shadow: 0 30px 70px -30px rgba(14,47,82,.7); }
.sheet-card h3 { margin: 0 0 12px; color: var(--navy-dark); font-size: 16px; }
.sheet-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid #f2f0eb; font-size: 14px; }
.sheet-row:last-child { border-bottom: 0; }
.sheet-row .grow { flex: 1; }

/* ------------------------------------------------------------------- gate */
#gate { min-height: 100vh; display: grid; place-items: center; background: var(--navy-light); }
.gate-card { background: #fff; padding: 34px 30px; border-radius: 18px; text-align: center; box-shadow: 0 30px 70px -34px rgba(14,47,82,.55); max-width: 380px; }
.gate-mark { width: 46px; height: 46px; border-radius: 12px; background: var(--navy-dark); color: #fff; display: grid; place-items: center; margin: 0 auto 14px; font-weight: 800; font-family: "Plus Jakarta Sans", sans-serif; }
.gate-card h1 { margin: 0 0 6px; font-size: 20px; color: var(--navy-dark); }
.btn { display: inline-block; margin-top: 14px; background: var(--navy); color: #fff; text-decoration: none; padding: 10px 18px; border-radius: 10px; font-weight: 600; font-size: 14px; }

/* --------------------------------------------------------------- mobile */
@media (max-width: 900px) {
  #app, #app.thread-open { grid-template-columns: 1fr; }
  #sidebar { position: fixed; inset: 0 auto 0 0; width: 84%; max-width: 320px; transform: translateX(-102%); transition: transform .2s; z-index: 40; }
  #app.side-open #sidebar { transform: none; }
  #thread { position: fixed; inset: 0; z-index: 50; }
  .msg-actions { opacity: 1; }
}

/* ------------------------------------------------------------- attachments */
.composer .attach { padding: 10px 11px; font-size: 15px; line-height: 1; }
.attachments { display: flex; flex-direction: column; gap: 8px; margin-top: 7px; }
.att-img {
  max-width: min(420px, 100%); max-height: 320px; border-radius: 12px; border: 1px solid var(--line);
  display: block; background: #f6f5f2; cursor: zoom-in;
}
.file-chip {
  display: inline-flex; align-items: center; gap: 10px; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: 11px; background: #fcfbf9; text-decoration: none; color: var(--ink); max-width: 380px;
}
.file-chip:hover { border-color: var(--navy); background: #fff; }
.file-chip .fic { width: 30px; height: 30px; border-radius: 8px; background: var(--navy-light); color: var(--navy);
  display: grid; place-items: center; font-size: 14px; flex: 0 0 auto; }
.file-chip .fmeta { display: flex; flex-direction: column; min-width: 0; }
.file-chip .fname { font-size: 13px; font-weight: 600; color: var(--navy-dark); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip .fsize { font-size: 11.5px; color: #6b7280; }
.upload-bar {
  position: relative; margin: 0 16px 8px; height: 26px; border-radius: 8px; background: var(--navy-light);
  overflow: hidden; display: flex; align-items: center;
}
#uploadFill { position: absolute; inset: 0 auto 0 0; width: 0%; background: #dbe8f8; transition: width .18s; }
#uploadText { position: relative; font-size: 11.5px; color: var(--navy); font-weight: 600; padding-left: 10px; }
.drop-zone {
  position: absolute; inset: 0; z-index: 45; display: grid; place-items: center;
  background: rgba(23,68,139,.08); border: 2px dashed var(--navy); color: var(--navy-dark);
  font-weight: 700; border-radius: 14px; margin: 10px; pointer-events: none;
}
#main { position: relative; }

/* --------------------------------------------------------- video + controls */
.att-video { max-width: min(520px, 100%); border-radius: 12px; border: 1px solid var(--line); background: #000; display: block; }
.ghost.tiny { padding: 4px 8px; font-size: 11.5px; }
.ghost.on { background: var(--navy); color: #fff; border-color: var(--navy); }
#uploadCancel { background: none; border: 0; color: var(--navy); font-size: 11.5px; font-weight: 700; text-decoration: underline; margin-left: auto; padding-right: 10px; position: relative; }

/* agents */
.msg-author.is-agent { color: #6d28d9; }
.agent-tag { font-size: 9px; letter-spacing: .06em; text-transform: uppercase; background: #f3ecff; color: #6d28d9; border-radius: 999px; padding: 2px 6px; font-weight: 700; vertical-align: middle; }
.agent-tag.off { background: #fdecec; color: #8d2020; }
.modal { position: fixed; inset: 0; z-index: 80; background: rgba(14,47,82,.42); display: flex; align-items: center; justify-content: center; padding: 18px; }
.modal-card { background: #fff; border-radius: 16px; max-width: 620px; width: 100%; max-height: 84vh; overflow: auto; padding: 18px 20px; box-shadow: 0 30px 60px -30px rgba(14,47,82,.5); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.modal-head h3 { font-family: 'Plus Jakarta Sans', system-ui, sans-serif; font-size: 16px; color: #0e2f52; margin: 0; }
.modal-sub { font-size: 12px; color: #6b7280; margin: 6px 0 14px; }
.agent-card { border: 1px solid #eee9e2; border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.agent-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.agent-name { font-weight: 700; color: #0e2f52; font-size: 13.5px; }
.agent-owner { font-size: 11px; color: #6b7280; }
.agent-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 6px; font-size: 11.5px; color: #374151; }
.agent-row label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: #6b7280; }
.agent-row input[type=number] { width: 76px; padding: 5px 7px; border: 1px solid #e4e1db; border-radius: 8px; font: inherit; }
.agent-chans { display: flex; gap: 10px; flex-wrap: wrap; }
.agent-chans .chk { display: flex; align-items: center; gap: 4px; text-transform: none; letter-spacing: 0; font-size: 12px; color: #1f2937; }
.agent-meta { font-size: 11px; color: #6b7280; }
.agent-empty { font-size: 12.5px; color: #6b7280; padding: 10px 2px; }
.btn.danger { border-color: #f3c9c9; color: #8d2020; }
