/*
 * CricketWindies reply surfaces
 *
 * This file is intentionally scoped. It must not be loaded as a global
 * replacement for global.css or theme.css.
 *
 * Integration hooks:
 *   - keep MyBB's existing #quickreply id on showthread
 *   - add cw-reply-page to the newreply.php body
 *   - add cw-reply-form to the outer new-reply table or form wrapper
 *
 * It does not target the masthead, navigation, footer, or unscoped MyBB
 * selectors.
 */

/* Shared reply tokens use the existing CricketWindies theme contract. */
#quickreply,
body.cw-reply-page .cw-reply-form {
  --reply-maroon: var(--maroon, #54102b);
  --reply-maroon-dark: var(--maroon-dark, #390a1d);
  --reply-gold: var(--gold, #edc268);
  --reply-ivory: var(--ivory, #fff9f0);
  --reply-paper: var(--paper, #faf8f5);
  --reply-surface: var(--surface, #ffffff);
  --reply-surface-alt: var(--surface-alt, #f7f5f2);
  --reply-surface-hover: var(--surface-hover, #f4f1ed);
  --reply-ink: var(--ink, #152033);
  --reply-muted: var(--muted, #5f6877);
  --reply-border: var(--border, #e4ddd7);
  --reply-border-strong: var(--border-strong, #d5cdc7);
  --reply-link: var(--blue-link, #07588c);
}

/* Quick reply on showthread.php */
#quickreply {
  width: 100%;
  margin-top: 22px;
  color: var(--reply-ink);
}

#quickreply > form {
  margin: 0;
}

#quickreply .tborder {
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--reply-border);
  border-radius: 5px;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--reply-surface);
  box-shadow: 0 1px 2px rgba(21, 32, 51, 0.05);
}

#quickreply .thead {
  padding: 12px 16px;
  background: var(--reply-maroon);
  color: var(--reply-ivory);
  font-size: 15px;
  line-height: 1.25;
}

#quickreply .thead a:link,
#quickreply .thead a:visited {
  color: var(--reply-ivory);
}

#quickreply .trow1,
#quickreply .trow2 {
  padding: 14px 16px;
  background: var(--reply-surface);
  color: var(--reply-ink);
  border-bottom: 1px solid var(--reply-border);
}

#quickreply .trow2 {
  background: var(--reply-surface-alt);
}

#quickreply .tborder > tbody > tr:last-child > td {
  border-bottom: 0;
}

#quickreply textarea[name="message"],
#quickreply textarea#message {
  display: block;
  width: 100%;
  min-height: 142px;
  box-sizing: border-box;
  margin: 0;
  padding: 12px 13px;
  border: 1px solid var(--reply-border-strong);
  border-radius: 4px;
  background: var(--reply-surface);
  color: var(--reply-ink);
  font: inherit;
  line-height: 1.45;
  resize: vertical;
}

#quickreply textarea[name="message"]::placeholder,
#quickreply textarea#message::placeholder {
  color: var(--reply-muted);
}

#quickreply textarea[name="message"]:focus,
#quickreply textarea#message:focus {
  border-color: var(--reply-link);
  outline: 3px solid var(--reply-gold);
  outline-offset: 2px;
}

#quickreply .quickreply_options,
#quickreply .quick_reply_options,
#quickreply #quickreply_buttons,
#quickreply .post_options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: 10px;
}

#quickreply .smalltext {
  color: var(--reply-muted);
  font-size: 12px;
}

/* Added on integration: .smalltext's muted-gray color is right for body
   copy, but the smilie inserter's own "Smilies" title reuses that same
   class sitting inside a maroon .thead bar — .thead's own ivory color only
   ever reaches links (.thead a:link/a:visited), so this muted gray was
   winning there instead, nearly unreadable against maroon. */
#quickreply .thead .smalltext,
body.cw-reply-page .cw-reply-form .thead .smalltext {
  color: var(--reply-ivory);
}

#quickreply input.button,
#quickreply button.button,
#quickreply a.button,
#quickreply .button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: 8px 15px;
  border: 1px solid var(--reply-maroon);
  border-radius: 4px;
  background: var(--reply-maroon);
  color: var(--reply-ivory) !important;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none !important;
}

