/*
 * Basecoat provides the component classes (btn, card, input, ...); basecoat.css
 * is vendored from basecoat-css@1.0.2 dist/basecoat.cdn.min.css. Color theming
 * comes from daisy_themes.css. Application-specific styles live here.
 */

/* The theme follows an explicit choice (html.dark, stored in localStorage) or
   the system preference — applied before first paint by the layout head script.
   Basecoat's dark tokens live under .dark, so form controls and scrollbars
   must match the chosen theme, not the OS one. */
:root {
  color-scheme: light;
}

:root.dark {
  color-scheme: dark;
}

/* Trix toolbar icons are black SVGs; invert them on dark. */
:root.dark trix-toolbar .trix-button::before {
  filter: invert(1);
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

body.authenticated {
  display: block;
  overflow: hidden;
}

.app-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 15rem minmax(0, 1fr);
  background: var(--background);
}

.app-shell:has(> .context-panel) {
  grid-template-columns: 15rem minmax(0, 1fr) minmax(17rem, 20rem);
}

.app-shell:has(> .list-panel) {
  grid-template-columns: 15rem 18rem minmax(0, 1fr);
}

.app-shell:has(> .list-panel):has(> .context-panel) {
  grid-template-columns: 15rem 17rem minmax(0, 1fr) minmax(16rem, 18rem);
}

.app-sidebar,
.list-panel,
.context-panel {
  min-width: 0;
  background: color-mix(in srgb, var(--muted) 32%, var(--background));
}

.list-panel {
  height: 100dvh;
  overflow-y: auto;
  padding: 1.25rem 0.75rem;
  border-right: 1px solid var(--border);
}

.list-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-block-end: 0.75rem;
  padding-inline: 0.5rem;
}

.list-panel-header h2 {
  font-size: 1rem;
}

.app-sidebar {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  padding: 1.25rem 1rem;
  border-right: 1px solid var(--border);
}

.sidebar-brand {
  padding-inline: 0.75rem;
  font-size: 1.125rem;
}

.primary-navigation,
#unread-counts {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.navigation-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 2.75rem;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius, 0.5rem);
  color: var(--muted-foreground);
  font-weight: 500;
  text-decoration: none;
}

.navigation-link:hover,
.navigation-link.active {
  color: var(--foreground);
  background: var(--accent);
}

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: auto;
  padding-inline: 0.75rem;
}

.workspace {
  min-width: 0;
  height: 100dvh;
  overflow-y: auto;
  padding: 2rem clamp(1rem, 3vw, 3rem);
}

.context-panel {
  height: 100dvh;
  overflow-y: auto;
  padding: 2rem 1.25rem;
  border-left: 1px solid var(--border);
}

.context-panel h2 {
  font-size: 1.125rem;
}

.mobile-back {
  display: none;
}

.mobile-context-link {
  display: none;
}

.site-header,
.site-footer {
  border-block: 1px solid var(--border);
}

.container {
  width: 100%;
  max-width: 64rem;
  margin-inline: auto;
  padding-inline: 1rem;
}

main.container {
  flex: 1;
  padding-block: 2rem;
}

.stack > * + * {
  margin-block-start: 1rem;
}

.hero {
  padding-block: 3rem 2rem;
}

.hero h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.hero p.lead {
  font-size: 1.125rem;
  color: var(--muted-foreground);
  max-width: 40rem;
}

.feature-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
}

/* Landing page: plasma network canvas behind translucent content, filling the
   whole viewport. The landing isolates its own stacking context so the
   fixed canvas (z-index: -1) still paints above the page and app-shell
   backgrounds but below the content — without the isolation it would fall
   behind the authenticated layout's opaque background. */
.landing {
  position: relative;
  isolation: isolate;
}

.landing-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
}

.landing > * + * {
  margin-block-start: 3.5rem;
}

.landing-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  align-items: center;
  gap: 3rem;
  padding-block: 4rem 1rem;
}

.hero-copy .badge {
  width: fit-content;
}

.hero-copy .actions {
  padding-block-start: 0.5rem;
}

.hero-preview {
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: color-mix(in srgb, var(--background) 92%, transparent);
  box-shadow: 0 20px 50px -24px color-mix(in srgb, var(--foreground) 35%, transparent);
}

.hero-preview-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-block-end: 1rem;
  padding-block-end: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.hero-preview .thread-messages {
  padding-block: 0;
}

