/* ==========================================================================
   KIBAGSENS Settings Modal / Forms
   Wiederverwendbare Vorlage für Popups, Einstellungen und Formulare
   ========================================================================== */

/* --------------------------------------------------------------------------
   Backdrop / Modal Shell
   -------------------------------------------------------------------------- */

.ks-modal-backdrop {
  position: fixed;

  /* Navbar bleibt sichtbar */
  top: calc(var(--nav-h) + 10px);
  left: 0;
  right: 0;
  bottom: 0;

  /* Unterhalb der Navbar, oberhalb des Seiteninhalts */
  z-index: calc(var(--nav-z, 1000) - 10);

  display: grid;
  place-items: center;

  padding: 16px;
  background: rgba(30, 30, 30, 0.50);

  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.ks-modal-backdrop[hidden] {
  display: none !important;
}

.ks-modal-card {
  position: relative;
  z-index: 1;

  width: min(1120px, calc(100vw - 32px));

  /*
    Fixe Höhe anhand des Viewports.
    Wichtig:
    - keine inhaltsabhängige Höhe
    - kein Springen beim Wechsel der Registerkarten
    - 100dvh ist für iPhone/Safari besser als 100vh
  */
  height: min(720px, calc(100vh - var(--nav-h) - 42px));
  height: min(720px, calc(100dvh - var(--nav-h) - 42px));

  min-height: 460px;
  max-height: calc(100vh - var(--nav-h) - 42px);
  max-height: calc(100dvh - var(--nav-h) - 42px);

  overflow: hidden;

  display: flex;
  flex-direction: column;

  color: var(--text);

  border: 1px solid color-mix(in srgb, var(--border-context, var(--border)) 35%, transparent);
  border-radius: 35px;

  background: var(--surface);

  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.sensor-edit-modal-card {
  width: min(940px, calc(100vw - 32px));
}


/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */

.ks-modal-header {
  flex: 0 0 auto;

  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;

  padding: 20px 24px 10px 24px;
}

.ks-modal-title {
  overflow-wrap: anywhere;
  font-size: 1.3rem;
  font-weight: 500;
  line-height: 1.25;
  color: var(--text);
}

.ks-modal-subtitle {
  margin-top: 3px;
  overflow-wrap: anywhere;
  font-size: 0.8rem;
  color: var(--muted);
}

.ks-modal-close {
  flex: 0 0 auto;
  position: relative;
  isolation: isolate;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  appearance: none;
  background: #373737;
  color: #fff;
  cursor: pointer;
  transition:
    background-color 150ms ease,
    border-color 150ms ease,
    transform 150ms ease;
}

.ks-modal-close::before,
.ks-modal-close::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 13px;
  height: 1px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .96);
  transform-origin: center;
}

.ks-modal-close::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