#quickreply input.button:hover,
#quickreply button.button:hover,
#quickreply a.button:hover,
#quickreply .button:hover {
  border-color: var(--reply-maroon-dark);
  background: var(--reply-maroon-dark);
}

#quickreply input.button[type="button"],
#quickreply input.button[name="previewpost"],
#quickreply input.button[name="saveasdraft"],
#quickreply button.button.secondary,
#quickreply a.button.secondary,
#quickreply .button.secondary {
  border-color: var(--reply-border-strong);
  background: var(--reply-surface);
  color: var(--reply-ink) !important;
}

#quickreply input.button[type="button"]:hover,
#quickreply input.button[name="previewpost"]:hover,
#quickreply input.button[name="saveasdraft"]:hover,
#quickreply button.button.secondary:hover,
#quickreply a.button.secondary:hover,
#quickreply .button.secondary:hover {
  border-color: var(--reply-maroon);
  background: var(--reply-surface-hover);
}

/* SCEditor is used by many MyBB 1.8 installations. Keep its rules scoped. */
#quickreply .sceditor-container,
body.cw-reply-page .cw-reply-form .sceditor-container {
  width: 100% !important;
  box-sizing: border-box;
  border: 1px solid var(--reply-border-strong);
  border-radius: 4px;
  background: var(--reply-surface);
}

#quickreply .sceditor-toolbar,
body.cw-reply-page .cw-reply-form .sceditor-toolbar {
  padding: 6px;
  border-bottom: 1px solid var(--reply-border);
  background: var(--reply-surface-alt);
}

#quickreply .sceditor-group,
body.cw-reply-page .cw-reply-form .sceditor-group {
  border: 1px solid var(--reply-border);
  border-radius: 3px;
  background: var(--reply-surface);
}

#quickreply .sceditor-button,
body.cw-reply-page .cw-reply-form .sceditor-button {
  width: 28px;
  height: 28px;
  border-radius: 2px;
  /* Added on integration: SCEditor's own stylesheet puts a 3px/5px
     asymmetric padding on this element, sized around its *original*
     button dimensions. Forcing a 28px box here without touching that
     padding left the 16px icon sitting off-center inside it — flex
     centering the icon (whatever its own SCEditor-set size/margin already
     is) sidesteps having to match paddings across two stylesheets. */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

#quickreply .sceditor-button:hover,
#quickreply .sceditor-button.active,
body.cw-reply-page .cw-reply-form .sceditor-button:hover,
body.cw-reply-page .cw-reply-form .sceditor-button.active {
  background: var(--reply-gold);
}

#quickreply .sceditor-container iframe,
#quickreply .sceditor-container textarea,
body.cw-reply-page .cw-reply-form .sceditor-container iframe,
body.cw-reply-page .cw-reply-form .sceditor-container textarea {
  min-height: 142px;
  box-sizing: border-box;
  background: var(--reply-surface);
  color: var(--reply-ink);
  font: inherit;
  line-height: 1.45;
}

#quickreply a:focus-visible,
#quickreply button:focus-visible,
#quickreply input:focus-visible,
#quickreply select:focus-visible,
#quickreply textarea:focus-visible,
body.cw-reply-page .cw-reply-form a:focus-visible,
body.cw-reply-page .cw-reply-form button:focus-visible,
body.cw-reply-page .cw-reply-form input:focus-visible,
body.cw-reply-page .cw-reply-form select:focus-visible,
body.cw-reply-page .cw-reply-form textarea:focus-visible {
  outline: 3px solid var(--reply-gold);
  outline-offset: 2px;
}

/* Full reply page: only the explicitly marked form is styled. */
body.cw-reply-page .cw-reply-form {
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--reply-border);
  border-radius: 5px;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--reply-surface);
  color: var(--reply-ink);
  box-shadow: 0 1px 2px rgba(21, 32, 51, 0.05);
}

body.cw-reply-page .cw-reply-form > tbody > tr > td,
body.cw-reply-page .cw-reply-form > tr > td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--reply-border);
  vertical-align: top;
}

body.cw-reply-page .cw-reply-form > tbody > tr:last-child > td,
body.cw-reply-page .cw-reply-form > tr:last-child > td {
  border-bottom: 0;
}

body.cw-reply-page .cw-reply-form .thead {
  padding: 13px 16px;
  background: var(--reply-maroon);
  color: var(--reply-ivory);
  font-size: 16px;
  line-height: 1.25;
}

