/* GhostChat — Design Foundation (UI-1) + Layout Skeleton (UI-2A) */

:root {
  /* Colors */
  --color-bg: #090b0d;
  --color-surface: #111417;
  --color-text: #e8ece9;
  --color-text-secondary: #9aa39d;
  --color-accent: #63d471;
  --color-border: #26352c;
  --color-error: #d96a6a;
  --color-selection-bg: rgba(99, 212, 113, 0.22);
  --color-selection-text: #e8ece9;
  --color-focus-ring: rgba(99, 212, 113, 0.45);
  --color-focus-ring-subtle: rgba(99, 212, 113, 0.18);

  /* Typography */
  --font-family: 'JetBrains Mono', 'IBM Plex Mono', ui-monospace, monospace;
  --font-size-sm: 0.8125rem;
  --font-size-base: 0.9375rem;
  --font-size-lg: 1rem;
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --line-height-base: 1.65;
  --line-height-tight: 1.4;

  /* Spacing */
  --space-0: 0;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 2.5rem;
  --space-8: 3rem;

  /* Border radius */
  --radius-none: 0;
  --radius-sm: 0.25rem;
  --radius-md: 0.375rem;
  --radius-lg: 0.5rem;

  /* Borders */
  --border-width: 1px;
  --border-style: solid;
  --border-color: var(--color-border);
  --border-default: var(--border-width) var(--border-style) var(--border-color);

  /* Transitions */
  --transition-fast: 120ms ease;
  --transition-base: 160ms ease;
  --transition-slow: 240ms ease;

  /* Layout dimensions */
  --layout-header-height: 48px;
  --layout-content-max-width: 62.5rem;
  --layout-content-padding-inline: var(--space-4);
  --layout-content-padding-block: var(--space-5);
  --layout-form-gap: var(--space-2);
  --composer-max-lines: 8;
  --conversation-marker-gap: 4px;
  --conversation-message-gap: 2px;
  --conversation-group-gap: 20px;
  --conversation-system-event-gap: 16px;
  --composer-padding-bottom: var(--space-5);

  /* Z-index */
  --z-base: 0;
  --z-raised: 10;
  --z-overlay: 100;

  /* Animation timing (reserved) */
  --duration-instant: 0ms;
  --duration-fast: 120ms;
  --duration-base: 160ms;
  --duration-slow: 240ms;
  --ease-default: ease;
  --ease-in-out: ease-in-out;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
  color-scheme: dark;
}

body {
  height: 100%;
  margin: 0;
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
  line-height: var(--line-height-base);
  color: var(--color-text);
  background-color: var(--color-bg);
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  min-height: 100dvh;
  min-width: 0;
}

.header {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  padding-inline: var(--layout-content-padding-inline);
  min-width: 0;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  width: 100%;
  max-width: var(--layout-content-max-width);
  height: var(--layout-header-height);
  max-height: var(--layout-header-height);
  border-bottom: var(--border-default);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-shrink: 0;
}

.header-copy-link {
  margin: 0;
  padding: 0;
  border: none;
  background: none;
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-normal);
  line-height: var(--line-height-tight);
  color: var(--color-text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--transition-fast);
}

.header-copy-link:hover {
  color: var(--color-text);
}

.header-copy-link:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.header-copy-link--success {
  color: var(--color-accent);
}

.header-copy-link--error {
  color: var(--color-error);
}

.header-room,
.header-status {
  margin: 0;
  min-width: 0;
}

.header-room {
  flex: 1 1 auto;
  font-size: var(--font-size-sm);
  line-height: var(--line-height-tight);
  color: var(--color-text-secondary);
  white-space: nowrap;
  overflow: hidden;
}

.header-room-prefix {
  color: var(--color-accent);
}

#room-id {
  color: var(--color-text);
}

.header-status {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
  font-size: var(--font-size-sm);
  line-height: var(--line-height-tight);
  color: var(--color-text-secondary);
}

.status-dot {
  flex-shrink: 0;
  font-size: 0.625rem;
  line-height: 1;
  color: var(--color-accent);
}

#status {
  margin: 0;
}

.conversation {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  justify-content: center;
  overflow: hidden;
  padding-inline: var(--layout-content-padding-inline);
}

.conversation-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--layout-content-max-width);
  min-width: 0;
  min-height: 0;
  flex: 1;
}

