/* Huddle — styled after Composer: Inter, a near-black page with a soft top glow, filled
   borderless cards lifted by shadow, white pill primary buttons, blue only for action/selection. */
:root {
  --page-top: #111113;
  --page-mid: #0a0a0b;
  --page-end: #070708;
  --card: #141418;
  --card-hover: #18181d;
  --well: rgba(255, 255, 255, 0.035);
  --raised: #1c1c22;
  --raised-hover: #24242c;
  --active: #222222;
  --hairline: rgba(255, 255, 255, 0.06);
  --highlight: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  --shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 2px 4px rgba(0, 0, 0, 0.28), 0 14px 32px rgba(0, 0, 0, 0.38), 0 36px 72px -20px rgba(0, 0, 0, 0.62);
  --shadow-sm: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 2px 4px rgba(0, 0, 0, 0.24), 0 10px 28px rgba(0, 0, 0, 0.32);
  --r-card: 1.15rem;
  --r-well: 0.85rem;
  --r-control: 0.7rem;
  --r-chip: 0.4375rem;
  --r-nav: 14px;
  --text: #ffffff;
  --body: #c6c6ce;
  --muted: #82828c;
  --muted-light: #a0a0a0;
  --faint: #5c5c66;
  --blue: #2f6bff;
  --blue-soft: rgba(47, 107, 255, 0.14);
  --blue-ink: #8fb0ff;
  --green: #34d399;
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.12);
  --code-bg: #1e1e1e;
  --mono: 'JetBrains Mono', 'Cascadia Code', Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { height: 100%; background: var(--page-end); -webkit-text-size-adjust: 100%; touch-action: manipulation; }
html::before {
  content: ''; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background: linear-gradient(180deg, var(--page-top) 0%, var(--page-mid) 42%, var(--page-end) 100%);
}
body {
  position: relative; z-index: 1; height: 100%; margin: 0; background: transparent; color: var(--text);
  font: 14px/1.55 Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; }