body.cw-reply-page .cw-reply-form .thead a:link,
body.cw-reply-page .cw-reply-form .thead a:visited {
  color: var(--reply-ivory);
}

body.cw-reply-page .cw-reply-form .tcat {
  background: var(--reply-surface-alt);
  color: var(--reply-ink);
  font-weight: 700;
}

body.cw-reply-page .cw-reply-form .trow1,
body.cw-reply-page .cw-reply-form .trow2 {
  background: var(--reply-surface);
  color: var(--reply-ink);
}

body.cw-reply-page .cw-reply-form .trow2 {
  background: var(--reply-surface-alt);
}

body.cw-reply-page .cw-reply-form > tbody > tr > td:first-child,
body.cw-reply-page .cw-reply-form > tr > td:first-child {
  width: 190px;
  background: var(--reply-surface-alt);
  color: var(--reply-ink);
  font-weight: 700;
}

body.cw-reply-page .cw-reply-form label,
body.cw-reply-page .cw-reply-form .field-label {
  color: var(--reply-ink);
  font-weight: 700;
}

body.cw-reply-page .cw-reply-form input.textbox,
body.cw-reply-page .cw-reply-form input[type="text"],
body.cw-reply-page .cw-reply-form input[type="url"],
body.cw-reply-page .cw-reply-form select,
body.cw-reply-page .cw-reply-form textarea {
  max-width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--reply-border-strong);
  border-radius: 4px;
  background: var(--reply-surface);
  color: var(--reply-ink);
  font: inherit;
}

body.cw-reply-page .cw-reply-form input.textbox,
body.cw-reply-page .cw-reply-form input[type="text"],
body.cw-reply-page .cw-reply-form input[type="url"],
body.cw-reply-page .cw-reply-form select {
  min-height: 38px;
  padding: 8px 10px;
}

body.cw-reply-page .cw-reply-form textarea {
  min-height: 142px;
  padding: 11px 12px;
  line-height: 1.45;
  resize: vertical;
}

body.cw-reply-page .cw-reply-form input.button,
body.cw-reply-page .cw-reply-form button.button,
body.cw-reply-page .cw-reply-form a.button,
body.cw-reply-page .cw-reply-form .button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: 8px 15px;
  border: 1px solid var(--reply-maroon);
  border-radius: 4px;
  background: var(--reply-maroon);
  color: var(--reply-ivory) !important;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none !important;
}

body.cw-reply-page .cw-reply-form input.button:hover,
body.cw-reply-page .cw-reply-form button.button:hover,
body.cw-reply-page .cw-reply-form a.button:hover,
body.cw-reply-page .cw-reply-form .button:hover {
  border-color: var(--reply-maroon-dark);
  background: var(--reply-maroon-dark);
}

body.cw-reply-page .cw-reply-form input.button[type="button"],
body.cw-reply-page .cw-reply-form input.button[name="previewpost"],
body.cw-reply-page .cw-reply-form input.button[name="saveasdraft"],
body.cw-reply-page .cw-reply-form button.button.secondary,
body.cw-reply-page .cw-reply-form a.button.secondary,
body.cw-reply-page .cw-reply-form .button.secondary {
  border-color: var(--reply-border-strong);
  background: var(--reply-surface);
  color: var(--reply-ink) !important;
}

body.cw-reply-page .cw-reply-form .smalltext {
  color: var(--reply-muted);
  font-size: 12px;
}

/* Scoped to body.cw-reply-page rather than .cw-reply-form: the stock
   newreply template renders {$preview}/{$reply_errors}/{$attacherror}/
   {$moderation_notice} BEFORE <form> even opens, as siblings of the
   .cw-reply-form table, not descendants of it — a .cw-reply-form ancestor
   requirement here would never match, so these boxes would stay entirely
   stock-styled. Same fix applied on newthread.css. */
body.cw-reply-page .preview,
body.cw-reply-page .cw-reply-preview {
  margin-bottom: 14px;
  padding: 13px 16px;
  border: 1px solid var(--reply-border);
  border-left: 4px solid var(--reply-gold);
  border-radius: 4px;
  background: #fffaf0;
  color: var(--reply-ink);
}

