.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 31, 54, 0.3);
  display: grid;
  place-items: center;
  z-index: 30;
}

.modal-backdrop[hidden] {
  display: none;
}

.line-manager-modal {
  width: min(1060px, calc(100% - 30px));
  height: min(680px, calc(100% - 30px));
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 18px 38px rgba(16, 32, 58, 0.22);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-head {
  height: 58px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-head h2 {
  margin: 0;
  font-size: 18px;
}

.modal-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 300px 1fr;
}

.line-library {
  border-right: 1px solid var(--line);
  padding: 12px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.line-library-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-weight: 600;
}

.line-library-list {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.line-library-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  background: #ffffff;
  cursor: pointer;
  text-align: left;
}

.line-library-item.active {
  border-color: var(--accent);
  background: var(--soft);
}

.line-library-item-title {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.line-library-item-title.temporary-imported {
  color: #1f6feb;
}

.line-library-item-tag {
  display: inline-flex;
  font-size: 12px;
  color: var(--muted);
}

.line-library-item-tag.temporary-imported {
  color: #1f6feb;
  font-weight: 700;
}

.line-type-temp-warning {
  border: 1px solid #e1bf62;
  border-radius: 10px;
  background: #fff6dc;
  color: #7a5600;
  padding: 10px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.line-type-temp-warning[hidden] {
  display: none !important;
}

.line-type-temp-warning-text {
  font-size: 13px;
  line-height: 1.35;
}

.line-library-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.line-library-preview-inline {
  width: 92px;
  min-width: 92px;
  height: 24px;
  display: block;
}

.shape-library-preview-inline {
  width: 36px;
  min-width: 36px;
  height: 36px;
  border: 1px solid #d7e1f0;
  border-radius: 6px;
  background: #fcfdff;
  object-fit: contain;
  padding: 2px;
}

.line-editor {
  padding: 14px;
  overflow: auto;
}

.line-type-preview {
  width: 100%;
  height: 90px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fcfdff;
}

.segments-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 12px 0 8px;
  font-weight: 600;
}

.segments-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.color-list-editor {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.color-list-item {
  display: grid;
  grid-template-columns: 72px minmax(64px, 1fr) minmax(150px, 1.2fr) auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fbfdff;
}

.color-list-item-label {
  font-size: 12px;
  font-weight: 700;
  color: #55667f;
}

.color-list-item input[type="color"] {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 2px;
  background: #fff;
}

.color-list-item input[type="range"] {
  width: 100%;
}

.alpha-control {
  display: grid;
  grid-template-columns: 14px minmax(72px, 1fr) 58px;
  gap: 6px;
  align-items: center;
}

.alpha-control-label {
  font-size: 12px;
  color: #5a6b84;
  text-align: center;
  font-weight: 700;
}

.alpha-control input[type="range"] {
  width: 100%;
  margin: 0;
}

.alpha-control-number {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 12px;
}

.segment-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #fbfdff;
}

.segment-item.dragging {
  opacity: 0.45;
}

.segment-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.segment-drag-handle {
  width: 30px;
  height: 30px;
  border: 1px dashed #b9c8e2;
  border-radius: 7px;
  background: #fff;
  padding: 4px;
  color: #5d6c84;
  cursor: grab;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.segment-drag-handle img {
  width: 14px;
  height: 14px;
  display: block;
}

/* Disabled ghost button style for modals */
.btn-ghost[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

.disabled-wrapper {
  display: inline-block;
  cursor: not-allowed;
}

/* small close icon in modal header */
.modal-head .btn-ghost img {
  width: 18px;
  height: 18px;
  display: block;
}

.segment-item.dragging {
  opacity: 0.45;
}

.segment-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr 1fr auto;
}

.segment-subgrid {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr;
  margin-top: 8px;
}

.segment-title {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

.field-compact {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-compact label {
  font-size: 12px;
  color: var(--muted);
}

.field-compact-toggle {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.field-compact input,
.field-compact select {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 8px;
}

.field-compact input[type="color"] {
  padding: 3px;
  min-height: 34px;
}

.line-settings-color-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.line-settings-color-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #f9fbff;
  display: grid;
  grid-template-columns: 72px minmax(64px, 1fr) minmax(150px, 1.2fr);
  gap: 8px;
  align-items: center;
}

.line-settings-color-item label {
  font-size: 12px;
  font-weight: 700;
  color: #55667f;
}

.line-settings-color-item input[type="color"] {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 2px;
  background: #fff;
}

.line-settings-color-item input[type="range"] {
  width: 100%;
}

.segment-fixed {
  display: flex;
  align-items: center;
  gap: 4px;
}

.modal-actions {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.line-manager-modal.export-modal {
  width: min(360px, calc(100% - 30px));
  height: auto;
  min-height: 0;
  max-height: calc(100% - 30px);
}

.line-manager-modal.export-modal .export-modal-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
}

.line-manager-modal.export-modal .export-modal-actions {
  margin-top: 2px;
  justify-content: flex-end;
}

@media (max-width: 960px) {
  .modal-body {
    grid-template-columns: 1fr;
  }

  .line-library {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: 220px;
  }

  .segment-grid {
    grid-template-columns: 1fr 1fr;
  }
}