svg.i { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--blue); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px; border: 0; border-radius: var(--r-control);
  background: var(--raised); color: var(--text); box-shadow: var(--highlight);
  font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .15s, opacity .15s;
}
.btn:hover { background: var(--raised-hover); }
.btn.primary { background: #fff; color: #000; box-shadow: none; border-radius: 999px; padding: 0 16px; }
.btn.primary:hover { background: rgba(255, 255, 255, 0.9); }
.btn.ghost { background: transparent; box-shadow: none; color: var(--muted-light); }
.btn.ghost:hover { background: var(--active); color: var(--text); }
.btn.danger { color: var(--red); }
.btn.danger.solid { background: #dc2626; color: #fff; }
.btn.icon { width: 32px; padding: 0; border-radius: 9px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.lg { height: 40px; padding: 0 18px; font-size: 14px; }
.link { background: none; border: 0; padding: 0; color: var(--muted-light); cursor: pointer; font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }
.link:hover { color: var(--text); }

/* ---------- form controls ---------- */
.field { display: grid; gap: 6px; }
.field > span { font-size: 12.5px; color: var(--muted-light); font-weight: 500; }
.input {
  width: 100%; height: 40px; padding: 0 12px; border-radius: var(--r-control);
  background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(255, 255, 255, 0.08); color: var(--text);
}
.input::placeholder, textarea::placeholder { color: var(--faint); }
.input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(47, 107, 255, 0.25); }
select.input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a0a0a0' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
select.input option { background: var(--raised); color: var(--text); }
.seg { display: flex; gap: 3px; height: 40px; padding: 3px; border-radius: var(--r-control); background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(255, 255, 255, 0.08); }
.seg label { flex: 1; position: relative; min-width: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: flex; align-items: center; justify-content: center; gap: 6px; height: 100%; padding: 0 10px; border-radius: 8px; color: var(--muted-light); font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: background .15s, color .15s; }
.seg span:hover { color: var(--text); }
.seg input:checked + span { background: var(--raised-hover); color: var(--text); box-shadow: var(--highlight); }
.seg input:focus-visible + span { box-shadow: 0 0 0 2px var(--blue); }
textarea.area { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.check { display: flex; gap: 8px; align-items: center; color: var(--muted-light); font-size: 13px; }
.check input { accent-color: var(--blue); width: 16px; height: 16px; }

/* ---------- sign in ---------- */
.signin { min-height: 100%; display: grid; place-items: center; padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); }
.signin-card { width: min(400px, 100%); background: var(--card); border-radius: var(--r-card); box-shadow: var(--shadow); padding: 28px 24px 24px; display: grid; gap: 18px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; letter-spacing: -0.01em; }
.brand img { width: 28px; height: 28px; border-radius: 8px; }
.signin-card h1 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.signin-card p { margin: -10px 0 0; color: var(--muted); }
.pin { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.pin input {
  width: 100%; min-width: 0; height: 52px; text-align: center; font-size: 22px; font-weight: 600; padding: 0;
  border-radius: var(--r-control); background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(255, 255, 255, 0.08); caret-color: var(--blue);
}
.pin input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(47, 107, 255, 0.25); }
.err { color: var(--red); font-size: 13px; min-height: 18px; margin-top: -8px; }
.signin-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 284px 1fr; height: 100vh; height: 100dvh; }
.side { display: flex; flex-direction: column; min-height: 0; padding: 14px 10px 10px; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 6px 14px; }
.side-scroll { overflow: auto; flex: 1; padding: 0 2px; scrollbar-width: thin; }
/* Same shape as the chat rows below it, so the sidebar reads as one list. */
.new-chat {
  width: 100%; height: 38px; margin: 0 0 10px; padding: 0 12px; gap: 10px;
  justify-content: flex-start; border-radius: var(--r-nav); font-size: 14px; font-weight: 500;
  background: var(--raised); color: var(--text);
}
.new-chat:hover { background: var(--raised-hover); }
.new-chat .plus { width: 22px; height: 22px; margin-left: -3px; border-radius: 7px; background: var(--blue); color: #fff; display: grid; place-items: center; }
.new-chat .plus svg.i { width: 14px; height: 14px; stroke-width: 2.4; }
.new-chat .kbd { margin-left: auto; color: var(--faint); font-size: 12px; font-weight: 500; }
.side-label { display: flex; align-items: center; justify-content: space-between; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; padding: 12px 12px 6px; }
.side-label .btn { height: 24px; width: 24px; }
.room {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border-radius: var(--r-nav);
  border: 0; background: none; text-align: left; cursor: pointer; color: var(--muted-light); font-size: 14px; font-weight: 500;
  transition: background .15s, color .15s;
}
.room:hover { background: var(--active); color: var(--text); }
.room.active { background: var(--active); color: var(--text); }
.room.unread { color: var(--text); font-weight: 600; }
.room-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.badge { margin-left: auto; background: var(--blue); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 600; min-width: 20px; height: 20px; padding: 0 6px; display: inline-grid; place-items: center; }
.person { display: flex; align-items: center; gap: 10px; padding: 7px 12px; color: var(--muted-light); font-size: 13.5px; }
.person .note { color: var(--faint); font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.on { background: var(--green); box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.15); }
.tag { font-size: 11px; line-height: 18px; padding: 0 7px; border-radius: var(--r-chip); background: var(--blue-soft); color: var(--blue-ink); font-weight: 600; }
.tag.admin { background: rgba(255, 255, 255, 0.07); color: var(--muted-light); }
.me-card { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: var(--r-well); background: var(--well); margin-top: 8px; }
.me-card .who { flex: 1; min-width: 0; display: grid; line-height: 1.3; }
.me-card .who b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-card .who span { font-size: 12px; color: var(--muted); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 10px 10px 10px 0; }
.panel { flex: 1; display: flex; flex-direction: column; min-height: 0; background: var(--card); border-radius: var(--r-card); box-shadow: var(--shadow-sm); overflow: hidden; }
.main-head { display: flex; align-items: center; gap: 10px; padding: 0 18px; height: 58px; flex: none; border-bottom: 1px solid var(--hairline); }
.main-head h1 { font-size: 15px; font-weight: 600; margin: 0; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main-head .sub { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.main-head .spacer { flex: 1; }
.main-head .titles { display: grid; min-width: 0; line-height: 1.3; }

.feed { flex: 1; overflow: auto; padding: 14px 0 8px; scrollbar-width: thin; }
.feed-empty { color: var(--muted); text-align: center; padding: 64px 24px; }
.older { display: flex; justify-content: center; padding: 4px 0 10px; }
.day { display: flex; align-items: center; justify-content: center; padding: 14px 0 6px; }
.day span { font-size: 11.5px; color: var(--muted); background: var(--well); padding: 2px 10px; border-radius: 999px; font-weight: 500; }
.system { display: flex; align-items: center; justify-content: center; gap: 6px; color: var(--muted); font-size: 12.5px; padding: 6px 16px; }
.system strong { color: var(--body); font-weight: 600; }
.msg { display: grid; grid-template-columns: 36px 1fr; gap: 12px; padding: 7px 20px; position: relative; }
.msg:hover { background: rgba(255, 255, 255, 0.015); }
.msg.cont { padding-top: 0; }
.msg.cont .avatar { visibility: hidden; height: 0; }
.msg.cont .meta { display: none; }
.msg.mentions-me { background: rgba(47, 107, 255, 0.07); }
.msg.mentions-me::before { content: ''; position: absolute; left: 0; top: 4px; bottom: 4px; width: 3px; border-radius: 0 3px 3px 0; background: var(--blue); }
.avatar { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; font-weight: 600; color: #fff; font-size: 14px; box-shadow: var(--highlight); }
.avatar svg.i { width: 18px; height: 18px; }
.avatar.sm { width: 30px; height: 30px; border-radius: 9px; font-size: 13px; }
.meta { display: flex; align-items: center; gap: 8px; margin-bottom: 1px; }
.meta .name { font-weight: 600; font-size: 14px; }
.meta .time { color: var(--faint); font-size: 12px; }
.acts-hover { margin-left: auto; opacity: 0; transition: opacity .15s; }
.msg:hover .acts-hover { opacity: 1; }
.acts-hover .btn { height: 26px; width: 26px; }
.body { color: var(--body); overflow-wrap: anywhere; }
.body p { margin: 0 0 6px; }
.body p:last-child { margin-bottom: 0; }
.body strong { color: var(--text); font-weight: 600; }
.body code { background: rgba(255, 255, 255, 0.07); border-radius: 5px; padding: 1px 5px; font: 12.5px/1.5 var(--mono); color: #e2e2e8; }
.body pre { background: var(--code-bg); border-radius: var(--r-well); padding: 12px 14px; overflow: auto; margin: 6px 0; }
.body pre code { background: none; padding: 0; color: #cccccc; }
.body a { color: var(--blue-ink); text-decoration: none; }
.body a:hover { text-decoration: underline; }
.body .at { color: var(--blue-ink); font-weight: 600; background: var(--blue-soft); border-radius: 5px; padding: 0 4px; }
.reply-ref { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; margin-bottom: 2px; min-width: 0; }
.reply-ref span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.shot { display: block; border-radius: var(--r-well); overflow: hidden; max-width: min(380px, 100%); box-shadow: var(--shadow-sm); }
.shot img { display: block; max-width: 100%; max-height: 300px; object-fit: contain; background: var(--well); }
.clip { max-width: min(440px, 100%); max-height: 300px; border-radius: var(--r-well); background: #000; }
.file-chip { display: inline-flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--r-well); background: var(--raised); box-shadow: var(--highlight); color: var(--text); text-decoration: none; max-width: 340px; transition: background .15s; }
.file-chip:hover { background: var(--raised-hover); }
.file-chip .ficon { width: 34px; height: 34px; border-radius: 9px; background: var(--blue-soft); color: var(--blue-ink); display: grid; place-items: center; flex: none; }
.file-chip > span { display: grid; min-width: 0; line-height: 1.35; }
.fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; font-size: 13.5px; }
.fsize { color: var(--muted); font-size: 12px; font-weight: 400; }

/* ---------- composer (the prompt box) ---------- */
.composer { padding: 6px 16px 16px; flex: none; position: relative; }
.composer-box {
  display: flex; align-items: flex-end; gap: 6px; padding: 8px; border-radius: var(--r-card);
  background: var(--raised); box-shadow: var(--shadow-sm); transition: box-shadow .15s;
}
.composer-box:focus-within { box-shadow: var(--shadow-sm), 0 0 0 1px rgba(47, 107, 255, 0.55); }
.composer textarea { flex: 1; border: 0; resize: none; background: transparent; max-height: 200px; min-height: 24px; padding: 6px 4px; line-height: 1.5; font-size: 14.5px; }
.composer textarea:focus { outline: none; }
.send { width: 34px; height: 34px; border-radius: 50%; border: 0; background: #fff; color: #000; display: grid; place-items: center; cursor: pointer; flex: none; transition: opacity .15s; }
.send:disabled { opacity: .35; cursor: default; }
.send svg.i { stroke-width: 2.2; }
.composer .hint { color: var(--faint); font-size: 12px; padding: 6px 6px 0; }
.pending { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 2px 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 3px 3px 10px; border-radius: 999px; background: var(--raised); box-shadow: var(--highlight); font-size: 12.5px; }
.chip .btn.icon { width: 24px; height: 24px; }
.replying { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted-light); padding: 0 6px 8px; min-width: 0; }
.replying span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.replying .btn { height: 24px; width: 24px; }
.suggest { position: absolute; bottom: calc(100% - 2px); left: 16px; background: var(--raised); border-radius: var(--r-well); box-shadow: var(--shadow); padding: 4px; min-width: 220px; z-index: 5; }
.suggest button { display: flex; gap: 10px; align-items: center; width: 100%; border: 0; background: none; padding: 7px 10px; border-radius: 9px; cursor: pointer; text-align: left; color: var(--body); }
.suggest button.sel, .suggest button:hover { background: var(--raised-hover); color: var(--text); }
.dropzone { position: fixed; inset: 14px; border-radius: var(--r-card); background: rgba(10, 10, 11, 0.82); box-shadow: inset 0 0 0 2px var(--blue); display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 600; font-size: 16px; color: var(--text); pointer-events: none; z-index: 40; backdrop-filter: blur(4px); }

/* ---------- dialogs ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal { width: min(640px, 100%); max-height: calc(100dvh - 32px); background: var(--card); border-radius: var(--r-card); box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; }
.modal.small { width: min(440px, 100%); }
.modal > form { display: flex; flex-direction: column; min-height: 0; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 14px 20px; border-bottom: 1px solid var(--hairline); }
.modal-head h2 { font-size: 15px; font-weight: 600; margin: 0; display: flex; align-items: center; gap: 10px; }
.modal-body { padding: 18px 20px; overflow: auto; display: grid; gap: 16px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--hairline); }
.modal p { margin: 0; color: var(--muted-light); }
.well { background: var(--well); border-radius: var(--r-well); padding: 4px 14px; }
.member-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; }
.member-row + .member-row { border-top: 1px solid var(--hairline); }
.member-row .info { flex: 1; min-width: 0; }
.member-row .who { display: flex; align-items: center; gap: 8px; font-weight: 600; flex-wrap: wrap; }
.member-row .note { font-size: 12.5px; color: var(--muted); font-weight: 400; margin-top: 2px; }
.member-row .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.add-member { display: grid; grid-template-columns: 1fr 210px auto; gap: 10px; align-items: end; }
.keybox { display: flex; gap: 10px; align-items: center; background: var(--blue-soft); border-radius: var(--r-well); padding: 12px 14px; }
.keybox code { flex: 1; overflow-wrap: anywhere; font: 12.5px/1.5 var(--mono); color: #dbe5ff; }
.warn { font-size: 13px; color: var(--muted-light); }
.warn code { font: 12px var(--mono); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.toast { position: fixed; right: 18px; bottom: 18px; max-width: min(420px, calc(100vw - 36px)); background: var(--raised); color: var(--text); padding: 10px 14px; border-radius: var(--r-well); box-shadow: var(--shadow); z-index: 30; font-size: 13.5px; }
.toast.bad { background: #3a1416; color: #ffd4d4; }

/* ---------- phone ---------- */
.only-narrow { display: none !important; }
@media (max-width: 760px) {
  .only-narrow { display: inline-flex !important; }
  .only-wide { display: none !important; }
  .shell { grid-template-columns: 1fr; }
  .shell[data-view="chat"] .side { display: none; }
  .shell[data-view="list"] .main { display: none; }
  .side { padding: calc(10px + env(safe-area-inset-top)) 10px calc(10px + env(safe-area-inset-bottom)); }
  .room { padding: 12px 12px; font-size: 15px; }
  .main { padding: 0; }
  .panel { border-radius: 0; box-shadow: none; background: transparent; }
  .main-head { padding: env(safe-area-inset-top) 8px 0 4px; height: calc(56px + env(safe-area-inset-top)); background: rgba(10, 10, 11, 0.85); backdrop-filter: blur(12px); }
  .msg { padding: 7px 14px; gap: 10px; grid-template-columns: 32px 1fr; }
  .avatar { width: 32px; height: 32px; border-radius: 10px; }
  .composer { padding: 6px 8px calc(8px + env(safe-area-inset-bottom)); }
  .composer .hint { display: none; }
  .composer textarea { font-size: 16px; } /* no zoom on focus in iOS */
  .input, .pin input { font-size: 16px; }
  .add-member { grid-template-columns: 1fr; }
  .member-row { flex-wrap: wrap; }
  .member-row .acts { width: 100%; justify-content: flex-start; }
  .modal { max-height: calc(100dvh - 24px); }
  .scrim { align-items: end; padding: 0; }
  .modal, .modal.small { width: 100%; border-radius: var(--r-card) var(--r-card) 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .acts-hover { opacity: 1; }
}