/* Note: headless Chrome (test screenshots) mis-paints var-based colors in this
   subtree when the dark class is added by script instead of server-rendered —
   bubbles show light-mode colors. Real browsers render correctly (verified in
   headed Chrome); computed styles are correct in both. */

.landing .card {
  background: color-mix(in srgb, var(--card) 94%, transparent);
}

.landing .card header {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.feature-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  flex-shrink: 0;
  border-radius: 0.625rem;
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  color: var(--primary);
}

.landing-points {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 1rem;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: color-mix(in srgb, var(--background) 92%, transparent);
}

.landing-points > div {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  font-size: 0.9375rem;
}

.landing-cta {
  text-align: center;
  padding-block: 2rem 3rem;
}

.powered-by {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding-block-end: 2.5rem;
  font-size: 0.9375rem;
  color: var(--muted-foreground);
}

.powered-by a {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--foreground);
  font-weight: 500;
  text-decoration: none;
}

.powered-by a:hover {
  text-decoration: underline;
}

.make-logo {
  height: 1.05em;
  width: auto;
  display: block;
}

.landing-cta .btn {
  margin-inline: auto;
}

@media (max-width: 52rem) {
  .landing-hero {
    grid-template-columns: 1fr;
    gap: 2rem;
    padding-block-start: 2rem;
  }
}

.site-header nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 0.75rem;
}

.site-footer .container {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
  padding-block: 1rem;
  color: var(--muted-foreground);
  font-size: 0.875rem;
}

.brand {
  font-weight: 600;
  text-decoration: none;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.nav-links form {
  display: inline;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.page-header h1 {
  font-size: 1.75rem;
  letter-spacing: -0.01em;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.actions form {
  display: inline;
}

.muted {
  color: var(--muted-foreground);
}

.narrow {
  max-width: 28rem;
}

.form-stack > * + * {
  margin-block-start: 1rem;
}

.field-error {
  color: var(--destructive);
  font-size: 0.875rem;
}

.address {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  user-select: all;
}

.card > section {
  padding-block: 0.5rem;
}

.message-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius, 0.5rem);
}

.message-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
}

.message-main {
  min-width: 0;
  overflow-wrap: anywhere;
}

.message-row + .message-row {
  border-top: 1px solid var(--border);
}

.message-row.unread .message-subject {
  font-weight: 600;
}

.message-subject {
  text-decoration: none;
}

.message-body {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius, 0.5rem);
  overflow-wrap: anywhere;
}

.message-body img {
  max-width: 100%;
}

/* Conversation list (groups pane and index) */
.conversation-list {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.conversation {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.625rem 0.5rem;
  border-radius: var(--radius, 0.5rem);
  text-decoration: none;
  color: inherit;
}

.conversation:hover,
.conversation.active {
  background: var(--accent);
}

.conversation-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.conversation-name {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-preview {
  font-size: 0.8125rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.25rem;
  flex-shrink: 0;
  font-size: 0.75rem;
}

/* Group thread (chat-style message history) */
.thread-messages {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-block: 0.5rem;
}

.chat-message {
  max-width: min(40rem, 92%);
  align-self: flex-start;
}

.chat-message.mine {
  align-self: flex-end;
}

.chat-meta {
  font-size: 0.8125rem;
  margin-block-end: 0.25rem;
}

.chat-message.mine .chat-meta {
  text-align: right;
}

.chat-permalink {
  color: inherit;
  text-decoration: none;
}

.chat-permalink:hover {
  text-decoration: underline;
}

.chat-bubble {
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  border-start-start-radius: 0.25rem;
  background: color-mix(in srgb, var(--muted) 32%, var(--background));
  overflow-wrap: anywhere;
}

.chat-message.mine .chat-bubble {
  border-start-start-radius: 1rem;
  border-start-end-radius: 0.25rem;
  background: var(--accent);
}

.chat-body {
  max-height: 24rem;
  overflow-y: auto;
}

.chat-body img {
  max-width: 100%;
}

.chat-body > :last-child {
  margin-block-end: 0;
}

.quoted-text {
  margin-block-start: 0.375rem;
  font-size: 0.8125rem;
}

.quoted-text summary {
  cursor: pointer;
  user-select: none;
}

.quoted-text[open] {
  color: var(--muted-foreground);
}

/* Emoji reactions: chips under the bubble, a details-based palette popover. */
.chat-reactions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  margin-block-start: 0.25rem;
}

.chat-message.mine .chat-reactions {
  justify-content: flex-end;
}

.reaction-chip,
.reaction-add {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 9999px;
  background: var(--background);
  color: var(--muted-foreground);
  font-size: 0.8125rem;
  line-height: 1.4;
  cursor: pointer;
  user-select: none;
}

.reaction-chip:hover,
.reaction-add:hover {
  border-color: var(--ring);
}

.reaction-chip.mine {
  border-color: var(--ring);
  background: var(--accent);
  color: var(--foreground);
}

.chat-reactions {
  position: relative;
}

.reaction-palette {
  position: absolute;
  bottom: calc(100% + 0.375rem);
  left: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.125rem;
  padding: 0.375rem;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--popover, var(--background));
  box-shadow: 0 8px 24px -12px color-mix(in srgb, var(--foreground) 40%, transparent);
}

