/**
 * Adjustment Toolbar Component
 *
 * Floating contextual toolbar that appears when a layer is selected.
 * Styling matches the original studio2 layer-toolbar (Figma-Make-style
 * image adjustment toolbar): header with drag handle + title + collapse
 * chevron, a wrapping row of vertical icon/label buttons, and an inline
 * slider drawer below.
 */

.s2h-adjustment-toolbar {
  position: fixed;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.13), 0 0 0 1px rgba(0, 0, 0, 0.05);
  width: fit-content;
  max-width: min(760px, calc(100vw - 24px));
  z-index: 50;
  pointer-events: auto;
}

.s2h-adjustment-toolbar[hidden] {
  display: none;
}

.s2h-adjustment-toolbar.dragging {
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18), 0 0 0 2px var(--primary);
}

/* Header: drag handle + title on the left, collapse chevron on the right */
.iat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px 4px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  cursor: grab;
  touch-action: none;
  user-select: none;
  white-space: nowrap;
}

.s2h-adjustment-toolbar.dragging .iat-header {
  cursor: grabbing;
}

.s2h-adjustment-toolbar.collapsed .iat-header {
  border-bottom: none;
}

.iat-drag-handle {
  display: flex;
  align-items: center;
  gap: 6px;
  color: rgba(0, 0, 0, 0.55);
}

.iat-drag-handle svg {
  width: 14px;
  height: 14px;
}

.iat-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(0, 0, 0, 0.55);
}

.iat-collapse-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: rgba(0, 0, 0, 0.55);
  cursor: pointer;
  padding: 0;
  transition: all 100ms ease;
  touch-action: manipulation;
  flex-shrink: 0;
}

.iat-collapse-btn:hover {
  background: rgba(0, 0, 0, 0.06);
  color: rgba(0, 0, 0, 0.8);
}

.iat-chevron {
  transition: transform 200ms ease;
}

/* Button row */
.iat-controls {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 2px;
  padding: 4px 6px 6px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.s2h-adjustment-toolbar.collapsed .iat-controls,
.s2h-adjustment-toolbar.collapsed .iat-drawer-panel {
  display: none !important;
}

.iat-empty-state {
  padding: 16px 20px;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  color: rgba(0, 0, 0, 0.45);
  font-family: 'Nunito Sans', sans-serif;
  white-space: nowrap;
}

.iat-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 7px 8px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: rgba(0, 0, 0, 0.6);
  cursor: pointer;
  font-family: 'Nunito Sans', sans-serif;
  font-size: 9px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  position: relative;
  transition: all 100ms ease;
  touch-action: manipulation;
  min-width: 44px;
}

.iat-btn:hover {
  background: rgba(0, 0, 0, 0.06);
  color: rgba(0, 0, 0, 0.9);
}

.iat-btn:active {
  background: rgba(0, 0, 0, 0.12);
}

.iat-btn.iat-btn-active {
  background: rgba(37, 99, 235, 0.08);
  color: rgb(37, 99, 235);
}

.iat-btn.iat-btn-active:hover {
  background: rgba(37, 99, 235, 0.14);
}

.iat-btn svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.iat-btn-label {
  text-align: center;
}

.iat-more-menu {
  position: relative;
  flex: 0 0 auto;
}

.iat-more-summary {
  list-style: none;
}

.iat-more-summary::-webkit-details-marker {
  display: none;
}

.iat-more-glyph {
  height: 15px;
  font-size: 17px;
  font-weight: 700;
  line-height: 8px;
  letter-spacing: 1px;
}

.iat-more-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(52px, 1fr));
  gap: 3px;
  width: min(210px, calc(100vw - 80px));
  max-height: min(280px, 45vh);
  overflow-y: auto;
  padding: 7px;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 9px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.2);
  z-index: 5;
}

.iat-more-menu-panel .iat-divider {
  display: none;
}

.iat-more-menu-panel .iat-btn {
  width: 100%;
}

.iat-btn.iat-btn-danger {
  color: rgba(0, 0, 0, 0.5);
}

.iat-btn.iat-btn-danger:hover {
  background: rgba(239, 68, 68, 0.08);
  color: rgb(220, 38, 38);
}

.iat-btn.iat-btn-danger:active {
  background: rgba(239, 68, 68, 0.14);
}

.iat-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.iat-btn:disabled:hover {
  background: transparent;
}

.iat-divider {
  width: 1px;
  height: 28px;
  background: rgba(0, 0, 0, 0.06);
  margin: 0 2px;
  flex-shrink: 0;
  align-self: center;
}

/* Drawer panel: houses one of the reusable plugins below the button row.
   Only one plugin (slider or style) is display:block at a time; JS toggles
   which, it never generates their markup. */
.iat-drawer-panel {
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  min-width: 220px;
}

.iat-drawer-slider,
.iat-drawer-style {
  padding: 8px 12px 12px;
}

.iat-slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.iat-slider-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(0, 0, 0, 0.55);
}

