:root {
  color-scheme: light dark;
  --bg-1: #eef6ec;
  --bg-2: #dcefe0;
  --card-bg: rgba(255, 255, 255, 0.72);
  --card-border: rgba(255, 255, 255, 0.6);
  --text: #16241a;
  --muted: #5b6f5e;
  --border: #d3e4d2;
  --accent: #2f9e5c;
  --accent-dark: #227a45;
  --accent-soft: rgba(47, 158, 92, 0.12);
  --danger: #d64545;
  --shadow: 0 8px 30px rgba(24, 60, 34, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-1: #0e1712;
    --bg-2: #142219;
    --card-bg: rgba(24, 38, 28, 0.7);
    --card-border: rgba(255, 255, 255, 0.08);
    --text: #eaf3ec;
    --muted: #9db6a2;
    --border: #253a2b;
    --accent: #47c47e;
    --accent-dark: #6fe0a2;
    --accent-soft: rgba(71, 196, 126, 0.16);
    --danger: #ff6b6b;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  --bg-1: #0e1712;
  --bg-2: #142219;
  --card-bg: rgba(24, 38, 28, 0.7);
  --card-border: rgba(255, 255, 255, 0.08);
  --text: #eaf3ec;
  --muted: #9db6a2;
  --border: #253a2b;
  --accent: #47c47e;
  --accent-dark: #6fe0a2;
  --accent-soft: rgba(71, 196, 126, 0.16);
  --danger: #ff6b6b;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

:root[data-theme="light"] {
  --bg-1: #eef6ec;
  --bg-2: #dcefe0;
  --card-bg: rgba(255, 255, 255, 0.72);
  --card-border: rgba(255, 255, 255, 0.6);
  --text: #16241a;
  --muted: #5b6f5e;
  --border: #d3e4d2;
  --accent: #2f9e5c;
  --accent-dark: #227a45;
  --accent-soft: rgba(47, 158, 92, 0.12);
  --danger: #d64545;
  --shadow: 0 8px 30px rgba(24, 60, 34, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  display: flex;
  justify-content: center;
  padding: 3rem 1rem;
  background:
    radial-gradient(1100px 500px at 15% -10%, var(--accent-soft), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, var(--accent-soft), transparent 55%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2));
  background-attachment: fixed;
}

body.no-scroll {
  overflow: hidden;
}

.wrap {
  width: 100%;
  max-width: 680px;
}

h1 {
  font-size: 1.5rem;
  margin: 0 0 0.15rem;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

h1::before {
  content: "🌱";
  font-size: 1.2em;
  filter: drop-shadow(0 2px 6px rgba(47, 158, 92, 0.35));
}

.tagline {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.3rem 0 0;
}

.tagline #versionStamp {
  opacity: 0.7;
  font-size: 0.9em;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  padding: 1.6rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.3rem;
  margin-top: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

input, textarea, select {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.95rem;
  background: rgba(255, 255, 255, 0.35);
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

:root[data-theme="dark"] input, :root[data-theme="dark"] textarea, :root[data-theme="dark"] select {
  background: rgba(255, 255, 255, 0.04);
}
@media (prefers-color-scheme: dark) {
  input, textarea, select { background: rgba(255, 255, 255, 0.04); }
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Die aufgeklappte <option>-Liste eines <select> ist ein natives, vom
   Browser gezeichnetes Popup, das die (halb-transparenten) --card-bg-
   Farben der Seite nicht zuverlaessig uebernimmt - ohne das hier waren
   Options im Dark Mode teils helle Schrift auf hellem (statt dunklem)
   Popup-Hintergrund und dadurch unlesbar. Deckende Farben statt der
   sonst ueblichen rgba()-Transparenz, weil Browser genau das fuer
   <option> zuverlaessig respektieren. */
select option {
  background-color: var(--bg-2);
  color: var(--text);
}

.branch-field {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}
.branch-field select {
  flex: 1;
}
.branch-field button {
  margin-top: 0;
  padding: 0.6rem 0.8rem;
  flex: 0 0 auto;
}

textarea {
  resize: vertical;
}

button {
  margin-top: 1.1rem;
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: white;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(47, 158, 92, 0.28);
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

button:active {
  transform: translateY(0);
}

button.secondary {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  box-shadow: none;
}

button.danger {
  background: linear-gradient(135deg, var(--danger), #a83232);
  box-shadow: 0 4px 14px rgba(214, 69, 69, 0.28);
}

button.danger-link {
  background: transparent;
  color: var(--danger);
  border: none;
  box-shadow: none;
  padding: 0.4rem 0.2rem;
  font-size: 0.8rem;
  font-weight: 500;
  text-decoration: underline;
  opacity: 0.75;
}

button.danger-link:hover {
  opacity: 1;
  transform: none;
  filter: none;
}

.tabs-nav {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  /* Verstecke Scrollbar wenn nicht nötig (4 Tabs passen immer auf normalen Screen) */
  scrollbar-width: none;
}

.tabs-nav::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  margin: 0;
  margin-bottom: -2px;
  padding: 0.7rem 1rem;
  background: transparent;
  color: var(--muted);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  box-shadow: none;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.tab-btn:hover {
  color: var(--text);
  transform: none;
  filter: none;
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.app-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.app-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.4);
  border: 1px solid var(--border);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

:root[data-theme="dark"] .app-row {
  background: rgba(255, 255, 255, 0.03);
}
@media (prefers-color-scheme: dark) {
  .app-row { background: rgba(255, 255, 255, 0.03); }
}

.app-row:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(24, 60, 34, 0.1);
  border-color: var(--accent);
}

.app-icon {
  font-size: 1.6rem;
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  border-radius: 12px;
}

.app-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.app-sync {
  font-size: 0.72rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 0.1rem;
}

.app-sync-error {
  color: var(--danger);
}

.app-name {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.01em;
}

.app-repo {
  font-size: 0.8rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.branch-pill {
  align-self: flex-start;
  margin-top: 0.15rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent-dark);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
}

.app-open {
  flex-shrink: 0;
  color: var(--accent-dark);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.85rem;
  white-space: nowrap;
}

.app-open:hover {
  text-decoration: underline;
}

.row-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.row-actions button {
  margin: 0;
  padding: 0.4rem 0.85rem;
  font-size: 0.78rem;
  box-shadow: none;
  white-space: nowrap;
}

#specCard summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  list-style: none;
}

#specCard summary::-webkit-details-marker {
  display: none;
}

#specCard summary::before {
  content: "▸ ";
  color: var(--accent);
}

#specCard details[open] summary::before {
  content: "▾ ";
}

.spec-output {
  margin: 0.85rem 0;
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem 1rem;
  font-family: "SF Mono", "Fira Code", Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.5;
  white-space: pre-wrap;
  max-height: 400px;
  overflow: auto;
}

:root[data-theme="dark"] .spec-output {
  background: rgba(255, 255, 255, 0.04);
}
@media (prefers-color-scheme: dark) {
  .spec-output { background: rgba(255, 255, 255, 0.04); }
}

.log-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 0.9rem;
  margin-bottom: 0.85rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: normal;
  color: var(--text);
  margin: 0;
  cursor: pointer;
}

.turbo-apps-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  padding: 0.75rem 0.9rem;
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 0.5rem;
}

