/* Communion — function-first prototype styles */

:root {
  --bg: #F4F7F8;             /* barely off-white page — slight cool tint to harmonize with brand text */
  --surface: #FFFFFF;        /* cards stay pure white so they have presence against the bg */
  --surface-soft: #EDF1F3;   /* hover/sub-surfaces — a touch cooler than bg */
  --topbar: #F4F7F8;         /* matches bg for a seamless top edge */
  --mint: #E4F0F2;           /* subtle cyan tint for active/grouped states */
  --line: #DDE3E6;           /* hairline — a step cooler so it reads as intentional */

  --brand: #15C6DC;        /* primary cyan */
  --brand-strong: #0FA6BA; /* text on light */
  --brand-ink: #0A7D8C;

  --ink: #0A7D8C;       /* primary text — uses the existing brand-ink dark blue */
  --ink-2: #2D6470;     /* secondary text — softer tint of the same blue family */
  --ink-3: #6F92A0;     /* tertiary/muted — even softer */
  --muted: #8AA0A6;

  --good: #1FA86A;
  --warn: #E08A00;
  --bad: #D03A3A;

  /* Semantic tints — overridden in dark theme below. */
  --input-bg: #FFFFFF;
  --unread-bg: #F0FDFE;
  --chip-hover: #C8F3F7;
  --good-bg: #E9F8F0;
  --warn-bg: #FFF6E5;
  --bad-bg:  #FBEBEB;
  --good-ink: var(--good);
  --warn-ink: var(--warn);
  --bad-ink:  var(--bad);
  --switch-off: #C8D3D6;
  --switch-thumb: #FFFFFF;

  --r-card: 14px;
  --r-pill: 999px;
  --r-input: 12px;

  --shadow-1: 0 1px 0 rgba(15, 27, 31, 0.04);
  --shadow-2: 0 6px 18px rgba(20, 184, 200, 0.10);
  --shadow-card: 0 1px 2px rgba(15, 27, 31, 0.04), 0 1px 6px rgba(15, 27, 31, 0.03);
  --shadow-sheet: 0 16px 48px rgba(15, 27, 31, 0.18);
  --hair: 1px solid var(--line);

  --tap: 44px;
  --bar-h: 64px;
  --topbar-h: 56px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-size: 16px;
  line-height: 1.45;
}

button { font: inherit; color: inherit; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 8px; top: -40px; background: var(--brand); color: #fff;
  padding: 8px 12px; border-radius: 8px; z-index: 100;
}
.skip-link:focus { top: 8px; }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

/* ------ Layout ------ */

.app {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}

.view {
  position: relative;
  padding-bottom: calc(var(--bar-h) + env(safe-area-inset-bottom, 0));
  outline: none;
}

.page { min-height: 100%; }

/* ------ Top bar ------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  min-height: var(--topbar-h);
  border-bottom: 1px solid var(--line);
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
}

.topbar-title-only,
.topbar-detail {
  grid-template-columns: auto 1fr auto;
}

.topbar-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  text-align: center;
  letter-spacing: -0.01em;
}

.topbar-title-only .topbar-title {
  grid-column: 1 / -1;
  text-align: center;
}

.search {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--input-bg);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: 6px 12px;
  min-height: 40px;
}
.search input {
  border: 0;
  outline: 0;
  background: transparent;
  width: 100%;
  font-size: 15px;
  color: var(--ink);
}
.search input::placeholder { color: var(--muted); }

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  border-radius: 50%;
  border: 0;
  background: transparent;
  color: var(--brand-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-soft); color: var(--ink); }
.icon-btn-primary {
  background: var(--brand);
  color: #fff;
}
.icon-btn-primary:hover { background: var(--brand-strong); }

.btn-primary {
  background: var(--brand);
  color: #fff;
  border: 0;
  padding: 9px 16px;
  border-radius: var(--r-pill);
  font-weight: 700;
  cursor: pointer;
  min-height: 40px;
}
.btn-primary:hover { background: var(--brand-strong); }
.btn-primary[disabled] { opacity: 0.5; cursor: not-allowed; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--mint);
  color: var(--brand-strong);
  border: 0;
  border-radius: var(--r-pill);
  padding: 6px 12px;
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  min-height: 32px;
  white-space: nowrap;
  transition: background 120ms ease;
}
.chip:hover { background: var(--chip-hover); }
.chip.is-active {
  background: var(--brand);
  color: #fff;
}

.community-select { max-width: 50vw; overflow: hidden; text-overflow: ellipsis; }

/* ------ Icons ------ */

