/* style.css – makerSpaceOS · KidsLab-Theme */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --header-h:   64px;
  --panel-w:    452px;

  /* Oberflächen – hell, warm */
  --bg:          #FBF8F3;   /* Papier */
  --bg-alt:      #F3EDE1;
  --surface:     #ffffff;
  --line:        #E5DFD0;   /* warme Haarlinie */
  --line-strong: #1a1a1a;   /* Sticker-Outline */

  /* Text */
  --text:        #111111;
  --text-muted:  #64748b;
  --text-subtle: #94a3b8;

  /* Crayon-Markenpalette */
  --brand-orange:#F39A1B; --brand-purple:#A57BC3; --brand-coral:#E98685;
  --brand-teal:  #4AB8A6; --brand-sky:   #4FBFE8; --brand-yellow:#F7D94C;
  --brand-red:   #E24D3D; --brand-blue:  #2563eb;

  /* Rollen */
  --accent:      #4AB8A6;   /* primäre "Ausführen"-Aktion */
  --danger:      #E24D3D;
  --purple:      #A57BC3;

  /* Dunkles Code-Panel (bleibt dunkel) */
  --code-bg:    #0f172a;
  --code-bar:   #16213e;
  --code-line:  #243049;
  --serial-bg:  #0d1117;
  --serial-fg:  #a5d6a7;

  --font-body:   'Inter', system-ui, sans-serif;
  --font-display:'Pixelify Sans', ui-rounded, cursive, system-ui;
  --font-mono:   'monofur', 'JetBrains Mono', ui-monospace, monospace;

  --radius-sm:6px; --radius-md:8px; --radius-lg:12px; --radius-pill:999px;
  --ease-out: cubic-bezier(.2,.7,.2,1);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  overflow: hidden;
}

/* ── Header ──────────────────────────────────────────────────────────────── */

#header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 3px solid var(--line-strong);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  gap: 16px;
  flex-shrink: 0;
  z-index: 10;
}

.logo { display: flex; align-items: center; gap: 14px; }
.logo-img { height: 30px; width: auto; display: block; }
.logo-divider { width: 1.5px; height: 30px; background: var(--line); }
.logo-titles { display: flex; flex-direction: column; line-height: 1; gap: 3px; }
.logo-text {
  font-family: var(--font-display);
  font-size: 21px; font-weight: 600; color: var(--text); letter-spacing: .2px;
}
.logo-sub {
  font-size: 10.5px; font-weight: 600; letter-spacing: .4px;
  color: var(--text-muted); text-transform: uppercase;
}

.connection-area { display: flex; align-items: center; gap: 10px; }
.header-divider { width: 1.5px; height: 26px; background: var(--line); margin: 0 2px; }

.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 13px;
  border-radius: var(--radius-pill);
  background: var(--surface);
  border: 1.5px solid var(--line);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.status-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--text-subtle);
  transition: background .3s, box-shadow .3s;
}
.status-dot.connected {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(74,184,166,.25);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 13px;
  border: 1.5px solid transparent;
  border-radius: 9px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: transform .12s var(--ease-out), box-shadow .12s, border-color .12s, background .12s;
}
.btn svg { width: 17px; height: 17px; flex-shrink: 0; }
.btn:disabled { cursor: not-allowed; }

/* Ghost – weiß + Haarlinie */
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn-ghost:not(:disabled):hover { border-color: var(--line-strong); transform: translateY(-1px); }

/* Sticker-Primäraktion (Verbinden / Ausführen) */
.btn-primary, .btn-warning {
  background: var(--accent);
  color: #0d2b27;
  border-color: var(--line-strong);
  font-weight: 700;
  box-shadow: 2px 2px 0 var(--line-strong);
}
.btn-primary:not(:disabled):hover, .btn-warning:not(:disabled):hover {
  transform: translate(-1px,-1px); box-shadow: 3px 3px 0 var(--line-strong);
}
.btn-primary:not(:disabled):active, .btn-warning:not(:disabled):active {
  transform: translate(1px,1px); box-shadow: 1px 1px 0 var(--line-strong);
}
.btn-primary:disabled, .btn-warning:disabled { opacity: .38; box-shadow: none; }

/* Gefahr (Stopp) */
.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: rgba(0,0,0,.15);
  font-weight: 700;
}
.btn-danger:not(:disabled):hover { transform: translateY(-1px); }
.btn-danger:disabled { opacity: .38; }