.iat-slider-value-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.iat-slider-value-input {
  width: 44px;
  padding: 2px 4px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  font-family: 'Nunito Sans', sans-serif;
  color: rgba(0, 0, 0, 0.8);
  text-align: right;
  background: #fff;
  -moz-appearance: textfield;
}

.iat-slider-value-input::-webkit-inner-spin-button,
.iat-slider-value-input::-webkit-outer-spin-button {
  margin: 0;
}

.iat-slider-value-input:focus {
  outline: none;
  border-color: rgb(37, 99, 235);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.iat-slider-unit {
  font-size: 11px;
  font-weight: 600;
  color: rgba(0, 0, 0, 0.55);
  font-family: 'Nunito Sans', sans-serif;
}

.iat-slider-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.iat-slider {
  flex: 1;
  height: 3px;
  border-radius: 2px;
  appearance: none;
  -webkit-appearance: none;
  background: rgba(0, 0, 0, 0.1);
  outline: none;
  cursor: pointer;
}

.iat-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.8);
  cursor: pointer;
}

.iat-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.8);
  cursor: pointer;
  border: none;
}

.iat-slider-reset {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: rgba(0, 0, 0, 0.6);
  cursor: pointer;
  transition: all 100ms ease;
  touch-action: manipulation;
}

.iat-slider-reset:hover:not(:disabled) {
  background: rgba(0, 0, 0, 0.06);
  color: rgba(0, 0, 0, 0.9);
}

.iat-slider-reset:active:not(:disabled) {
  background: rgba(0, 0, 0, 0.12);
}

.iat-slider-reset:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.iat-slider-reset svg {
  width: 16px;
  height: 16px;
}

/* Text style drawer plugin */
.iat-style-row {
  display: flex;
  align-items: center;
  gap: 2px;
}

.iat-style-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: rgba(0, 0, 0, 0.6);
  cursor: pointer;
  transition: all 100ms ease;
  touch-action: manipulation;
}

.iat-style-btn:hover {
  background: rgba(0, 0, 0, 0.06);
  color: rgba(0, 0, 0, 0.9);
}

.iat-style-btn.iat-btn-active {
  background: rgba(37, 99, 235, 0.08);
  color: rgb(37, 99, 235);
}

.iat-shade-inline-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(0, 0, 0, 0.55);
  white-space: nowrap;
  margin-right: 2px;
}

/* Compact inline shade slider - sits directly in the B/I/U row and fills
   the rest of the available width. Track always paints white (left) to
   black (right) in screen space; the native input's raw value runs the
   opposite way (100 at the white/left end, 0 at the black/right end) so
   the displayed number always matches the color it produces - see
   AdjustmentToolbarComponent.applyShadeValue. */
.iat-shade-slider {
  flex: 1 1 auto;
  min-width: 40px;
  background: linear-gradient(to right, #fff, #000);
  border: 1px solid rgba(0, 0, 0, 0.15);
}

.iat-shade-slider::-webkit-slider-thumb {
  background: #fff;
  border: 1.5px solid rgba(0, 0, 0, 0.4);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.iat-shade-slider::-moz-range-thumb {
  background: #fff;
  border: 1.5px solid rgba(0, 0, 0, 0.4);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.iat-shade-value-input {
  width: 34px;
  padding-right: 2px;
  -moz-appearance: textfield;
}

.iat-shade-value-input::-webkit-inner-spin-button,
.iat-shade-value-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Custom font picker. Native iOS select menus ignore option font-family,
   so the listbox is rendered in-page and each option previews its font. */
.iat-font-picker {
  position: relative;
  flex: 0 0 auto;
}

.iat-font-picker summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 30px;
  padding: 0 8px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 6px;
  background: #fff;
  color: rgba(0, 0, 0, 0.8);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  width: 116px;
  list-style: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.iat-font-picker summary::-webkit-details-marker {
  display: none;
}

.iat-font-picker summary::after {
  content: '▾';
  margin-left: 8px;
  font-family: sans-serif;
  font-size: 9px;
}

.iat-font-picker[open] summary,
.iat-font-picker summary:focus {
  outline: none;
  border-color: rgb(37, 99, 235);
}

.iat-font-menu {
  position: fixed;
  width: 190px;
  max-height: min(320px, 50vh);
  overflow-y: auto;
  padding: 5px;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
  z-index: 4;
}

.iat-font-menu button {
  display: block;
  width: 100%;
  padding: 8px 9px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: rgba(0, 0, 0, 0.82);
  font-size: 15px;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}

.iat-font-menu button:hover,
.iat-font-menu button[aria-selected="true"] {
  background: rgba(37, 99, 235, 0.1);
  color: rgb(37, 99, 235);
}

@media (max-width: 600px) and (orientation: portrait) {
  .s2h-adjustment-toolbar {
    /* 52px rail + 32px vertical ruler + 12px window gutter. */
    max-width: calc(100vw - 96px);
  }

  .iat-controls {
    overflow-x: visible;
    scrollbar-width: none;
  }
}
