:root {
  --bg0: #0a1221;
  --bg1: #0f1b33;
  --panel: rgba(255, 255, 255, .06);
  --panel2: rgba(255, 255, 255, .09);
  --accent: #7c5cff;
  --accent2: #ffcf5a;
  --good: #4ade80;
  --danger: #ff5c7a;
  --text: #eef2ff;
  --muted: rgba(238, 242, 255, .70);
  --shadow: 0 18px 60px rgba(0, 0, 0, .45);
  --btnH: 44px;
  --btnR: 12px;
  --pad: 24px;
}

@media (max-width: 980px) {
  :root {
    --pad: 16px;
  }
}

@media (pointer:coarse) {
  :root {
    --btnH: 48px;
    --btnR: 14px;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  background: radial-gradient(1200px 800px at 18% 18%, rgba(66, 105, 220, .25) 0%, transparent 55%),
    radial-gradient(900px 700px at 82% 0%, rgba(140, 90, 255, .22) 0%, transparent 60%),
    linear-gradient(180deg, var(--bg1), var(--bg0));
  color: var(--text);
  overflow: hidden;
}

/* ===== Экран проектов ===== */
.projects-screen {
  position: fixed;
  inset: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 24px;
  padding-top: calc(24px + env(safe-area-inset-top));
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.projects-container {
  max-width: 900px;
  margin: 0 auto;
}

.projects-header {
  margin-bottom: 40px;
}

.projects-logo {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo-icon {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, rgba(124, 92, 255, .92), rgba(255, 207, 90, .88));
  box-shadow: 0 12px 30px rgba(0, 0, 0, .4);
  font-size: 26px;
}

.logo-title {
  font-weight: 900;
  font-size: 32px;
  letter-spacing: -0.5px;
}

.logo-sub-text {
  margin-top: 4px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.projects-content {
  margin-top: 20px;
}

.projects-title {
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 8px;
}

.projects-subtitle {
  font-size: 15px;
  color: var(--muted);
  margin-bottom: 28px;
}

.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.project-card {
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .10);
  border-radius: 18px;
  padding: 20px;
  cursor: pointer;
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
  position: relative;
}

.project-card:hover {
  background: rgba(255, 255, 255, .09);
  border-color: rgba(124, 92, 255, .4);
  transform: translateY(-2px);
}

.project-card:active {
  transform: translateY(0);
}

.project-preview {
  width: 100%;
  height: 140px;
  background: #1a2744;
  border-radius: 12px;
  margin-bottom: 14px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.project-preview img,
.project-preview canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

.project-preview-placeholder {
  font-size: 48px;
  opacity: 0.3;
}

.project-info {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.project-name {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
  word-break: break-word;
}

.project-meta {
  font-size: 12px;
  color: var(--muted);
}

.project-delete {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: rgba(255, 92, 122, .15);
  border: 1px solid rgba(255, 92, 122, .3);
  color: var(--danger);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease, transform .15s ease;
  flex-shrink: 0;
}

.project-delete:hover {
  background: rgba(255, 92, 122, .25);
  transform: scale(1.05);
}

.add-project-card {
  background: rgba(124, 92, 255, .08);
  border: 2px dashed rgba(124, 92, 255, .35);
  border-radius: 18px;
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
  position: relative;
  overflow: hidden;
}

.add-project-card:hover {
  background: rgba(124, 92, 255, .14);
  border-color: rgba(124, 92, 255, .55);
  transform: translateY(-2px);
}

.add-project-card input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.add-project-icon {
  font-size: 42px;
  margin-bottom: 12px;
}

.add-project-text {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
}

.add-project-hint {
  font-size: 13px;
  color: var(--muted);
}

/* ===== Экран приложения ===== */
.app-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: relative;
  z-index: 2000;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  padding-left: calc(16px + env(safe-area-inset-left));
  padding-right: calc(16px + env(safe-area-inset-right));
  background: rgba(10, 15, 30, 0.85);
  /* Затемнил для контраста */
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(255, 255, 255, .1);
  box-shadow: 0 8px 32px rgba(0, 0, 0, .4);
  flex-wrap: nowrap;

  /* SCROLLABLE FIX */
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
}

/* Prevent icons from squishing */
.topbar>* {
  flex-shrink: 0;
}

.topbar::-webkit-scrollbar {
  display: none;
}

.btn-back {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--btnH);
  padding: 0 14px;
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: var(--btnR);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s ease, transform .15s ease;
  flex-shrink: 0;
}

.btn-back:hover {
  background: rgba(255, 255, 255, .10);
  transform: translateY(-1px);
}

.back-icon {
  font-size: 18px;
}

.project-name-top {
  font-size: 15px;
  font-weight: 800;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 250px;
  margin-left: 4px;
}

.app-brand-mini {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: 8px;
  padding: 0 14px;
  height: var(--btnH);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--btnR);
  user-select: none;
  cursor: pointer;
  opacity: 0.85;
  transition: all 0.2s ease;
}

.app-brand-mini:hover {
  opacity: 1;
  background: rgba(124, 92, 255, 0.08);
  border-color: rgba(124, 92, 255, 0.2);
}

.brand-icon {
  font-size: 18px;
}

.brand-text {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: -0.3px;
  color: var(--text);
}

@media (max-width: 600px) {
  .app-brand-mini {
    display: none;
  }
}

/* Selection Mode */
#selectBtn.active {
  background: linear-gradient(135deg, #7c5cff 0%, #a78bfa 100%);
  border-color: rgba(124, 92, 255, .6);
  box-shadow: 0 4px 20px rgba(124, 92, 255, .5),
    0 0 30px rgba(124, 92, 255, .4);
}

/* Clean/Reset existing selection-panel styles first */
.selection-panel {
  position: absolute;
  /* Changed from fixed to align with canvas if needed, or fixed logic in JS. Let's stick to fixed bottom */
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(124, 92, 255, 0.3);
  border-radius: 50px;
  /* Pill shape */
  padding: 6px;
  /* Tight padding */
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.1) inset;
  z-index: 5000;
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.19, 1, 0.22, 1);
}

.selection-panel.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

/* The Shining Star Button */
#selectionAiBtn {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #d946ef 100%);
  border: none;
  border-radius: 40px;
  padding: 0 20px;
  height: 44px;
  /* Big touch target */
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(124, 92, 255, 0.4);
  position: relative;
  overflow: hidden;
  transition: transform 0.2s;
  white-space: nowrap;
}

#selectionAiBtn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(124, 92, 255, 0.6);
}

#selectionAiBtn:active {
  transform: scale(0.95);
}

/* Shimmer Effect */
#selectionAiBtn::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 50%;
  height: 100%;
  background: linear-gradient(90deg,
      transparent,
      rgba(255, 255, 255, 0.4),
      transparent);
  transform: skewX(-20deg);
  animation: shine 3s infinite;
}

@keyframes shine {
  0% {
    left: -100%;
  }

  20% {
    left: 200%;
  }

  100% {
    left: 200%;
  }
}

/* Mini Close Button */
.selection-close-mini {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 14px;
}

.selection-close-mini:hover {
  background: rgba(255, 92, 122, 0.2);
  color: #ff5c7a;
  border-color: rgba(255, 92, 122, 0.3);
}

/* Selection panel styles removed - handled in MODERNIZED SELECTION PANEL section */





.selection-preview img {
  max-width: 100%;
  max-height: 240px;
  object-fit: contain;
  position: relative;
  z-index: 1;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, .1));
}

.selection-actions {
  display: flex;
  gap: 10px;
}

.selection-actions .btn {
  flex: 1;
  font-size: 13px;
  height: 42px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.selection-actions .btn svg {
  width: 14px;
  height: 14px;
}

.spacer {
  flex: 1 1 auto;
  min-width: 12px;
}

.rightbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  height: var(--btnH);
}

/* Кнопки */
.btn {
  height: var(--btnH);
  padding: 0 20px;
  border: none;
  border-radius: var(--btnR);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all .25s cubic-bezier(0.4, 0, 0.2, 1);
  background: linear-gradient(135deg, rgba(255, 255, 255, .12), rgba(255, 255, 255, .06));
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, .15);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .2),
    0 0 0 0 rgba(124, 92, 255, 0);
  user-select: none;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, .15), transparent);
  opacity: 0;
  transition: opacity .25s ease;
}

.btn:hover:not(:disabled)::before {
  opacity: 1;
}

.btn:hover:not(:disabled) {
  transform: translateY(2px) !important;
  /* ЕЩЕ СИЛЬНЕЕ ВНИЗ */
  box-shadow: 0 2px 8px rgba(0, 0, 0, .3),
    0 0 8px rgba(124, 92, 255, .1);
  border-color: rgba(255, 255, 255, .3);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .2);
}

.btn:disabled {
  opacity: .35;
  cursor: not-allowed;
  filter: grayscale(0.5);
}

.btn-primary {
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.45) 0%, rgba(167, 139, 250, 0.35) 100%);
  border: 1px solid rgba(124, 92, 255, .4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 4px 16px rgba(124, 92, 255, 0.15);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.6) 0%, rgba(167, 139, 250, 0.5) 100%);
  box-shadow: 0 8px 24px rgba(124, 92, 255, 0.3);
}

.btn-danger {
  background: linear-gradient(135deg, rgba(255, 92, 122, 0.3) 0%, rgba(255, 143, 163, 0.2) 100%);
  border: 1px solid rgba(255, 92, 122, .3);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 4px 16px rgba(255, 92, 122, 0.15);
}

.btn-danger:hover:not(:disabled) {
  background: linear-gradient(135deg, rgba(255, 92, 122, 0.5) 0%, rgba(255, 143, 163, 0.4) 100%);
  box-shadow: 0 8px 24px rgba(255, 92, 122, 0.3);
}