.ic, .ic-sm, .ic-xs {
  fill: currentColor;
  flex: none;
}
.ic { width: 24px; height: 24px; }
.ic-sm { width: 20px; height: 20px; }
.ic-xs { width: 16px; height: 16px; }

/* ------ Feed ------ */

.feed { padding: 12px; display: flex; flex-direction: column; gap: 12px; }

.post-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-card);
  transition: box-shadow 120ms ease, transform 120ms ease;
}
.post-card:hover {
  box-shadow: 0 2px 4px rgba(15, 27, 31, 0.04), 0 8px 24px rgba(15, 27, 31, 0.06);
}

.post-head {
  display: flex;
  align-items: center;
  gap: 10px;
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--mint);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px;
  color: var(--brand-strong);
  flex: none;
}
.avatar-lg { width: 72px; height: 72px; font-size: 32px; }

.author { font-weight: 600; color: var(--ink); font-size: 14px; letter-spacing: -0.01em; }
.meta { color: var(--ink-3); font-size: 12px; }
.dot { color: var(--ink-3); margin: 0 4px; }

.post-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.015em;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.post-body {
  margin: 0;
  color: var(--ink-2);
  font-size: 15px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.post-image {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 10px;
  background: var(--mint);
  border: 1px solid var(--line);
}

.post-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.rel-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: var(--r-pill);
  padding: 5px 10px;
  border: 1px solid currentColor;
  font-weight: 600;
  font-size: 12px;
  background: var(--surface);
  cursor: pointer;
  min-height: 28px;
}
.rel-chip .ic-xs { fill: currentColor; }
.rel-good { color: var(--good); }
.rel-warn { color: var(--warn); }
.rel-bad  { color: var(--bad); }
.rel-neutral { color: var(--brand-strong); }

/* ------ Unverified tag ------ */

.badge-unverified {
  margin-left: auto;
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--warn-bg); color: var(--warn-ink);
  border: 1.5px solid var(--warn);
  border-radius: var(--r-pill);
  padding: 2px 10px;
  font-size: 11px; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.06em;
  white-space: nowrap;
}
.badge-unverified::before { content: "!"; font-weight: 900; }

.post-card.is-unverified { border-color: var(--warn); }

.license-pill {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: var(--r-pill);
  font-size: 11px; font-weight: 700;
  background: var(--mint); color: var(--brand-strong);
}

/* ------ Post detail ------ */

.post-detail { padding: 16px; display: flex; flex-direction: column; gap: 14px; }

.detail-head { display: flex; align-items: center; gap: 10px; }
.detail-title { font-size: 22px; font-weight: 800; margin: 0; color: var(--ink); }
.detail-body { font-size: 16px; color: var(--ink-2); white-space: pre-wrap; }
.detail-image {
  width: 100%; max-height: 420px; object-fit: cover;
  border-radius: 12px; border: 1px solid var(--line);
}

