/* Sigma Summit — Albufeira, Algarve.
   Atlantic teal and turquoise coves, ochre limestone cliffs, terracotta
   roofs, calçada waves on sun-bleached sand. */

:root {
  --sea: #0f6e84;
  --sea-deep: #0b3945;
  --sea-ink: #072630;
  --lagoon: #2bb3b1;
  --terracotta: #c4502e;
  --terracotta-deep: #a53f22;
  --ochre: #e0922f;
  --sand-gold: #f5cf8a;
  --cliff: #c8792f;

  --bg: #faf6ee;
  --surface: #ffffff;
  --surface-2: #f3ecdf;
  --text: #1a2a30;
  --muted: #5b6d73;
  --border: #e6dccb;
  --link: #0f6e84;
  --mention-bg: #fff1d6;
  --shadow: 0 1px 2px rgba(7, 38, 48, 0.06), 0 8px 24px rgba(7, 38, 48, 0.08);
  --radius: 14px;

  --side-text: #eaf4f5;
  --side-muted: rgba(234, 244, 245, 0.6);

  --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;

  /* Calçada portuguesa "mar largo" waves, as paved through Albufeira's old town. */
  --waves-light: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='32' viewBox='0 0 64 32'%3E%3Cpath d='M0 8q16-8 32 0t32 0M0 24q16-8 32 0t32 0' fill='none' stroke='rgba(255,255,255,0.06)' stroke-width='1.4'/%3E%3C/svg%3E");
  --waves-paper: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='32' viewBox='0 0 64 32'%3E%3Cpath d='M0 8q16-8 32 0t32 0M0 24q16-8 32 0t32 0' fill='none' stroke='rgba(15,110,132,0.055)' stroke-width='1.4'/%3E%3C/svg%3E");
  /* The Atlantic rolling in along the top of the conversation. */
  --shoreline: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='20' viewBox='0 0 80 20'%3E%3Cpath d='M0 0H80V12q-10 6-20 0t-20 0-20 0-20 0z' fill='rgb(43,179,177)' fill-opacity='0.55'/%3E%3Cpath d='M0 0H80V7q-10-5-20 0t-20 0-20 0-20 0z' fill='rgb(15,110,132)'/%3E%3Cpath d='M80 7q-10-5-20 0t-20 0-20 0-20 0' fill='none' stroke='rgba(255,255,255,0.55)' stroke-width='1'/%3E%3C/svg%3E");

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b161b;
    --surface: #11212a;
    --surface-2: #172c36;
    --text: #e6f0f2;
    --muted: #95aab1;
    --border: #223a45;
    --link: #7fd3e0;
    --mention-bg: rgba(224, 146, 47, 0.13);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    --waves-paper: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='32' viewBox='0 0 64 32'%3E%3Cpath d='M0 8q16-8 32 0t32 0M0 24q16-8 32 0t32 0' fill='none' stroke='rgba(111,216,212,0.045)' stroke-width='1.4'/%3E%3C/svg%3E");
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg { flex: none; }

/* ------------------------------------------------------------------ layout */

.app {
  display: grid;
  grid-template-columns: 284px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

/* ----------------------------------------------------------------- sidebar */

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--waves-light), var(--sea-deep);
  color: var(--side-text);
  border-right: 1px solid rgba(0, 0, 0, 0.2);
  position: relative;
}
.sidebar::after {
  /* thin coastline stripe down the edge: cove, cliff, rooftops */
  content: '';
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 3px;
  background: linear-gradient(180deg, var(--lagoon) 0 34%, var(--ochre) 34% 72%, var(--terracotta) 72% 100%);
  opacity: 0.9;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.brand-logo { width: 42px; height: 42px; filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.3)); }
.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.15;
}
.brand p {
  margin: 2px 0 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--sand-gold);
}

.side-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 6px 12px 16px; }
.side-section h2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 18px 10px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--side-muted);
}
.count {
  font-size: 11px;
  letter-spacing: 0;
  background: rgba(255, 255, 255, 0.1);
  color: var(--side-text);
  border-radius: 999px;
  padding: 0 8px;
}

