/**
 * @file
 * Layout Builder admin UI fixes for bootstrap_subtheme.
 *
 * The theme's global styles (.btn, .container, etc.) interfere with
 * Layout Builder's admin interface. These overrides restore the expected
 * LB appearance without affecting the rest of the site.
 */

/* ==========================================================================
   Action buttons: Save layout, Discard changes, Revert to defaults
   The theme's .btn makes these pill-shaped (border-radius: 20em) and
   oversized (min-width: 8.8rem, padding: .6em 2em). Reset for LB form.
   ========================================================================== */

.layout-builder-form .form-actions .btn,
.layout-builder-form .form-actions .button,
.layout-builder-form .form-actions input[type="submit"] {
  border-radius: 4px;
  min-width: auto;
  padding: 8px 16px;
  font-size: 14px;
  line-height: 1.4;
  display: inline-block;
  margin-right: 8px;
  margin-bottom: 0;
  vertical-align: middle;
}

/* Primary save button styling */
.layout-builder-form .form-actions .button--primary,
.layout-builder-form .form-actions input.button--primary[type="submit"] {
  background-color: #2f91da;
  color: #fff;
  border: 1px solid #2f91da;
}

.layout-builder-form .form-actions .button--primary:hover {
  background-color: #1a7cc0;
  border-color: #1a7cc0;
}

/* Secondary buttons (Discard, Revert) */
.layout-builder-form .form-actions .button:not(.button--primary),
.layout-builder-form .form-actions input[type="submit"]:not(.button--primary) {
  background-color: #fff;
  color: #333;
  border: 1px solid #ccc;
}

.layout-builder-form .form-actions .button:not(.button--primary):hover {
  background-color: #f5f5f5;
  border-color: #999;
}

/* Actions bar layout — ensure buttons are in a row, not stacked */
.layout-builder-form .form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: #f7f7f7;
  border-top: 1px solid #ccc;
  margin: 0 -1.5em;
  padding-left: 1.5em;
}

/* Content preview toggle — keep it inline with buttons */
.layout-builder-form .form-actions .form-item {
  margin: 0;
  display: inline-flex;
  align-items: center;
}

/* ==========================================================================
   Global alert fixes.
   The subtheme's alert.twig override uses inline SVG icons and BS4-compatible
   close buttons. These styles ensure alerts look correct site-wide.
   ========================================================================== */

/* Alert icon — inline SVG, consistent sizing and color */
.alert .alert-icon {
  flex-shrink: 0;
  margin-right: 12px;
  width: 20px;
  height: 20px;
}