.ai-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 12px 14px;
}
.ai-panel summary {
  display: flex; align-items: center; gap: 10px;
  cursor: pointer;
  list-style: none;
  font-weight: 700;
  color: var(--brand-strong);
}
.ai-panel summary::-webkit-details-marker { display: none; }
.ai-panel .ai-band {
  height: 6px; border-radius: 3px; margin-top: 8px;
  background: linear-gradient(to right, var(--bad), var(--warn), var(--good));
  position: relative;
}
.ai-panel .ai-band::after {
  content: ""; position: absolute; top: -3px; width: 12px; height: 12px;
  background: #111; border-radius: 50%; transform: translateX(-50%);
  left: var(--pct, 50%);
}
.ai-summary { margin: 10px 0 0; color: var(--ink-2); font-size: 15px; }
.ai-claims { margin: 10px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.ai-claim {
  display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}
.ai-claim .score {
  font-weight: 700; font-variant-numeric: tabular-nums;
}
.ai-sources { margin: 10px 0 0; font-size: 14px; color: var(--ink-2); }
.ai-sources a { color: var(--brand-strong); }
.ai-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

.detail-action-row { display: flex; gap: 8px; flex-wrap: wrap; }

.rating {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-card); padding: 10px 12px;
}
.rating .stars { display: inline-flex; gap: 2px; }
.star {
  background: transparent; border: 0; cursor: pointer; padding: 4px;
  color: var(--muted); font-size: 22px; line-height: 1;
}
.star.is-on { color: #E5A800; }

.comments { display: flex; flex-direction: column; gap: 10px; }
.comments h3 { margin: 0; font-size: 16px; color: var(--ink); }
.comment {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px;
}
.comment .author { font-size: 13px; }
.comment p { margin: 4px 0 0; color: var(--ink-2); font-size: 14px; }
.comment-reply { padding-left: 24px; }
.comment-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.comment-form input {
  border: 1px solid var(--line); border-radius: var(--r-pill);
  padding: 9px 14px; font: inherit; outline: 0;
}
.comment-form input:focus { border-color: var(--brand); }

/* ------ Messages ------ */

.tabs {
  display: flex; gap: 4px; padding: 8px 12px;
  background: var(--bg); border-bottom: 1px solid var(--line);
  position: sticky; top: var(--topbar-h); z-index: 4;
}
.tab {
  background: transparent; border: 0; color: var(--ink-2);
  padding: 8px 14px; border-radius: var(--r-pill); font-weight: 600;
  cursor: pointer; min-height: 36px;
}
.tab.is-active { background: var(--brand); color: #fff; }

.thread-list { display: flex; flex-direction: column; }
.thread-row {
  display: grid; grid-template-columns: auto 1fr auto;
  align-items: center; gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer; background: var(--surface);
}
.thread-row:hover { background: var(--surface-soft); }
.thread-name { font-weight: 700; color: var(--brand-strong); }
.thread-snippet { color: var(--ink-2); font-size: 14px; }
.thread-time { color: var(--ink-3); font-size: 12px; align-self: start; }

.thread-messages {
  padding: 12px 12px 16px;
  display: flex; flex-direction: column; gap: 8px;
}
.bubble {
  max-width: 78%;
  border-radius: 14px; padding: 8px 12px;
  background: var(--surface); border: 1px solid var(--line);
  color: var(--ink);
}
.bubble .from { font-size: 12px; color: var(--brand-strong); font-weight: 600; margin-bottom: 2px; }
.bubble.me { background: var(--brand); color: #fff; align-self: flex-end; border-color: var(--brand); }
.bubble.me .from { color: #E5FCFF; }
.bubble .time { display: block; margin-top: 4px; font-size: 11px; color: inherit; opacity: 0.65; }

.composer-bar {
  position: sticky; bottom: 0;
  display: grid; grid-template-columns: 1fr auto; gap: 8px;
  background: var(--topbar);
  padding: 8px 12px;
  border-top: 1px solid var(--line);
}
.composer-bar input {
  border: 1px solid var(--line); border-radius: var(--r-pill);
  padding: 10px 14px; outline: 0; font: inherit;
  background: var(--input-bg); color: var(--ink);
}
.composer-bar input:focus { border-color: var(--brand); }

.fab-secondary {
  position: fixed; right: 16px;
  bottom: calc(var(--bar-h) + env(safe-area-inset-bottom, 0) + 16px);
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--brand); color: #fff; border: 0;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-2); cursor: pointer; z-index: 5;
}

/* ------ Composer ------ */

.composer { padding: 12px; display: flex; flex-direction: column; gap: 12px; }

.composer-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}
.composer-card > * + * { border-top: 1px solid var(--line); }
.composer-card input,
.composer-card textarea {
  width: 100%; border: 0; outline: 0; padding: 12px 14px;
  font: inherit; resize: vertical;
  background: transparent;
  color: var(--ink); /* inherits dark teal in light mode, light off-white in dark mode */
}
.composer-card input::placeholder,
.composer-card textarea::placeholder { color: var(--ink-3); }
.composer-card input { font-size: 20px; font-weight: 700; }
.composer-card textarea { min-height: 120px; }

.char-row {
  border-top: 0 !important;
  padding: 0 14px 6px;
  font-size: 12px; color: var(--ink-3); text-align: right;
}

.attach-row { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.attach-btn {
  width: 100%;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--mint); color: var(--brand-strong);
  border: 1px dashed var(--brand);
  border-radius: var(--r-card); padding: 18px;
  cursor: pointer; font-weight: 600;
}
.attach-preview {
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
}
.attach-preview img {
  width: 100%;
  max-height: 240px;
  object-fit: cover;
  border-radius: 10px;
  display: block;
}
.attach-preview-meta {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.attach-preview-name {
  color: var(--ink-2); font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.attach-remove {
  display: inline-flex; align-items: center; gap: 4px;
  background: transparent; color: var(--bad);
  border: 1px solid var(--line); border-radius: var(--r-pill);
  padding: 6px 12px; font-weight: 600; font-size: 13px; cursor: pointer;
}
.attach-remove:hover { background: var(--bad-bg); }
.attach-remove .ic-sm { width: 14px; height: 14px; fill: currentColor; }

.tag-row { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.tag-row input {
  background: var(--input-bg); color: var(--ink);
  border: 1px solid var(--line) !important; border-radius: var(--r-pill);
  padding: 9px 14px !important; font-size: 14px !important; font-weight: 500 !important;
}
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-pill {
  background: var(--brand); color: #fff;
  border-radius: var(--r-pill); padding: 5px 10px; font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px;
}
.tag-pill button { background: transparent; border: 0; color: inherit; cursor: pointer; }

.hint { color: var(--ink-3); font-size: 13px; margin: 0 4px; }

/* ------ Notifications ------ */

.filter-chips {
  display: flex; gap: 6px; overflow-x: auto; padding: 10px 12px;
  background: var(--bg); border-bottom: 1px solid var(--line);
  position: sticky; top: var(--topbar-h); z-index: 4;
}
.filter-chips::-webkit-scrollbar { display: none; }

.notif-list { display: flex; flex-direction: column; gap: 10px; padding: 12px; }
.notif-row {
  display: grid; grid-template-columns: auto 1fr auto;
  gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: 10px 14px;
  cursor: pointer;
}
.notif-row.is-unread { border-color: var(--brand); background: var(--unread-bg); }
.notif-cat {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--mint); color: var(--brand-strong);
  display: inline-flex; align-items: center; justify-content: center;
}
.notif-text { color: var(--ink); font-size: 14px; }
.notif-time { color: var(--ink-3); font-size: 12px; white-space: nowrap; }

/* ------ Profile ------ */

.profile-head {
  display: grid; grid-template-columns: 1fr auto; gap: 12px;
  padding: 16px; align-items: center;
  border-bottom: 1px solid var(--line);
}
.profile-id h2 { margin: 0; font-size: 22px; color: var(--brand-strong); }
.profile-id .row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.muted { color: var(--ink-3); font-size: 13px; margin: 4px 0 0; }

.stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  padding: 12px; border-bottom: 1px solid var(--line);
}
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-card); padding: 10px;
  display: flex; flex-direction: column; align-items: center;
}
.stat-n { font-size: 20px; font-weight: 700; color: var(--ink); letter-spacing: -0.015em; }
.stat-l { font-size: 12px; color: var(--ink-3); margin-top: 2px; }

.settings {
  list-style: none; margin: 12px; padding: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  overflow: hidden;
}
.settings li + li { border-top: 1px solid var(--line); }
.setting {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  background: transparent; border: 0;
  padding: 13px 16px;
  font-weight: 500; color: var(--ink); cursor: pointer;
  min-height: 48px;
  text-align: left;
}
.setting:hover { background: var(--surface-soft); }
.setting .ic-sm {
  color: var(--ink-3);
  width: 18px; height: 18px;
}

/* ------ Bottom taskbar ------ */

.taskbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--bar-h) + env(safe-area-inset-bottom, 0));
  padding-bottom: env(safe-area-inset-bottom, 0);
  background: var(--bg);
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  z-index: 20;
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
}
.tb-item {
  background: transparent; border: 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  color: var(--ink-3);
  font-size: 11px; font-weight: 500;
  position: relative;
  min-height: var(--tap);
  transition: color 120ms ease;
}
.tb-item[aria-current="page"] { color: var(--brand-strong); font-weight: 600; }
.tb-item[aria-current="page"] .ic { fill: var(--brand-strong); }
.tb-primary {
  position: relative;
  align-self: center;
}
.tb-plus {
  position: absolute;
  top: -20px; left: 50%; transform: translateX(-50%);
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--brand); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(20, 184, 200, 0.35);
  border: 3px solid var(--bg);
  transition: transform 120ms ease;
}
.tb-plus:hover { transform: translateX(-50%) scale(1.04); }
.tb-primary .ic { width: 24px; height: 24px; }