.btn-sm {
  height: 36px;
  padding: 0 12px;
  font-size: 12px;
}

.btn svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  transition: transform .2s ease;
}

.btn:hover:not(:disabled) svg {
  transform: scale(1.1);
}

/* Анимация иконки "Печать сеткой" (4 квадратика) */
.tile {
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-origin: center center;
  fill: currentColor !important;
  stroke: none !important;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  /* Только трансформ анимируем */
}

/* Сбрасываем лишние стили с группы */
.tiled-group {
  stroke: none !important;
}

.btn-tiled {
  color: #fff !important;
  /* Всегда белый текст/иконка */
}

.btn-tiled:hover:not(:disabled) .t1 {
  transform: translate(-2px, -2px);
}

.btn-tiled:hover:not(:disabled) .t2 {
  transform: translate(2px, -2px);
}

.btn-tiled:hover:not(:disabled) .t3 {
  transform: translate(-2px, 2px);
}

.btn-tiled:hover:not(:disabled) .t4 {
  transform: translate(2px, 2px);
}



/* === TOOL BUTTONS (Unified Design) === */

.btn-icon-only {
  min-width: var(--btnH);
  height: var(--btnH);
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  position: relative;
  overflow: hidden;
  border-radius: var(--btnR);
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .15);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .15);
  color: #fff;
  cursor: pointer;
  transition: all 0.3s ease;
}

.btn-icon-only svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  stroke: #fff;
  color: #fff;
}

/* Label hidden by default */
.btn-icon-only .btn-label-text {
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  max-width: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-width 0.3s ease, opacity 0.2s ease, margin 0.3s ease;
  margin-left: 0;
}

/* === HOVER: Expand horizontally === */
.btn-icon-only:hover:not(:disabled) {
  padding: 0 16px;
}

.btn-icon-only:hover:not(:disabled) .btn-label-text {
  max-width: 100px;
  opacity: 1;
  margin-left: 8px;
}

/* Disabled state */
.btn-icon-only:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* === Subtle color accents on hover === */
/* === PERMANENT DISTINCT COLORS FOR TOOLS === */
/* All buttons have a solid colored background with white icons */

/* Ruler: Amber/Orange */
/* Ruler: Colors controlled by .uncalibrated/.calibrated state classes */
.btn-calibration {
  transition: all 0.2s ease;
}

/* Text: Cyan/Teal */
.btn-tool-text {
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.3), rgba(6, 182, 212, 0.15));
  border-color: rgba(6, 182, 212, 0.5);
}

.btn-tool-text svg {
  stroke: #fff !important;
  color: #fff !important;
}

.btn-tool-text:hover:not(:disabled) {
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.5), rgba(6, 182, 212, 0.3));
  border-color: rgba(6, 182, 212, 0.7);
  box-shadow: 0 0 20px rgba(6, 182, 212, 0.3);
}

/* Select/Scissors: Rose/Pink */
.btn-tool-select {
  background: linear-gradient(135deg, rgba(244, 63, 94, 0.3), rgba(244, 63, 94, 0.15));
  border-color: rgba(244, 63, 94, 0.5);
}

.btn-tool-select svg {
  stroke: #fff !important;
  color: #fff !important;
}

.btn-tool-select:hover:not(:disabled) {
  background: linear-gradient(135deg, rgba(244, 63, 94, 0.5), rgba(244, 63, 94, 0.3));
  border-color: rgba(244, 63, 94, 0.7);
  box-shadow: 0 0 20px rgba(244, 63, 94, 0.3);
}

/* Extract: Violet/Purple */
.btn-extract {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.3), rgba(139, 92, 246, 0.15));
  border-color: rgba(139, 92, 246, 0.5);
}

.btn-extract svg {
  stroke: #fff !important;
  color: #fff !important;
}

.btn-extract:hover:not(:disabled) {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.5), rgba(139, 92, 246, 0.3));
  border-color: rgba(139, 92, 246, 0.7);
  box-shadow: 0 0 20px rgba(139, 92, 246, 0.3);
}

/* Print (Tiled): Emerald/Green */
.btn-primary.btn-tiled {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.3), rgba(16, 185, 129, 0.15));
  border-color: rgba(16, 185, 129, 0.5);
  box-shadow: none;
  background-image: none;
}

.btn-primary.btn-tiled svg {
  stroke: #fff !important;
  color: #fff !important;
}

.btn-primary.btn-tiled:hover:not(:disabled) {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.5), rgba(16, 185, 129, 0.3));
  border-color: rgba(16, 185, 129, 0.7);
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.3);
}

/* === CALIBRATION STATUS COLORS === */

/* Uncalibrated: Amber */
.btn-calibration.uncalibrated {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.3), rgba(245, 158, 11, 0.15));
  border-color: rgba(245, 158, 11, 0.5);
}

.btn-calibration.uncalibrated svg {
  stroke: #fff !important;
  color: #fff !important;
}

.btn-calibration.uncalibrated:hover:not(:disabled) {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.5), rgba(245, 158, 11, 0.3));
  border-color: rgba(245, 158, 11, 0.7);
  box-shadow: 0 0 20px rgba(245, 158, 11, 0.3);
}

/* Calibrated: Green */
.btn-calibration.calibrated {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.3), rgba(16, 185, 129, 0.15));
  border-color: rgba(16, 185, 129, 0.5);
}

.btn-calibration.calibrated svg {
  stroke: #fff !important;
  color: #fff !important;
}

.btn-calibration.calibrated:hover:not(:disabled) {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.5), rgba(16, 185, 129, 0.3));
  border-color: rgba(16, 185, 129, 0.7);
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.3);
}

/* Tape Measure: Tongue pulses in/out */
.btn-calibration .tape-tongue {
  transition: transform 0.3s ease;
  transform: translateX(0);
  /* Изначально высунута */
}

/* Ruler Icon specific */
.tape-measure-icon {
  overflow: visible;
  width: 22px !important;
  height: 22px !important;
}

.tape-tongue {
  transform-origin: center;
  transition: transform 0.2s;
}

.btn-calibration:hover .tape-tongue {
  animation: tape-pulse 0.6s ease-in-out infinite alternate;
}

@keyframes tape-pulse {
  0% {
    transform: translateX(0);
  }

  100% {
    transform: translateX(4px);
  }
}

/* Scissors: Blades open/close (CUTTING) */
.btn-tool-select .blade-top,
.btn-tool-select .blade-bottom {
  transition: transform 0.2s ease;
}

.btn-tool-select:hover .blade-top {
  animation: cut-top 0.4s ease-in-out infinite;
}

.btn-tool-select:hover .blade-bottom {
  animation: cut-bottom 0.4s ease-in-out infinite;
}

@keyframes cut-top {

  0%,
  100% {
    transform: rotate(0deg);
  }

  50% {
    transform: rotate(-12deg);
  }
}

@keyframes cut-bottom {

  0%,
  100% {
    transform: rotate(0deg);
  }

  50% {
    transform: rotate(12deg);
  }
}

/* Extract: Arrow moves up */
.btn-extract .arrow-up {
  transition: transform 0.3s ease;
}

.btn-extract:hover .arrow-up {
  animation: arrow-fly 0.6s ease-in-out infinite;
}

@keyframes arrow-fly {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-3px);
  }
}

/* Printer: Paper comes out (moves down) */
.btn-tiled .paper-out {
  transition: transform 0.3s ease;
}

.btn-tiled:hover .paper-out {
  animation: paper-print 0.8s ease-in-out infinite;
}

@keyframes paper-print {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(2px);
  }
}





/* Print: Paper feeding */
.btn-primary.btn-tiled:hover .print-paper {
  animation: paper-feed 1s ease-in-out infinite;
}

@keyframes paper-feed {
  0% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(3px);
  }

  100% {
    transform: translateY(0);
  }
}



.btn-primary:hover:not(:disabled) {
  background: #7c3aed !important;
  border-color: #7c3aed !important;
}



/* Scissors Animation */
.scissors-upper,
.scissors-lower {
  transform-origin: 12px 12px;
  transition: transform 0.2s ease;
}

/* Modal / Tiled Print Icon animation */
.btn-tiled:hover:not(:disabled) .tiled-icon {
  animation: tiled-zoom 0.5s ease-in-out infinite alternate;
}