.channel-list, .user-list { list-style: none; margin: 0; padding: 0; }

.channel-btn {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: rgba(234, 244, 245, 0.78);
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.channel-btn:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }
.channel-btn:focus-visible { outline: 2px solid var(--ochre); outline-offset: 1px; }
.channel-btn.active { background: rgba(255, 255, 255, 0.13); color: #fff; font-weight: 600; }
.channel-btn.active::before {
  content: '';
  position: absolute;
  left: -12px; top: 7px; bottom: 7px;
  width: 4px;
  border-radius: 0 4px 4px 0;
  background: var(--ochre);
}
.channel-btn.unread { color: #fff; font-weight: 600; }
.channel-btn .hash { color: rgba(234, 244, 245, 0.4); font-weight: 500; }
.channel-btn .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  min-width: 20px;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}
.badge.hot { background: var(--terracotta); box-shadow: 0 0 0 2px rgba(196, 80, 46, 0.25); }

.user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 10px;
  font-size: 14px;
  color: rgba(234, 244, 245, 0.9);
}
.user .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user .you { color: var(--side-muted); font-size: 12px; }

.avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--sea);
  flex: none;
  user-select: none;
}
.avatar.sm { position: relative; width: 26px; height: 26px; border-radius: 8px; font-size: 10.5px; }
.avatar.sm::after {
  content: '';
  position: absolute;
  right: -3px; bottom: -3px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #2fcf73;
  border: 2px solid var(--sea-deep);
}

.me {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 12px 16px;
  border: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.18);
  color: var(--side-text);
  text-align: left;
  cursor: pointer;
}
.me:hover { background: rgba(0, 0, 0, 0.28); }
.me:focus-visible { outline: 2px solid var(--ochre); outline-offset: -2px; }
.me-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.me-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-sub { font-size: 12px; color: var(--side-muted); }
.gear { width: 18px; height: 18px; fill: none; stroke: var(--side-muted); stroke-width: 1.7; }

/* -------------------------------------------------------------------- chat */

.chat {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--waves-paper), var(--bg);
}

.shoreline {
  flex: none;
  height: 20px;
  background: var(--shoreline) repeat-x 0 0 / 80px 20px;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 2px 28px 14px;
  border-bottom: 1px solid var(--border);
}
.header-text { flex: 1; min-width: 0; }
.chat-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.chat-header h2 .hash { color: var(--terracotta); margin-right: 1px; }
.chat-header p {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.conn::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: #999; }
.conn.live::before { background: #1fae5b; box-shadow: 0 0 0 3px rgba(31, 174, 91, 0.2); }
.conn.connecting::before { background: var(--ochre); animation: pulse 1s ease-in-out infinite alternate; }
.conn.offline::before { background: var(--terracotta); }
@keyframes pulse { to { opacity: 0.35; } }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--ochre); }
.icon-btn:focus-visible { outline: 2px solid var(--ochre); outline-offset: 2px; }
.icon-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.bell { position: relative; }
.bell.on { color: var(--sea); }
.bell.on::after {
  content: '';
  position: absolute;
  top: 7px; right: 8px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--sea);
  border: 1.5px solid var(--surface);
}
.bell.blocked { color: var(--muted); }
.menu-btn { display: none; }

.notif-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 14px 28px 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--ochre);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 14px;
}
.notif-banner p { margin: 0; flex: 1; }
.notif-banner-icon { font-size: 20px; }
.notif-banner-actions { display: flex; gap: 8px; flex: none; }

/* ---------------------------------------------------------------- messages */

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 28px 8px;
  overscroll-behavior: contain;
}