/* ------ Side rail (desktop) ------ */

.side-rail { display: none; }

/* ------ Sheets ------ */

dialog.sheet {
  border: 0; padding: 0; background: transparent;
  width: 100%; max-width: 480px;
  margin: auto;
}
dialog.sheet::backdrop { background: rgba(15, 27, 31, 0.4); }

.sheet > * {
  background: var(--surface);
}
.sheet-title {
  margin: 0; padding: 16px 18px 12px;
  font-size: 16px; font-weight: 600; color: var(--ink);
  letter-spacing: -0.01em;
  border-top-left-radius: 14px; border-top-right-radius: 14px;
}
.sheet-list { list-style: none; margin: 0; padding: 6px 0; }
.sheet-list button {
  width: 100%; text-align: left; background: transparent; border: 0;
  padding: 12px 16px; cursor: pointer; font-size: 15px; color: var(--ink);
  min-height: 44px;
}
.sheet-list button:hover { background: var(--surface-soft); }
.sheet-list button[aria-current="true"] { color: var(--brand-strong); font-weight: 700; }

.sheet-close {
  width: 100%; padding: 12px;
  background: var(--mint); color: var(--brand-strong);
  border: 0; cursor: pointer; font-weight: 700;
  border-bottom-left-radius: 14px; border-bottom-right-radius: 14px;
  min-height: 48px;
}