@keyframes tiled-zoom {
  from {
    transform: scale(1);
  }

  to {
    transform: scale(1.15);
    filter: drop-shadow(0 0 5px #7c5cff);
  }
}


.btn-tool-select:hover:not(:disabled) .scissors-upper {
  animation: cut-upper 0.6s ease-in-out infinite;
}

.btn-tool-select:hover:not(:disabled) .scissors-lower {
  animation: cut-lower 0.6s ease-in-out infinite;
}

@keyframes cut-upper {

  0%,
  100% {
    transform: rotate(0deg);
  }

  50% {
    transform: rotate(-25deg);
  }
}

@keyframes cut-lower {

  0%,
  100% {
    transform: rotate(0deg);
  }

  50% {
    transform: rotate(25deg);
  }
}

/* Extract Page "Tear" Animation */
.btn-extract:hover:not(:disabled) .extract-icon {
  animation: extract-shake 0.4s ease-in-out infinite;
}

.btn-extract:hover:not(:disabled) .extract-line-1 {
  animation: tear-line-1 0.6s ease-in-out infinite;
}

.btn-extract:hover:not(:disabled) .extract-line-2 {
  animation: tear-line-2 0.6s ease-in-out infinite;
}

@keyframes extract-shake {

  0%,
  100% {
    transform: scale(1.1) rotate(0deg);
  }

  25% {
    transform: scale(1.1) rotate(-3deg);
  }

  75% {
    transform: scale(1.1) rotate(3deg);
  }
}

@keyframes tear-line-1 {

  0%,
  100% {
    transform: translateX(0);
    opacity: 1;
  }

  50% {
    transform: translateX(4px);
    opacity: 0.5;
  }
}

@keyframes tear-line-2 {

  0%,
  100% {
    transform: translateX(0);
    opacity: 1;
  }

  50% {
    transform: translateX(-3px);
    opacity: 0.5;
  }
}

/* New Brand Calibration Button */
.btn-brand-calib {
  display: flex;
  align-items: center;
  gap: 12px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 6px 16px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-left: 20px;
  height: 48px;
  text-align: left;
}

.btn-brand-calib:hover {
  background: rgba(255, 255, 255, 0.05);
}

.brand-text-col {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.app-brand-text {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.3px;
  color: #fff;
}

.brand-status {
  font-size: 11px;
  font-weight: 700;
  color: #a5b4fc;
  /* Лиловый оттенок для лучшей видимости на темном */
  opacity: 1;
}

/* States for Calib Brand */
.btn-brand-calib.calibrated {
  border-color: rgba(74, 222, 128, 0.3);
  background: rgba(74, 222, 128, 0.1);
}

.btn-brand-calib.calibrated .brand-status {
  color: #4ade80;
  opacity: 1;
}

.btn-brand-calib.calibrating {
  border-color: rgba(255, 207, 90, 0.5);
  background: rgba(255, 207, 90, 0.15);
  animation: pulse-border 1.5s infinite;
}

.btn-brand-calib.calibrating .brand-status {
  color: #ffcf5a;
}

@keyframes pulse-border {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 207, 90, 0.4);
  }

  70% {
    box-shadow: 0 0 0 6px rgba(255, 207, 90, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(255, 207, 90, 0);
  }
}

/* Brand Tooltip */
.has-tooltip {
  position: relative;
}

.brand-tooltip {
  position: absolute;
  top: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: #0f172a;
  /* СПЛОШНОЙ ЦВЕТ, без прозрачности */
  border: 1px solid rgba(124, 92, 255, 0.5);
  border-radius: 12px;
  padding: 14px 16px;
  min-width: 260px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(124, 92, 255, 0.2);
  z-index: 10001;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: all 0.2s ease;
}

.has-tooltip:hover .brand-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(12px);
}

.tooltip-title {
  font-size: 13px;
  /* Крупнее */
  font-weight: 700;
  color: #fff;
  /* Белый */
  margin-bottom: 8px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.tooltip-item {
  font-size: 13px;
  /* Крупнее */
  color: #e2e8f0;
  /* Ярко-светлый */
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tooltip-kbd {
  background: rgba(124, 92, 255, 0.3);
  border: 1px solid rgba(124, 92, 255, 0.4);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
}

.tooltip-icon {
  font-size: 14px;
}

.tooltip-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
  margin: 10px 0;
}

/* Distinct Button Colors */
.btn-extract {
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.35) 0%, rgba(99, 102, 241, 0.25) 100%);
  border: 1px solid rgba(99, 102, 241, 0.3);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: white;
  margin-right: 12px;
}

.btn-extract:hover:not(:disabled) {
  background: #4f46e5 !important;
  border-color: #4f46e5 !important;
  box-shadow: 0 4px 15px rgba(79, 70, 229, 0.4);
}

.btn-tool-select {
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.3) 0%, rgba(56, 189, 248, 0.2) 100%);
  border: 1px solid rgba(14, 165, 233, 0.3);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: white;
}

.btn-tool-select:hover:not(:disabled) {
  background: #0284c7 !important;
  border-color: #0284c7 !important;
  box-shadow: 0 4px 15px rgba(14, 165, 233, 0.4);
}

.btn-tool-select.active {
  background: #fff !important;
  color: #0ea5e9 !important;
  border-color: #fff !important;
}

/* Hide mini brand default since we replaced it with button */
.app-brand-mini {
  display: flex;
}

/* Logo Styles */
.app-brand,
.app-brand-mini {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  letter-spacing: -0.02em;
  position: relative;
  text-decoration: none;
}

.app-brand-text {
  background: linear-gradient(135deg, #fff 0%, #a5b4fc 100%);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  position: relative;
  z-index: 1;
}

.app-logo-icon {
  width: 24px;
  height: 24px;
  filter: drop-shadow(0 0 12px rgba(124, 92, 255, 0.8));
  animation: float-logo 3s ease-in-out infinite;
  color: white;
  /* Для currentColor */
}

@keyframes float-logo {

  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }

  50% {
    transform: translateY(-3px) rotate(5deg);
  }
}

/* Calibrated Button - Subtle */
.btn-calibrate.calibrated {
  background: rgba(74, 222, 128, 0.1);
  border-color: rgba(74, 222, 128, 0.2);
  color: #86efac;
  box-shadow: none;
}

.btn-calibrate.calibrated:hover:not(:disabled) {
  background: rgba(74, 222, 128, 0.15);
  border-color: rgba(74, 222, 128, 0.3);
  box-shadow: 0 4px 12px rgba(74, 222, 128, 0.1);
}

.btn-calibrate.calibrating {
  background: linear-gradient(135deg, #ffcf5a 0%, #fde68a 100%);
  border-color: rgba(255, 207, 90, .4);
  animation: pulse-glow 1.5s ease-in-out infinite;
}

@keyframes pulse-glow {

  0%,
  100% {
    box-shadow: 0 4px 16px rgba(255, 207, 90, .4),
      0 0 20px rgba(255, 207, 90, .2);
  }

  50% {
    box-shadow: 0 8px 24px rgba(255, 207, 90, .6),
      0 0 35px rgba(255, 207, 90, .4);
  }
}

/* Сегментные контролы */
.seg {
  display: flex;
  align-items: center;
  height: var(--btnH);
  border-radius: var(--btnR);
  overflow: hidden;
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .10);
  box-shadow: 0 6px 16px rgba(0, 0, 0, .12);
}

.seg>* {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.seg>*+* {
  border-left: 1px solid rgba(255, 255, 255, .10);
}

.seg-zoom {
  border-color: rgba(124, 92, 255, .38);
  background: rgba(124, 92, 255, .10);
}

.seg-btn {
  width: 48px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 22px;
  font-weight: 900;
  cursor: pointer;
  transition: background .14s ease;
}

.seg-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, .06);
}

.seg-btn:disabled {
  opacity: .40;
  cursor: not-allowed;
}

.seg-mid {
  min-width: 90px;
  padding: 0 12px;
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  user-select: none;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.seg-mid:hover {
  background: rgba(255, 255, 255, .1);
  color: #fff;
  transform: translateY(2px) scale(1.05);
  /* Чуть приседает, как бы выдавливая меню */
  animation: page-pulse 1s infinite alternate;
}

@keyframes page-pulse {
  from {
    text-shadow: 0 0 5px rgba(124, 92, 255, 0.5);
  }

  to {
    text-shadow: 0 0 15px rgba(124, 92, 255, 0.8);
  }
}

.zoom-mid {
  min-width: 70px;
  padding: 0 10px;
  font-weight: 800;
  font-size: 13px;
  user-select: none;
}

.counter {
  height: var(--btnH);
  min-width: 110px;
  padding: 0 14px;
  border-radius: var(--btnR);
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 255, 255, .12);
  box-shadow: 0 6px 16px rgba(0, 0, 0, .12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
  transition: all 0.2s ease;
  cursor: pointer;
  user-select: none;
}

.counter:hover {
  background: rgba(124, 92, 255, 0.15);
  border-color: rgba(124, 92, 255, 0.4);
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(124, 92, 255, 0.15);
}

.counter:active {
  transform: translateY(1px);
}

/* Main */
.main {
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
}

.main::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.main::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, .2);
}

.main::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, .2);
  border-radius: 8px;
}

.canvas-wrapper {
  display: block;
  position: relative;
  padding: var(--pad);
  margin: auto;
  flex-shrink: 0;
}

.main {
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  transition: padding-left 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.main.ai-open {
  padding-left: 380px;
}

.sheet {
  position: relative;
  display: inline-block;
  vertical-align: top;
  margin: 0 auto;
}

#pdfCanvas {
  display: block;
  background: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

#rulerCanvas {
  position: absolute;
  top: 0;
  left: 0;
  cursor: crosshair;
  z-index: 10;
  touch-action: pan-x pan-y;
}

/* Floating button */
.floating-btn {
  position: fixed;
  bottom: calc(90px + env(safe-area-inset-bottom));
  right: calc(24px + env(safe-area-inset-right));
  width: 64px;
  height: 64px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .10);
  border: 1px solid rgba(255, 255, 255, .20);
  color: var(--text);
  font-size: 32px;
  font-weight: 900;
  cursor: move;
  touch-action: none;
  box-shadow: 0 12px 36px rgba(0, 0, 0, .35);
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  z-index: 2500;
  transition: transform .14s ease, background .14s ease;
}

.floating-btn:hover {
  transform: scale(1.05);
  background: rgba(255, 255, 255, .14);
}

.floating-btn.active {
  background: rgba(124, 92, 255, .22);
  border-color: rgba(124, 92, 255, .6);
}

/* Hint bar */
.hint-bar {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 18px;
  background: rgba(0, 0, 0, .5);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  z-index: 2000;
  white-space: nowrap;
}

.kbd {
  padding: 2px 8px;
  display: inline-flex;
  align-items: center;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, .18);
  background: rgba(255, 255, 255, .08);
  color: rgba(255, 255, 255, .95);
  font-weight: 800;
  font-size: 11px;
  margin-right: 4px;
}

