/*
 * @staros/messaging-mod — styles.
 *
 * DISARTO identity: monochrome dark canvas, flame-orange accent, mono uppercase
 * labels, soft elevation, generous radii, and real hover/active/focus-visible
 * states. Component rules consume local tokens; no scattered raw hex.
 *
 * Loaded once by the host (mirrors the @staros/web-shell CSS contract).
 * All rules are scoped under the `.mm-` prefix.
 */

:where(.mm-channel-list, .mm-message-stream, .mm-thread) {
  --mm-bg: var(--star-surface-sunken, rgb(16 19 22));
  --mm-surface: var(--star-surface, rgb(22 25 29));
  --mm-surface-raised: var(--star-surface-raised, rgb(28 32 36));
  --mm-surface-hover: color-mix(in srgb, var(--mm-surface-raised) 88%, var(--mm-accent) 12%);
  --mm-surface-active: color-mix(in srgb, var(--mm-surface-raised) 78%, var(--mm-accent) 22%);
  --mm-border: var(--star-border, rgb(242 243 244 / 10%));
  --mm-border-strong: var(--star-border-strong, rgb(242 243 244 / 20%));
  --mm-text: var(--star-text, rgb(242 243 244));
  --mm-text-muted: var(--star-text-muted, rgb(144 151 160));
  --mm-accent: rgb(245 100 30);
  --mm-accent-hover: rgb(255 131 71);
  --mm-accent-on: var(--star-accent-on, rgb(255 255 255));
  --mm-accent-weak: color-mix(in srgb, var(--mm-accent) 16%, transparent);
  --mm-danger: var(--star-danger, rgb(220 38 38));
  --mm-shadow: var(--star-shadow-2, 0 1px 2px rgb(0 0 0 / 50%), 0 12px 30px -12px rgb(0 0 0 / 60%));
  --mm-radius: var(--star-radius-control, 12px);
  --mm-radius-sm: var(--star-radius-sm, 10px);
  --mm-avatar-size: 28px;
  font-family: var(--star-font-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, system-ui, sans-serif);
  color: var(--mm-text);
  box-sizing: border-box;
}

:where(.mm-channel-list, .mm-message-stream, .mm-thread) *,
:where(.mm-channel-list, .mm-message-stream, .mm-thread) *::before,
:where(.mm-channel-list, .mm-message-stream, .mm-thread) *::after {
  box-sizing: inherit;
}

/* ── Channel list ─────────────────────────────────────────────────────────── */
.mm-channel-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 220px;
  height: 100%;
  padding: 8px;
  background: var(--mm-bg);
  overflow-y: auto;
}

.mm-channel-list__heading {
  margin: 10px 8px 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-family: var(--star-font-mono, "IBM Plex Mono", ui-monospace, monospace);
  color: var(--mm-text-muted);
}

.mm-channel-list__group {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.mm-channel-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: var(--mm-radius-sm);
  background: color-mix(in srgb, var(--mm-surface) 70%, transparent);
  color: var(--mm-text);
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.mm-channel-row:hover {
  background: var(--mm-surface-hover);
  border-color: var(--mm-border);
}

.mm-channel-row:focus-visible {
  outline: 2px solid var(--mm-accent);
  outline-offset: 2px;
}

.mm-channel-row:active {
  background: var(--mm-surface-active);
  transform: translateY(1px);
}

.mm-channel-row--active {
  /* All-sides hairline marker (inset box-shadow, no layout shift) + tint +
     weight — never a left-side accent rail (the #1 AI-dashboard tell). */
  background: var(--mm-accent-weak);
  box-shadow: inset 0 0 0 1px var(--mm-accent);
  font-weight: 700;
}

.mm-channel-row--muted {
  opacity: 0.6;
}

.mm-channel-row__hash {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--mm-avatar-size);
  height: var(--mm-avatar-size);
  flex: 0 0 auto;
  color: var(--mm-text-muted);
  font-family: var(--star-font-mono, "IBM Plex Mono", ui-monospace, monospace);
  font-weight: 700;
}

.mm-channel-row__main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1 1 auto;
}

.mm-channel-row__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mm-channel-row__topic {
  font-size: 12px;
  color: var(--mm-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Avatar chip ──────────────────────────────────────────────────────────── */
.mm-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--mm-avatar-size);
  height: var(--mm-avatar-size);
  flex: 0 0 auto;
  border-radius: var(--mm-radius-sm);
  color: var(--mm-accent-on);
  font-size: 11px;
  font-family: var(--star-font-mono, "IBM Plex Mono", ui-monospace, monospace);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  user-select: none;
}

/* ── Unread badge ─────────────────────────────────────────────────────────── */
.mm-unread-badge {
  flex: 0 0 auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--mm-radius-sm);
  background: var(--mm-accent);
  color: var(--mm-accent-on);
  font-size: 11px;
  font-family: var(--star-font-mono, "IBM Plex Mono", ui-monospace, monospace);
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