.chat-message.mine .reaction-palette {
  left: auto;
  right: 0;
}

.reaction-palette button {
  padding: 0.25rem 0.375rem;
  border: 0;
  border-radius: 0.5rem;
  background: transparent;
  font-size: 1.125rem;
  line-height: 1;
  cursor: pointer;
}

.reaction-palette button:hover {
  background: var(--accent);
}

.chat-attachments {
  margin-block-start: 0.5rem;
  padding-inline-start: 1.25rem;
  font-size: 0.875rem;
}

.chat-images {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-block-start: 0.5rem;
}

.chat-images:first-child {
  margin-block-start: 0;
}

.chat-image {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 16rem;
  border-radius: 0.5rem;
}

/* Link preview card, like any messenger */
.link-card {
  display: flex;
  align-items: stretch;
  max-width: 26rem;
  margin-block-start: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  overflow: hidden;
  background: var(--background);
  color: inherit;
  text-decoration: none;
}

.link-card:hover {
  background: var(--accent);
}

.link-card-image {
  width: 5.5rem;
  min-height: 5.5rem;
  object-fit: cover;
  flex-shrink: 0;
}

.link-card-text {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  padding: 0.5rem 0.75rem;
  min-width: 0;
}

.link-card-title {
  font-weight: 600;
  font-size: 0.875rem;
  overflow-wrap: anywhere;
}

.link-card-description {
  font-size: 0.8125rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.link-card-domain {
  font-size: 0.75rem;
}

.thread-older {
  text-align: center;
  font-size: 0.875rem;
}

.workspace:has(.thread) {
  padding-block-end: 0;
}

.thread-composer {
  position: sticky;
  bottom: 0;
  margin-block-start: 1rem;
  padding-block: 0.75rem 1rem;
  background: var(--background);
  border-top: 1px solid var(--border);
}

.thread-composer-form > * + * {
  margin-block-start: 0.5rem;
}

.thread-composer .trix-content {
  min-height: 5rem;
}

.thread-composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.thread-composer p.muted {
  font-size: 0.75rem;
}

/* Appearance settings: theme gallery with per-card palette previews. Each
   preview span carries data-color-theme, so the theme's own tokens style it. */
.theme-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr));
  gap: 0.5rem;
  max-height: 15rem;
  overflow-y: auto;
  padding: 3px; /* room for the checked ring */
  border: 1px solid var(--border);
  border-radius: var(--radius, 0.5rem);
}

.theme-card {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  cursor: pointer;
}

.theme-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.theme-card-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.625rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--background);
  color: var(--foreground);
}

.theme-card:has(input:checked) .theme-card-preview,
.theme-card input:focus-visible ~ .theme-card-preview {
  box-shadow: 0 0 0 2px var(--ring);
}

.preview-bubble {
  padding: 0.125rem 0.5rem;
  border-radius: 0.625rem;
  background: var(--muted);
  color: var(--foreground);
  font-size: 0.8125rem;
}

.preview-dot {
  width: 1rem;
  height: 1rem;
  border-radius: 9999px;
  background: var(--primary);
  flex-shrink: 0;
}