/* Loading */
.loading {
  position: fixed;
  inset: 0;
  background: #0a1221;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.loading.active {
  display: flex;
  animation: fadeIn .2s;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.loading-card {
  width: min(480px, calc(100vw - 40px));
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.loading-title {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.loading-title strong {
  font-size: 18px;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.5px;
}

.loading-title .brand {
  font-size: 13px;
  font-weight: 800;
  opacity: .6;
}

.loading-sub {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 12px;
}

.bar {
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .10);
}

.bar>i {
  display: block;
  height: 100%;
  width: 34%;
  background: linear-gradient(90deg, rgba(124, 92, 255, 0), rgba(124, 92, 255, .85), rgba(255, 207, 90, .85), rgba(124, 92, 255, 0));
  transform: translateX(-60%);
  animation: slide 1.05s linear infinite;
}

@keyframes slide {
  to {
    transform: translateX(250%);
  }
}

/* Calibration hint */
.calib-hint {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(15, 23, 42, 0.95);
  color: #fff;
  padding: 12px 24px;
  border-radius: 50px;
  font-size: 15px;
  font-weight: 600;
  pointer-events: none;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  z-index: 2000;
  border: 1px solid rgba(255, 255, 255, 0.1);
  text-align: center;
}

.calib-hint.active {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .65);
  backdrop-filter: blur(10px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  padding: 20px;
}


.modal-backdrop {
  position: fixed;
  inset: 0;
  background: transparent;
  z-index: 1;
  cursor: pointer;
}

.modal.active {
  display: flex;
  animation: fadeIn .2s;
}

.modal-content {
  width: min(400px, 100%);
  background: rgba(20, 28, 48, .95);
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--shadow);
  position: relative;
  z-index: 2;
  overflow: hidden;
  /* Ensure content doesn't spill out */
  display: flex;
  flex-direction: column;
}

/* Specific styles just for the AI Modal content wrapper */
.ai-modal-content {
  width: min(500px, 95vw);
  /* Slightly wider for the chat interface */
  max-width: 500px;
  height: min(600px, 80vh);
  /* Fixed height for chat scrolling */
  padding: 0;
  /* Remove padding to let children fill the space */
  display: flex;
  flex-direction: column;
}

.ai-modal-content .modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 0;
  /* Override default margin */
  flex-shrink: 0;
}

/* The settings toolbar inside AI modal */
.ai-settings {
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding: 12px 20px !important;
  /* Force padding overrides */
  flex-shrink: 0;
}

/* The main body of the AI modal (preview + chat + input) */
.ai-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  min-height: 0;
  /* Crucial for flex scrolling */
}

/* Fix for the cost counter color - clear, not green */
#aiCostCounter {
  background: rgba(255, 255, 255, 0.1) !important;
  border-color: rgba(255, 255, 255, 0.15) !important;
  color: rgba(255, 255, 255, 0.7) !important;
}

.modal-content h3 {
  font-size: 17px;
  font-weight: 800;
  margin-bottom: 14px;
}

.modal-text {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 16px;
  line-height: 1.5;
}

.modal-content input[type="number"],
.modal-content input[type="text"] {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  font-size: 18px;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 14px;
  background: rgba(255, 255, 255, .06);
  color: var(--text);
  margin-bottom: 14px;
  text-align: center;
  font-weight: 700;
}

.modal-content input:focus {
  outline: none;
  border-color: rgba(124, 92, 255, .55);
  box-shadow: 0 0 0 3px rgba(124, 92, 255, .18);
}

.modal-btns {
  display: flex;
  gap: 10px;
}

.modal-btns .btn {
  flex: 1;
}

/* Thumbnails */
.thumbs-panel {
  position: fixed;
  left: 14px;
  right: 14px;
  top: 70px;
  max-height: 45vh;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(255, 255, 255, .12);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-radius: 20px;
  padding: 16px;
  z-index: 9000;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .5);

  /* Dropdown effect */
  opacity: 0;
  transform: translateY(-20px) scale(0.98);
  pointer-events: none;
  visibility: hidden;
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.thumbs-panel.active {
  opacity: 1 !important;
  transform: translateY(0) scale(1) !important;
  pointer-events: auto !important;
  visibility: visible !important;
}

/* Состояние "подсказки" (чуть-чуть выезжает) */
.thumbs-panel.peek {
  opacity: 0.4;
  visibility: visible;
  transform: translateY(-12px) scale(0.99);
  pointer-events: none;
}

.thumbs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.thumbs-title {
  font-size: 13px;
  font-weight: 800;
  opacity: .9;
  display: flex;
  align-items: center;
  gap: 8px;
}

.thumbs-title .pill {
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .14);
  background: rgba(255, 255, 255, .06);
  font-size: 11px;
  font-weight: 800;
}

.thumbs-actions {
  display: flex;
  gap: 6px;
}

.thumbs-act {
  height: 34px;
  width: 38px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .12);
  color: var(--text);
  cursor: pointer;
  font-size: 16px;
  font-weight: 900;
  transition: transform .14s ease, background .14s ease;
}

.thumbs-act:hover {
  background: rgba(255, 255, 255, .09);
  transform: translateY(-1px);
}

.thumbs-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 6px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

.thumbs-strip::-webkit-scrollbar {
  height: 8px;
}

.thumbs-strip::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, .06);
  border-radius: 999px;
}

.thumbs-strip::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, .18);
  border-radius: 999px;
}

.thumb {
  flex: 0 0 auto;
  width: 80px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .10);
  padding: 6px 6px 8px;
  cursor: pointer;
  transition: transform .12s ease, background .12s ease;
  scroll-snap-align: start;
}

.thumb:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, .09);
}

.thumb.active {
  border-color: rgba(124, 92, 255, .6);
  background: rgba(124, 92, 255, .12);
}

.thumb canvas,
.thumb img {
  width: 100%;
  height: auto;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 6px 14px rgba(0, 0, 0, .2);
  display: block;
}

.thumb.skeleton canvas {
  background: linear-gradient(90deg, rgba(255, 255, 255, .06) 0%, rgba(255, 255, 255, .12) 35%, rgba(255, 255, 255, .06) 70%);
  background-size: 220% 100%;
  animation: shimmer 1.2s linear infinite;
}

/* Extract Pages Modal Styles */
.extract-modal-container {
  width: 90%;
  max-width: 1000px;
  height: 85vh;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 2;
}

.extract-modal-container .modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
}

.extract-grid-wrapper {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: #141416;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  margin: 16px 0;
}

.extract-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 20px;
}

.page-card {
  background: linear-gradient(145deg, rgba(40, 40, 50, 0.9), rgba(30, 30, 40, 0.95));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 12px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  user-select: none;
  box-shadow:
    0 4px 6px rgba(0, 0, 0, 0.3),
    0 10px 20px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transform-style: preserve-3d;
  perspective: 1000px;
}

.page-card:hover {
  background: linear-gradient(145deg, rgba(50, 50, 65, 0.95), rgba(40, 40, 55, 0.98));
  transform: translateY(-8px) rotateX(2deg);
  box-shadow:
    0 8px 15px rgba(0, 0, 0, 0.4),
    0 20px 40px rgba(0, 0, 0, 0.3),
    0 0 30px rgba(99, 102, 241, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  border-color: rgba(99, 102, 241, 0.3);
}

.page-card.selected {
  border-color: #6366f1;
  background: linear-gradient(145deg, rgba(99, 102, 241, 0.25), rgba(79, 82, 221, 0.2));
  box-shadow:
    0 8px 20px rgba(99, 102, 241, 0.3),
    0 15px 35px rgba(0, 0, 0, 0.4),
    0 0 40px rgba(99, 102, 241, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
  transform: translateY(-4px) scale(1.02);
}

.page-card canvas,
.page-card img {
  width: 100%;
  height: auto;
  border-radius: 10px;
  background: #fff;
  margin-bottom: 10px;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  transition: transform 0.3s ease;
}

.page-card:hover canvas,
.page-card:hover img {
  transform: scale(1.02);
}

.page-card-number {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.7);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.page-card.selected .page-card-number {
  color: #fff;
  font-weight: 700;
}

/* === SIZE CONTROL === */
.extract-size-control {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(139, 92, 246, 0.1));
  border-radius: 40px;
  border: 1px solid rgba(99, 102, 241, 0.3);
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.15);
}

.size-icon {
  font-size: 16px;
  opacity: 0.7;
  filter: grayscale(0.5);
}

.size-icon.large {
  font-size: 22px;
  opacity: 0.9;
  filter: none;
}

.size-slider {
  width: 120px;
  height: 8px;
  -webkit-appearance: none;
  appearance: none;
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.3), rgba(139, 92, 246, 0.5));
  border-radius: 10px;
  outline: none;
  cursor: pointer;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3);
}

.size-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(145deg, #fff, #e0e0e0);
  cursor: pointer;
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.3),
    0 0 0 3px rgba(99, 102, 241, 0.4);
  transition: all 0.2s ease;
}

.size-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.4),
    0 0 0 4px rgba(99, 102, 241, 0.6);
}

/* === PREVIEW POPUP (MacOS Quick Look Style) === */
.extract-preview {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  z-index: 999999;
  /* Maximal z-index to overlay EVERYTHING */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s cubic-bezier(0.33, 1, 0.68, 1);
}

.extract-preview.visible {
  opacity: 1;
  pointer-events: none;
}

/* Visual feedback when pressing a card */
.page-card:active {
  transform: scale(0.94) !important;
  transition: transform 0.1s;
}