.ks-modal-close::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.ks-modal-close:hover {
  border-color: rgba(255, 255, 255, .28);
  background: color-mix(in srgb, #202833 90%, transparent);
  transform: translateY(-1px);
}

.ks-modal-close:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent, #0ea5e9) 72%, #fff);
  outline-offset: 2px;
  border-color: color-mix(in srgb, var(--accent, #0ea5e9) 72%, #fff);
}

.ks-modal-close:active {
  background: color-mix(in srgb, #0f141b 94%, transparent);
  transform: translateY(0) scale(.96);
}

@media (prefers-reduced-motion: reduce) {
  .ks-modal-close {
    transition: none;
  }
}


/* --------------------------------------------------------------------------
   Form Base
   -------------------------------------------------------------------------- */

.ks-form {
  flex: 1 1 auto;
  min-height: 0;

  display: flex;
  flex-direction: column;

  padding: 0 24px 20px 24px;
}


.ks-form-tabs {
  flex: 0 0 auto;
  margin: 10px 0 14px 0;
}

.ks-form-tab {
  flex: 0 0 auto;
}


/* --------------------------------------------------------------------------
   Scrollbarer Formularbereich
   -------------------------------------------------------------------------- */

.ks-form-panels {
  flex: 1 1 auto;
  min-height: 0;

  overflow-y: auto;
  overflow-x: hidden;

  padding-right: 4px;

  -webkit-overflow-scrolling: touch;
}

.ks-form-panel {
  display: none;
}

.ks-form-panel.active {
  display: block;
}


.ks-color-shell {
  width: 72px;
  height: 32px;
  min-height: 32px;

  display: flex;
  align-items: center;
  justify-content: center;
}

.ks-field--inline .ks-color {
  justify-self: start;
}

.ks-field-pair--color-symbol {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(92px, max-content) minmax(0, 1fr);
  gap: 12px 14px;
  align-items: end;
}

.ks-field-pair--color-symbol .ks-field {
  min-width: 0;
}

.ks-field-pair--color-symbol .ks-field--inline {
  align-items: center;
}

/* --------------------------------------------------------------------------
   Statusbox
   -------------------------------------------------------------------------- */

.ks-status-box {
  margin: 24px 0 0 0;
  padding: 18px 12px 10px 12px;

  border: 1px solid var(--border);
  border-radius: 14px;

  background: color-mix(in srgb, var(--surface) 68%, transparent);
}

.ks-status-box legend {
  padding: 0 6px;
  font-size: 0.9rem;
  color: var(--text);
}

.ks-status-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
}

.ks-status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  padding: 3px 7px;
  border-radius: 6px;

  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
}

.ks-status-badge--expired {
  color: #e43214;
  background: color-mix(in srgb, #e43214 12%, transparent);
}

.ks-status-text {
  font-size: 0.82rem;
  color: var(--text);
}


/* --------------------------------------------------------------------------
   Actions / Buttons
   -------------------------------------------------------------------------- */

.ks-modal-actions {
  flex: 0 0 auto;

  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;

  padding-top: 18px;
}

.ks-modal-actions-right {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* --------------------------------------------------------------------------
   Mobile / iPhone
   -------------------------------------------------------------------------- */

@media (max-width: 760px) {
  .ks-modal-backdrop {
    top: var(--nav-h);
    place-items: stretch;
    align-items: stretch;
    justify-items: stretch;

    padding: 0;
  }

  .ks-modal-card {
    width: 100%;

    /*
      Fixe iPhone-Höhe:
      - unabhängig vom Inhalt
      - angepasst an sichtbare Browserhöhe
      - Navbar bleibt sichtbar
    */
    height: calc(100vh - var(--nav-h));
    height: calc(100dvh - var(--nav-h));

    min-height: 0;

    max-height: none;

    border-width: 0;
    border-radius: 0;
  }

  .ks-modal-header {
    flex: 0 0 auto;
    align-items: center;
    padding: 14px 16px 8px 16px;
  }

  .ks-modal-title {
    font-size: 1.08rem;
  }

  .ks-modal-subtitle {
    font-size: 0.76rem;
  }

  .ks-modal-close {
    width: 32px;
    height: 32px;
  }

  .ks-form {
    flex: 1 1 auto;
    min-height: 0;
    padding: 0 16px 14px 16px;
  }

  .ks-form-tabs {
    flex: 0 0 auto;
    width: 100%;
    margin: 8px 0 12px 0;
  }

  .ks-form-tab {
    padding: 0 12px;
  }

  .ks-form-panels {
    flex: 1 1 auto;
    min-height: 0;

    overflow-y: auto;
    overflow-x: hidden;

    -webkit-overflow-scrolling: touch;
  }

  .ks-modal-actions {
    flex: 0 0 auto;
  }

  .ks-form-grid {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .ks-field {
    display: grid;
    gap: 6px;
  }

  .ks-field + .ks-field {
    margin-top: 5px;
  }

  .ks-field-pair--color-symbol .ks-field + .ks-field {
    margin-top: 5px;
  }

  .ks-field label {
    padding-left: 4px;
  }

  .ks-status-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .ks-modal-actions {
    flex-direction: column-reverse;
    align-items: stretch;
    gap: 10px;
    padding-top: 14px;
  }

  .ks-modal-actions-right {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .ks-btn {
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

@media (max-width: 420px) {
  .ks-modal-header {
    padding-inline: 14px;
  }

  .ks-form {
    padding-inline: 14px;
  }
}