/* KI-Block – lila Outline */
.btn-ai {
  background: var(--surface);
  color: var(--purple);
  border-color: var(--purple);
  font-weight: 700;
}
.btn-ai:not(:disabled):hover { background: #f6f0fa; transform: translateY(-1px); }

/* Icon-Buttons (in den dunklen Panel-Headern) */
.btn-icon {
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: #94a3b8;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.btn-icon svg { width: 17px; height: 17px; }
.btn-icon:hover  { color: #e2e8f0; background: rgba(255,255,255,.08); }
.btn-icon.active { color: var(--accent); }

/* ── Haupt-Layout ────────────────────────────────────────────────────────── */

#main {
  display: flex;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

/* ── Blockly-Panel ───────────────────────────────────────────────────────── */

#blockly-panel {
  flex: 1 1 auto;
  min-width: 0;
  position: relative;
  background: var(--bg);
}
#blockly-workspace { position: absolute; inset: 0; }

/* ── Resize-Divider ──────────────────────────────────────────────────────── */

#divider {
  width: 5px;
  background: var(--line);
  cursor: col-resize;
  flex-shrink: 0;
  transition: background .15s;
}
#divider:hover { background: var(--accent); }

/* Serial-Monitor vertikal verschiebbar */
#serial-divider {
  height: 6px;
  flex-shrink: 0;
  cursor: row-resize;
  background: var(--code-line);
  border-top: 1px solid var(--code-bg);
  transition: background .15s;
}
#serial-divider:hover { background: var(--accent); }

/* Code-Editor ausgeblendet: Serial füllt den Platz */
#code-panel.code-collapsed #code-editor-wrapper,
#code-panel.code-collapsed #serial-divider { display: none; }
#code-panel.code-collapsed #serial-output { flex: 1 1 0; }

/* Ausblend-Button: Chevron gedreht im aktiven Zustand */
#btn-toggle-code svg { transition: transform .15s; }
#btn-toggle-code.active svg { transform: rotate(-180deg); }

/* ── Code-Panel (dunkel) ─────────────────────────────────────────────────── */

#code-panel {
  width: var(--panel-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--code-bg);
  border-left: 1.5px solid var(--line-strong);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--code-bar);
  border-bottom: 1px solid var(--code-line);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: #7dd3fc;
  flex-shrink: 0;
}
.panel-actions { display: flex; gap: 4px; }

/* ── CodeMirror ──────────────────────────────────────────────────────────── */

#code-editor-wrapper { flex: 1 1 0; min-height: 0; overflow: hidden; }

.CodeMirror {
  height: 100% !important;
  font-family: var(--font-mono) !important;
  font-size: 15px !important;
  line-height: 1.7 !important;
}

/* ── Serieller Monitor (dunkel) ──────────────────────────────────────────── */

#serial-output {
  flex: 0 0 160px;
  overflow-y: auto;
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.65;
  color: var(--serial-fg);
  background: var(--serial-bg);
  border-top: 1px solid var(--code-line);
  white-space: pre-wrap;
  word-break: break-all;
}

#serial-input-row {
  display: flex;
  gap: 8px;
  padding: 10px;
  background: var(--code-bg);
  border-top: 1px solid var(--code-line);
  flex-shrink: 0;
}
#serial-input {
  flex: 1;
  background: var(--serial-bg);
  border: 1.5px solid var(--code-line);
  border-radius: 7px;
  color: #e2e8f0;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 7px 11px;
  outline: none;
  transition: border-color .12s;
}
#serial-input:focus { border-color: var(--accent); }
#serial-input:disabled { opacity: .4; }

#btn-send {
  background: none;
  color: #94a3b8;
  border: 1.5px solid var(--code-line);
  font-weight: 600;
}
#btn-send:not(:disabled):hover { border-color: var(--accent); color: #e2e8f0; transform: none; }

/* ── Toast ───────────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--surface);
  color: var(--text);
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 2px 12px rgba(17,17,17,.18);
  border-left: 4px solid var(--text-subtle);
  transition: transform .3s var(--ease-out), opacity .3s;
  opacity: 0;
  z-index: 100;
  pointer-events: none;
}
.toast.show  { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.ok    { border-left-color: var(--accent); }
.toast.warn  { border-left-color: var(--brand-orange); }
.toast.error { border-left-color: var(--danger); }

/* ── Responsive Overhaul ────────────────────────────────────────────────── */