body.cw-reply-page .notice,
body.cw-reply-page .error,
body.cw-reply-page .red_alert,
body.cw-reply-page .invalid_field {
  margin: 10px 0;
  padding: 11px 13px;
  border: 1px solid var(--reply-border);
  border-left: 4px solid var(--reply-gold);
  border-radius: 4px;
  background: #fffaf0;
  color: var(--reply-ink);
}

body.cw-reply-page .error,
body.cw-reply-page .red_alert,
body.cw-reply-page .invalid_field {
  border-left-color: #8b2731;
  background: #fff4f4;
}

body.cw-reply-page .error li,
body.cw-reply-page .red_alert li,
body.cw-reply-page .invalid_field li,
body.cw-reply-page .notice li {
  color: var(--reply-ink);
}

body.cw-reply-page .cw-reply-form .post_options,
body.cw-reply-page .cw-reply-form .reply-options,
body.cw-reply-page .cw-reply-form .cw-reply-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 700px) {
  #quickreply {
    margin-top: 16px;
  }

  #quickreply .thead,
  #quickreply .trow1,
  #quickreply .trow2,
  body.cw-reply-page .cw-reply-form > tbody > tr > td,
  body.cw-reply-page .cw-reply-form > tr > td {
    padding: 12px;
  }

  body.cw-reply-page .cw-reply-form,
  body.cw-reply-page .cw-reply-form > tbody,
  body.cw-reply-page .cw-reply-form > tbody > tr,
  body.cw-reply-page .cw-reply-form > tr {
    display: block;
  }

  body.cw-reply-page .cw-reply-form > tbody > tr > td,
  body.cw-reply-page .cw-reply-form > tr > td {
    display: block;
    width: auto !important;
  }

  body.cw-reply-page .cw-reply-form > tbody > tr > td:first-child,
  body.cw-reply-page .cw-reply-form > tr > td:first-child {
    padding-bottom: 7px;
    border-bottom: 0;
  }

  #quickreply .quickreply_options,
  #quickreply .quick_reply_options,
  #quickreply #quickreply_buttons,
  #quickreply .post_options,
  body.cw-reply-page .cw-reply-form .post_options,
  body.cw-reply-page .cw-reply-form .reply-options,
  body.cw-reply-page .cw-reply-form .cw-reply-actions {
    align-items: stretch;
  }

  #quickreply input.button,
  #quickreply button.button,
  #quickreply a.button,
  body.cw-reply-page .cw-reply-form input.button,
  body.cw-reply-page .cw-reply-form button.button,
  body.cw-reply-page .cw-reply-form a.button {
    min-height: 40px;
  }
}

@media (max-width: 450px) {
  #quickreply input.button,
  #quickreply button.button,
  #quickreply a.button,
  body.cw-reply-page .cw-reply-form input.button,
  body.cw-reply-page .cw-reply-form button.button,
  body.cw-reply-page .cw-reply-form a.button {
    flex: 1 1 100%;
    width: 100%;
  }

  #quickreply .sceditor-toolbar,
  body.cw-reply-page .cw-reply-form .sceditor-toolbar {
    overflow-x: auto;
    white-space: nowrap;
  }
}

/*
 * Added on integration, not part of the original handoff file: the preview
 * notice's background is a hardcoded light cream (#fffaf0) with no
 * dark-mode counterpart, same gap already found and fixed twice elsewhere
 * on this theme (the PM-unread banner, the profile "no bio" empty state) —
 * fixed here too rather than left to resurface as the same report again.
 * Also covers .notice/.error/.red_alert/.invalid_field (e.g. the "subject
 * is missing" validation box), which had the identical hardcoded-light gap
 * plus were entirely unscoped until the .cw-reply-form-ancestor fix above.
 */
[data-theme="dark"] body.cw-reply-page .preview,
[data-theme="dark"] body.cw-reply-page .cw-reply-preview,
[data-theme="dark"] body.cw-reply-page .notice {
  background: rgba(237, 194, 104, .12);
  border-color: rgba(237, 194, 104, .35);
}

[data-theme="dark"] body.cw-reply-page .error,
[data-theme="dark"] body.cw-reply-page .red_alert,
[data-theme="dark"] body.cw-reply-page .invalid_field {
  background: rgba(139, 39, 49, .18);
  border-color: rgba(139, 39, 49, .4);
}