.alert-success .alert-icon { fill: #3c763d; }
.alert-warning .alert-icon { fill: #8a6d3b; }
.alert-danger .alert-icon  { fill: #a94442; }
.alert-info .alert-icon    { fill: #31708f; }

/* Alert close button — style BS4 .close to look clean */
.alert .alert-close-btn {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  padding: 4px 8px;
  background: transparent;
  border: none;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  color: #000;
  opacity: 0.4;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.alert .alert-close-btn:hover,
.alert .alert-close-btn:focus {
  opacity: 0.75;
  outline: none;
}

/* Alert message content — flex layout */
.alert .alert-message {
  flex: 1;
}

/* Alert layout — position relative for close button placement */
.alert.alert-dismissible {
  position: relative;
  display: flex;
  align-items: center;
  padding-right: 48px;
}

/* ==========================================================================
   Layout Builder message banner
   .layout-builder__message > .alert-wrapper > .alert.alert-success
   Also contains nested .messages--warning for "unsaved changes"
   ========================================================================== */

/* Main container: sticky bar pinned to bottom of viewport */
.layout-builder__message {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 500;
  margin: 0;
  padding: 0;
  transition: right 0.3s ease;
}

/* When off-canvas sidebar is open, shrink the bar so it doesn't overlap.
   Drupal's off-canvas defaults to ~400px wide on desktop. The sidebar
   renders on the right side of the viewport. */
body.js-off-canvas-dialog-open .layout-builder__message {
  right: 400px;
}

/* Drupal sets --drupal-off-canvas-width as an inline style on <body> in
   some versions; use it when available for exact sizing. */
@supports (right: var(--drupal-off-canvas-width, 400px)) {
  body.js-off-canvas-dialog-open .layout-builder__message {
    right: var(--drupal-off-canvas-width, 400px);
  }
}

/* The alert-wrapper inside the LB message */
.layout-builder__message .alert-wrapper,
.layout-builder__message [data-drupal-messages] {
  margin: 0;
  padding: 0;
  width: 100%;
}

/* The main alert bar — full-width, edge-to-edge */
.layout-builder__message .alert {
  margin: 0;
  border: none;
  border-radius: 0;
  padding: 10px 20px;
  font-size: 13px;
  line-height: 1.5;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: none;
}

.layout-builder__message .alert.alert-success {
  background-color: #f0f7ed;
  border-top: 2px solid #77b259;
  color: #555;
}

.layout-builder__message .alert.alert-warning {
  background-color: #fdf8eb;
  border-top: 2px solid #d4a843;
  color: #7a6d4a;
}

/* Smaller icon inside the LB banner */
.layout-builder__message .alert .alert-icon {
  width: 16px;
  height: 16px;
  margin-right: 8px;
}

.layout-builder__message .alert-success .alert-icon { fill: #77b259; }
.layout-builder__message .alert-warning .alert-icon { fill: #d4a843; }

/* Tighten the message text content */
.layout-builder__message .alert .alert-message {
  font-size: 13px;
  color: #555;
}

.layout-builder__message .alert-warning .alert-message {
  color: #7a6d4a;
}

/* Style the "edit template" link */
.layout-builder__message .alert a {
  color: #2f91da;
  text-decoration: underline;
}

.layout-builder__message .alert a:hover {
  color: #1a7cc0;
}

/* Subtler close button in the LB banner */
.layout-builder__message .alert .alert-close-btn {
  opacity: 0.3;
  font-size: 16px;
  right: 8px;
}

.layout-builder__message .alert .alert-close-btn:hover {
  opacity: 0.7;
}

/* --- Nested "unsaved changes" warning --- */
.layout-builder__message .messages--warning,
.layout-builder__message .alert .messages--warning {
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  background: none;
}

.layout-builder__message .messages--warning .messages__content,
.layout-builder__message .messages--warning .alert-warning {
  margin: 0;
  padding: 6px 20px;
  border: none;
  border-radius: 0;
  border-top: 1px solid #e0d8c1;
  background-color: #fdf8eb;
  font-size: 12px;
  color: #7a6d4a;
  box-shadow: none;
}

.layout-builder__message .messages--warning .visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   Remove .container constraint from blocks inside Layout Builder.
   The theme's block.html.twig wraps all blocks in .container which
   constrains Layout Builder blocks to a max-width. Reset inside LB.
   ========================================================================== */

.layout-builder .block > .container {
  max-width: none;
  width: 100%;
  padding-left: 0;
  padding-right: 0;
}

/* ==========================================================================
   Remove block-system-main-block padding inside LB editing context.
   ========================================================================== */

.layout-builder-form .block-system-main-block {
  padding-top: 0;
  padding-bottom: 0;
}

/* ==========================================================================
   Ensure Layout Builder add-section and add-block links aren't affected
   by the theme's pill button style.
   ========================================================================== */

.layout-builder__link--add {
  border-radius: 0;
  min-width: auto;
  padding: 0.25em 0.5em 0.25em 1.3em;
  font-size: 13px;
}

/* ==========================================================================
   Ensure off-canvas dialogs aren't clipped by overflow-x: hidden on html.
   ========================================================================== */

html.ui-dialog-content-is-open,
html.js-off-canvas-dialog-open,
html.ui-dialog-off-canvas {
  overflow-x: visible;
}

/* ==========================================================================
   Give the layout builder form some bottom padding so the fixed message
   banner doesn't cover the last section's content.
   ========================================================================== */

.layout-builder-form {
  padding-bottom: 80px;
}

/* ==========================================================================
   Prevent .modal-block { width/height: 0 !important } in the theme's
   main.css from collapsing Layout Builder dialog elements.
   ========================================================================== */

.layout-builder .modal-block,
#drupal-off-canvas .modal-block,
.ui-dialog .modal-block {
  width: auto !important;
  height: auto !important;
}

/* ==========================================================================
   Lower navbar z-index when off-canvas dialog is open.
   The theme uses z-index: 999 on .site-header / .navbar-toggler (mobile),
   which sits above Drupal's off-canvas tray (~z-index 501).
   ========================================================================== */

body.js-off-canvas-dialog-open .site-header,
body.js-off-canvas-dialog-open .navbar-toggler,
body.js-off-canvas-dialog-open .site-header .navbar-brand {
  z-index: 400;
}

/* ==========================================================================
   Reset pill-shaped buttons inside off-canvas dialogs.
   The theme's global .btn { border-radius: 20em } also hits buttons
   rendered in the off-canvas tray (Add block, Update, Remove, etc.).
   ========================================================================== */

#drupal-off-canvas .btn,
#drupal-off-canvas input[type="submit"],
#drupal-off-canvas .button {
  border-radius: 4px;
  min-width: auto;
  padding: 8px 16px;
}