.extract-preview-content {
  background: rgba(40, 40, 45, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 0;
  /* Minimized padding like Quick Look */
  box-shadow:
    0 50px 100px rgba(0, 0, 0, 0.5),
    0 10px 30px rgba(0, 0, 0, 0.3);
  transform: scale(0.95) translateY(10px);
  transition: transform 0.4s cubic-bezier(0.19, 1, 0.22, 1);
  /* Eloquent smooth pop */
  max-width: 80vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.extract-preview.visible .extract-preview-content {
  transform: scale(1) translateY(0);
}

.extract-preview img {
  max-width: 90vw;
  height: 80vh;
  /* Force height to match container limit */
  width: auto;
  /* Maintain aspect ratio */
  object-fit: contain;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: block;
}

.extract-preview-page {
  text-align: center;
  padding: 12px;
  font-size: 15px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.05);
  /* Slight footer contrast */
}

/* Checkmark badge */
.page-card::after {
  content: '✓';
  position: absolute;
  top: 8px;
  right: 8px;
  background: #6366f1;
  color: white;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: bold;
  opacity: 0;
  transform: scale(0.5);
  transition: all 0.2s;
}

.page-card.selected::after {
  opacity: 1;
  transform: scale(1);
}

@keyframes shimmer {
  to {
    background-position: -220% 0;
  }
}

.thumb-label {
  margin-top: 6px;
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  color: var(--text);
  opacity: .85;
}

/* Responsive */
@media (max-width: 780px) {
  .back-text {
    display: none;
  }

  .btn-back {
    padding: 0 12px;
  }

  .topbar .project-name {
    max-width: 120px;
  }
}

@media (pointer:coarse) {
  .thumb {
    width: 90px;
  }

  .floating-btn {
    width: 68px;
    height: 68px;
    font-size: 34px;
  }
}

/* EXTRACT MODAL FIXES */


/* FINAL EXTRACT MODAL STYLES */
#extractModal {
  display: none;
  align-items: center;
  justify-content: center;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(10px);
}

#extractModal.active,
#extractModal[aria-hidden="false"] {
  display: flex !important;
}

#extractModal .extract-modal-container {
  width: 95vw;
  height: 90vh;
  background: #151517;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.9);
  display: flex;
  flex-direction: column;
  padding: 24px;
}

#extractModal .extract-grid-wrapper {
  flex: 1;
  overflow-y: auto;
  background: #0d0d0f;
  border-radius: 8px;
  padding: 20px;
  margin: 16px 0;
}

#extractModal .extract-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 24px;
  width: 100%;
}

.page-card canvas {
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
  border-radius: 6px;
}

/* Tiled Printing Styles */
.print-tiled-content {
  width: 900px !important;
  max-width: 95vw !important;
  background: #0f172a !important;
  border-radius: 24px !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6) !important;
  padding: 0 !important;
}

.print-tiled-body {
  display: flex;
  gap: 24px;
  padding: 24px;
  min-height: 460px;
}

/* Контейнер всего превью (черная область) */
.print-tiled-preview-container {
  flex: 1;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Паттерн шахматки для прозрачности */
  background-image:
    linear-gradient(45deg, #1e293b 25%, transparent 25%),
    linear-gradient(-45deg, #1e293b 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1e293b 75%),
    linear-gradient(-45deg, transparent 75%, #1e293b 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

/* Обертка-стек: имеет конкретные размеры (WxH) целевого формата */
.tiled-preview-wrapper {
  position: relative;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  cursor: grab;
  display: flex;
  padding: 0;
  margin: 0;
  overflow: hidden;
  /* Важно для сканера */
}

/* Эффект сканера */
.tiled-preview-wrapper.scanning::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 6px;
  /* Чуть толще */
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 25px 10px rgba(124, 92, 255, 0.6), 0 0 10px 2px rgba(124, 92, 255, 1);
  z-index: 1000;
  /* Поверх сетки */
  animation: scanline 2.5s ease-in-out infinite;
  opacity: 0;
}

@keyframes scanline {
  0% {
    top: -10%;
    opacity: 0;
  }

  10% {
    opacity: 1;
  }

  90% {
    opacity: 1;
  }

  100% {
    top: 110%;
    opacity: 0;
  }
}

.tiled-preview-wrapper:active {
  cursor: grabbing;
}

/* Канвас - нижний слой */
#tiledPreviewCanvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 2px;
  /* Чуть-чуть скруглить углы бумаги */
}

/* Сетка - верхний слой, перекрывает канвас точно 1 в 1 */
.tiled-grid-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  /* Чтобы клики проходили сквозь сетку для Pan */
  display: grid;
  z-index: 10;
  /* Граница всего листа */
  border: 1px solid rgba(124, 92, 255, 0.5);
}

/* Ячейка сетки (один лист А4) */
.tiled-sheet-unit {
  /* Тонкие линии реза - синий цвет для контраста с чертежом */
  border-right: 1px solid rgba(124, 92, 255, 0.3);
  border-bottom: 1px solid rgba(124, 92, 255, 0.3);
  /* Без фона, чтобы видеть чертеж! */
  background: transparent;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 2px;
}

/* Подсказка с номером листа */
.tiled-sheet-unit::after {
  content: attr(data-coord);
  background: rgba(124, 92, 255, 0.9);
  color: #fff;
  padding: 1px 3px;
  border-radius: 2px;
  font-size: 9px;
  font-weight: 600;
  opacity: 0.7;
}


.print-tiled-controls {
  width: 300px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.format-chips {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  /* Align bottom to show height difference */
  flex-wrap: wrap;
  margin-top: 10px;
  padding-bottom: 4px;
}

.chip {
  /* No flex-grow: use fixed visual sizes */
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.05);
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
}

.chip:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  transform: translateY(-2px);
}

.chip.active {
  background: #6366f1;
  border-color: #6366f1;
  color: #fff;
  box-shadow: 0 8px 16px rgba(99, 102, 241, 0.4);
  transform: translateY(-2px);
}

/* Visual sizes - proportional scale */
.chip[data-format="A0"] {
  width: 70px;
  height: 90px;
  font-size: 20px;
}

.chip[data-format="A1"] {
  width: 58px;
  height: 76px;
  font-size: 18px;
}

.chip[data-format="A2"] {
  width: 48px;
  height: 64px;
  font-size: 16px;
}

.chip[data-format="A3"] {
  width: 40px;
  height: 54px;
  font-size: 14px;
}

.chip[data-format="A4"] {
  width: 32px;
  height: 44px;
  font-size: 12px;
}



