/* ── Hero with integrated tab bar ───────────────────────────── */
/* Three-column grid: title (left) | tab bar (centered) | upload btn (right) */
.bead-hero-library {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 26px 4px 18px;
}

.bead-hero-library h1 {
  grid-column: 1;
  margin: 0;
}

.bead-hero-library .bead-tab-bar {
  grid-column: 2;
}

.bead-hero-library .upload-btn-blue {
  grid-column: 3;
  justify-self: end;
}

/* ── Tab Navigation ──────────────────────────────────────────── */
.bead-tab-bar {
  display: inline-flex;
  background: #eef1f5;
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
  flex-shrink: 0;
}

.bead-tab {
  display: inline-flex;
  align-items: center;
  padding: 8px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  color: #64748b;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  white-space: nowrap;
}

.bead-tab:hover {
  color: #475569;
  text-decoration: none;
}

.bead-tab.active {
  background: #fff;
  color: #1677ff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* ── Upload button (blue, not full-width) ────────────────────── */
.upload-btn-blue {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border: 0;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  color: #fff;
  background: linear-gradient(145deg, #1677ff, #0f62d9);
  box-shadow: 0 4px 14px rgba(22,119,255,0.22);
  transition: all 0.18s ease;
}

.upload-btn-blue:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(22,119,255,0.30);
}

/* ── Card Grid ──────────────────────────────────────────────── */
.library-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 260px));
  gap: 18px;
  justify-content: center;
  align-items: start;
}

.library-card {
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  border: 1px solid rgba(128, 144, 166, 0.24);
  position: relative;
  box-shadow: 0 1px 2px rgba(21, 31, 45, 0.04), 0 14px 34px rgba(32, 45, 64, 0.08);
  contain: layout paint style;
}

.library-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.90);
  z-index: 2;
}

@media (hover: hover) and (pointer: fine) {
  .library-card:hover {
    transform: translateY(-3px);
    border-color: rgba(22,119,255,0.28);
    box-shadow: 0 3px 8px rgba(21, 31, 45, 0.06), 0 18px 42px rgba(32, 45, 64, 0.13);
  }
}

.library-card-image {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  display: block;
  padding: 10px;
  background:
    linear-gradient(90deg, rgba(87, 104, 124, 0.055) 1px, transparent 1px),
    linear-gradient(180deg, rgba(87, 104, 124, 0.055) 1px, transparent 1px),
    linear-gradient(135deg, #fbfcfe, #f2f6fa);
  background-size: 14px 14px, 14px 14px, auto;
  border-bottom: 1px solid rgba(128, 144, 166, 0.18);
  box-sizing: border-box;
}

.library-card-body {
  min-height: 48px;
  padding: 10px 12px 12px;
  background: linear-gradient(180deg, #fff, #fbfcfe);
}

.library-card-title {
  font-size: 13px;
  font-weight: 700;
  color: #243044;
  line-height: 1.35;
  text-align: center;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

/* ── Empty State ────────────────────────────────────────────── */
.library-empty {
  text-align: center;
  padding: 80px 20px;
  color: #94a3b8;
}

.library-empty .material-symbols-outlined {
  font-size: 56px;
  display: block;
  margin-bottom: 14px;
}

.library-empty p {
  font-size: 15px;
  margin: 0;
}

/* ── Spinner ────────────────────────────────────────────────── */
.library-spinner {
  display: flex;
  justify-content: center;
  padding: 40px;
}

.library-spinner .spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #e2e8f0;
  border-top-color: #1677ff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ── Modal Overlay ──────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
  padding: 20px;
}

.modal-overlay.visible {
  opacity: 1;
  visibility: visible;
}

.modal-panel {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
  overflow-x: hidden;
  box-shadow: 0 24px 64px rgba(0,0,0,0.20);
  transform: translateY(10px);
  transition: transform 0.25s ease;
}

.modal-overlay.visible .modal-panel {
  transform: translateY(0);
}

.modal-panel-lg {
  max-width: 900px;
}

/* !important guards needed because Bootstrap 5.3 (loaded last)
   has built-in .modal-header / .modal-body / .modal-footer rules
   that would otherwise override our padding */
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px !important;
  border-bottom: 1px solid #e2e8f0 !important;
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 700;
  color: #1e293b;
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  color: #475569;
  background: #f1f5f9;
}

.modal-body {
  padding: 24px !important;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 20px 24px 24px !important;
  border-top: 1px solid #e2e8f0 !important;
}

/* Override .primary-btn width:100% in modal context */
.modal-footer .primary-btn,
.modal-footer .btn-cancel {
  width: auto !important;
  min-width: 100px;
  min-height: 44px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(22,119,255,0.18);
}

#uploadModal .modal-footer {
  display: block;
}

