/* Akzentfarben über GlassKit-Tokens (nur --gl-*-Overrides) */
:root {
  --gl-color-primary: #6d8cff;
  --gl-color-primary-dark: #4a63d8;
  --gl-color-primary-mid: #5a74ee;
  --gl-color-bg-dark: #0d1526;
  --gl-color-bg-mid: #14213d;
  --gl-color-bg-light: #182a4a;
}

/* Light-Theme: dunklere Indigo-Variante für ausreichend Kontrast.
   ACHTUNG: :root und [data-theme=light] haben GLEICHE Spezifität — die
   Hintergrund-Tokens müssen hier explizit wieder hell gesetzt werden,
   sonst gewinnen die dunklen :root-Werte oben (spätere Quellreihenfolge). */
[data-theme="light"] {
  --gl-color-primary: #4a63d8;
  --gl-color-primary-dark: #3a4fb0;
  --gl-color-primary-mid: #4259c4;
  --gl-color-bg-dark: #e8ecf1;
  --gl-color-bg-mid: #f0f4f8;
  --gl-color-bg-light: #f5f7fa;
  --gl-border-subtle: rgba(15, 35, 55, 0.14);
}

html,
body {
  margin: 0;
  min-height: 100vh;
  /* Hintergrund muss bei viewport-fit=cover hinter Notch/Island reichen */
  background: var(--gl-color-bg-dark);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  color: var(--gl-color-text);
}

.glass-bg {
  min-height: 100vh;
}

.muted {
  color: var(--gl-color-text-muted);
  font-size: 0.85rem;
}

/* --- Shell ---------------------------------------------------------------- */

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  /* Safe-Areas (iPhone Dynamic Island / abgerundete Ecken) */
  padding: calc(0.9rem + env(safe-area-inset-top))
    calc(1.25rem + env(safe-area-inset-right))
    0.9rem
    calc(1.25rem + env(safe-area-inset-left));
}

/* Logo + Titel links (iPhone-Icon-Stil) */
.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.logo {
  width: 38px;
  height: 38px;
  border-radius: 22%;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.28);
  display: block;
}

.logo--lg {
  width: 76px;
  height: 76px;
  align-self: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

/* Theme-Toggle (glk-pill mit Sonne/Mond) */
.theme-toggle svg {
  width: 18px;
  height: 18px;
  display: block;
}

/* Ladeanimation im Header während Generierung */
.gen-spinner {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--gl-color-text-muted);
  font-size: 0.85rem;
}

.gen-spinner__ring {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--gl-border-medium);
  border-top-color: var(--gl-color-primary);
  animation: gen-spin 0.8s linear infinite;
}

@keyframes gen-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .gen-spinner__ring {
    animation-duration: 2.4s;
  }
}

/* Spinner im Generieren-Button (auf Primary-Farbe) */
.btn-loading {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
}

.gen-spinner__ring--on-primary {
  border-color: rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
}

.desktop-nav {
  display: flex;
  gap: 0.5rem;
}

.app-main {
  flex: 1;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.25rem 2rem;
}

.app-loading {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

/* Mobile Tab-Bar unten, Desktop-Nav ausblenden */
.mobile-tabs {
  display: none;
}

@media (max-width: 900px) {
  .desktop-nav {
    display: none;
  }
  .mobile-tabs {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    padding: 0.4rem calc(0.6rem + env(safe-area-inset-right))
      calc(0.4rem + env(safe-area-inset-bottom))
      calc(0.6rem + env(safe-area-inset-left));
    background: rgba(13, 21, 38, 0.72);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--gl-border-subtle);
  }
  [data-theme="light"] .mobile-tabs {
    background: rgba(245, 247, 250, 0.78);
  }
  .app-main {
    padding-bottom: 5.5rem;
  }
}

/* --- Login ---------------------------------------------------------------- */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.login-card {
  width: min(92vw, 380px);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 0.5rem 0.25rem;
}

/* --- Studio --------------------------------------------------------------- */

.studio-grid {
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 900px) {
  .studio-grid {
    grid-template-columns: 1fr;
  }
}

.panel-body {
  display: flex;
  flex-direction: column;
  /* Panel nie höher als der Viewport (Header ~74px + Main-Padding) */
  max-height: calc(100vh - 160px);
}