.theme-card-name {
  font-size: 0.75rem;
  color: var(--muted-foreground);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The default cards preview the Basecoat palette for their scheme, regardless
   of the page's current mode (vega token values). */
.theme-card-default-light {
  --background: oklch(100% 0 0);
  --foreground: oklch(14.5% 0 0);
  --muted: oklch(97% 0 0);
  --primary: oklch(20.5% 0 0);
  --border: oklch(92.2% 0 0);
}

.theme-card-default-dark {
  --background: oklch(14.5% 0 0);
  --foreground: oklch(98.5% 0 0);
  --muted: oklch(26.9% 0 0);
  --primary: oklch(92.2% 0 0);
  --border: oklch(100% 0 0 / .1);
}

/* Shows the "Details" link only when the context panel is hidden. */
.context-link {
  display: none;
}

/* Composer */
.composer trix-editor {
  min-height: 14rem;
  border: 1px solid var(--border);
  border-radius: var(--radius, 0.5rem);
  padding: 0.75rem;
  background: var(--background);
}

.composer trix-toolbar .trix-button-group {
  border-color: var(--border);
}

.composer trix-toolbar .trix-button-group--file-tools {
  display: none; /* attachments use the file field below */
}

/* Mid-width screens: the groups pane leaves no room for the context panel,
   so it opens as a full-screen overlay from the "Details" link instead. */
@media (min-width: 64rem) and (max-width: 71.999rem) {
  .app-shell:has(> .list-panel):has(> .context-panel) {
    grid-template-columns: 15rem 17rem minmax(0, 1fr);
  }

  .app-shell:has(> .list-panel) > .context-panel {
    display: none;
  }

  .app-shell:has(> .list-panel) > .context-panel:target {
    position: fixed;
    z-index: 30;
    inset: 0;
    display: block;
    height: 100dvh;
    overflow-y: auto;
    padding: 2rem clamp(1rem, 10vw, 6rem);
    border: 0;
    background: var(--background);
  }

  .app-shell:has(> .list-panel) > .context-panel:target > * + * {
    margin-block-start: 1rem;
  }

  .app-shell:has(> .list-panel) > .context-panel:target .mobile-back {
    display: inline-flex;
    margin-block-end: 0.5rem;
    color: var(--muted-foreground);
    text-decoration: none;
  }

  .app-shell:has(> .list-panel) .context-link {
    display: inline-flex;
  }
}

@media (max-width: 63.999rem) {
  body.authenticated {
    overflow: auto;
  }

  .list-panel {
    display: none;
  }

  .context-link {
    display: inline-flex;
  }

  .thread-composer {
    /* Stuck above the fixed bottom navigation. The matching top margin keeps
       the lifted composer from covering the last message at full scroll. */
    bottom: calc(4rem + env(safe-area-inset-bottom));
    margin-block-start: calc(5rem + env(safe-area-inset-bottom));
  }

  .app-shell,
  .app-shell:has(> .context-panel) {
    display: block;
    min-height: 100dvh;
  }

  .app-sidebar {
    position: fixed;
    z-index: 20;
    inset: auto 0 0;
    width: 100%;
    height: calc(4rem + env(safe-area-inset-bottom));
    display: block;
    padding: 0.375rem 0.5rem calc(0.375rem + env(safe-area-inset-bottom));
    border: 0;
    border-top: 1px solid var(--border);
    background: color-mix(in srgb, var(--background) 94%, transparent);
    backdrop-filter: blur(1rem);
  }

  .sidebar-brand,
  .sidebar-footer {
    display: none;
  }

  .primary-navigation {
    display: flex;
    flex-direction: row;
    gap: 0.25rem;
  }

  #unread-counts {
    display: contents;
  }

  .navigation-link {
    flex: 1;
    min-width: 0;
    min-height: 3.25rem;
    flex-direction: column;
    justify-content: center;
    gap: 0.125rem;
    padding: 0.25rem;
    font-size: 0.75rem;
  }

  .navigation-link .badge {
    position: absolute;
    transform: translate(1.25rem, -0.75rem);
  }

  .workspace {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
    padding: max(1rem, env(safe-area-inset-top)) 1rem calc(5rem + env(safe-area-inset-bottom));
  }

  .context-panel {
    display: none;
  }

  .context-panel:target {
    position: fixed;
    z-index: 30;
    inset: 0;
    display: block;
    height: 100dvh;
    overflow-y: auto;
    padding: max(1rem, env(safe-area-inset-top)) 1rem calc(1rem + env(safe-area-inset-bottom));
    border: 0;
    background: var(--background);
  }

  .context-panel:target > * + * {
    margin-block-start: 1rem;
  }

  .mobile-back {
    display: inline-flex;
    margin-block-end: 0.5rem;
    color: var(--muted-foreground);
    text-decoration: none;
  }

  .mobile-context-link {
    display: inline-flex;
  }

  .mobile-back::before {
    content: "\2039";
    margin-inline-end: 0.35rem;
    font-size: 1.25em;
    line-height: 1;
  }

  .page-header {
    align-items: flex-start;
  }

  .page-header h1 {
    overflow-wrap: anywhere;
  }

  .message-row {
    align-items: flex-start;
    padding-inline: 0.75rem;
  }
}
