/* ============================================================
   ClarityBOT — Компоненты
   ============================================================ */

/* ================= CARD ================= */
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1), var(--sh-in);
  transition: border-color var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease),
              transform var(--dur-2) var(--ease);
}
.card-pad { padding: var(--s6); }
.card-pad-sm { padding: var(--s4); }

/* Интерактивная карточка — мягкий подъём и потепление границы */
.card-hover:hover {
  border-color: var(--border-2);
  box-shadow: var(--sh-2), var(--sh-in);
  transform: translateY(-1px);
}

.card-head {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s5) var(--s6);
  border-bottom: 1px solid var(--border);
}
.card-head h3 { flex: 1; }
.card-body { padding: var(--s6); }
.card-foot {
  padding: var(--s4) var(--s6);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}

/* ================= ICON TILE ================= */
.tile {
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  background: var(--stone-bg);
  color: var(--stone);
  border: 1px solid color-mix(in srgb, currentColor 16%, transparent);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.35);
}
.tile-lg { width: 42px; height: 42px; border-radius: var(--r-md); }
.tile.kraft  { background: var(--kraft-bg);  color: var(--kraft); }
.tile.manilla{ background: var(--manilla-bg);color: var(--manilla); }
.tile.cactus { background: var(--cactus-bg); color: var(--cactus); }
.tile.sky    { background: var(--sky-bg);    color: var(--sky); }
.tile.olive  { background: var(--olive-bg);  color: var(--olive); }
.tile.plum   { background: var(--plum-bg);   color: var(--plum); }
.tile.rose   { background: var(--rose-bg);   color: var(--rose); }
.tile.accent { background: var(--accent-soft); color: var(--accent); }

/* ================= BUTTON ================= */
.btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 16px;
  font-family: var(--font-ui); font-size: 13.5px; font-weight: 500;
  border-radius: var(--r-sm); border: 1px solid transparent;
  cursor: pointer; white-space: nowrap; user-select: none;
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease),
              color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease),
              transform var(--dur-1) var(--ease);
}
.btn:active { transform: translateY(.5px); }
.btn:disabled { opacity: .45; pointer-events: none; }

.btn-primary {
  background: var(--accent); color: var(--accent-ink);
  border-color: color-mix(in srgb, var(--accent) 78%, #000);
  box-shadow: var(--sh-1), inset 0 1px 0 rgba(255,255,255,.18);
}
.btn-primary:hover { background: var(--accent-h); }

.btn-secondary {
  background: var(--surface); color: var(--text);
  border-color: var(--border-2);
  box-shadow: var(--sh-1), var(--sh-in);
}
.btn-secondary:hover { background: var(--surface-2); border-color: var(--border-str); }

.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger {
  background: var(--danger-bg); color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 24%, transparent);
}
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 16%, var(--danger-bg)); }

.btn-sm { height: 31px; padding: 0 11px; font-size: 12.5px; border-radius: var(--r-xs); }
.btn-lg { height: 46px; padding: 0 22px; font-size: 15px; border-radius: var(--r-md); }
.btn-icon { width: 34px; padding: 0; }
.btn-block { width: 100%; }

/* Состояние «готово» — галочка вместо текста, без дёрганья ширины */
.btn .btn-label, .btn .btn-done { transition: opacity var(--dur-2) var(--ease), transform var(--dur-2) var(--ease); }
.btn .btn-done { position: absolute; inset: 0; display: grid; place-items: center; opacity: 0; transform: scale(.8); }
.btn.is-done .btn-label { opacity: 0; transform: scale(.9); }
.btn.is-done .btn-done  { opacity: 1; transform: scale(1); }

/* ================= FIELD ================= */
.field-label {
  display: block; margin-bottom: 6px;
  font-size: 12.5px; font-weight: 500; color: var(--text-2);
}
.field {
  width: 100%; height: 38px; padding: 0 12px;
  font-family: var(--font-ui); font-size: 13.5px; color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  box-shadow: inset 0 1px 2px rgba(60,50,35,.04);
  transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease),
              background var(--dur-1) var(--ease);
}
textarea.field { height: auto; padding: 10px 12px; line-height: 1.55; resize: vertical; min-height: 84px; }
select.field {
  appearance: none; padding-right: 32px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2386837A' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
}
.field::placeholder { color: var(--text-3); }
.field:hover { border-color: var(--border-str); }
.field:focus {
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}
.field-hint { margin-top: 6px; font-size: 12px; color: var(--text-3); }

.field-group { position: relative; }
.field-group .field-ico {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--text-3); pointer-events: none;
}
.field-group .field-ico ~ .field { padding-left: 34px; }