.conversation-inner {
  flex: 1;
  min-height: 0;
  min-width: 0;
  padding-top: var(--layout-content-padding-block);
  padding-bottom: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.conversation-inner:has(#messages:empty) {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.conversation-empty {
  display: none;
  margin: 0;
  text-align: center;
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-tight);
}

.conversation-inner:has(#messages:empty) .conversation-empty {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}

.conversation-empty-line {
  display: block;
  overflow-wrap: break-word;
}

.conversation-inner:has(#messages:not(:empty)) .conversation-empty {
  display: none;
}

#messages {
  margin: 0;
  padding: 0;
  min-width: 0;
}

#messages:not(:empty) {
  width: 100%;
}

.composer {
  flex-shrink: 0;
  min-width: 0;
  padding-top: var(--conversation-group-gap);
  padding-bottom: var(--composer-padding-bottom);
}

::selection,
::-moz-selection {
  background-color: var(--color-selection-bg);
  color: var(--color-selection-text);
}

.header-room::selection,
.header-room::-moz-selection,
.header-status::selection,
.header-status::-moz-selection,
.message-group .message::selection,
.message-group .message::-moz-selection,
.system-event::selection,
.system-event::-moz-selection,
.conversation-empty::selection,
.conversation-empty::-moz-selection,
#message-input::selection,
#message-input::-moz-selection {
  background-color: var(--color-selection-bg);
  color: var(--color-selection-text);
}

:focus {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
}

* {
  scrollbar-color: var(--color-border) var(--color-bg);
  scrollbar-width: thin;
}

*::-webkit-scrollbar {
  width: 0.5rem;
  height: 0.5rem;
}

*::-webkit-scrollbar-track {
  background: var(--color-bg);
}

*::-webkit-scrollbar-thumb {
  background-color: var(--color-border);
  border-radius: var(--radius-sm);
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  padding: var(--space-2) var(--space-3);
  border: var(--border-default);
  border-radius: var(--radius-sm);
  background-color: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  transition:
    border-color var(--transition-fast),
    color var(--transition-fast);
}

button:hover:not(:disabled) {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.message-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.message-group + .message-group {
  margin-top: var(--conversation-group-gap);
}

.participant-marker {
  margin-bottom: var(--conversation-marker-gap);
  color: var(--color-text);
  line-height: var(--line-height-base);
}

.message-group .message-list {
  display: flex;
  flex-direction: column;
  gap: var(--conversation-message-gap);
  width: 100%;
  min-width: 0;
}

.message-group .message {
  margin: 0;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
  line-height: var(--line-height-base);
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
}

.system-event {
  margin: 0;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
  line-height: var(--line-height-base);
  color: var(--color-text-secondary);
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
}

.message-group + .system-event {
  margin-top: var(--conversation-group-gap);
}

.system-event + .message-group,
.system-event + .system-event {
  margin-top: var(--conversation-system-event-gap);
}

#message-form,
.composer-form {
  display: flex;
  align-items: baseline;
  gap: 0;
  margin: 0;
}

.composer-prompt {
  flex-shrink: 0;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
  color: var(--color-text);
  line-height: var(--line-height-base);
  margin-inline-end: 1ch;
  user-select: none;
}

#message-input {
  flex: 1;
  min-width: 0;
  min-height: calc(var(--font-size-base) * var(--line-height-base));
  max-height: calc(var(--font-size-base) * var(--line-height-base) * var(--composer-max-lines));
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
  line-height: var(--line-height-base);
  color: var(--color-text);
  caret-color: var(--color-accent);
  resize: none;
  overflow-y: auto;
  field-sizing: content;
  appearance: none;
  -webkit-appearance: none;
  box-shadow: none;
  outline: none;
  transition: height var(--transition-base);
}

#message-input::placeholder {
  color: var(--color-text-secondary);
}

#message-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#message-input:focus {
  outline: none;
  box-shadow: none;
}

#message-input:focus-visible {
  outline: 1px solid var(--color-focus-ring-subtle);
  outline-offset: 3px;
}

@media (max-width: 40rem) {
  :root {
    --layout-content-padding-inline: var(--space-3);
    --layout-content-padding-block: var(--space-4);
  }

  .header-status #status {
    max-width: 7rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
