/*
 * Zykar UI
 * Small, dependency-free component layer for the dashboard.
 * The existing legacy class names remain supported by styles.css.
 */

:root {
  --zykar-duration-fast: 140ms;
  --zykar-duration-base: 220ms;
  --zykar-duration-slow: 420ms;
  --zykar-ease-out: cubic-bezier(.16, 1, .3, 1);
  --zykar-focus: 0 0 0 3px rgba(49, 92, 255, .22);
}

@keyframes zykar-enter {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes zykar-check {
  from { transform: scale(.65) rotate(-8deg); opacity: .2; }
  to { transform: scale(1) rotate(0); opacity: 1; }
}

@keyframes zykar-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(44, 155, 104, .28); }
  50% { box-shadow: 0 0 0 5px rgba(44, 155, 104, 0); }
}

/* Component: accessible custom checkbox */
.checkbox-row,
.checkbox-inline {
  position: relative;
}

.nestjs-checkbox,
.checkbox-inline input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  display: inline-grid;
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin: 0;
  place-content: center;
  color: var(--ink);
  background: var(--paper-bright);
  border: 1px solid #8e918d;
  border-radius: 3px;
  cursor: pointer;
  transition:
    background var(--zykar-duration-fast) var(--zykar-ease-out),
    border-color var(--zykar-duration-fast) var(--zykar-ease-out),
    transform var(--zykar-duration-fast) var(--zykar-ease-out);
}

.nestjs-checkbox::before,
.checkbox-inline input[type="checkbox"]::before {
  width: 10px;
  height: 10px;
  content: "";
  transform: scale(0) rotate(-8deg);
  background: currentColor;
  clip-path: polygon(14% 44%, 0 59%, 39% 100%, 100% 20%, 84% 7%, 38% 70%);
}

.nestjs-checkbox:hover,
.checkbox-inline input[type="checkbox"]:hover {
  border-color: var(--blue);
  transform: translateY(-1px);
}

.nestjs-checkbox:checked,
.checkbox-inline input[type="checkbox"]:checked {
  color: var(--ink);
  background: var(--lime);
  border-color: var(--ink);
}

.nestjs-checkbox:checked::before,
.checkbox-inline input[type="checkbox"]:checked::before {
  animation: zykar-check var(--zykar-duration-base) var(--zykar-ease-out) both;
  transform: scale(1) rotate(0);
}

.nestjs-checkbox:focus-visible,
.checkbox-inline input[type="checkbox"]:focus-visible {
  outline: none;
  box-shadow: var(--zykar-focus);
}