.info-stats {
  background: rgba(30, 41, 59, 0.5);
  padding: 16px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.stat {
  font-size: 14px;
  color: #94a3b8;
  margin-bottom: 8px;
}

.stat:last-child {
  margin-bottom: 0;
}

.stat span {
  color: #fff;
  font-weight: 800;
  float: right;
}

.modal-btns {
  display: flex;
  gap: 12px;
  margin-top: auto;
}

.modal-btns .btn {
  flex: 1;
  height: 44px;
}

/* Custom Checkbox */
.checkbox-container {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: #cbd5e1;
  user-select: none;
}

.checkbox-container input {
  display: none;
}

.checkmark {
  width: 20px;
  height: 20px;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  position: relative;
  transition: all 0.2s;
}

.checkbox-container:hover .checkmark {
  border-color: rgba(255, 255, 255, 0.4);
}

.checkbox-container input:checked+.checkmark {
  background: #7c5cff;
  border-color: #7c5cff;
}

.checkbox-container input:checked+.checkmark:after {
  content: "";
  position: absolute;
  left: 6px;
  top: 2px;
  width: 5px;
  height: 10px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* Стили для маленьких кнопок зума */
.btn-icon-tiny {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #e2e8f0;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 16px;
  line-height: 1;
  padding: 0;
}

.btn-icon-tiny:hover {
  background: rgba(124, 92, 255, 0.2);
  border-color: rgba(124, 92, 255, 0.4);
  color: #fff;
}

.btn-icon-tiny:active {
  transform: scale(0.95);
}

/* Welcome Toast */
.welcome-toast {
  position: fixed;
  bottom: 24px;
  left: 24px;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(124, 92, 255, 0.3);
  border-radius: 16px;
  padding: 16px 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(124, 92, 255, 0.2);
  z-index: 10000;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  animation: slideInLeft 0.5s ease-out;
}

.welcome-toast:hover {
  transform: translateX(4px);
  box-shadow: 0 12px 40px rgba(124, 92, 255, 0.3), 0 0 0 1px rgba(124, 92, 255, 0.4);
  border-color: rgba(124, 92, 255, 0.5);
}

.toast-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toast-icon {
  font-size: 28px;
  animation: wave 0.6s ease-in-out infinite;
}

.toast-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toast-title {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 0 10px rgba(124, 92, 255, 0.5);
}

.toast-message {
  font-size: 12px;
  color: #94a3b8;
}

@keyframes slideInLeft {
  from {
    transform: translateX(-100%);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes wave {

  0%,
  100% {
    transform: rotate(0deg);
  }

  25% {
    transform: rotate(-10deg);
  }

  75% {
    transform: rotate(10deg);
  }
}

@keyframes fadeOut {
  to {
    opacity: 0;
    transform: translateX(-20px) scale(0.95);
  }
}

.welcome-toast.hiding {
  animation: fadeOut 0.3s ease-out forwards;
}

.welcome-toast.thankyou .toast-title {
  color: #4ade80;
  text-shadow: 0 0 10px rgba(74, 222, 128, 0.5);
}

.welcome-toast.thankyou .toast-message {
  color: #86efac;
}

.welcome-toast.thankyou .toast-icon {
  animation: none;
}

/* Ruler Button Status Colors - REMOVED TO MATCH OTHER BUTTONS */
/* Using simple accent indicator instead */

.btn-calibration {
  /* Inherit layout from btn-icon-only, just specific colors/borders */
  transition: background 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
    border-color 0.3s,
    transform 0.2s;
}

/* Make the SVG icon larger */
.btn-calibration svg {
  width: 28px;
  height: 28px;
}

/* Add a tiny status dot instead of coloring the whole button */
.btn-calibration::before {
  content: '';
  position: absolute;
  top: 6px;
  right: 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--text);
  opacity: 0.3;
}

.btn-calibration.uncalibrated::before {
  background-color: #f59e0b;
  /* Amber dot */
  opacity: 1;
  box-shadow: 0 0 5px rgba(245, 158, 11, 0.5);
}

.btn-calibration.calibrated::before {
  background-color: #22c55e;
  /* Green dot */
  opacity: 1;
  box-shadow: 0 0 5px rgba(34, 197, 94, 0.5);
}

.btn-calibration.calibrating::before {
  background-color: #3b82f6;
  /* Blue dot */
  opacity: 1;
  box-shadow: 0 0 8px #3b82f6;
  animation: pulse-dot 1s infinite;
}

@keyframes pulse-dot {

  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }

  50% {
    opacity: 0.6;
    transform: scale(1.3);
  }
}

/* Hover effects matching other buttons */
.btn-calibration:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
}

/* Tape Measure Animation */
.tape-icon {
  overflow: visible;
}

.tape-case {
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-origin: center bottom;
}

/* Keep the tape line static (no extra movement) */
.tape-line {
  transition: none;
}

.btn-calibration:hover .tape-case {
  transform: translateY(-2px) rotate(-3deg);
}

/* === TAPE MEASURE ANIMATION (Pulsing Tongue) === */


.btn-calibration:hover .tape-line {
  animation: tape-pulse 0.6s ease-in-out infinite !important;
}

/* Tongue (the protruding part) – visible by default, retracts on hover */
.tape-tongue {
  transform-origin: left center;
  transform: scaleX(1);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.btn-calibration:hover .tape-tongue {
  transform: scaleX(0);
}

/* === PRINT TILES ANIMATION (Sequential Fly-Out) === */
.btn-tiled .tile {
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) !important;
}

.btn-tiled:hover .t1 {
  transform: translate(-3px, -3px) !important;
  transition-delay: 0s !important;
}

.btn-tiled:hover .t2 {
  transform: translate(3px, -3px) !important;
  transition-delay: 0.05s !important;
}

.btn-tiled:hover .t3 {
  transform: translate(-3px, 3px) !important;
  transition-delay: 0.1s !important;
}

.btn-tiled:hover .t4 {
  transform: translate(3px, 3px) !important;
  transition-delay: 0.15s !important;
}

/* === УНИФИКАЦИЯ КНОПОК === */
/* Все расширяемые кнопки одного размера (или минимального), чтобы выпадашка была ровной */
.btn-expandable {
  min-width: 120px;
  justify-content: center;
  position: relative;
  /* Важно для absolute */
  gap: 8px !important;
  /* Центрирование с отступом */
  padding-left: 10px !important;
  padding-right: 10px !important;
}

/* Убираем старый маргин */
.btn-label {
  margin-left: 0 !important;
}

/* Выпадающий лейбл - СТРОГО по ширине кнопки (как единый блок) */
.btn-expandable:hover .btn-label-extra {
  width: calc(100% + 2px) !important;
  /* Перекрываем бордеры */
  min-width: calc(100% + 2px) !important;
  left: -1px !important;
  transform: none !important;

  /* Центрирование текста */
  display: flex !important;
  justify-content: center;
  align-items: center;
  text-align: center;

  /* Скругления снизу, так как у кнопки они убраны */
  border-bottom-left-radius: 6px;
  border-bottom-right-radius: 6px;
}

/* === FINAL BUTTON LAYOUT FIX (ROW) === */
.btn-expandable {
  /* Flexbox Layout: Row (Icon Left, Text Right) */
  display: inline-flex !important;
  flex-direction: row !important;
  align-items: center !important;
  justify-content: center !important;

  /* Размеры увеличены */
  min-width: 140px !important;
  height: 42px !important;
  padding: 0 16px !important;
  gap: 10px !important;

  position: relative !important;
}

.btn-expandable svg {
  display: block !important;
  margin: 0 !important;
  flex-shrink: 0 !important;
  width: 22px !important;
  /* Увеличено с дефолтных */
  height: 22px !important;
  stroke-width: 1.8px !important;
}

.btn-expandable .btn-label {
  display: block !important;
  margin: 0 !important;
  text-align: center !important;
  line-height: normal !important;
}

/* === NO DROPDOWNS === */
.btn-expandable:hover .btn-label-extra {
  display: none !important;
}

/* Возвращаем скругление при наведении (так как выпадашки нет) */
.btn-expandable:hover,
.btn-calibration:hover,
.btn-calibration.uncalibrated:hover,
.btn-calibration.calibrated:hover {
  border-bottom-left-radius: 6px !important;
  border-bottom-right-radius: 6px !important;
}

/* === TYPOGRAPHY UPDATE === */
.btn-expandable .btn-label {
  text-transform: lowercase !important;
  /* Все буквы строчные */
  font-size: 15px !important;
  /* Чуть крупнее для читаемости */
  font-weight: 500 !important;
  letter-spacing: 0.3px !important;
}

/* === TYPOGRAPHY UPDATE (Final Uppercase) === */
.btn-expandable .btn-label {
  text-transform: uppercase !important;
  font-size: 16px !important;
  font-weight: 700 !important;
  letter-spacing: 0.8px !important;
}

/* === ICON SIZE FIX (Revert to Small) === */
/* Переопределяется ниже */

/* === ICON-FIRST EXPANDABLE BUTTONS === */
.btn-expandable {
  min-width: auto !important;
  padding: 10px 14px !important;
  gap: 0 !important;
  /* Убираем gap, управляем через margin */
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

/* Большие иконки */
.btn-expandable svg {
  width: 22px !important;
  height: 22px !important;
  stroke-width: 2px !important;
  transition: transform 0.3s ease !important;
  flex-shrink: 0 !important;
}

/* Текст скрыт по умолчанию */
.btn-expandable .btn-label,
.btn-expandable .btn-label-text {
  max-width: 0 !important;
  opacity: 0 !important;
  overflow: hidden !important;
  margin-left: 0 !important;
  white-space: nowrap !important;
  font-size: 12px !important;
  font-weight: 700 !important;
  color: #fff !important;
  transition: max-width 0.35s ease, opacity 0.25s ease, margin-left 0.35s ease !important;
}

/* При наведении — текст появляется */
.btn-expandable:hover .btn-label,
.btn-expandable:hover .btn-label-text {
  max-width: 100px !important;
  opacity: 1 !important;
  margin-left: 10px !important;
}

/* Иконка при наведении — легкое увеличение */
.btn-expandable:hover svg {
  transform: scale(1.1) !important;
}

/* === TAPE MEASURE ANIMATION (Pulsing Tongue) === */
@keyframes tape-pulse {

  0%,
  100% {
    transform: translateX(0);
  }

  50% {
    transform: translateX(5px);
  }
}

.btn-calibration:hover .tape-line {
  animation: tape-pulse 0.6s ease-in-out infinite !important;
}

/* === PRINT TILES ANIMATION (Sequential Fly-Out) === */
.btn-tiled .tile {
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) !important;
}

.btn-tiled:hover .t1 {
  transform: translate(-3px, -3px) !important;
  transition-delay: 0s !important;
}

.btn-tiled:hover .t2 {
  transform: translate(3px, -3px) !important;
  transition-delay: 0.05s !important;
}

.btn-tiled:hover .t3 {
  transform: translate(-3px, 3px) !important;
  transition-delay: 0.1s !important;
}

.btn-tiled:hover .t4 {
  transform: translate(3px, 3px) !important;
  transition-delay: 0.15s !important;
}

/* === TAPE MEASURE ANIMATION (Tongue Extends from Case) === */
.tape-tongue {
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.btn-calibration:hover .tape-tongue {
  transform: scaleX(1);
}

/* Деления на ленте - контрастные */
.tape-tongue line {
  stroke: #1e293b !important;
}

/* === EXTRACT ANIMATION (Flying Page) === */
.flying-page {
  transform-origin: center;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s;
}

.btn-extract:hover .flying-page {
  transform: translate(4px, -6px) rotate(5deg);
}

/* === PRINT TILES ANIMATION (Looping Scatter) === */
@keyframes tile-float-1 {

  0%,
  100% {
    transform: translate(0, 0);
  }

  50% {
    transform: translate(-2px, -2px);
  }
}

@keyframes tile-float-2 {

  0%,
  100% {
    transform: translate(0, 0);
  }

  50% {
    transform: translate(2px, -2px);
  }
}

@keyframes tile-float-3 {

  0%,
  100% {
    transform: translate(0, 0);
  }

  50% {
    transform: translate(-2px, 2px);
  }
}

@keyframes tile-float-4 {

  0%,
  100% {
    transform: translate(0, 0);
  }

  50% {
    transform: translate(2px, 2px);
  }
}

.btn-tiled:hover .t1 {
  animation: tile-float-1 0.8s ease-in-out infinite;
}

.btn-tiled:hover .t2 {
  animation: tile-float-2 0.8s ease-in-out infinite 0.1s;
}

.btn-tiled:hover .t3 {
  animation: tile-float-3 0.8s ease-in-out infinite 0.2s;
}

.btn-tiled:hover .t4 {
  animation: tile-float-4 0.8s ease-in-out infinite 0.3s;
}

/* Увеличить max-width для длинных надписей */
.btn-expandable:hover .btn-label {
  max-width: 200px !important;
}

/* === FINAL ANIMATION OVERRIDE === */
@keyframes tape-loop-final {

  0%,
  100% {
    transform: translateX(0);
  }

  50% {
    transform: translateX(4px);
  }
}

.btn-calibration:hover .tape-tongue {
  animation: tape-loop-final 1.2s ease-in-out infinite !important;
}

@keyframes fly-loop-final {
  0% {
    transform: translate(0, 0);
    opacity: 1;
  }

  50% {
    transform: translate(5px, -5px);
    opacity: 0;
  }

  51% {
    transform: translate(-3px, 3px);
    opacity: 0;
  }

  100% {
    transform: translate(0, 0);
    opacity: 1;
  }
}

.btn-extract:hover .flying-page {
  animation: fly-loop-final 1.2s ease-in-out infinite !important;
}

/* Scissors Animation - Full Snip */
.btn-tool-select:hover .blade-top {
  transform-origin: 9px 12px;
  animation: snip-top 1.2s cubic-bezier(0.22, 1, 0.36, 1) infinite;
}

.btn-tool-select:hover .blade-bottom {
  transform-origin: 9px 12px;
  animation: snip-bottom 1.2s cubic-bezier(0.22, 1, 0.36, 1) infinite;
}

@keyframes snip-top {

  0%,
  100% {
    transform: rotate(0deg);
  }

  50% {
    transform: rotate(-30deg);
  }

  /* Open */
  60% {
    transform: rotate(10deg);
  }

  /* Cross/Cut */
}

@keyframes snip-bottom {

  0%,
  100% {
    transform: rotate(0deg);
  }

  50% {
    transform: rotate(30deg);
  }

  /* Open */
  60% {
    transform: rotate(-10deg);
  }

  /* Cross/Cut */
}

/* Fix Modal Buttons Layout */
.modal-btns {
  flex-wrap: wrap;
  gap: 8px;
}

.modal-btns .btn {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0 10px;
  white-space: nowrap;
}

/* Specifically for Tiled Print modal */
.print-tiled-controls .modal-btns {
  display: flex;
  gap: 8px;
}

.print-tiled-controls .modal-btns .btn {
  font-size: 13px;
  flex: 1;
  /* Distribute equally initially */
}

/* Give "Save PDF" slightly more space if needed, or rely on wrap */
.print-tiled-controls .modal-btns .btn:first-child {
  flex: 1;
}

.print-tiled-controls .modal-btns .btn:nth-child(2) {
  flex: 0.8;
}

.print-tiled-controls .modal-btns .btn:last-child {
  flex: 1.5;
}

@keyframes print-loop-final {
  0% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(5px);
  }

  100% {
    transform: translateY(0);
  }
}

.btn-tiled:hover .printing-page {
  animation: print-loop-final 1.2s ease-in-out infinite !important;
}


/* Button Tool Calibrate style */
.btn-tool-calibrate:hover:not(:disabled) {
  border-color: rgba(6, 182, 212, 0.4);
  background: rgba(6, 182, 212, 0.12);
  /* Cyan tint */
}

/* Text Tool Animation: Wave Effect */
.btn-tool-text svg {
  transform-origin: center center;
  transition: transform 0.2s ease;
}

button.btn-tool-text:hover svg {
  animation: text-wave 0.6s ease-in-out infinite both !important;
}

@keyframes text-wave {
  0% {
    transform: rotate(0deg);
  }

  25% {
    transform: rotate(-15deg);
  }

  75% {
    transform: rotate(15deg);
  }

  100% {
    transform: rotate(0deg);
  }
}

/* Color Buttons Logic */
.color-btn {
  cursor: pointer !important;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
}

.color-btn:hover {
  transform: scale(1.1);
  z-index: 10;
}

.color-btn.active {
  transform: scale(1.1);
  box-shadow: 0 0 0 2px #1e293b, 0 0 0 4px #7c5cff !important;
  border-color: transparent !important;
  z-index: 5;
}

/* AI Tool Styles */
.btn-tool-ai {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.3), rgba(168, 85, 247, 0.15));
  border-color: rgba(139, 92, 246, 0.5);
  color: #c4b5fd;
}