.sheet-cta {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px;
  background: var(--surface);
  color: var(--brand-strong);
  border: 0;
  border-top: 1px solid var(--line);
  font-weight: 700; cursor: pointer;
  min-height: 48px;
}
.sheet-cta:hover { background: var(--surface-soft); }
.sheet-cta .ic-sm { fill: currentColor; }

.sheet-tall #aiSheetBody { padding: 14px 16px; max-height: 60vh; overflow: auto; }

/* ------ Loading overlay ------ */

.loading-overlay {
  position: fixed;
  inset: 0;
  background: #F4EFE2; /* cream — matches the icon's painted background so its frame melts in */
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: loading-fade-in 200ms ease-out;
}
.loading-overlay[hidden] { display: none; }

.loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 32px 28px;
  text-align: center;
  max-width: 320px;
}

.loading-logo {
  width: 180px;
  height: 180px;
  object-fit: contain;
  display: block;
  background: transparent;
  animation: loading-pulse 1800ms ease-in-out infinite;
  filter: drop-shadow(0 8px 24px rgba(21, 198, 220, 0.25));
}

@keyframes loading-pulse {
  0%, 100% { transform: scale(1);    opacity: 1; }
  50%      { transform: scale(1.06); opacity: 0.92; }
}

html.reduce-motion .loading-logo {
  animation: none;
}

.loading-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: #0A7D8C;
  letter-spacing: -0.01em;
}
.loading-sub {
  margin: 0;
  font-size: 13px;
  color: #6C8389;
}

@keyframes loading-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes loading-pulse {
  0%, 100% { transform: scale(1);   opacity: 1;   }
  50%      { transform: scale(1.08); opacity: 0.85; }
}
@keyframes loading-wave {
  0%   { transform: scale(0.6); opacity: 0.7; border-width: 3px; }
  100% { transform: scale(1.6); opacity: 0;   border-width: 1px; }
}

/* Loading overlay stays brand-cream in both themes so the icon's frame
   melts into the backdrop the same way regardless of system theme. */

/* Respect reduced motion */
html.reduce-motion .loading-logo,
html.reduce-motion .loading-wave {
  animation: none;
}
html.reduce-motion .loading-wave { opacity: 0.3; }

/* ------ Toast ------ */

.toast {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--bar-h) + env(safe-area-inset-bottom, 0) + 12px);
  /* Inverts naturally: dark teal bg + light text in light mode,
     light bg + dark text in dark mode — always legible. */
  background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: var(--r-pill);
  font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow-2);
  z-index: 50;
}

/* ------ Settings: shared sub-page ------ */

.sub-page { padding: 12px 14px; display: flex; flex-direction: column; gap: 12px; }

.section-h {
  margin: 8px 4px 4px;
  font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--ink-3);
}

.list-group {
  list-style: none; margin: 0; padding: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  overflow: hidden;
}
.list-group li + li { border-top: 1px solid var(--line); }
.list-row {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: 0;
  padding: 14px 14px;
  cursor: pointer;
  min-height: 52px;
  color: var(--ink);
  text-align: left;
}
.list-row:hover { background: var(--surface-soft); }
.list-row .row-ic { color: var(--brand-strong); }
.list-row .row-label { font-weight: 600; }
.list-row .row-label.danger { color: var(--bad); }
.list-row .row-meta { color: var(--ink-3); font-size: 13px; justify-self: end; }
.list-row .chev { color: var(--ink-3); }
.list-row-static { cursor: default; }
.list-row-static:hover { background: transparent; }

.list-row:not(:has(.row-ic)) { grid-template-columns: 1fr auto auto; }

.link {
  background: transparent; border: 0; color: var(--brand-strong);
  font-weight: 700; cursor: pointer; padding: 6px 8px;
  min-height: 32px;
}
.link:hover { text-decoration: underline; }

.row-meta + .link { margin-left: 4px; }

.badge-pill {
  display: inline-block; min-width: 18px; padding: 1px 6px;
  border-radius: var(--r-pill); background: var(--bad); color: #fff;
  font-size: 11px; font-weight: 800; line-height: 16px; text-align: center;
}

/* ------ Forms / inputs ------ */

.form-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 8px;
}

.field-label {
  display: block;
  font-size: 13px; font-weight: 700;
  color: var(--ink-2);
}