.auto-response-content {
  min-width: 220px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.auto-response-form {
  display: grid;
  grid-template-columns: minmax(210px, .8fr) minmax(320px, 1.55fr) auto auto;
  align-items: start;
  gap: 14px;
}

.auto-response-form textarea {
  min-height: 70px;
  resize: vertical;
}

.auto-response-form .form-field-group {
  min-width: 0;
  align-self: start;
}

.auto-response-form .form-field-group small {
  display: block;
  min-height: 16px;
  margin-top: 2px;
  color: var(--ink-soft);
  font-size: .68rem;
  line-height: 1.35;
}

.auto-response-form .checkbox-inline,
.auto-response-form > button {
  align-self: end;
  min-height: 40px;
  margin-bottom: 16px;
}

.auto-response-form > button {
  white-space: nowrap;
}

@media (max-width: 900px) {
  .auto-response-form {
    grid-template-columns: minmax(0, 1fr);
  }

  .auto-response-form .checkbox-inline,
  .auto-response-form > button {
    width: 100%;
    margin-bottom: 0;
  }
}

/* Component: shared interactive states */
:where(button, a, input, textarea, select):focus-visible {
  outline: none;
  box-shadow: var(--zykar-focus);
}

:where(.btn-install-bot, .btn-nav-sync, .btn-lang-switch, .btn-nestjs-pill-primary, .btn-modal-action, .sidebar-link) {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

:where(.btn-install-bot, .btn-nav-sync, .btn-lang-switch, .btn-nestjs-pill-primary, .btn-modal-action, .sidebar-link)::after {
  position: absolute;
  inset: 0;
  z-index: -1;
  content: "";
  background: rgba(255, 255, 255, .18);
  opacity: 0;
  transform: translateX(-105%);
  transition: transform var(--zykar-duration-base) var(--zykar-ease-out), opacity var(--zykar-duration-fast) ease;
}

:where(.btn-install-bot, .btn-nav-sync, .btn-lang-switch, .btn-nestjs-pill-primary, .btn-modal-action, .sidebar-link):hover::after {
  opacity: 1;
  transform: translateX(0);
}

:where(.btn-install-bot, .btn-nav-sync, .btn-lang-switch, .btn-nestjs-pill-primary, .btn-modal-action, .sidebar-link):active {
  transform: translateY(1px);
}

.btn-nestjs-pill-primary:disabled,
.btn-modal-action:disabled {
  cursor: not-allowed;
  opacity: .55;
  transform: none;
  box-shadow: none;
}

/* Component: close control */
.btn-close-modal {
  position: relative;
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  color: var(--ink-soft);
  border: 1px solid transparent;
  border-radius: 3px;
  transition:
    color var(--zykar-duration-fast) ease,
    background var(--zykar-duration-fast) ease,
    border-color var(--zykar-duration-fast) ease,
    transform var(--zykar-duration-fast) var(--zykar-ease-out);
}

.btn-close-modal:hover {
  color: var(--ink);
  background: var(--lime);
  border-color: var(--ink);
  transform: rotate(90deg);
}

.btn-close-modal:active {
  transform: rotate(90deg) scale(.9);
}

/* Component: small status and loading primitives */
.zykar-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--green);
  font: 700 .62rem var(--mono);
  text-transform: uppercase;
}

.zykar-status::before {
  width: 6px;
  height: 6px;
  content: "";
  background: currentColor;
  border-radius: 50%;
}

.zykar-skeleton {
  position: relative;
  overflow: hidden;
  min-height: 12px;
  background: #e4e2db;
  border-radius: 2px;
}

.zykar-skeleton::after {
  position: absolute;
  inset: 0;
  content: "";
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.55), transparent);
  transform: translateX(-100%);
  animation: zykar-skeleton 1.4s ease-in-out infinite;
}

@keyframes zykar-skeleton {
  to { transform: translateX(100%); }
}

/* Component: panels and navigation */
.overview-card,
.overview-panel,
.nestjs-card-panel {
  transition:
    border-color var(--zykar-duration-base) ease,
    box-shadow var(--zykar-duration-base) var(--zykar-ease-out),
    transform var(--zykar-duration-base) var(--zykar-ease-out);
}

.overview-card:hover,
.overview-panel:hover,
.nestjs-card-panel:hover {
  transform: translateY(-2px);
  box-shadow: 7px 9px 0 rgba(17, 19, 21, .12);
}

.tab-content.active {
  animation: zykar-enter var(--zykar-duration-slow) var(--zykar-ease-out) both;
}

.sidebar-link {
  transform-origin: left center;
}

.sidebar-link:hover {
  transform: translateX(3px);
}

.sidebar-link.active:hover {
  transform: translateX(3px) translateY(-1px);
}