.btn-tool-ai svg {
  stroke: #c4b5fd !important;
  color: #c4b5fd !important;
}

.btn-tool-ai:hover:not(:disabled) {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.5), rgba(168, 85, 247, 0.3));
  border-color: rgba(139, 92, 246, 0.8);
  box-shadow: 0 0 20px rgba(139, 92, 246, 0.3);
  color: #fff;
}

.btn-tool-ai:hover:not(:disabled) svg {
  stroke: #fff !important;
  color: #fff !important;
}

.btn-tool-ai.active {
  background: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
  border-color: rgba(255, 255, 255, 0.5);
  color: #fff;
  box-shadow: 0 0 25px rgba(139, 92, 246, 0.5);
}

.btn-tool-ai.active svg {
  stroke: #fff !important;
  color: #fff !important;
}

/* AI Modal */
.ai-modal-content {
  width: 500px;
  max-width: 90vw;
  display: flex;
  flex-direction: column;
  height: 80vh;
  max-height: 700px;
  padding: 0;
  background: linear-gradient(145deg, #1e1b2e, #13111c);
  border: 1px solid rgba(139, 92, 246, 0.2);
}

.ai-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 16px;
  gap: 16px;
}

.ai-preview-container {
  height: 150px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.05);
  flex-shrink: 0;
}

.ai-preview-container img {
  max-height: 100%;
  max-width: 100%;
  object-fit: contain;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.ai-chat-area {
  flex: 1;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.ai-message {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  max-width: 90%;
}

.ai-message.system {
  align-self: center;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.7);
  font-size: 13px;
  text-align: center;
}

.ai-message.user {
  align-self: flex-end;
  background: rgba(139, 92, 246, 0.3);
  border: 1px solid rgba(139, 92, 246, 0.4);
  color: #fff;
  border-top-right-radius: 2px;
}

.ai-message.ai {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #eef2ff;
  border-top-left-radius: 2px;
}

.ai-input-area {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

#aiPromptInput {
  flex: 1;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 12px;
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  resize: none;
  min-height: 46px;
  max-height: 100px;
  outline: none;
  transition: border-color 0.2s;
}

#aiPromptInput:focus {
  border-color: rgba(139, 92, 246, 0.6);
}

#aiSendBtn {
  width: 46px;
  height: 46px;
  padding: 0;
  border-radius: 12px;
  flex-shrink: 0;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  border: none;
}

/* AI Button Specific Styles aligned with Header */
.btn-tool-ai {
  margin-left: 12px;
  background: rgba(124, 92, 255, 0.15);
  border: 1px solid rgba(124, 92, 255, 0.3);
  box-shadow: 0 0 10px rgba(124, 92, 255, 0.2);
  display: flex !important;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  transition: all 0.3s ease;
}

.btn-tool-ai:hover {
  background: rgba(124, 92, 255, 0.25);
  box-shadow: 0 0 15px rgba(124, 92, 255, 0.4);
}

.btn-tool-ai .ai-icon-sparkles {
  width: 20px;
  height: 20px;
  filter: drop-shadow(0 0 5px rgba(124, 92, 255, 0.5));
}

/* ========== MODERNIZED AI MODAL ========== */
.ai-modal-content {
  max-width: 1000px !important;
  width: 90vw;
  height: 85vh;
  max-height: 85vh;
  min-height: 600px;
  display: flex;
  flex-direction: column;
  padding: 0 !important;
  overflow: hidden;
  margin: 3vh auto;
  border-radius: 16px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.ai-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.15), rgba(124, 92, 255, 0.05));
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.ai-header-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
}

.ai-sparkle {
  font-size: 24px;
  animation: sparkle 2s ease-in-out infinite;
}

@keyframes sparkle {

  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }

  50% {
    opacity: 0.7;
    transform: scale(1.1);
  }
}

.ai-model-selector {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ai-model-selector select {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  padding: 10px 16px;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  transition: all 0.2s;
  min-width: 180px;
}

.ai-model-selector select:hover {
  border-color: rgba(124, 92, 255, 0.5);
  background: rgba(0, 0, 0, 0.4);
}

.ai-model-selector select:focus {
  border-color: rgba(124, 92, 255, 0.8);
  box-shadow: 0 0 15px rgba(124, 92, 255, 0.3);
}

.ai-cost-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.8);
}

.ai-cost-badge button {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  font-size: 16px;
  padding: 0;
  transition: color 0.2s;
}

.ai-cost-badge button:hover {
  color: #fff;
}

.ai-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px 24px;
  gap: 16px;
  overflow: hidden;
}


/* AI Toolbar */
.ai-preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: #111;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.ai-tools-left,
.ai-tools-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

.ai-tool-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #ccc;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.2s;
}

.ai-tool-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.ai-tool-btn.active {
  background: rgba(124, 92, 255, 0.5);
  border-color: rgba(124, 92, 255, 0.5);
  color: #fff;
}

.ai-tool-btn.text-danger {
  color: #ff6b6b;
  border-color: rgba(255, 107, 107, 0.3);
}

.ai-tool-btn.text-danger:hover {
  background: rgba(255, 107, 107, 0.2);
}


/* Scrollable Container (Native Scrollbars) */
.ai-preview-container {
  position: relative;
  width: 100%;
  height: 50vh;
  min-height: 200px;
  max-height: 70vh;
  resize: vertical;
  overflow: auto;
  /* ENABLE NATIVE SCROLLBARS */
  background: #050505;
  border-bottom: 2px solid rgba(124, 92, 255, 0.2);
  display: block;
  /* Not flex, to allow scroll */
  padding: 0;
}

/* Canvas Wrapper (can be huge) */
.ai-canvas-wrapper {
  display: flex;
  align-items: flex-start;
  /* IMPORTANT: Align top-left */
  justify-content: flex-start;
  min-width: 100%;
  min-height: 100%;
  width: fit-content;
  /* Allow growing */
  height: fit-content;
  padding: 20px;
  /* Space around canvas */
}

#aiPreviewCanvas {
  display: block;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
  /* Cursor handles by JS */
}

.ai-preview-overlay {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 10;
  opacity: 0.7;
  transition: opacity 0.3s;
}

.ai-preview-container:hover .ai-preview-overlay {
  opacity: 0.2;
  /* Fade out on hover to see clearly */
}