textarea, input[type="text"].std-input, input[type="email"].std-input, input[type="password"].std-input, .select {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-input);
  background: var(--surface);
  color: var(--ink);
  outline: 0;
  min-height: 44px;
}
.form-section textarea {
  width: 100%; font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-input);
  background: var(--surface);
  color: var(--ink);
  outline: 0;
  resize: vertical;
  min-height: 96px;
}
.form-section textarea:focus,
.select:focus { border-color: var(--brand); }

.select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%),
                    linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: right 16px top 50%, right 11px top 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 28px;
}

.error { color: var(--bad); font-size: 13px; margin: 0; }

.btn-secondary {
  background: var(--mint); color: var(--brand-strong);
  border: 1px solid var(--brand);
  padding: 9px 16px; border-radius: var(--r-pill);
  font-weight: 700; cursor: pointer; min-height: 40px;
}
.btn-secondary:hover { background: var(--chip-hover); }

.btn-ghost {
  background: transparent; color: var(--ink-2);
  border: 1px solid var(--line);
  padding: 9px 16px; border-radius: var(--r-pill);
  font-weight: 700; cursor: pointer; min-height: 40px;
}
.btn-ghost:hover { border-color: var(--brand); color: var(--brand-strong); }

.btn-block { width: 100%; }

.sticky-action {
  position: sticky;
  bottom: 0;
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom, 0));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  margin-top: 8px;
}

/* ------ Edit profile ------ */

.avatar-xl { width: 96px; height: 96px; font-size: 44px; }
.pic-edit {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: center;
}
.pic-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.pic-actions .hint { margin: 4px 0 0; }

/* ------ Toggle switch ------ */

.switch-row {
  display: grid; grid-template-columns: 1fr auto; gap: 10px;
  align-items: center;
  padding: 8px 0;
}
.switch-row + .switch-row { border-top: 1px solid var(--line); }
.switch-body strong { display: block; font-weight: 700; }
.switch-body small { display: block; color: var(--ink-3); font-size: 12px; margin-top: 2px; }

.switch { position: relative; display: inline-block; }
.switch input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.switch-track {
  display: block; width: 46px; height: 26px;
  background: var(--switch-off);
  border-radius: var(--r-pill);
  position: relative;
  transition: background 120ms ease;
}
.switch-thumb {
  position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--switch-thumb);
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
  transition: transform 120ms ease;
}
.switch input:checked + .switch-track { background: var(--brand); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(20px); }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--brand); outline-offset: 2px; }

/* ------ Segmented control ------ */

.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--mint);
  border-radius: var(--r-pill);
  padding: 4px;
  gap: 2px;
}
.seg button {
  background: transparent; border: 0;
  padding: 8px 10px;
  border-radius: var(--r-pill);
  font-weight: 700; color: var(--ink-2);
  cursor: pointer;
  min-height: 36px;
}
.seg button[aria-checked="true"] {
  background: var(--brand); color: #fff;
}

/* ------ Radio list ------ */

.radio-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.radio {
  display: grid; grid-template-columns: auto 1fr;
  align-items: center; gap: 12px;
  padding: 10px 4px;
  cursor: pointer;
  border-radius: 10px;
}
.radio:hover { background: var(--surface-soft); }
.radio input { position: absolute; opacity: 0; pointer-events: none; }
.radio-mark {
  width: 22px; height: 22px; border-radius: 50%;
  border: 1.5px solid var(--ink-3); position: relative; flex: none;
}
.radio input:checked + .radio-mark {
  border-color: var(--brand);
}
.radio input:checked + .radio-mark::after {
  content: ""; position: absolute; inset: 4px;
  border-radius: 50%; background: var(--brand);
}
.radio input:focus-visible + .radio-mark { outline: 3px solid var(--brand); outline-offset: 2px; }
.radio-body strong { display: block; }
.radio-body small { display: block; color: var(--ink-3); font-size: 12px; margin-top: 2px; }

/* ------ Password strength ------ */

.pw-field { position: relative; }
.pw-field input {
  width: 100%; font: inherit;
  padding: 10px 70px 10px 12px;
  border: 1px solid var(--line); border-radius: var(--r-input);
  background: var(--surface); color: var(--ink);
  outline: 0; min-height: 44px;
}
.pw-field input:focus { border-color: var(--brand); }
.pw-field .pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
}