/* Native select controls stay in the form tree but are replaced visually. */
.zykar-select-source {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  clip-path: inset(50%) !important;
}
.zykar-select { position: relative; width: 100%; min-width: 0; }
.zykar-select-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  color: var(--ink);
  background: var(--paper-bright);
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: pointer;
  text-align: left;
  font: 600 .78rem var(--sans);
}
.zykar-select-trigger:hover, .zykar-select.is-open .zykar-select-trigger { border-color: var(--ink); }
.zykar-select-trigger:disabled { cursor: not-allowed; opacity: .6; }
.zykar-select-value { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.zykar-select-chevron { flex: 0 0 9px; width: 9px; height: 9px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg) translateY(-2px); transition: transform var(--zykar-duration-fast) ease; }
.zykar-select.is-open .zykar-select-chevron { transform: rotate(225deg) translate(-1px, -1px); }
.zykar-select-menu {
  position: absolute;
  z-index: 80;
  top: calc(100% + 6px);
  left: 0;
  width: 100%;
  max-height: min(340px, 55vh);
  padding: 6px;
  overflow: auto;
  color: var(--ink);
  background: var(--paper-bright);
  border: 1px solid var(--ink);
  border-radius: 6px;
  box-shadow: 0 14px 34px rgba(17, 19, 21, .2);
}
.zykar-select-menu[hidden] { display: none; }
.zykar-select-search { position: sticky; top: 0; z-index: 1; width: 100%; margin-bottom: 5px; padding: 9px 10px; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 4px; font: .75rem var(--sans); }
.zykar-select-option { display: flex; align-items: center; width: 100%; min-height: 36px; padding: 8px 10px; color: var(--ink); background: transparent; border: 0; border-radius: 4px; cursor: pointer; text-align: left; font: 500 .75rem var(--sans); }
.zykar-select-option:hover, .zykar-select-option:focus-visible, .zykar-select-option[aria-selected="true"] { background: #e9edff; outline: 0; }
.zykar-select-option[aria-selected="true"] { color: #1738bd; font-weight: 700; }
.zykar-select-option:disabled { cursor: not-allowed; opacity: .48; }
.zykar-select-option[hidden] { display: none; }
.zykar-select-group { padding: 9px 10px 4px; color: var(--ink-soft); font: 700 .58rem var(--mono); letter-spacing: .08em; text-transform: uppercase; }
.zykar-select-group-options[hidden], .zykar-select-group[hidden] { display: none; }
.zykar-select-server { width: 100%; }
.zykar-select-server .zykar-select-trigger { min-height: 25px; padding: 0; color: #fff; background: transparent; border: 0; border-radius: 0; font-size: .73rem; font-weight: 800; }
.zykar-select-server .zykar-select-trigger:hover, .zykar-select-server.is-open .zykar-select-trigger { border: 0; }
.zykar-select-server .zykar-select-menu { min-width: 230px; }
.zykar-select-server .zykar-select-menu { width: max(100%, 230px); }

/* Switches use the same palette and spacing as the dashboard controls. */
.zykar-switch-row { display: flex !important; align-items: center; gap: 10px; cursor: pointer; }
.zykar-switch-row input[type="checkbox"] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.zykar-switch-row input[type="checkbox"]:focus-visible { outline: 0; box-shadow: none; }
.zykar-switch-track { position: relative; display: inline-flex; flex: 0 0 38px; width: 38px; height: 22px; align-items: center; padding: 3px; background: #d3d0c7; border: 1px solid #aaa79e; border-radius: 99px; transition: background var(--zykar-duration-fast) ease, border-color var(--zykar-duration-fast) ease; }
.zykar-switch-track::after { width: 14px; height: 14px; content: ""; background: #fff; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform var(--zykar-duration-fast) var(--zykar-ease-out); }
.zykar-switch-row input:checked + .zykar-switch-track { background: var(--lime); border-color: var(--ink); }
.zykar-switch-row input:checked + .zykar-switch-track::after { transform: translateX(16px); background: var(--ink); }
.zykar-switch-row input:focus-visible + .zykar-switch-track { box-shadow: var(--zykar-focus); }
.zykar-checkbox-control { display: flex; align-items: center; gap: 9px; cursor: pointer; }
.zykar-range { display: grid; gap: 9px; }
.zykar-range input[type="range"] { width: 100%; height: 22px; margin: 0; appearance: none; background: transparent; cursor: pointer; }
.zykar-range input[type="range"]::-webkit-slider-runnable-track { height: 6px; background: linear-gradient(to right, var(--blue) 0 var(--range-progress, 50%), #d3d0c7 var(--range-progress, 50%) 100%); border: 1px solid rgba(17,19,21,.16); border-radius: 99px; }
.zykar-range input[type="range"]::-moz-range-track { height: 6px; background: #d3d0c7; border: 1px solid rgba(17,19,21,.16); border-radius: 99px; }
.zykar-range input[type="range"]::-moz-range-progress { height: 6px; background: var(--blue); border-radius: 99px; }
.zykar-range input[type="range"]::-webkit-slider-thumb { width: 18px; height: 18px; margin-top: -7px; appearance: none; background: var(--lime); border: 2px solid var(--ink); border-radius: 50%; box-shadow: 0 2px 5px rgba(17,19,21,.18); }
.zykar-range input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; background: var(--lime); border: 2px solid var(--ink); border-radius: 50%; box-shadow: 0 2px 5px rgba(17,19,21,.18); }
.zykar-range input[type="range"]:focus-visible { outline: 0; }
.zykar-range input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px rgba(49,92,255,.2); }
.zykar-range output { color: var(--ink-soft); font: 600 .65rem var(--mono); }
.zykar-color-picker { display: grid; gap: 10px; }
.zykar-color-swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.zykar-color-swatches button { width: 27px; height: 27px; background: var(--swatch); border: 2px solid var(--paper-bright); border-radius: 50%; box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.zykar-color-swatches button[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--ink); }
.zykar-color-value { display: flex; align-items: center; gap: 10px; }
.zykar-color-value .color-picker-input { width: 115px; min-height: 38px; padding: 8px 10px; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 4px; font: 600 .72rem var(--mono); text-transform: uppercase; }
.has-zykar-modal { overflow: hidden; }
.service-row strong[data-status="offline"] { color: var(--red); }
.service-row strong[data-status="offline"] b { background: var(--red); }
.service-row strong[data-status="unknown"] { color: var(--ink-soft); }
.service-row strong[data-status="unknown"] b { background: #a5a39d; }
.overview-live[data-status="offline"] span { background: var(--red); }
.overview-live[data-status="unknown"] span { background: #a5a39d; }

/* In-app dialogs and notifications replace browser alert/confirm/prompt UI. */
.zykar-dialog-backdrop { position: fixed; inset: 0; z-index: 500; display: grid; place-items: center; padding: 20px; background: rgba(17, 19, 21, .62); backdrop-filter: blur(3px); }
.zykar-dialog { width: min(480px, 100%); padding: 23px; color: var(--ink); background: var(--paper-bright); border: 1px solid var(--ink); border-radius: 8px; box-shadow: 0 22px 65px rgba(0,0,0,.24); }
.zykar-dialog:focus { outline: 0; }
.zykar-dialog h2 { font-size: 1.08rem; letter-spacing: -.035em; }
.zykar-dialog > p { margin: 8px 0 18px; color: var(--ink-soft); font-size: .82rem; line-height: 1.55; }
.zykar-dialog-label { display: grid; gap: 8px; margin: 12px 0 18px; color: var(--ink-soft); font: 700 .62rem var(--mono); text-transform: uppercase; }
.zykar-dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 20px; }
.zykar-button-danger { color: #fff !important; background: #b9322b !important; border-color: #8f211b !important; }
.zykar-toast-region { position: fixed; right: 22px; bottom: 22px; z-index: 600; display: grid; width: min(380px, calc(100vw - 32px)); gap: 8px; pointer-events: none; }
.zykar-toast { padding: 12px 15px; color: #fff; background: var(--ink); border-left: 4px solid var(--blue); border-radius: 5px; box-shadow: 0 12px 32px rgba(0,0,0,.18); font-size: .8rem; line-height: 1.45; animation: zykar-enter var(--zykar-duration-base) var(--zykar-ease-out) both; }
.zykar-toast-success { border-color: var(--green); }
.zykar-toast-error { border-color: var(--red); }
.zykar-toast-warning { border-color: #d28b00; }

@media (max-width: 560px) {
  .zykar-toast-region { right: 16px; bottom: 16px; }
  .zykar-dialog { padding: 18px; }
}

.overview-live span,
.service-row strong b {
  animation: zykar-pulse 2.4s ease-in-out infinite;
}

/* Component: fields */
:where(.input-nestjs-field, .textarea-nestjs-field, .input-select-field, .nestjs-search-pill) {
  transition:
    border-color var(--zykar-duration-fast) ease,
    box-shadow var(--zykar-duration-fast) ease,
    background var(--zykar-duration-fast) ease;
}

:where(.input-nestjs-field, .textarea-nestjs-field, .input-select-field):hover {
  border-color: #9da2a0;
  background: #fff;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}