@media (max-width: 1024px) {
  :root {
    --panel-w: 350px;
  }
}

@media (max-width: 768px) {
  #header {
    height: auto;
    flex-direction: column;
    padding: 12px;
    gap: 12px;
    text-align: center;
  }

  .logo {
    justify-content: center;
  }

  .connection-area {
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
  }

  .header-divider {
    display: none;
  }

  #main {
    flex-direction: column;
  }

  #divider {
    display: none; /* Disable resize divider on mobile for simplicity */
  }

  #code-panel {
    width: 100% !important;
    height: 40vh;
    border-left: none;
    border-top: 3px solid var(--line-strong);
  }

  #blockly-panel {
    height: 60vh;
  }

  .btn {
    padding: 10px 16px;
    font-size: 14px;
  }

  #ai-drawer, #history-drawer {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .logo-titles {
    display: none; /* Hide sub-titles on very small screens to save space */
  }
  
  .logo-img {
    height: 24px;
  }

  .status-indicator {
    font-size: 11px;
    padding: 4px 8px;
  }
}

/* ── Drawer (KI + Verlauf, hell) ─────────────────────────────────────────── */

#ai-drawer, #history-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 420px;
  height: 100vh;
  background: var(--surface);
  border-left: 1.5px solid var(--line);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .25s var(--ease-out);
  z-index: 200;
  box-shadow: -4px 0 24px rgba(17,17,17,.12);
}
#history-drawer { width: 440px; }
#ai-drawer.open, #history-drawer.open { transform: translateX(0); }

#ai-overlay, #history-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(17,17,17,.25);
  z-index: 199;
}
#ai-overlay.show, #history-overlay.show { display: block; }

#history-list { padding: 12px 14px; overflow-y: auto; flex: 1; }
.history-io-bar { display: flex; gap: 8px; padding: 10px 16px 4px; border-bottom: 1px solid var(--line); }
.history-io-bar .btn { flex: 1; justify-content: center; }
.history-empty { color: var(--text-muted); font-size: 13px; line-height: 1.5; }
.history-item {
  background: var(--bg-alt);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  margin-bottom: 8px;
}
.history-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.history-ts { font-size: 12px; color: var(--text); font-weight: 600; }
.history-preview {
  margin: 6px 0 0;
  padding: 8px 10px;
  background: var(--code-bg);
  color: #e2e8f0;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11px;
  white-space: pre-wrap;
  overflow-x: auto;
  max-height: 80px;
}
.btn-sm { padding: 4px 10px; font-size: 12px; }

.diff-add  { color: #86efac; display: block; }
.diff-rem  { color: #fca5a5; display: block; }
.diff-eq   { color: var(--text-muted); display: block; font-style: italic; }
.diff-more { color: var(--text-muted); display: block; font-style: italic; }

/* KI-Einstellungen */
#ai-settings {
  padding: 10px 14px;
  background: var(--bg-alt);
  border-bottom: 1.5px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#ai-settings label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  font-weight: 600;
}
#ai-settings input {
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px;
  padding: 6px 9px;
  outline: none;
  font-family: var(--font-mono);
  transition: border-color .12s;
}
#ai-settings input:focus { border-color: var(--accent); }
#ai-save-btn {
  align-self: flex-end;
  padding: 6px 13px;
  background: var(--accent);
  color: #0d2b27;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--line-strong);
  transition: transform .12s var(--ease-out), box-shadow .12s;
}
#ai-save-btn:hover { transform: translate(-1px,-1px); box-shadow: 3px 3px 0 var(--line-strong); }