.strength { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.strength-bar { height: 6px; background: var(--mint); border-radius: 3px; overflow: hidden; }
.strength-bar > div {
  height: 100%; width: 0%;
  background: var(--bad);
  transition: width 120ms ease, background 120ms ease;
}
.strength[data-level="weak"] .strength-bar > div     { width: 33%; background: var(--bad); }
.strength[data-level="medium"] .strength-bar > div   { width: 66%; background: var(--warn); }
.strength[data-level="strong"] .strength-bar > div   { width: 100%; background: var(--good); }

.reqs { list-style: none; margin: 0; padding: 0; font-size: 13px; color: var(--ink-3); display: flex; flex-direction: column; gap: 2px; }
.reqs li::before { content: "○ "; }
.reqs li.is-met { color: var(--good); }
.reqs li.is-met::before { content: "✓ "; font-weight: 700; }

.match { font-size: 13px; margin: 0; }
.match.is-ok { color: var(--good); }
.match.is-bad { color: var(--bad); }

/* ------ ToS / banners ------ */

.banner {
  background: var(--surface-soft);
  border: 1px solid var(--brand);
  border-radius: var(--r-card);
  padding: 10px 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}
.banner.banner-warn { border-color: var(--warn); background: var(--warn-bg); color: var(--warn-ink); }
.banner.banner-good { border-color: var(--good); background: var(--good-bg); color: var(--good-ink); }
.banner.banner-bad  { border-color: var(--bad);  background: var(--bad-bg);  color: var(--bad-ink);  }
.banner-actions { display: flex; gap: 6px; }

.tos-text {
  max-height: 50vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 12px 14px;
  font-size: 14px; color: var(--ink-2);
}
.tos-text h4 { color: var(--ink); margin: 12px 0 4px; }
.tos-text p { margin: 6px 0; }

/* ------ Permissions ------ */

.perm-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}
.perm-head { display: flex; align-items: center; gap: 10px; }
.perm-name { font-weight: 700; }
.perm-status {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 700;
  padding: 2px 8px; border-radius: var(--r-pill);
  background: var(--mint); color: var(--brand-strong);
  white-space: nowrap;
}
.perm-status.is-granted { background: var(--good-bg); color: var(--good-ink); }
.perm-status.is-denied  { background: var(--bad-bg);  color: var(--bad-ink);  }
.perm-status.is-none    { background: var(--mint); color: var(--ink-3); }
.perm-status::before { content: "●"; font-size: 8px; }

.perm-desc { color: var(--ink-2); font-size: 13px; grid-column: 1 / -1; margin: 0; }
.perm-unavail { color: var(--warn); font-size: 12px; grid-column: 1 / -1; margin: 0; }
.perm-action { grid-row: 1; align-self: start; justify-self: end; }
.perm-action.with-switch { padding: 0; min-height: 26px; }

/* ------ Empty state ------ */

.empty-state {
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--r-card);
  padding: 24px;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}

/* ------ Sheet variants ------ */

.sheet-body { padding: 12px 16px; }
.sheet-body input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-input);
  font: inherit; outline: 0;
  background: var(--surface);
  color: var(--ink);
  min-height: 44px;
  letter-spacing: 0.3em;
  font-variant-numeric: tabular-nums;
}
.sheet-body input[type="text"]:focus { border-color: var(--brand); }
.sheet-row {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  border-bottom-left-radius: 14px; border-bottom-right-radius: 14px;
}

/* ------ Decline dialog ------ */

.decline-head {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 18px 8px;
  background: var(--surface);
  border-top-left-radius: 14px; border-top-right-radius: 14px;
}
.decline-head .sheet-title { padding: 0; border-radius: 0; }
.decline-icon {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bad-bg); color: var(--bad);
  border-radius: 50%; flex: 0 0 36px;
}
.decline-icon svg { width: 22px; height: 22px; fill: currentColor; }
.decline-body { padding: 4px 18px 14px; }
.decline-lead { margin: 6px 0 12px; color: var(--ink); font-weight: 500; }
.decline-reason {
  background: var(--bad-bg);
  border-left: 3px solid var(--bad);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
}
.decline-reason strong { color: var(--bad); font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; }
.decline-reason p { margin: 4px 0 0; color: var(--ink-2); }
.decline-rules { margin: 8px 0; }
.decline-rules summary { cursor: pointer; color: var(--brand-strong); font-weight: 600; }
.decline-rules ul { margin: 8px 0 0 18px; padding: 0; color: var(--ink-2); }
.decline-rules li { margin-bottom: 4px; }

/* ------ Dark theme ------ */