/* ── Message stream ───────────────────────────────────────────────────────── */
.mm-message-stream {
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100%;
  padding: 14px;
  background: var(--mm-bg);
  overflow-y: auto;
}

.mm-msg-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mm-msg-group__head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}

.mm-msg-group__name {
  font-weight: 600;
  font-size: 13px;
}

.mm-msg-group__time {
  font-size: 11px;
  color: var(--mm-text-muted);
}

/* own messages align right and tint, without a purple/blue echo color */
.mm-msg-group--self .mm-msg-group__head {
  flex-direction: row-reverse;
}

.mm-msg-group--self {
  align-items: flex-end;
}

.mm-msg {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: 6px;
  max-width: min(72ch, 80%);
  padding: 6px 10px;
  border-radius: var(--mm-radius);
  background: var(--mm-surface);
  border: 1px solid var(--mm-border);
  box-shadow: var(--mm-shadow);
}

.mm-msg-group--self .mm-msg {
  background: var(--mm-accent-weak);
  align-self: flex-end;
}

.mm-msg__text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.4;
  flex: 1 1 auto;
}

.mm-msg__edited {
  font-size: 11px;
  color: var(--mm-text-muted);
  font-style: italic;
}

.mm-msg__reply {
  margin-left: auto;
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: var(--mm-text-muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: var(--mm-radius-sm);
}

.mm-msg__reply:hover {
  color: var(--mm-accent);
  background: var(--mm-surface-hover);
}

.mm-msg__reply:focus-visible {
  outline: 2px solid var(--mm-accent);
  outline-offset: 2px;
}

.mm-msg__reply:active {
  color: var(--mm-accent-hover);
  transform: translateY(1px);
}

/* ── Thread view ──────────────────────────────────────────────────────────── */
.mm-thread {
  display: flex;
  flex-direction: column;
  min-width: 300px;
  height: 100%;
  background: var(--mm-bg);
  border-left: 1px solid var(--mm-border);
}

.mm-thread__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--mm-border);
}

.mm-thread__title {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-family: var(--star-font-mono, "IBM Plex Mono", ui-monospace, monospace);
}

.mm-thread__close {
  border: 0;
  background: transparent;
  color: var(--mm-text-muted);
  font: inherit;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--mm-radius-sm);
}

.mm-thread__close:hover {
  background: var(--mm-surface-hover);
  color: var(--mm-text);
}

.mm-thread__close:focus-visible {
  outline: 2px solid var(--mm-accent);
  outline-offset: 2px;
}

.mm-thread__close:active {
  transform: translateY(1px);
}

.mm-msg--root {
  /* The thread's root message reads as a neutral quote block (faint surface
     tint + 2px neutral border), NOT a colored selection rail. */
  margin: 10px 12px;
  padding-left: 12px;
  border-left: 2px solid var(--mm-border);
  background: var(--mm-surface);
  border-radius: 0 var(--mm-radius) var(--mm-radius) 0;
}

.mm-thread__replies {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 12px 12px;
  overflow-y: auto;
}

/* ── Composer ─────────────────────────────────────────────────────────────── */
.mm-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--mm-border);
  background: var(--mm-surface);
}

.mm-composer__input {
  flex: 1 1 auto;
  resize: none;
  font: inherit;
  font-size: 14px;
  line-height: 1.4;
  padding: 8px 10px;
  border: 1px solid var(--mm-border);
  border-radius: var(--mm-radius);
  background: var(--mm-bg);
  color: var(--mm-text);
}

.mm-composer__input:focus-visible {
  outline: 2px solid var(--mm-accent);
  outline-offset: 2px;
  border-color: var(--mm-accent);
}

.mm-composer__send {
  flex: 0 0 auto;
  border: 0;
  border-radius: var(--mm-radius);
  background: var(--mm-accent);
  color: var(--mm-accent-on);
  font: inherit;
  font-weight: 600;
  font-family: var(--star-font-mono, "IBM Plex Mono", ui-monospace, monospace);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 8px 14px;
  cursor: pointer;
}

.mm-composer__send:hover:not(:disabled) {
  /* GPU-safe: subtle lift via transform only */
  transform: translateY(-1px);
  background: var(--mm-accent-hover);
}

.mm-composer__send:focus-visible {
  outline: 2px solid var(--mm-accent);
  outline-offset: 2px;
}

.mm-composer__send:active:not(:disabled) {
  transform: translateY(1px);
}

.mm-composer__send:disabled {
  background: var(--mm-border);
  color: var(--mm-text-muted);
  cursor: not-allowed;
}

/* GPU-safe motion: the only transition in the mod is a transform on Send hover. */
.mm-composer__send {
  transition: transform 120ms ease, opacity 120ms ease;
}

/* ── Shared ───────────────────────────────────────────────────────────────── */
.mm-empty {
  margin: 16px 12px;
  color: var(--mm-text-muted);
  font-size: 13px;
  font-style: italic;
}

@media (prefers-reduced-motion: reduce) {
  .mm-composer__send {
    transition: none;
  }
  .mm-composer__send:hover:not(:disabled) {
    transform: none;
  }
}