.ai-hint-badge {
  background: rgba(0, 0, 0, 0.6);
  color: rgba(255, 255, 255, 0.8);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(4px);
  pointer-events: none;
  /* Let clicks pass through hint */
}

/* Controls Overlay */
.ai-preview-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
  z-index: 20;
}

.ai-mode-group {
  display: flex;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 2px;
}

.ai-tool-btn {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.ai-tool-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.ai-tool-btn.active {
  background: rgba(124, 92, 255, 0.4);
  color: #fff;
}

#aiToolClear {
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

#aiToolClear:hover {
  background: rgba(255, 100, 100, 0.2);
}

/* Add a hint for resizing */
.ai-preview-container::after {
  content: "III";
  position: absolute;
  bottom: 2px;
  right: 50%;
  transform: translateX(50%);
  color: rgba(255, 255, 255, 0.3);
  font-size: 10px;
  letter-spacing: 2px;
  pointer-events: none;
}

.ai-preview-container img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  /* Fit within the resizeable container */
  max-height: none;
  /* Remove limit so it follows container */
  box-shadow: none;
  border: none;
}


.ai-chat-area {
  flex: 1;
  /* Grow to fill available space */
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 200px;
  padding: 16px;
  /* More padding */
}

.ai-message {
  padding: 14px 18px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  max-width: 90%;
}

.ai-message.system {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.7);
  align-self: center;
  text-align: center;
  font-size: 13px;
}

.ai-message.user {
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.4), rgba(124, 92, 255, 0.2));
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.ai-message.ai {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.ai-input-area {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.ai-input-area textarea {
  flex: 1;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  padding: 14px 18px;
  color: #fff;
  font-size: 15px;
  font-family: inherit;
  resize: none;
  min-height: 52px;
  max-height: 120px;
  outline: none;
  transition: all 0.2s;
}

.ai-input-area textarea:focus {
  border-color: rgba(124, 92, 255, 0.6);
  background: rgba(0, 0, 0, 0.4);
}

.ai-attach-btn {
  width: 44px !important;
  height: 44px !important;
  padding: 0 !important;
  border-radius: 12px !important;
  background: rgba(255, 255, 255, 0.05) !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  color: rgba(255, 255, 255, 0.6) !important;
  margin-right: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.ai-attach-btn:hover {
  background: rgba(255, 255, 255, 0.15) !important;
  color: #fff !important;
  border-color: rgba(255, 255, 255, 0.3) !important;
}

.ai-attachments-preview {
  display: flex;
  gap: 10px;
  padding: 0 16px;
  margin-bottom: 8px;
  overflow-x: auto;
  min-height: 0;
}

.ai-attachments-preview:empty {
  margin-bottom: 0;
  display: none;
}

.attachment-chip {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.15);
  flex-shrink: 0;
  background: #000;
}

.attachment-chip img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.8;
  transition: opacity 0.2s;
}

.attachment-chip:hover img {
  opacity: 1;
}

.attachment-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  cursor: pointer;
  z-index: 10;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.attachment-remove:hover {
  background: #ff4757;
  border-color: #ff4757;
}

.ai-send-btn {
  width: 52px !important;
  height: 52px !important;
  padding: 0 !important;
  border-radius: 14px !important;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #6366f1, #a855f7) !important;
  border: none !important;
  box-shadow: 0 4px 15px rgba(124, 92, 255, 0.4);
  transition: all 0.2s;
}

.ai-send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(124, 92, 255, 0.6);
}

/* ========== MODERNIZED SELECTION PANEL ========== */
.selection-panel {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 20px;
  padding: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  z-index: 5000;
  display: flex;
  flex-direction: column;
  gap: 12px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: 400px;
  width: 90vw;
}

.selection-panel.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.selection-panel .selection-preview {
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  max-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.selection-panel .selection-preview img {
  max-width: 100%;
  max-height: 180px;
  object-fit: contain;
}

.selection-panel .selection-actions {
  display: flex;
  gap: 10px;
}

.selection-panel .selection-actions .btn {
  flex: 1;
  justify-content: center;
  padding: 12px 16px;
  font-size: 14px;
}

/* ===== AI SIDEBAR (Copilot) ===== */
.ai-sidebar {
  position: fixed;
  top: 52px;
  /* Below topbar */
  left: 0;
  bottom: 0;
  width: 380px;
  min-width: 300px;
  max-width: 80vw;
  background: #0f0f10;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 1000;
  display: flex;
  flex-direction: column;

  transform: translateX(-110%);
  transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5);
}

@media (max-width: 600px) {
  .ai-sidebar {
    width: 100% !important;
    min-width: 100% !important;
    max-width: 100% !important;
    border-right: none;
  }
}

.ai-sidebar.open {
  transform: translateX(0);
}

.ai-sidebar-resizer {
  position: absolute;
  top: 0;
  bottom: 0;
  right: -5px;
  width: 10px;
  cursor: col-resize;
  z-index: 10;
  /* invisible but grabbable */
}

/* Header */
.ai-sidebar-header {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.ai-header-title {
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
}

.ai-header-controls .btn-icon-tiny {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  font-size: 14px;
}

.ai-header-controls .btn-icon-trash-glow {
  background: rgba(255, 69, 58, 0.2);
  color: #ff453a;
  border: 1px solid rgba(255, 69, 58, 0.3);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  margin-right: 8px;
  font-size: 14px;
  cursor: pointer;
}

.ai-header-controls .btn-icon-trash-glow:hover {
  background: #ff453a;
  color: white;
  box-shadow: 0 0 12px rgba(255, 69, 58, 0.6);
  border-color: transparent;
  transform: scale(1.05);
}

.ai-header-controls .btn-icon-trash-glow.confirm-state {
  width: auto;
  padding: 0 10px;
  background: #ff453a;
  color: white;
  font-weight: 600;
  font-size: 12px;
  box-shadow: 0 0 15px rgba(255, 69, 58, 0.8);
  animation: pulse-red 1s infinite;
}

@keyframes pulse-red {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 69, 58, 0.7);
  }

  70% {
    box-shadow: 0 0 0 6px rgba(255, 69, 58, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(255, 69, 58, 0);
  }
}

/* Model Bar */
.ai-sidebar-model-bar {
  padding: 8px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #0a0a0a;
}

.compact-select {
  background: rgba(255, 255, 255, 0.08);
  /* Slightly lighter background */
  border: 1px solid rgba(255, 255, 255, 0.15);
  /* Subtle border */
  border-radius: 8px;
  /* Rounded corners */
  color: #fff;
  /* Brighter text */
  font-size: 13px;
  font-weight: 600;
  /* More readable */
  outline: none;
  max-width: 250px;
  /* Wider to fit text */
  padding: 6px 10px;
  /* Comfortable padding */
  cursor: pointer;
  transition: all 0.2s ease;
  /* Custom arrow */
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

.compact-select:hover {
  background-color: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.3);
}

.compact-select:focus {
  border-color: #7c5cff;
  box-shadow: 0 0 0 2px rgba(124, 92, 255, 0.2);
}

.compact-select optgroup {
  color: #a78bfa;
  /* Header color */
  font-style: normal;
  font-weight: 800;
  background: #1a1a1a;
}

.compact-select option {
  background: #0f172a;
  color: #fff;
  padding: 8px;
}

.ai-cost-badge.compact {
  font-size: 11px;
  padding: 2px 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

/* Tools Bar */
.ai-sidebar-tools {
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

/* Chat Area */
.ai-chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: #0f0f10;
}

.ai-message {
  font-size: 14px;
  line-height: 1.5;
  padding: 10px 14px;
  border-radius: 12px;
  max-width: 90%;
  word-wrap: break-word;
}

.ai-message.system {
  background: rgba(124, 92, 255, 0.1);
  border: 1px dashed rgba(124, 92, 255, 0.3);
  color: #a78bfa;
  align-self: center;
  text-align: center;
  font-size: 13px;
}

.ai-message.user {
  background: #2a2a2a;
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 2px;
}

.ai-message.ai {
  background: #1a1a1a;
  color: #eee;
  align-self: flex-start;
  border-bottom-left-radius: 2px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

/* Input Area */
.ai-input-wrapper {
  background: #1a1a1a;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding: 12px;
}

.ai-attachments-preview {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 8px;
}

.att-chip {
  background: #333;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.ai-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

#aiPromptInput {
  flex: 1;
  background: #0f0f10;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 8px 12px;
  color: #fff;
  font-size: 14px;
  resize: none;
  max-height: 120px;
  min-height: 36px;
}

#aiPromptInput:focus {
  border-color: #7c5cff;
  outline: none;
}

.btn-icon {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #aaa;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-send {
  background: #7c5cff;
  border: none;
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-send:hover {
  background: #6b4ce6;
}
/* === AI LOADING ANIMATION (Nebula Pulse) === */
.ai-thinking-container {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 4px;
}

.ai-orb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7c5cff, #d946ef);
  box-shadow: 0 0 20px rgba(124, 92, 255, 0.6);
  animation: orb-pulse 2s infinite ease-in-out;
  position: relative;
  flex-shrink: 0;
}

.ai-orb::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-top-color: rgba(255, 255, 255, 0.6);
  animation: orb-spin 1.5s infinite linear;
}

.ai-thinking-text {
  font-size: 14px;
  font-weight: 600;
  color: #c4b5fd;
  animation: text-fade 2s infinite;
  letter-spacing: 0.5px;
}

@keyframes orb-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 20px rgba(124, 92, 255, 0.6); }
  50% { transform: scale(1.1); box-shadow: 0 0 35px rgba(217, 70, 239, 0.8); }
}

@keyframes orb-spin {
  to { transform: rotate(360deg); }
}

@keyframes text-fade {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; text-shadow: 0 0 10px rgba(196, 181, 253, 0.5); }
}
