/* AI Control, full-height spawn map under admin chrome */
.page-ai-control {
  display: flex;
  flex-direction: column;
  /* dvh statt vh: mobile Browser rechnen 100vh inklusive der Adressleiste, die
     beim Scrollen verschwindet, die Seite waere sonst dauerhaft zu hoch. */
  min-height: 100vh;
  height: 100vh;
  min-height: 100dvh;
  height: 100dvh;
  overflow: hidden;
}

.page-ai-control .site-top,
.page-ai-control .admin-subnav {
  flex: 0 0 auto;
}

.ai-shell {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 280px;
  background: #1a1814;
}

.ai-palette,
.ai-inspector {
  background: #241f18;
  border-right: 1px solid var(--line);
  padding: 0.85rem 0.75rem 1rem;
  overflow: auto;
  min-height: 0;
}

.ai-inspector {
  border-right: none;
  border-left: 1px solid var(--line);
}

.ai-palette h1,
.ai-inspector h1 {
  margin: 0 0 0.55rem;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.ai-panel-sub {
  margin-top: 1.25rem !important;
}

.ai-hint {
  margin: 0 0 0.75rem;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}

.ai-palette-group {
  margin-bottom: 0.85rem;
}

.ai-palette-group h2 {
  margin: 0 0 0.4rem;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.ai-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.ai-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.45rem 0.28rem 0.28rem;
  background: #16120e;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: grab;
  user-select: none;
  color: var(--ink);
  font-size: 0.78rem;
}

.ai-chip:active {
  cursor: grabbing;
}

.ai-chip.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.ai-chip img {
  width: 22px;
  height: 22px;
  object-fit: contain;
  pointer-events: none;
}

.ai-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: #141810;
}

.ai-stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.ai-stage-credit {
  position: absolute;
  left: 0.65rem;
  bottom: 0.45rem;
  font-size: 0.72rem;
  color: var(--muted);
  pointer-events: none;
}

.ai-stage-credit a {
  color: var(--accent);
  pointer-events: auto;
}

.ai-map-status {
  position: absolute;
  right: 0.65rem;
  bottom: 0.45rem;
  margin: 0;
  font-size: 0.72rem;
  color: var(--muted);
  background: rgba(20, 24, 16, 0.72);
  padding: 0.2rem 0.45rem;
  border-radius: 3px;
  max-width: 55%;
  text-align: right;
}

.ai-tooltip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  padding: 0.35rem 0.5rem;
  background: rgba(20, 18, 14, 0.92);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 0.78rem;
  color: var(--ink);
  white-space: nowrap;
}

.ai-tooltip.hidden {
  display: none;
}

.ai-rule-form {
  display: grid;
  gap: 0.55rem;
}

.ai-rule-form label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.ai-rule-form input[type="text"],
.ai-rule-form input[type="number"] {
  background: #16120e;
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 0.45rem 0.55rem;
  width: 100%;
}

.ai-rule-form input[readonly] {
  opacity: 0.85;
}

.ai-check {
  display: flex !important;
  grid-template-columns: none;
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
  color: var(--ink) !important;
}

.ai-coords {
  margin: 0.15rem 0 0;
  font-size: 0.72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

.ai-form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.25rem;
}

.ai-rule-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.ai-rule-list li {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  padding: 0.35rem 0.4rem;
  background: #16120e;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.78rem;
}

.ai-rule-list li:hover {
  border-color: #5a4e3e;
}

.ai-rule-list li.is-selected {
  border-color: var(--accent);
}

.ai-rule-list li.is-off {
  opacity: 0.5;
}

.ai-rule-list img {
  width: 20px;
  height: 20px;
  object-fit: contain;
  flex: 0 0 auto;
  margin-top: 0.1rem;
}

.ai-rule-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.ai-rule-top {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}

.ai-rule-name {
  font-weight: 600;
}

.ai-rule-list .meta {
  color: var(--muted);
  font-size: 0.7rem;
  margin-left: auto;
  flex: 0 0 auto;
}

.ai-rule-note {
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.3;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.ai-drag-ghost {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.5rem;
  background: rgba(36, 31, 24, 0.95);
  border: 1px solid var(--accent);
  border-radius: 4px;
  font-size: 0.8rem;
  color: var(--ink);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}

.ai-drag-ghost img {
  width: 24px;
  height: 24px;
}

@media (max-width: 960px) {
  .ai-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(280px, 1fr) auto;
  }
  .ai-palette,
  .ai-inspector {
    border: none;
    border-bottom: 1px solid var(--line);
    max-height: 220px;
  }
}


/* ---------------------------------------------------------------------------
   Schmale Bildschirme. Die drei Spalten (220px Palette | Karte | 280px
   Inspektor) brauchen allein an den Raendern 500 px, auf einem 390-px-Telefon
   fiel der Inspektor rechts aus dem Bild. Untereinander statt nebeneinander.
   --------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .page-ai-control {
    height: auto;
    overflow: visible;
  }
  .ai-shell {
    grid-template-columns: 1fr;
  }
  .ai-palette,
  .ai-inspector {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: 38vh;
    -webkit-overflow-scrolling: touch;
  }
  .ai-stage {
    min-height: 55vh;
    order: -1; /* die Karte zuerst, danach Palette und Inspektor */
  }
  .ai-stage canvas {
    touch-action: none; /* eigene Zoom-/Schiebegesten, keine Browsergeste */
  }
}

/* Sichere Bereiche: die Seite reicht wegen viewport-fit=cover bis unter Notch
   und Home-Leiste. Ohne diese Abstaende liegt der Inspektor unten teilweise
   unter der Home-Leiste des iPhones und laesst sich dort nicht bedienen. */
.ai-shell {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
.ai-inspector {
  padding-bottom: calc(1rem + env(safe-area-inset-bottom));
}
@media (max-width: 900px) {
  .ai-palette,
  .ai-inspector {
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  }
}