/* ================= SWITCH ================= */
.switch {
  position: relative; flex: none;
  width: 38px; height: 22px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  cursor: pointer; padding: 0;
  box-shadow: inset 0 1px 2px rgba(60,50,35,.07);
  transition: background var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease);
}
.switch::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(60,50,35,.22), 0 0 0 .5px rgba(60,50,35,.06);
  transition: transform var(--dur-2) var(--ease-out), background var(--dur-2) var(--ease);
}
.switch[aria-checked="true"] {
  background: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 76%, #000);
}
.switch[aria-checked="true"]::after { transform: translateX(16px); background: #fff; }

/* Строка настройки с тумблером */
.setting {
  display: flex; align-items: center; gap: var(--s4);
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
}
.setting:last-child { border-bottom: 0; padding-bottom: 0; }
.setting:first-child { padding-top: 0; }
.setting-text { flex: 1; min-width: 0; }
.setting-text .t { font-size: 13.5px; font-weight: 500; }
.setting-text .d { font-size: 12.5px; color: var(--text-3); margin-top: 1px; }

/* ================= BADGE / PILL ================= */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px;
  font-size: 11.5px; font-weight: 500; line-height: 1;
  border-radius: var(--r-xs);
  background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--border);
}
.badge.ok     { background: var(--ok-bg);     color: var(--ok);     border-color: color-mix(in srgb, var(--ok) 22%, transparent); }
.badge.warn   { background: var(--warn-bg);   color: var(--warn);   border-color: color-mix(in srgb, var(--warn) 22%, transparent); }
.badge.danger { background: var(--danger-bg); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 22%, transparent); }
.badge.accent { background: var(--accent-soft); color: var(--accent-text); border-color: var(--accent-line); }

/* LIVE — пульсирующая точка */
.badge-live {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 9px 0 8px;
  font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: #fff; background: var(--live);
  border-radius: var(--r-xs);
  box-shadow: 0 1px 3px color-mix(in srgb, var(--live) 40%, transparent);
}
.badge-live .dot { width: 6px; height: 6px; border-radius: 50%; background: #fff; }
.badge-live .dot { animation: livePulse 1.9s var(--ease) infinite; }
@keyframes livePulse {
  0%, 100% { opacity: 1;   box-shadow: 0 0 0 0 rgba(255,255,255,.6); }
  50%      { opacity: .55; box-shadow: 0 0 0 4px rgba(255,255,255,0); }
}

.chip {
  display: inline-flex; align-items: center; gap: 7px;
  height: 32px; padding: 0 6px 0 12px;
  font-size: 13px; border-radius: var(--r-full);
  background: var(--surface-2); border: 1px solid var(--border-2);
  cursor: pointer;
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
}
.chip:hover { background: var(--surface-3); border-color: var(--border-str); }
.chip .x {
  width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center; color: var(--text-3);
}
.chip .x:hover { background: var(--danger-bg); color: var(--danger); }

/* Табы-фильтры */
.segmented {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-sm);
}
.segmented button {
  height: 28px; padding: 0 13px;
  font-family: var(--font-ui); font-size: 13px; font-weight: 500;
  color: var(--text-2); background: transparent; border: 0;
  border-radius: var(--r-xs); cursor: pointer;
  transition: all var(--dur-1) var(--ease);
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-selected="true"] {
  background: var(--surface); color: var(--text);
  box-shadow: var(--sh-1), var(--sh-in);
}

/* ================= TOOLTIP ================= */
.tip { position: relative; }
.tip::after {
  content: attr(data-tip);
  position: absolute; left: 50%; bottom: calc(100% + 8px);
  transform: translateX(-50%) translateY(3px);
  padding: 5px 9px; white-space: nowrap;
  font-size: 12px; font-weight: 500;
  color: var(--text-inv); background: var(--surface-inv);
  border-radius: var(--r-xs); box-shadow: var(--sh-2);
  opacity: 0; pointer-events: none;
  transition: opacity var(--dur-2) var(--ease), transform var(--dur-2) var(--ease-out);
  z-index: 60;
}
.tip:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Обе подсказки в панели живут в шапке, а она прижата к верху окна —
   над кнопкой места нет, и текст уезжал за край экрана. Разворачиваем вниз.
   Правую вдобавок прижимаем к краю кнопки: она последняя в ряду, и по
   центру подсказка вылезала бы за окно. */
.topbar .tip::after {
  top: calc(100% + 8px); bottom: auto;
  transform: translateX(-50%) translateY(-3px);
}
.topbar .tip:hover::after { transform: translateX(-50%) translateY(0); }

.topbar .tip:last-child::after       { left: auto; right: 0; transform: translateY(-3px); }
.topbar .tip:last-child:hover::after { transform: translateY(0); }

