/* =========================================================
   Chattable — RikkiOS theme bridge
   Colors follow ../../../style.css and styles/themes/*.
   Layout dimensions remain controlled by Chattable/RikkiOS.
   ========================================================= */

:root {
  color-scheme: light;

  /* Typography */
  --gb-font: Tahoma, "MS Sans Serif", Geneva, sans-serif;
  --gb-font-size: var(--font-size-base, 12px);
  --gb-line-height: 1.4;

  /* Existing layout values */
  --gb-max-width: 640px;
  --gb-gap: 1rem;
  --gb-padding: 1.25rem;
  --gb-radius: 0;
  --gb-shadow: 3px 3px 8px rgb(0 0 0 / 28%);
  --gb-transition: 80ms linear;

  /* RikkiOS chrome and surfaces */
  --gb-chrome:
    var(--retro-chrome,
      var(--face,
        var(--win-body-bg, #ece9d8)));

  --gb-bg:
    var(--retro-field,
      var(--notepad-bg,
        var(--input-bg, #ffffff)));

  --gb-panel:
    var(--retro-chrome,
      var(--win-body-bg,
        var(--face, #ece9d8)));

  --gb-text:
    var(--retro-text,
      var(--text,
        var(--win-body-text, #000000)));

  --gb-input-text:
    var(--notepad-text,
      var(--input-text,
        var(--gb-text)));

  --gb-muted: var(--muted, #555555);
  --gb-placeholder: var(--gb-muted);

  /* Bevel colors */
  --gb-highlight:
    var(--retro-bevel-light,
      var(--highlight, #ffffff));

  --gb-face-light:
    var(--retro-bevel-mid,
      var(--face-light, #dfdfdf));

  --gb-border:
    var(--retro-bevel-dark,
      var(--shadow, #808080));

  --gb-deep-border:
    var(--retro-bevel-deep,
      var(--dark-shadow, #000000));

  /* Selection, title bars, and links */
  --gb-selection:
    var(--retro-selection,
      var(--selection,
        var(--selection-color, #3169c6)));

  --gb-selection-text:
    var(--retro-selection-text,
      var(--selection-text, #ffffff));

  --gb-title-bg:
    var(--retro-title-active,
      var(--title-active,
        var(--win-title-active, #000080)));

  --gb-title-text:
    var(--retro-title-active-text,
      var(--title-text,
        var(--win-title-text, #ffffff)));

  --gb-link: var(--gb-selection);
  --gb-link-hover: var(--gb-selection);

  /* Inputs */
  --gb-input-bg:
    var(--retro-field,
      var(--notepad-bg,
        var(--input-bg, #ffffff)));

  --gb-input-border: var(--gb-border);
  --gb-input-focus-border: var(--gb-selection);
  --gb-input-focus-ring: var(--gb-selection);

  /* Buttons */
  --gb-button-bg: var(--gb-chrome);
  --gb-button-text: var(--gb-text);

  --gb-button-hover-bg:
    var(--retro-hover,
      var(--explorer-file-hover,
        var(--face-light, #dfdfdf)));

  --gb-button-active-bg: var(--gb-selection);
  --gb-button-active-text: var(--gb-selection-text);

  /* Status surfaces */
  --gb-status-bg:
    var(--retro-hover,
      var(--explorer-file-hover, #dce8f6));

  --gb-status-text: var(--gb-text);
  --gb-status-border: var(--gb-selection);

  /* Messages */
  --gb-message-bg: var(--gb-input-bg);
  --gb-message-border: var(--gb-border);
  --gb-message-meta-color: var(--gb-muted);

  /* Errors */
  --gb-error-bg: #fff0f0;
  --gb-error-text: #9b1c1c;
  --gb-error-border: #b85656;
}

/* Explicit OS dark themes take precedence over OS/browser preference. */

:root[data-theme="dark"] {
  color-scheme: dark;

  --gb-bg: var(--input-bg);
  --gb-panel: var(--face);
  --gb-input-bg: var(--input-bg);
  --gb-input-text: var(--input-text);

  --gb-message-bg: #1d1d23;
  --gb-message-border: var(--shadow);

  --gb-button-hover-bg: #3a3a40;
  --gb-status-bg: #292943;
  --gb-status-text: #ededff;
  --gb-status-border: var(--selection);

  --gb-link: #aaaae8;
  --gb-link-hover: #d0d0ff;
  --gb-placeholder: #a8a8a8;

  --gb-error-bg: #351719;
  --gb-error-text: #ffc6c6;
  --gb-error-border: #874348;
}

:root[data-theme="vista-dark"] {
  color-scheme: dark;

  --gb-button-hover-bg: #36434d;
  --gb-status-bg: #1c3546;
  --gb-status-text: #edf4f8;
  --gb-status-border: #52778f;

  --gb-link: #8dc9dc;
  --gb-link-hover: #c4f2ff;

  --gb-error-bg: #391c22;
  --gb-error-text: #ffd1d1;
  --gb-error-border: #87515a;
}

/* Vista keeps the theme palettes but uses softer geometry. */

:root[data-theme^="vista"] {
  --gb-font: "Segoe UI", Tahoma, sans-serif;
  --gb-radius: 4px;
  --gb-shadow: 3px 4px 14px rgb(0 0 0 / 28%);
}

/* =========================================================
   Base chat
   ========================================================= */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--gb-bg);
  color: var(--gb-text);
}

body {
  font-family: var(--gb-font);
  font-size: var(--gb-font-size);
  line-height: var(--gb-line-height);
}

#main,
#background {
  background: var(--gb-bg);
  color: var(--gb-text);
}

#main,
#background,
.msgBody,
#input,
#nameEntry {
  -webkit-user-select: text;
  user-select: text;
}

#background {
  scrollbar-width: thin;
  scrollbar-color: var(--gb-chrome) var(--gb-face-light);
}

a {
  color: var(--gb-link);
  text-underline-offset: 0.15em;
}

a:hover {
  color: var(--gb-link-hover);
  text-decoration-thickness: 2px;
}

button,
input,
textarea {
  font: inherit;
}

button {
  color: var(--gb-button-text);
}

::selection {
  background: var(--gb-selection);
  color: var(--gb-selection-text);
}

/* =========================================================
   Banner
   ========================================================= */

#top_banner {
  padding: 0.65rem var(--gb-padding);
  background: var(--gb-title-bg);
  color: var(--gb-title-text);
  border-bottom: 1px solid var(--gb-deep-border);
  font-size: 0.85rem;
  font-weight: 700;
  text-shadow: 1px 1px rgb(0 0 0 / 35%);
}

#top_banner a {
  color: inherit;
}

/* =========================================================
   Messages
   ========================================================= */

.msgWrapper {
  min-width: 0;
}

.allMessages {
  position: relative;
  width: auto;
  max-width: min(88%, 52rem);
  margin: 0.6rem;
  padding: 0.75rem 0.85rem;
  overflow-wrap: anywhere;
  background: var(--gb-message-bg);
  color: var(--gb-text);
  border: 1px solid var(--gb-message-border);
  border-radius: var(--gb-radius);
  box-shadow:
    inset 1px 1px var(--gb-highlight),
    inset -1px -1px var(--gb-face-light);
}

.allMessages.received {
  background: var(--gb-message-bg);
  border-color: var(--gb-message-border);
}

.allMessages.sent {
  background: var(--gb-status-bg);
  border-color: var(--gb-status-border);
}

.senderInfo {
  margin-bottom: 0.3rem;
  color: var(--gb-link);
  font-size: 0.85rem;
  font-weight: 700;
}

.senderInfo a {
  color: inherit;
}

.msgBody {
  margin: 0;
  color: var(--gb-text);
  font: inherit;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  cursor: text;
}

#timestamp {
  color: var(--gb-message-meta-color);
  font-size: 0.72rem;
  font-style: italic;
}

/* Private messages */

.allMessages.pm {
  padding-top: 2rem;
  background: var(--gb-error-bg);
  border-color: var(--gb-error-border);
}

.allMessages.pm::before {
  content: "Private message";
  position: absolute;
  top: 0.45rem;
  left: 0.85rem;
  color: var(--gb-error-text);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Replies and quotes */

.reply,
.msgBody blockquote {
  margin: 0.5rem 0;
  padding: 0.45rem 0.75rem;
  background: var(--gb-panel);
  color: var(--gb-muted);
  border: 1px solid var(--gb-border);
  border-left: 3px solid var(--gb-selection);
  font-style: italic;
}

/* Pinned messages */

.pinned {
  border-color: var(--gb-selection);
  box-shadow:
    0 0 0 1px var(--gb-selection),
    inset 1px 1px var(--gb-highlight);
}

/* Highlighted/pinged names */

.highlight {
  padding: 0.05rem 0.25rem;
  background: var(--gb-selection);
  color: var(--gb-selection-text);
  border: 1px solid var(--gb-selection);
  border-radius: 0;
  font-weight: 700;
}

/* =========================================================
   Badges
   ========================================================= */

.mod,
.owner,
.beta {
  display: inline-block;
  margin-inline: 0.2rem;
  padding: 0.05rem 0.3rem;
  background: var(--gb-chrome);
  border: 1px solid currentColor;
  border-radius: 0;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1.3;
  text-transform: uppercase;
}

.owner {
  color: var(--gb-error-text);
}

.mod {
  color: var(--gb-link);
}

.beta {
  color: var(--gb-muted);
}

/* =========================================================
   Message input
   ========================================================= */

#textInput {
  background: var(--gb-chrome);
  border-top: 1px solid var(--gb-highlight);
  box-shadow: 0 -1px var(--gb-border);
}

#input,
#nameEntry {
  width: 100%;
  min-height: 2.75rem;
  max-height: 9rem;
  margin: 0;
  padding: 0.65rem 0.75rem;
  overflow-y: auto;
  background: var(--gb-input-bg);
  color: var(--gb-input-text);
  border: 2px solid;
  border-color:
    var(--gb-deep-border)
    var(--gb-highlight)
    var(--gb-highlight)
    var(--gb-deep-border);
  border-radius: 0;
  box-shadow: inset 1px 1px var(--gb-border);
  font: inherit;
  line-height: var(--gb-line-height);
}

#input:empty::before {
  content: "Send Message [Enter to send]";
  color: var(--gb-placeholder);
  pointer-events: none;
}

#input:focus,
#nameEntry:focus {
  outline: 1px dotted var(--gb-input-focus-border);
  outline-offset: -4px;
  border-color:
    var(--gb-deep-border)
    var(--gb-highlight)
    var(--gb-highlight)
    var(--gb-deep-border);
  box-shadow: inset 1px 1px var(--gb-input-focus-border);
}

#input::placeholder,
#nameEntry::placeholder {
  color: var(--gb-placeholder);
  opacity: 1;
}

/* =========================================================
   Buttons and menus
   ========================================================= */

#loadMore,
#scrollToBottom,
#account,
#save,
#closeSettingsBtn,
#emojiTrayToggle {
  padding: 0.5rem 0.8rem;
  background: var(--gb-button-bg);
  color: var(--gb-button-text);
  border: 2px solid;
  border-color:
    var(--gb-highlight)
    var(--gb-deep-border)
    var(--gb-deep-border)
    var(--gb-highlight);
  border-radius: var(--gb-radius);
  box-shadow:
    inset 1px 1px var(--gb-face-light),
    inset -1px -1px var(--gb-border);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    background var(--gb-transition),
    color var(--gb-transition);
}

#loadMore:hover,
#scrollToBottom:hover,
#account:hover,
#save:hover,
#closeSettingsBtn:hover,
#emojiTrayToggle:hover {
  background: var(--gb-button-hover-bg);
  color: var(--gb-button-text);
}

#loadMore:active,
#scrollToBottom:active,
#account:active,
#save:active,
#closeSettingsBtn:active,
#emojiTrayToggle:active {
  background: var(--gb-button-active-bg);
  color: var(--gb-button-active-text);
  border-color:
    var(--gb-deep-border)
    var(--gb-highlight)
    var(--gb-highlight)
    var(--gb-deep-border);
  box-shadow: none;
}

#dltranscript {
  display: inline-block;
  margin: 0.5rem 0;
  color: var(--gb-link);
}

.ctxMenuOption {
  padding: 0.45rem 0.65rem;
  background: var(--gb-chrome);
  color: var(--gb-text);
}

.ctxMenuOption:hover {
  background: var(--gb-selection);
  color: var(--gb-selection-text);
}

#settingsWindow,
.dialogueModal,
#settingsMenu {
  background: var(--gb-chrome);
  color: var(--gb-text);
  border: 2px solid;
  border-color:
    var(--gb-highlight)
    var(--gb-deep-border)
    var(--gb-deep-border)
    var(--gb-highlight);
  border-radius: var(--gb-radius);
  box-shadow: var(--gb-shadow);
}

#settings {
  opacity: 0.85;
  color: inherit;
  cursor: pointer;
}

#settings:hover {
  opacity: 1;
}

#settingsMenu hr {
  width: 100%;
  height: 2px;
  margin: 1rem 0;
  background: transparent;
  border: 0;
  border-top: 1px solid var(--gb-border);
  border-bottom: 1px solid var(--gb-highlight);
}

#settingsMenu input[type="text"],
#name {
  padding: 0.55rem 0.7rem;
  background: var(--gb-input-bg);
  color: var(--gb-input-text);
  border: 2px solid;
  border-color:
    var(--gb-deep-border)
    var(--gb-highlight)
    var(--gb-highlight)
    var(--gb-deep-border);
  border-radius: 0;
  box-shadow: inset 1px 1px var(--gb-border);
}

#settingsMenu input[type="text"]:focus,
#name:focus {
  outline: 1px dotted var(--gb-input-focus-border);
  outline-offset: -4px;
}

/* =========================================================
   Reply banner, emoji, and typing indicator
   ========================================================= */

#replyBanner {
  padding: 0.55rem 0.75rem;
  background: var(--gb-status-bg);
  color: var(--gb-status-text);
  border: 1px solid var(--gb-status-border);
  border-radius: var(--gb-radius);
}

#emojiTray {
  background: var(--gb-chrome);
  color: var(--gb-text);
  border: 2px solid;
  border-color:
    var(--gb-highlight)
    var(--gb-deep-border)
    var(--gb-deep-border)
    var(--gb-highlight);
  border-radius: var(--gb-radius);
  box-shadow: var(--gb-shadow);
}

.emoji {
  font-size: 1.25rem;
}

.allMessages.containsOnlyEmojis .emoji {
  font-size: 2rem;
}

.emojiInGrid {
  cursor: pointer;
  transition: transform var(--gb-transition);
}

.emojiInGrid:hover {
  transform: scale(1.15);
}

#is_typing {
  padding: 0.3rem 0.55rem;
  background: var(--gb-chrome);
  color: var(--gb-muted);
  border: 1px solid var(--gb-border);
  border-radius: var(--gb-radius);
  font-size: 0.75rem;
}

/* Vista controls use its thinner borders and small corner radius. */

:root[data-theme^="vista"] :is(
  #loadMore,
  #scrollToBottom,
  #account,
  #save,
  #closeSettingsBtn,
  #emojiTrayToggle
) {
  border: 1px solid var(--vista-border);
  border-radius: 3px;
  box-shadow: inset 0 1px rgb(255 255 255 / 45%);
}

:root[data-theme^="vista"] :is(
  #input,
  #nameEntry,
  #settingsMenu input[type="text"],
  #name
) {
  border: 1px solid var(--shadow);
  border-radius: 3px;
  box-shadow: inset 0 1px 2px rgb(0 0 0 / 8%);
}

/* Keyboard controls */

a:focus-visible,
button:focus-visible,
#input:focus-visible,
#settings:focus-visible,
.ctxMenuOption:focus-visible {
  outline: 1px dotted var(--gb-input-focus-border);
  outline-offset: 2px;
}

/* Preserve the existing narrow-column behavior. */

@media (max-width: 600px) {
  .allMessages {
    max-width: calc(100% - 1.2rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --gb-transition: none;
  }

  .emojiInGrid:hover {
    transform: none;
  }
}