:root[data-theme="dark"] .turbo-apps-list {
  background: rgba(255, 255, 255, 0.04);
}
@media (prefers-color-scheme: dark) {
  .turbo-apps-list { background: rgba(255, 255, 255, 0.04); }
}

.checkbox-label input[type="checkbox"] {
  width: auto;
  accent-color: var(--accent);
  cursor: pointer;
}

.log-controls select {
  width: auto;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.35);
  color: var(--text);
  font-size: 0.85rem;
}

.log-controls #logSearch {
  flex: 1;
  min-width: 160px;
}

.log-controls button {
  margin: 0;
  padding: 0.4rem 0.85rem;
  font-size: 0.85rem;
}

.log-output {
  margin: 0;
  background: #0d1512;
  color: #c9e8d3;
  border-radius: 12px;
  padding: 0.9rem 1rem;
  font-family: "SF Mono", "Fira Code", Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.5;
  max-height: 420px;
  overflow: auto;
  white-space: pre;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.log-output.wrap {
  white-space: pre-wrap;
  word-break: break-word;
}

.log-line-error {
  color: #ff8a8a;
}

.log-line-warn {
  color: #ffcf6b;
}

.log-line-restart {
  color: #7ab8ff;
}

.log-line-success {
  color: #7be0a0;
}

/* "position: relative; left: 50%; margin-left: -50vw" haette hier NICHT
   funktioniert: Prozentwerte fuer "left"/"margin" beziehen sich auf die
   Breite des Containing Blocks - das ist hier ".wrap" (max. 680px), nicht
   der Viewport. "position: fixed" loest das sauber, weil es sich immer am
   Viewport orientiert, unabhaengig von verschachtelten Eltern-Containern. */
#logs-tab.fullwidth {
  position: fixed;
  /* "inset: 0" (top/right/bottom/left: 0) allein spannt eine fixierte Box
     bereits exakt ueber den Viewport. */
  inset: 0;
  max-width: none;
  margin: 0;
  border-radius: 0;
  z-index: 1000;
  padding: 1.6rem;
  /* NICHT "auto": die Karte selbst soll nicht scrollen, sonst scrollen die
     Controls (Auto-Refresh etc.) oben mit weg - nur ".log-output" darunter
     soll scrollbar sein. */
  overflow: hidden;
  box-sizing: border-box;
  display: block;
}

/* Nach mehreren gescheiterten Anlaeufen mit Flexbox-Stretch (align-items,
   flex:1, min-height/min-width:0 - diverse Browser/Umgebungen haben das
   trotzdem unterschiedlich/gar nicht sauber gerendert, Scrollbars blieben
   verschwunden) jetzt bewusst OHNE Flex-Layout: die Hoehe von ".log-output"
   wird explizit ueber "calc(100vh - ...)" berechnet (Platz fuer Titel,
   Controls-Zeile und Meta-Zeile darunter abgezogen) statt sich auf
   Flex-Grow/Stretch-Verhalten zu verlassen - deterministisch, keine
   Ratespiele mit Flex-Kindern mehr. */
#logs-tab.fullwidth .log-output {
  display: block;
  width: 100%;
  box-sizing: border-box;
  height: calc(100vh - 13rem);
  max-height: none;
  overflow: auto;
}

@media (max-width: 560px) {
  .app-row {
    flex-wrap: wrap;
  }
  .app-info {
    flex-basis: 100%;
    order: -1;
  }
}

.error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 0.5rem;
  min-height: 1.1rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.topbar > div {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.topbar button {
  margin-top: 0;
}

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