/* ================= DIALOG ================= */
.dlg {
  width: min(420px, calc(100vw - 32px));
  padding: 0; border: 1px solid var(--border-2);
  border-radius: var(--r-lg);
  background: var(--surface); color: var(--text);
  box-shadow: var(--sh-3);
  animation: dlgIn var(--dur-3) var(--ease-out);
}
.dlg::backdrop {
  background: rgba(25, 25, 23, .40);
  backdrop-filter: blur(3px);
  animation: dlgFade var(--dur-3) var(--ease);
}
@keyframes dlgIn   { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes dlgFade { from { opacity: 0; } to { opacity: 1; } }

.dlg-body { padding: var(--s6); margin: 0; }
.dlg-title { font-family: var(--font-display); font-size: 18px; font-weight: 500; letter-spacing: -.015em; }
.dlg-text { margin-top: 8px; font-size: 13.5px; color: var(--text-2); line-height: 1.55; }
.dlg-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: var(--s6); padding-top: var(--s5);
  border-top: 1px solid var(--border);
}
.dlg-actions .btn { min-width: 96px; }

/* ================= COMMAND PALETTE ================= */
.pal {
  width: min(560px, calc(100vw - 32px));
  max-height: 70vh; padding: 0;
  margin-top: 12vh;               /* повыше центра — так привычнее */
  border: 1px solid var(--border-2); border-radius: var(--r-lg);
  background: var(--surface); color: var(--text);
  box-shadow: var(--sh-3);
  overflow: hidden;
  animation: dlgIn var(--dur-3) var(--ease-out);
}
.pal::backdrop { background: rgba(25,25,23,.40); backdrop-filter: blur(3px); }

.pal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px; height: 52px;
  border-bottom: 1px solid var(--border);
}
.pal-input {
  flex: 1; min-width: 0; height: 100%;
  font-family: var(--font-ui); font-size: 15px; color: var(--text);
  background: transparent; border: 0; outline: none;
}
.pal-input::placeholder { color: var(--text-3); }

.pal-list { max-height: calc(70vh - 100px); overflow-y: auto; padding: 6px; }
.pal-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 10px;
  font-family: var(--font-ui); font-size: 13.5px; color: var(--text);
  background: transparent; border: 0; border-radius: var(--r-sm);
  cursor: pointer; text-align: left;
}
.pal-item .ico { color: var(--text-3); flex: none; }
.pal-item.on { background: var(--accent-soft); }
.pal-item.on .ico { color: var(--accent-text); }
.pal-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pal-kind {
  flex: none; font-size: 11px; color: var(--text-3);
  padding: 2px 7px; border-radius: var(--r-xs);
  background: var(--surface-2); border: 1px solid var(--border);
}
.pal-empty { padding: 28px 16px; text-align: center; font-size: 13px; color: var(--text-3); }

.pal-foot {
  display: flex; gap: 16px; padding: 9px 14px;
  border-top: 1px solid var(--border); background: var(--surface-2);
  font-size: 11.5px; color: var(--text-3);
}
.pal kbd, .search-btn kbd {
  font-family: var(--font-mono); font-size: 10.5px;
  padding: 2px 5px; margin: 0 2px; border-radius: var(--r-xs);
  background: var(--surface); border: 1px solid var(--border-2);
  color: var(--text-3); box-shadow: 0 1px 0 var(--border-2);
}

/* Подсветка строки, на которую перешли из палитры */
@keyframes flashRow {
  0%, 100% { background: transparent; }
  30%      { background: var(--accent-soft); }
}
.list-row.flash { animation: flashRow 1.2s var(--ease); }

/* ================= SEARCH DROPDOWN ================= */
.search-wrap { position: relative; }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 50;
  max-height: 290px; overflow-y: auto; padding: 5px;
  background: var(--surface); border: 1px solid var(--border-2);
  border-radius: var(--r-md); box-shadow: var(--sh-3);
  display: none;
}
.search-results.show { display: block; }
.search-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 6px 8px;
  font-family: var(--font-ui); font-size: 13.5px; color: var(--text);
  background: transparent; border: 0; border-radius: var(--r-xs);
  cursor: pointer; text-align: left;
}
.search-item:hover { background: var(--surface-2); }
.search-item img {
  width: 27px; height: 36px; flex: none;
  border-radius: var(--r-xs); object-fit: cover;
  background: var(--surface-3);
}

/* ================= EMPTY STATE ================= */
.empty {
  display: flex; flex-direction: column; align-items: center;
  text-align: center; padding: var(--s9) var(--s6);
  color: var(--text-3);
}
.empty svg { color: var(--border-str); margin-bottom: var(--s4); }
.empty .t { font-size: 14px; font-weight: 500; color: var(--text-2); }
.empty .d { font-size: 13px; margin-top: 4px; max-width: 280px; }