:root[data-theme="dark"] {
  --bg: #0B1416;
  --surface: #12201F;
  --surface-soft: #0E1A1B;
  --topbar: #0E2628;
  --mint: #0F2A2D;
  --line: #1E4044;

  --brand: #2DD3E8;
  --brand-strong: #7FE2F0;
  --brand-ink: #BFF1F8;

  --ink: #E6F4F6;
  --ink-2: #B7D0D4;
  --ink-3: #82A0A6;
  --muted: #6B8589;

  --shadow-2: 0 6px 18px rgba(0,0,0,0.35);

  /* Dark-mode tints — flip the light "tinted background, dark text" pattern
     into "darker background, bright text" so contrast stays AA. */
  --input-bg: #16292B;
  --unread-bg: #143438;
  --chip-hover: #163C40;
  --good-bg: #0F2A1F;
  --warn-bg: #2A2010;
  --bad-bg:  #2A1313;
  --good-ink: #4FD49A;
  --warn-ink: #F1B450;
  --bad-ink:  #FF7373;
  --switch-off: #2A4549;
  --switch-thumb: #E6F4F6;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #0B1416;
    --surface: #12201F;
    --surface-soft: #0E1A1B;
    --topbar: #0E2628;
    --mint: #0F2A2D;
    --line: #1E4044;
    --brand: #2DD3E8;
    --brand-strong: #7FE2F0;
    --brand-ink: #BFF1F8;
    --ink: #E6F4F6;
    --ink-2: #B7D0D4;
    --ink-3: #82A0A6;
    --muted: #6B8589;
    --shadow-2: 0 6px 18px rgba(0,0,0,0.35);
    --input-bg: #16292B;
    --unread-bg: #143438;
    --chip-hover: #163C40;
    --good-bg: #0F2A1F;
    --warn-bg: #2A2010;
    --bad-bg:  #2A1313;
    --good-ink: #4FD49A;
    --warn-ink: #F1B450;
    --bad-ink:  #FF7373;
    --switch-off: #2A4549;
    --switch-thumb: #E6F4F6;
  }
}

/* ------ Reduced motion class (when user opts in) ------ */

html.reduce-motion *,
html.reduce-motion *::before,
html.reduce-motion *::after {
  animation-duration: 0.01ms !important;
  transition-duration: 0.01ms !important;
}

/* ------ Desktop (≥1025px) ------ */

@media (min-width: 1025px) {
  .app {
    grid-template-columns: 240px 1fr;
  }
  .taskbar { display: none; }
  .view { padding-bottom: 0; }

  .side-rail {
    display: flex; flex-direction: column;
    padding: 18px 12px; gap: 2px;
    border-right: 1px solid var(--line);
    background: var(--bg);
    position: sticky; top: 0; height: 100vh;
  }
  .brand {
    display: flex; align-items: center; gap: 10px;
    padding: 4px 10px 16px; text-decoration: none;
    color: var(--ink);
  }
  .brand-mark { width: 72px; height: 72px; }
  .brand-text { font-size: 20px; font-weight: 700; letter-spacing: -0.015em; }

  .side-nav { display: flex; flex-direction: column; gap: 2px; }
  .side-nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 9px 12px; border-radius: 10px;
    background: transparent; border: 0; cursor: pointer;
    color: var(--ink-2); font-weight: 500; font-size: 14px;
    text-align: left; position: relative;
    min-height: 40px;
    transition: background 120ms ease, color 120ms ease;
  }
  .side-nav-item:hover { background: var(--surface-soft); color: var(--ink); }
  .side-nav-item[aria-current="page"] {
    background: var(--mint); color: var(--brand-strong);
    border: 0;
    font-weight: 600;
  }
  .side-nav-item.is-primary {
    background: var(--brand); color: #fff;
    margin-bottom: 4px;
  }
  .side-nav-item.is-primary:hover { background: var(--brand-strong); }
  .side-nav-item.is-primary[aria-current="page"] {
    background: var(--brand-strong);
    color: #fff;
    border: 0;
  }
  .side-nav-divider {
    height: 1px;
    background: var(--line);
    margin: 8px 4px;
  }
  .side-nav-item.side-nav-secondary {
    background: var(--mint);
    color: var(--brand-strong);
  }
  .side-nav-item.side-nav-secondary:hover {
    background: var(--chip-hover);
  }
  .side-nav-item .badge {
    margin-left: auto; background: var(--bad); color: #fff;
    border-radius: var(--r-pill); padding: 2px 8px; font-size: 12px; font-weight: 700;
  }

  .feed { max-width: 720px; margin: 0 auto; }
  .post-detail { max-width: 720px; margin: 0 auto; }
  .composer { max-width: 720px; margin: 0 auto; }
  .notif-list { max-width: 720px; margin: 0 auto; }
  .profile-head, .stats, .settings { max-width: 720px; margin-left: auto; margin-right: auto; }
  .sub-page { max-width: 720px; margin: 0 auto; }

  .thread-messages { max-width: 720px; margin: 0 auto; width: 100%; }
  .composer-bar { max-width: 720px; margin: 0 auto; }

  .community-select { max-width: none; }
}