.msg {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  column-gap: 12px;
  margin: 0 -12px;
  padding: 6px 12px;
  border-radius: 10px;
}
.msg + .msg:not(.grouped) { margin-top: 6px; }
.msg:hover { background: rgba(127, 127, 127, 0.07); }
.msg.grouped { padding-top: 1px; padding-bottom: 1px; }
.msg.mention { background: var(--mention-bg); box-shadow: inset 3px 0 0 var(--ochre); }
.msg .gutter-time {
  visibility: hidden;
  font-size: 10.5px;
  color: var(--muted);
  text-align: right;
  line-height: 22px;
  font-variant-numeric: tabular-nums;
}
.msg.grouped:hover .gutter-time { visibility: visible; }
.msg-head { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.msg-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-name .you { font-weight: 500; color: var(--muted); font-size: 12px; margin-left: 4px; }
.msg-time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.msg-body { overflow-wrap: anywhere; white-space: normal; }
.msg-body a { color: var(--link); text-underline-offset: 2px; }

.mention-tag {
  padding: 0 3px;
  border-radius: 4px;
  background: rgba(15, 110, 132, 0.12);
  color: var(--sea);
  font-weight: 600;
}
.mention-tag.is-me { background: rgba(196, 80, 46, 0.12); color: var(--terracotta); }
@media (prefers-color-scheme: dark) {
  .mention-tag { color: #6fd8d4; background: rgba(111, 216, 212, 0.12); }
  .mention-tag.is-me { color: #ff7a8c; background: rgba(255, 122, 140, 0.14); }
}

.day {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0 10px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.day::before, .day::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.system {
  margin: 8px 0;
  text-align: center;
  font-size: 13px;
  font-style: italic;
  color: var(--muted);
}

.empty {
  max-width: 420px;
  margin: 12vh auto 0;
  padding: 28px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.empty h3 { margin: 12px 0 6px; font-family: var(--font-display); font-size: 22px; font-weight: 600; }
.empty p { margin: 0; color: var(--muted); }
.empty .emblem {
  /* An Algarve sunset over the Atlantic, with a sea stack off the cliffs. */
  display: inline-block;
  width: 58px; height: 40px;
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 70%, #fff4dc 0 9px, transparent 9.5px),
    linear-gradient(180deg, #f6b35c 0 64%, var(--sea) 64% 100%);
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.empty .emblem::before {
  content: '';
  position: absolute;
  left: 0; bottom: 0;
  width: 13px; height: 26px;
  border-radius: 0 6px 0 0;
  background: var(--cliff);
}
.empty .emblem::after {
  content: '';
  position: absolute;
  right: 8px; bottom: 6px;
  width: 6px; height: 13px;
  border-radius: 3px 3px 0 0;
  background: var(--cliff);
}

.new-pill {
  position: absolute;
  left: 50%;
  bottom: 118px;
  transform: translateX(-50%);
  padding: 7px 16px;
  border: 0;
  border-radius: 999px;
  background: var(--sea);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(7, 38, 48, 0.3);
  cursor: pointer;
}

/* ---------------------------------------------------------------- composer */

.composer-wrap { padding: 0 28px 18px; }
.typing { height: 22px; padding: 2px 4px; font-size: 12.5px; color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.typing strong { color: var(--text); font-weight: 600; }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 8px 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer:focus-within { border-color: var(--ochre); box-shadow: 0 0 0 3px rgba(224, 146, 47, 0.25), var(--shadow); }
.composer textarea {
  flex: 1;
  min-height: 38px;
  max-height: 180px;
  padding: 8px 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: inherit;
  font: inherit;
  line-height: 1.45;
}
.send-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  background: var(--terracotta);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.send-btn svg { width: 16px; height: 16px; fill: currentColor; }
.send-btn:hover:not(:disabled) { background: var(--terracotta-deep); }
.send-btn:focus-visible { outline: 2px solid var(--ochre); outline-offset: 2px; }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.hint { margin: 7px 4px 0; font-size: 11.5px; color: var(--muted); }
kbd {
  padding: 0 5px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface);
  font-family: inherit;
  font-size: 10.5px;
}

/* ----------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.btn:focus-visible { outline: 2px solid var(--ochre); outline-offset: 2px; }
.btn-primary { background: var(--sea); color: #fff; }
.btn-primary:hover { background: #0b5a6c; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--ochre); }
.btn-danger { background: var(--terracotta); color: #fff; }
.btn-danger:hover { background: var(--terracotta-deep); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-block { width: 100%; height: 44px; margin-top: 18px; }

/* ----------------------------------------------------------------- dialogs */

.dialog {
  width: min(460px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35);
  overflow: auto;
}
.dialog::backdrop { background: rgba(7, 38, 48, 0.6); backdrop-filter: blur(3px); }
.dialog form { margin: 0; }

.dialog-hero {
  position: relative;
  padding: 26px 26px 22px;
  background: var(--waves-light), var(--sea-deep);
  color: var(--side-text);
}
.dialog-hero::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 5px;
  background: linear-gradient(90deg, var(--lagoon) 0 34%, var(--ochre) 34% 72%, var(--terracotta) 72% 100%);
}
.dialog-hero h2 { margin: 4px 0 6px; font-family: var(--font-display); font-size: 25px; font-weight: 600; line-height: 1.2; }
.dialog-hero p { margin: 0; color: rgba(234, 244, 245, 0.8); font-size: 14px; }
.dialog-hero .eyebrow {
  color: var(--sand-gold);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.dialog-body { padding: 22px 26px 24px; }
.dialog-body > label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; }
.dialog input[type='text'], .dialog input:not([type]) {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.dialog input:not([type]):focus { outline: 0; border-color: var(--ochre); box-shadow: 0 0 0 3px rgba(224, 146, 47, 0.25); }
.field-help { margin: 6px 0 0; font-size: 12.5px; color: var(--muted); }

.prefs { margin: 20px 0 0; padding: 0; border: 0; }
.prefs legend { margin-bottom: 8px; padding: 0; font-size: 13px; font-weight: 600; }
.radio {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}
.radio + .radio { margin-top: 6px; }
.radio:has(input:checked) { border-color: var(--sea); background: rgba(15, 110, 132, 0.06); }
.radio input { margin-top: 3px; accent-color: var(--sea); }
.radio span { display: flex; flex-direction: column; }
.radio strong { font-size: 14px; font-weight: 600; }
.radio small { font-size: 12.5px; color: var(--muted); }

.notif-state {
  margin-top: 16px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 13px;
  color: var(--muted);
}
.notif-state strong { color: var(--text); }
.settings-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.confirm { width: min(400px, calc(100vw - 32px)); text-align: center; }
.confirm .dialog-body { padding-top: 26px; }
.confirm h2 { margin: 14px 0 6px; font-family: var(--font-display); font-size: 22px; font-weight: 600; }
.confirm p { margin: 0; color: var(--muted); font-size: 14px; }
.confirm .dialog-footer { justify-content: center; }
.confirm-photo {
  display: block;
  width: 120px;
  height: 120px;
  margin: 0 auto;
  border-radius: 12px;
  object-fit: cover;
  box-shadow: var(--shadow);
}

/* ------------------------------------------------------------------ toasts */

.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(380px, calc(100vw - 32px));
}
.toast {
  padding: 11px 14px;
  border-left: 4px solid var(--sea);
  border-radius: 10px;
  background: var(--sea-ink);
  color: #fff;
  font-size: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  animation: toast-in 0.2s ease-out;
}
.toast.error { border-left-color: var(--terracotta); }
.toast.mention { border-left-color: var(--ochre); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ------------------------------------------------------------------ photos */

.ratio { display: block; }
.photo, .gallery-tile {
  position: relative;
  display: block;
  overflow: hidden;
  background: var(--surface-2);
}
.photo-open {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
}
.photo img, .gallery-tile img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.35s ease, filter 0.2s;
}
.photo img.ready, .gallery-tile img.ready { opacity: 1; }
.photo-open:focus-visible { outline: 3px solid var(--ochre); outline-offset: -3px; }

/* Delete your own photos: a button in the corner, shown on hover or focus.
   Touch screens delete from the photo viewer instead. */
.photo-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(7, 38, 48, 0.78);
  color: #fff;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
}
.photo-delete svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.photo:hover .photo-delete, .gallery-tile:hover .photo-delete, .photo-delete:focus-visible { opacity: 1; }
.photo-delete:hover { background: var(--terracotta); }
.photo-delete:focus-visible { outline: 2px solid var(--ochre); outline-offset: 1px; }
@media (hover: none) { .photo-delete { display: none; } }

/* In a message: one photo keeps its shape; several form a tidy collage. */
.msg-photos {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 440px;
  margin-top: 6px;
  border-radius: 12px;
  overflow: hidden;
}
.msg-photos.single { overflow: visible; border-radius: 0; }
.msg-photos.single .photo { border-radius: 12px; box-shadow: var(--shadow); }
.photo-row { display: flex; gap: 4px; }
.photo { min-width: 0; }
.photo:hover img.ready { filter: brightness(1.06); }
.photo-more {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(7, 38, 48, 0.55);
  color: #fff;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.msg.flash { animation: flash 1.8s ease-out; }
@keyframes flash {
  0%, 30% { background: rgba(224, 146, 47, 0.28); }
  100% { background: transparent; }
}

.photos-btn.active { color: var(--sea); border-color: var(--ochre); background: var(--surface-2); }
@media (prefers-color-scheme: dark) {
  .photos-btn.active { color: #7fd3e0; }
}

/* ---------------------------------------------------------- composer tray */

.composer { flex-wrap: wrap; padding-left: 8px; }
.attach-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.attach-btn svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.attach-btn:hover { background: var(--surface-2); color: var(--sea); }
.attach-btn:focus-visible { outline: 2px solid var(--ochre); outline-offset: 2px; }
@media (prefers-color-scheme: dark) {
  .attach-btn:hover { color: #7fd3e0; }
}

.tray {
  display: flex;
  flex-basis: 100%;
  gap: 8px;
  margin: 0 0 4px;
  padding: 4px 4px 10px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  scrollbar-width: thin;
}
.tile {
  position: relative;
  flex: none;
  width: 72px;
  height: 72px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-2);
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile img:not([src]) { visibility: hidden; }
.tile[data-status='queued'], .tile[data-status='processing'] { animation: shimmer 1.2s ease-in-out infinite alternate; }
.tile[data-status='uploading'] img, .tile[data-status='processing'] img { filter: brightness(0.75); }
.tile-progress {
  position: absolute;
  left: 7px; right: 7px; bottom: 7px;
  height: 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.45);
  overflow: hidden;
}
.tile-progress > span { display: block; height: 100%; width: 0; background: #fff; border-radius: 4px; transition: width 0.2s; }
.tile[data-status='done'] .tile-progress, .tile[data-status='error'] .tile-progress { display: none; }
.tile[data-status='error'] { box-shadow: inset 0 0 0 2px var(--terracotta); }
.tile[data-status='error'] img { filter: grayscale(1) brightness(0.55); }
.tile[data-status='error']::after {
  content: '!';
  position: absolute;
  left: 6px; top: 5px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--terracotta);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  line-height: 18px;
  text-align: center;
}
.tile-remove, .tile-retry {
  position: absolute;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
}
.tile-remove { top: 4px; right: 4px; width: 22px; height: 22px; background: rgba(7, 38, 48, 0.78); }
.tile-remove:hover { background: var(--terracotta); }
.tile-retry { left: 50%; top: 50%; width: 34px; height: 34px; transform: translate(-50%, -50%); background: rgba(7, 38, 48, 0.8); }
.tile-retry:hover { background: var(--sea); }
.tile-remove svg, .tile-retry svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.tile-retry svg { width: 18px; height: 18px; }
.tile-add {
  display: grid;
  place-items: center;
  border: 1.5px dashed var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.tile-add:hover { border-color: var(--ochre); color: var(--text); }
.tile-add svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
@keyframes shimmer { from { opacity: 1; } to { opacity: 0.55; } }

.send-btn.busy { opacity: 0.85; cursor: progress; }
.send-btn.busy svg { display: none; }
.send-btn.busy::before, .spinner {
  content: '';
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: middle;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------- drop zone */

.drop-zone {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(11, 57, 69, 0.72);
  backdrop-filter: blur(3px);
  pointer-events: none;
  animation: fade-in 0.12s ease-out;
}
.drop-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 40px 56px;
  border: 2px dashed var(--sand-gold);
  border-radius: 22px;
  color: #fff;
  text-align: center;
}
.drop-card svg { width: 46px; height: 46px; margin-bottom: 6px; fill: none; stroke: var(--sand-gold); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.drop-card strong { font-family: var(--font-display); font-size: 24px; font-weight: 600; }
.drop-card span { color: rgba(255, 255, 255, 0.75); }
@keyframes fade-in { from { opacity: 0; } }

/* ----------------------------------------------------------------- gallery */

.gallery {
  position: absolute;
  inset: 20px 0 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background: var(--waves-paper), var(--bg);
  animation: gallery-in 0.18s ease-out;
}
@keyframes gallery-in { from { opacity: 0; transform: translateY(8px); } }
.gallery-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 2px 28px 14px;
  border-bottom: 1px solid var(--border);
}
.gallery-heading { flex: 1; min-width: 0; }
.gallery-heading h2 { margin: 0; font-family: var(--font-display); font-size: 24px; font-weight: 600; line-height: 1.2; }
.gallery-heading p { margin: 2px 0 0; min-height: 1.5em; font-size: 13px; color: var(--muted); }
.gallery-add svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }

.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
}
.segmented button {
  padding: 6px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed='true'] { background: var(--sea); color: #fff; }
.segmented button:focus-visible { outline: 2px solid var(--ochre); outline-offset: 1px; }

.gallery-body {
  --row-h: 200px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 28px 28px;
  overscroll-behavior: contain;
}
.gallery-day {
  margin: 20px 0 10px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
/* Justified rows: each tile grows in proportion to its shape, so every
   photo in a row ends up the same height. The filler keeps the last row
   from stretching. */
.gallery-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.gallery-grid::after { content: ''; flex-grow: 999999; }
.gallery-tile { border-radius: 8px; }
.gallery-tile:hover img.ready { transform: scale(1.04); }
.tile-info {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 22px 10px 8px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.62), transparent);
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
  text-align: left;
  opacity: 0;
  transition: opacity 0.2s;
}
.tile-info > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gallery-tile:hover .tile-info, .gallery-tile:focus-within .tile-info { opacity: 1; }
@media (hover: none) { .tile-info { display: none; } }
.tile-channel { flex: none; padding: 0 7px; border-radius: 999px; background: rgba(255, 255, 255, 0.22); font-size: 11px; }
.skeleton .gallery-tile { cursor: default; animation: shimmer 1s ease-in-out infinite alternate; }
.gallery-more { padding: 24px; text-align: center; color: var(--muted); font-size: 13px; }
.gallery-more .spinner { width: 14px; height: 14px; margin-right: 6px; }
.gallery-empty { margin-top: 8vh; }
.gallery-empty .btn { margin-top: 16px; }

/* ---------------------------------------------------------- photo viewer */

.lb {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: rgb(4 14 18 / var(--lb-fade, 1));
  color: #fff;
  overflow: hidden;
}
.lb[open] { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; animation: fade-in 0.15s ease-out; }
.lb::backdrop { background: transparent; }
.lb-bar, .lb-foot, .lb-nav { transition: opacity 0.2s; }
.lb-bar, .lb-foot { position: relative; z-index: 2; opacity: var(--lb-fade, 1); }
.lb-idle .lb-bar, .lb-idle .lb-foot, .lb-idle .lb-nav { opacity: 0; pointer-events: none; }

.lb-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px 16px;
}
.lb-meta { display: flex; flex: 1; align-items: center; gap: 10px; min-width: 0; }
.lb-avatar { width: 34px; height: 34px; font-size: 12px; }
.lb-who { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.lb-who strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-who span { font-size: 12px; color: rgba(255, 255, 255, 0.65); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-actions { display: flex; align-items: center; gap: 2px; flex: none; }
.lb-count { margin-right: 8px; font-size: 13px; color: rgba(255, 255, 255, 0.7); font-variant-numeric: tabular-nums; white-space: nowrap; }
.lb-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #fff;
  cursor: pointer;
}
.lb-btn:hover { background: rgba(255, 255, 255, 0.12); }
.lb-btn:focus-visible, .lb-nav:focus-visible, .lb-thumb:focus-visible { outline: 2px solid var(--sand-gold); outline-offset: 2px; }
.lb-btn svg, .lb-nav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.lb-zoomed [data-act='zoom'] { background: rgba(255, 255, 255, 0.16); }
.lb-delete:hover { background: var(--terracotta); }

.lb-stage { position: relative; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
.lb-zoomed .lb-stage { cursor: grab; }
.lb-zoomed .lb-stage:active { cursor: grabbing; }
.lb-img {
  position: absolute;
  max-width: none;
  border-radius: 2px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  transform-origin: center;
  will-change: transform;
  -webkit-user-drag: none;
  transition: opacity 0.25s;
}
.lb-img.animating { transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.25s; }
.lb-spinner {
  position: absolute;
  right: 18px; bottom: 16px;
  width: 20px; height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.lb-nav {
  position: absolute;
  top: 50%;
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  margin-top: -25px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.42);
  color: #fff;
  cursor: pointer;
}
.lb-nav:hover { background: rgba(0, 0, 0, 0.7); }
.lb-nav svg { width: 26px; height: 26px; stroke-width: 2; }
.lb-nav.prev { left: 16px; }
.lb-nav.next { right: 16px; }
@media (hover: none) { .lb-nav, .lb-btn[data-act='zoom'] { display: none; } }

.lb-foot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 8px 16px max(14px, env(safe-area-inset-bottom));
}
.lb-caption {
  max-width: 720px;
  max-height: 5.5em;
  margin: 0;
  overflow-y: auto;
  color: rgba(255, 255, 255, 0.92);
  font-size: 14.5px;
  text-align: center;
  overflow-wrap: anywhere;
  white-space: pre-line;
}
.lb-strip { display: flex; gap: 6px; max-width: 100%; padding: 3px; overflow-x: auto; scrollbar-width: none; }
.lb-strip::-webkit-scrollbar { display: none; }
.lb-thumb {
  position: relative;
  flex: none;
  width: 54px;
  height: 54px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  overflow: hidden;
  opacity: 0.45;
  cursor: pointer;
  transition: opacity 0.15s;
}
.lb-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lb-thumb:hover { opacity: 0.8; }
.lb-thumb.active { opacity: 1; box-shadow: 0 0 0 2px var(--sand-gold); }

/* ------------------------------------------------------------------ mobile */

@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: min(300px, 86vw);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }
  .app.sidebar-open .sidebar { transform: none; box-shadow: 12px 0 40px rgba(0, 0, 0, 0.35); }
  .scrim { position: fixed; inset: 0; z-index: 35; background: rgba(7, 38, 48, 0.5); }
  .menu-btn { display: inline-grid; }
  .chat-header { padding: 2px 16px 12px; gap: 10px; }
  .chat-header h2 { font-size: 20px; }
  .conn { padding: 4px 9px; font-size: 0; gap: 0; }
  .conn::before { margin: 0; }
  .notif-banner { margin: 10px 16px 0; flex-wrap: wrap; }
  .notif-banner-actions { width: 100%; justify-content: flex-end; }
  .messages { padding: 10px 16px 6px; }
  .composer-wrap { padding: 0 12px calc(12px + env(safe-area-inset-bottom)); }
  .hint { display: none; }
  .new-pill { bottom: 96px; }
  .toasts { right: 16px; left: 16px; bottom: 90px; max-width: none; }
  .msg-photos { max-width: 100%; }
  .tile { width: 64px; height: 64px; }
  .gallery-header { padding: 2px 16px 12px; gap: 10px; }
  .gallery-heading h2 { font-size: 20px; }
  .gallery-add span { display: none; }
  .gallery-add { width: 38px; padding: 0; }
  .segmented { order: 3; width: 100%; }
  .segmented button { flex: 1; }
  .gallery-body { --row-h: 118px; padding: 2px 12px 20px; }
  .gallery-grid { gap: 4px; }
  .gallery-tile { border-radius: 6px; }
  .drop-card { padding: 28px 24px; }
  .lb-bar { padding-left: 12px; padding-right: 6px; }
  .lb-count { margin-right: 2px; font-size: 12px; }
  .lb-btn { width: 38px; height: 38px; }
  .lb-avatar { display: none; }
  .lb-who span { font-size: 11.5px; }
  .lb-thumb { width: 44px; height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