#uploadModal .modal-footer .primary-btn {
  width: 100% !important;
  min-height: 48px;
}

/* Download button inside settings — keep it full width of the settings column */
.download-settings .primary-btn {
  width: 100% !important;
  box-shadow: 0 2px 8px rgba(22,119,255,0.18);
}

.download-settings .download-btn-more {
  width: 36px !important;
  min-width: 36px;
  flex-shrink: 0;
  border-radius: 0 8px 8px 0;
  border-left: 1px solid rgba(255,255,255,0.25);
  padding: 0;
}

.download-settings .download-btn-more span {
  font-size: 20px;
}

.download-settings .download-btn-row {
  position: relative;
}

.download-settings .download-more-popover {
  bottom: calc(100% + 6px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.12);
  padding: 4px;
}

.download-settings .download-more-popover .toggle-row {
  margin: 0;
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 13px;
}

.download-settings .download-more-popover .toggle-row:hover {
  background: #f1f5f9;
}

/* ── Upload Form ────────────────────────────────────────────── */
.form-group {
  margin-bottom: 18px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #475569;
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 14px;
  color: #1e293b;
  outline: none;
  transition: border-color 0.15s;
  box-sizing: border-box;
  font-family: inherit;
}

.form-input:focus {
  border-color: #1677ff;
  box-shadow: 0 0 0 3px rgba(22,119,255,0.10);
}

.upload-drop {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 32px 20px;
  height: 220px;
  border: 2px dashed #cbd5e1;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.90), rgba(242,247,252,0.92)),
    linear-gradient(150deg, rgba(22,119,255,0.08), transparent 42%),
    linear-gradient(330deg, rgba(224,151,73,0.12), transparent 44%);
  box-sizing: border-box;
}

.upload-drop:hover {
  border-color: #1677ff;
  background: #f0f7ff;
}

.upload-preview {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 10px;
  box-sizing: border-box;
}

.upload-drop.has-image {
  border-style: solid;
  border-color: rgba(22,119,255,0.34);
  background: #f8fafc;
}

.upload-drop.dragging {
  border-color: rgba(22,119,255,0.75);
  background: #f7fbff;
}

.upload-drop.has-image .upload-preview {
  display: block;
}

.upload-drop-hint {
  display: flex;
  align-items: center;
  flex-direction: column;
  gap: 8px;
  color: #64748b;
  text-align: center;
  pointer-events: none;
  z-index: 2;
}

.upload-drop.has-image .upload-drop-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  flex-direction: row;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  color: #fff;
  background: linear-gradient(180deg, transparent, rgba(15,23,42,0.62));
}

.upload-drop .material-symbols-outlined {
  font-size: 36px;
  color: #94a3b8;
}

.upload-drop.has-image .material-symbols-outlined {
  font-size: 18px;
  color: rgba(255,255,255,0.90);
}

.upload-drop strong {
  font-size: 14px;
  color: #475569;
}

.upload-drop.has-image strong {
  color: #fff;
  font-size: 13px;
}

.upload-drop small {
  font-size: 12px;
  color: #94a3b8;
}

.upload-drop.has-image small {
  display: none;
}

.upload-filename {
  font-size: 13px;
  color: #1677ff;
  margin-top: 8px;
}

.upload-progress {
  margin-top: 14px;
}

.progress-bar {
  height: 6px;
  background: #e2e8f0;
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(135deg, #1677ff, #0f62d9);
  border-radius: 3px;
  transition: width 0.2s ease;
}

.progress-text {
  font-size: 12px;
  color: #64748b;
  margin-top: 8px;
  text-align: center;
}

.upload-note {
  font-size: 12px;
  color: #94a3b8;
  margin-top: 18px;
  text-align: center;
}

.btn-cancel {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 22px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
  color: #475569;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-cancel:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

/* ── Download Modal Layout ──────────────────────────────────── */
.download-modal-body {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 24px;
  padding: 20px 24px;
  align-items: start;
}

.download-preview {
  height: 420px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8fafc;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}

.download-preview .canvas-shell {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 12px;
  box-sizing: border-box;
  background: none; /* override main .canvas-shell checkerboard */
}

.download-preview .canvas-shell canvas {
  display: block;
  flex-shrink: 0;
}

.download-preview .empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: #94a3b8;
  font-size: 14px;
  position: absolute;
  inset: 0;
  justify-content: center;
  z-index: 1;
}

.download-preview .empty-state.hidden {
  display: none;
}

.download-settings {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.download-settings .control-group {
  margin-bottom: 0;
}

.download-settings .control-label {
  font-size: 12px;
  font-weight: 700;
  color: #64748b;
  margin-bottom: 6px;
  text-transform: none;
  letter-spacing: 0.02em;
}

.download-settings .segmented-group {
  display: inline-flex;
  flex-wrap: wrap;
  background: #eef1f5;
  border-radius: 8px;
  padding: 2px;
  gap: 1px;
}

.download-settings .segmented-btn {
  padding: 6px 12px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  color: #64748b;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.download-settings .segmented-btn.active {
  background: #fff;
  color: #1677ff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.download-settings .segmented-btn:hover:not(.active) {
  color: #475569;
}

.download-settings .toggle-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
}

.download-settings .toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: #475569;
  cursor: pointer;
  padding: 2px 0;
}

