/* Палитра команд Ctrl+K (js/palette.js). Все цвета — токены тем base.css;
   работает во всех 4 темах без отдельных правил. */

.palette-overlay {
  position: fixed;
  inset: 0;
  z-index: 120; /* поверх drawer (58/59), модалок (100) и bell (70); ниже тостов (1000) */
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12dvh var(--s4) var(--s4);
  background: var(--scrim, rgba(0, 0, 0, 0.35));
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  /* Волна 5б: fade скрима на токенах (Obsidian §13 — синхронно с панелью) */
  animation: fade-in calc(var(--duration-fast, 150ms) * var(--motion-scale, 1)) var(--ease-out);
}

.palette {
  /* Волна 17 — токены prompts Obsidian (tokens.md): width 700px,
     max-width 80vw, max-height 70vh, радиус 12 (radius-l ≈ --r-control). */
  width: min(700px, 80vw);
  max-height: 70dvh;
  display: flex;
  flex-direction: column;
  border-radius: var(--r-control);
  border: 1px solid var(--separator);
  background: var(--surface);
  backdrop-filter: var(--glass);
  -webkit-backdrop-filter: var(--glass);
  box-shadow: var(--shadow-lift);
  overflow: hidden;
  /* Волна 5б: palette-enter из motion.css (scale 0.96→1 + fade, §13). */
  animation: palette-enter calc(var(--duration-normal, 250ms) * var(--motion-scale, 1)) var(--ease-out) backwards;
}
/* Exit: palette.js вешает .closing на overlay и ждёт exitDurationMs —
   мягкий fade короче входа (better-ui: exit softer). */
.palette-overlay.closing {
  animation: fade-in calc(var(--duration-fast, 150ms) * var(--motion-scale, 1)) var(--ease-out) reverse both;
}
.palette-overlay.closing .palette {
  animation: sheet-exit calc(var(--duration-fast, 150ms) * var(--motion-scale, 1)) var(--ease-out) both;
}

.palette-input-row {
  position: relative; /* якорь для круглой ✕ справа в поле */
  display: flex;
  align-items: center;
  gap: var(--s2);
  /* Волна 17: --prompt-input-height эталона = 40px (десктоп) */
  min-height: 40px;
  box-sizing: border-box;
  padding: var(--s2) var(--s4);
  border-bottom: 1px solid var(--separator);
}
.palette-search-icon {
  width: 18px;
  height: 18px;
  color: var(--hint);
  flex: none;
}
.palette-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  padding: 2px 0;
}
.palette-input:focus { outline: none; }
.palette-input::placeholder { color: var(--hint); }

/* ✕ очистки: круглая, абсолютно справа в поле, полупрозрачная. */
.palette-clear {
  position: absolute;
  /* на десктопе — левее kbd Esc; на мобиле (kbd скрыт) переопределяется */
  right: calc(var(--s3) + 38px);
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--fill);
  color: var(--hint);
  font-size: var(--font-sm);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.6;
  flex: none;
  padding: 0;
  transition: opacity 120ms ease-out, background-color 120ms ease-out, transform 120ms ease-out;
}
/* hit-area 32→44px: невидимый ореол, визуал кнопки не меняется */
.palette-clear::after { content: ''; position: absolute; inset: -6px; border-radius: 50%; }
/* hover — только точный указатель (на таче не залипает) */
@media (hover: hover) and (pointer: fine) {
  .palette-clear:hover { opacity: 1; }
}
.palette-clear:active { opacity: 1; background: var(--separator); }

.palette-kbd {
  font-family: var(--font-mono);
  font-size: var(--font-xs);
  color: var(--hint);
  background: var(--fill);
  border-radius: 6px;
  padding: 2px 6px;
  flex: none;
}

.palette-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--s2);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.palette-item {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s2) var(--s3);
  min-height: 44px;
  border-radius: var(--r-control);
  text-align: left;
  color: var(--text);
  width: 100%;
}
@media (hover: hover) and (pointer: fine) {
  .palette-item:hover { background: var(--fill); }
}
.palette-item:active { background: var(--fill); }
/* текст выбранного пункта на accent-soft: --accent давал <4.5 в тёмных темах
   (AMOLED 2.46:1) → accent-strong; иконка (.palette-item-icon) остаётся --accent */
.palette-item.sel {
  background: var(--accent-soft);
  color: var(--accent-strong);
}
.palette-item.sel .palette-item-sub { color: var(--accent-strong); opacity: 0.75; }

.palette-item-icon {
  width: 18px;
  height: 18px;
  flex: none;
  color: var(--hint);
}
.palette-item.sel .palette-item-icon { color: var(--accent); }

.palette-item-title {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.palette-item-sub {
  flex: none;
  max-width: 45%;
  font-size: 12px;
  color: var(--hint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.palette-empty {
  padding: var(--s6) var(--s4);
  text-align: center;
  color: var(--hint);
  font-size: 14px;
}

.palette-foot {
  display: flex;
  gap: var(--s4);
  padding: var(--s2) var(--s4);
  border-top: 1px solid var(--separator);
  color: var(--hint);
  font-size: 12px;
}
.palette-hint { display: inline-flex; align-items: center; gap: 6px; }

@keyframes palette-fade { from { opacity: 0; } }
@keyframes palette-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.98); }
}

@media (max-width: 600px) {
  /* Полноэкранный оверлей поверх контента (Obsidian Mobile). */
  .palette-overlay {
    padding: 0;
    align-items: stretch;
  }
  .palette {
    width: 100%;
    max-width: 100vw;
    max-height: none;
    height: 100dvh;
    border-radius: 0;
    border: none;
    box-shadow: none;
  }
  /* Список сверху, скроллится; поле внизу над клавиатурой. */
  .palette-list { flex: 1; }
  /* Поле — пилюля над клавиатурой. Волна 17: --prompt-input-height
     на мобиле = --touch-size-l = 52px (эталон; тач-минимум 44 соблюдён). */
  .palette-input-row {
    order: 2;
    margin: 8px;
    border: none;
    border-radius: var(--r-pill);
    background: var(--surface-2, var(--fill));
    padding: 0 var(--s4);
    min-height: 52px;
  }
  .palette-clear { right: 10px; width: 36px; height: 36px; }
  .palette-input { min-height: 52px; }
  .palette-input-row .palette-kbd { display: none; } /* kbd не нужны на таче */
  .palette-foot { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  :root:not([data-motion-force='1']) .palette-overlay,
  :root:not([data-motion-force='1']) .palette { animation: none; }
}