/* Eigener Scrollbereich: Inhalt scrollt, der Footer bleibt kleben */
.panel-scroll {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  scrollbar-width: thin;
}

.panel-footer {
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-top: 0.9rem;
  /* gläserner Verlauf: scrollender Inhalt scheint darunter durch */
  background: linear-gradient(
    to bottom,
    rgba(13, 21, 38, 0) 0%,
    rgba(13, 21, 38, 0.82) 32%,
    rgba(13, 21, 38, 0.94) 100%
  );
  backdrop-filter: blur(6px);
}

[data-theme="light"] .panel-footer {
  background: linear-gradient(
    to bottom,
    rgba(245, 247, 250, 0) 0%,
    rgba(245, 247, 250, 0.85) 32%,
    rgba(245, 247, 250, 0.96) 100%
  );
}

/* Einspaltig (mobil): Panel fließt normal mit, kein eigener Scroll */
@media (max-width: 900px) {
  .panel-body {
    max-height: none;
  }
  .panel-scroll {
    overflow-y: visible;
  }
}

.mode-row {
  display: flex;
  justify-content: flex-start;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

@media (max-width: 480px) {
  .field-grid {
    grid-template-columns: 1fr;
  }
}

.dropzone {
  border: 1.5px dashed var(--gl-border-medium);
  border-radius: var(--gl-radius-input);
  padding: 1rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
  transition:
    border-color 0.15s ease,
    background 0.15s ease;
}

/* Kompakte, einzeilige Variante (Studio-Panel) */
.dropzone--compact {
  flex-direction: row;
  justify-content: flex-start;
  gap: 0.6rem;
  padding: 0.55rem 0.8rem;
  text-align: left;
  cursor: pointer;
}

.dropzone-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--gl-icon-muted);
}

/* Kamera-Aufnahme: nur auf Touch-Geräten sichtbar (Desktop: redundant) */
.camera-btn {
  display: none;
  margin-left: auto;
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border: 1px solid var(--gl-border-subtle);
  border-radius: var(--gl-radius-xs);
  background: var(--gl-surface-2);
  color: var(--gl-icon-default);
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

.camera-btn svg {
  width: 17px;
  height: 17px;
  display: block;
}

@media (pointer: coarse) {
  .camera-btn {
    display: inline-flex;
  }
}

.dropzone-text {
  font-size: 0.82rem;
  line-height: 1.3;
}

.dropzone.is-over {
  border-color: var(--gl-color-primary);
  background: var(--gl-surface-2);
}

.thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.thumb {
  position: relative;
  width: 84px;
  height: 84px;
  border-radius: var(--gl-radius-sm);
  overflow: hidden;
  border: 1px solid var(--gl-border-subtle);
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  cursor: pointer;
  line-height: 1;
}

.thumb-kind {
  position: absolute;
  left: 2px;
  bottom: 2px;
  font-size: 0.6rem;
  background: rgba(0, 0, 0, 0.65);
  padding: 1px 5px;
  border-radius: 999px;
  color: #fff;
}

.canvas .empty-state {
  display: grid;
  place-items: center;
  min-height: 40vh;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.result-img {
  width: 100%;
  border-radius: var(--gl-radius-sm);
  display: block;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.6rem;
}

.btn-link {
  text-decoration: none;
  display: inline-flex;
}

/* --- Historie ------------------------------------------------------------- */

.history-wrap {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.history-toolbar {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.history-toolbar glk-select {
  width: 220px;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.history-card-btn {
  display: block;
  width: 100%;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
}

.history-card-btn img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--gl-radius-sm);
  display: block;
}

.history-card-meta {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-top: 0.5rem;
}

.history-prompt {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

/* --- Detail-Modal --------------------------------------------------------- */

.detail-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: min(92vw, 720px);
  /* Modal darf nie höher als der Viewport werden — sonst sind Inhalte
     (z.B. Tool-Formular) unerreichbar. */
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

.detail-img {
  width: 100%;
  max-height: 55vh;
  object-fit: contain;
  border-radius: var(--gl-radius-sm);
  background: rgba(0, 0, 0, 0.25);
}

.detail-meta {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.meta-row {
  display: flex;
  gap: 0.75rem;
  font-size: 0.88rem;
}

.meta-row > span:first-child {
  min-width: 150px;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tool-palette {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.tool-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.4rem;
}