/* Chat-Verlauf */
#ai-messages {
  flex: 1 1 0;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ai-msg-user {
  align-self: flex-end;
  background: var(--accent);
  color: #0d2b27;
  border-radius: 12px 12px 2px 12px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  max-width: 85%;
}
.ai-msg-bot {
  align-self: flex-start;
  background: var(--bg-alt);
  border: 1.5px solid var(--line);
  border-radius: 12px 12px 12px 2px;
  padding: 10px 12px;
  font-size: 13px;
  max-width: 95%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ai-msg-bot .ai-block-label { font-weight: 700; font-size: 14px; color: var(--text); }
.ai-msg-bot pre {
  background: var(--code-bg);
  border-radius: var(--radius-sm);
  padding: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  overflow-x: auto;
  max-height: 140px;
  overflow-y: auto;
  color: var(--serial-fg);
}
.ai-msg-bot .ai-actions { display: flex; gap: 6px; }
.ai-add-btn {
  padding: 5px 11px;
  background: var(--accent);
  color: #0d2b27;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.ai-add-btn:hover { transform: translateY(-1px); }
.ai-add-btn:disabled { opacity: .4; cursor: default; }
.ai-del-btn {
  padding: 5px 11px;
  background: var(--surface);
  color: var(--text-muted);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
}
.ai-del-btn:hover { color: var(--danger); border-color: var(--danger); }

.ai-msg-error {
  align-self: flex-start;
  background: rgba(226,77,61,.1);
  border: 1.5px solid var(--danger);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-size: 12px;
  color: #b5403f;
  max-width: 95%;
}
.ai-msg-thinking {
  align-self: flex-start;
  color: var(--text-muted);
  font-size: 12px;
  font-style: italic;
  animation: ai-pulse 1.2s ease-in-out infinite;
}
@keyframes ai-pulse { 0%,100% { opacity: .5; } 50% { opacity: 1; } }

/* KI-Eingabe */
#ai-input-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  border-top: 1.5px solid var(--line);
  flex-shrink: 0;
}
#ai-input {
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 13px;
  padding: 8px 11px;
  outline: none;
  resize: none;
  font-family: var(--font-body);
  line-height: 1.4;
  transition: border-color .12s;
}
#ai-input:focus { border-color: var(--accent); }
#ai-send-btn {
  align-self: flex-end;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--accent);
  color: #0d2b27;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--line-strong);
  transition: transform .12s var(--ease-out), box-shadow .12s;
}
#ai-send-btn svg { width: 16px; height: 16px; }
#ai-send-btn:hover:not(:disabled) { transform: translate(-1px,-1px); box-shadow: 3px 3px 0 var(--line-strong); }
#ai-send-btn:disabled { opacity: .4; cursor: default; box-shadow: none; }

/* ── Blockly-Anpassungen (helles Theme) ──────────────────────────────────── */

.blocklyToolboxDiv {
  background: var(--surface) !important;
  border-right: 1.5px solid var(--line) !important;
  padding: 10px 8px !important;
}
.blocklyToolboxDiv::before {
  content: 'Bausteine';
  display: block;
  padding: 4px 8px 10px;
  font: 700 10.5px/1 var(--font-body);
  letter-spacing: .6px; text-transform: uppercase; color: #94a3b8;
}
.blocklyTreeRow {
  display: flex !important; align-items: center;
  padding: 8px 10px !important; margin-bottom: 2px;
  border-radius: 8px !important;
  border: 1.5px solid transparent !important;
  transition: transform .1s cubic-bezier(.2,.7,.2,1);
}
.blocklyTreeRow:hover {
  transform: translateX(2px);
  background-color: rgba(74,184,166,.10) !important;
}
.blocklyTreeRow.blocklyTreeSelected {
  background-color: rgba(74,184,166,.16) !important;
  border-color: rgba(74,184,166,.4) !important;
}
.cb-cat-square {
  display: inline-block;
  width: 13px; height: 13px; flex-shrink: 0;
  margin-right: 10px;
  vertical-align: middle;
  border-radius: 4px;
  border: 1.5px solid rgba(0,0,0,.22);
}
.blocklyTreeLabel { color: #1e293b !important; font-size: 13.5px !important; font-weight: 600 !important; }

/* Zelos: Flyout-Panel */
.blocklyFlyout           { filter: drop-shadow(2px 0 8px rgba(17,17,17,.12)); }
.blocklyFlyoutBackground { fill: var(--bg-alt) !important; }

/* Blöcke: Schriftgröße für Lesbarkeit */
.blocklyText      { font-size: 13px !important; }
.blocklyHtmlInput { font-size: 13px !important; }

/* Zelos: farbige Hinterleuchtung beim Hover */
.blocklyDraggable:hover > .blocklyPath { filter: brightness(1.06); }

/* Workspace-Hintergrund */
.blocklyMainBackground { fill: var(--bg) !important; }

/* Pin-Dropdown: Höhe begrenzen → Grove-Anschlüsse zuerst sichtbar, Einzel-Pins per Scroll */
.blocklyDropDownContent { max-height: 300px; overflow-y: auto; }