.download-settings .toggle-row input[type="checkbox"] {
  display: none;
}

.download-settings .toggle-track {
  position: relative;
  width: 40px;
  height: 22px;
  background: #cbd5e1;
  border-radius: 11px;
  transition: background 0.2s;
  flex-shrink: 0;
}

.download-settings .toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.download-settings .toggle-row input:checked + .toggle-track {
  background: #1677ff;
}

.download-settings .toggle-row input:checked + .toggle-track::after {
  transform: translateX(18px);
}

/* ── Toast ──────────────────────────────────────────────────── */
.toast {
  position: fixed;
  top: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: #1e293b;
  color: #fff;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  z-index: 2000;
  opacity: 0;
  text-align: center;
  transition: transform 0.3s ease, opacity 0.3s ease;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.20);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Responsive ─────────────────────────────────────────────── */
/* Hero mobile: same 700px breakpoint as the generator page so
   the tab bar position is identical when switching between pages */
@media (max-width: 700px) {
  .bead-hero-library {
    grid-template-columns: minmax(0, 1fr) 36px minmax(0, 1fr);
    gap: 10px;
    padding-top: 18px;
    padding-bottom: 12px;
    width: 100%;
  }

  .bead-hero-library h1 {
    grid-column: 1;
    grid-row: 1;
    margin: 0;
  }

  .bead-hero-library .bead-tab-bar {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
  }

  .bead-hero-library .upload-btn-blue {
    grid-column: 2;
    grid-row: 1;
    justify-self: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 50%;
    background: #fff;
    color: #1677ff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.10);
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .bead-hero-library .upload-btn-blue:hover {
    transform: none;
  }

  .bead-hero-library .upload-btn-blue .btn-label {
    display: none;
  }

  .bead-hero-library .upload-btn-blue .material-symbols-outlined {
    font-size: 20px;
  }

  .bead-tab {
    padding: 8px 14px;
    font-size: 13px;
    min-height: 36px;
  }
}

@media (max-width: 768px) {
  .library-cards {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
  }

  .library-card {
    box-shadow: 0 1px 2px rgba(21, 31, 45, 0.04), 0 10px 24px rgba(32, 45, 64, 0.08);
  }

  .library-card:active {
    transform: scale(0.985);
  }

  .library-card-image {
    padding: 8px;
    background-size: 12px 12px, 12px 12px, auto;
  }

  .library-card-body {
    min-height: 44px;
    padding: 9px 10px 10px;
  }

  .download-modal-body {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    gap: 18px;
  }

  .download-preview {
    height: 300px;
  }

  .download-settings {
    gap: 18px;
  }

  .download-settings .control-label {
    font-size: 13px;
    margin-bottom: 8px;
  }

  .download-settings .segmented-group {
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    padding: 4px;
    border-radius: 10px;
    width: 100%;
  }

  .download-settings .segmented-btn {
    flex: 1 1 0;
    min-width: 0;
    min-height: 42px;
    padding: 10px 2px;
    border-radius: 8px;
    font-size: 13px;
  }

  .download-settings .toggle-list {
    gap: 8px;
  }

  .download-settings .toggle-row {
    min-height: 52px;
    padding: 12px 13px;
    border-radius: 10px;
    background: #f5f8fb;
    font-size: 15px;
    font-weight: 600;
  }

  .download-settings .toggle-track {
    width: 50px;
    height: 28px;
    border-radius: 999px;
  }

  .download-settings .toggle-track::after {
    top: 3px;
    left: 3px;
    width: 22px;
    height: 22px;
  }

  .download-settings .toggle-row input:checked + .toggle-track::after {
    transform: translateX(22px);
  }

  .modal-panel-lg {
    max-width: 95vw;
  }

  .modal-body {
    padding: 18px !important;
  }

  .modal-footer {
    padding: 16px 18px 20px !important;
  }

  .upload-drop {
    height: 200px;
  }
}

@media (max-width: 480px) {
  .library-cards {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .library-card-title {
    font-size: 12px;
  }

  .modal-panel {
    max-width: 95vw;
    border-radius: 12px;
  }

  .modal-header {
    padding: 16px 18px 12px !important;
  }

  .modal-body {
    padding: 16px !important;
  }

  .modal-footer {
    padding: 14px 16px 18px !important;
  }
}
