/* ============================================================
   Scriptbuilder – Style Guide
   Orientiert an: APPs/STYLE-GUIDE.md (Dailybase Design System)
   ============================================================ */

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

/* ── CSS VARIABLEN ── */
:root {
  /* Basis */
  --bg:           #f4f5f7;
  --surface:      #ffffff;
  --surface-warm: #fffcee;
  --border:       #e2e4e9;
  --text:         #1a1d23;
  --text-sec:     #6b7280;

  /* Navigation (linke Sidebar) */
  --nav-bg:       #1e2129;
  --nav-text:     #f0f1f3;
  --nav-border:   #2d3340;
  --nav-accent:   #3b82f6;

  /* Buttons */
  --btn-primary:  #1e2129;
  --btn-orange:   #f59e0b;
  --btn-green:    #10b981;
  --btn-red:      #b91c1c;
  --btn-blue:     #3b82f6;

  /* Typografie */
  --text-micro:   12px;
  --text-sm:      13px;
  --text-base:    14px;
  --text-md:      16px;
  --text-lg:      20px;

  /* Layout */
  --nav-width:    220px;
  --radius-btn:   6px;
  --radius-card:  8px;
  --radius-input: 7px;

  /* Font */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-size: var(--text-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   APP SHELL
   ============================================================ */

#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ============================================================
   SIDEBAR (Navigation / Verwaltung)
   ============================================================ */

#sidebar {
  width: var(--nav-width);
  background: var(--nav-bg);
  color: var(--nav-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid var(--nav-border);
  overflow: hidden;
}

.sb-header {
  padding: 18px 16px 12px;
  border-bottom: 1px solid var(--nav-border);
}

.sb-tool-name {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--nav-text);
  letter-spacing: -0.01em;
}

.sb-version {
  font-size: 10px;
  color: #9ca3af;
  margin-top: 2px;
}

.sb-status {
  padding: 10px 16px;
  font-size: var(--text-micro);
  color: #9ca3af;
  border-bottom: 1px solid var(--nav-border);
  min-height: 34px;
}

.sb-status.ok  { color: #10b981; }
.sb-status.err { color: #f87171; }

.sb-section {
  padding: 10px 16px 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #4b5563;
  border-bottom: 1px solid var(--nav-border);
}

.sb-footer {
  margin-top: auto;
  padding: 12px 16px;
  border-top: 1px solid var(--nav-border);
}

/* ============================================================
   MAIN AREA
   ============================================================ */

#main {
  flex: 1;
  display: grid;
  grid-template-columns: 200px 200px 200px 1fr;
  overflow: hidden;
}

/* ============================================================
   PANELS (3 Listen-Spalten)
   ============================================================ */

.panel {
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  padding: 10px 12px 9px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  background: var(--bg);
}

.panel-label {
  font-size: var(--text-micro);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-sec);
}

.panel-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-sec);
  background: var(--border);
  padding: 1px 7px;
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
}

.panel-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.panel-list::-webkit-scrollbar { width: 4px; }
.panel-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── STRUCTURE LIST ITEMS ── */
.list-item {
  padding: 7px 12px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.15s, border-color 0.15s;
  display: flex;
  align-items: center;
  gap: 7px;
  user-select: none;
}

.list-item:hover  { background: #f0f2f5; }
.list-item.active {
  background: #eff6ff;
  border-left-color: var(--btn-blue);
}

.list-item .item-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.list-item[data-level="modul"]     .item-dot { background: #3b82f6; }
.list-item[data-level="kapitel"]   .item-dot { background: #10b981; }
.list-item[data-level="teil"]      .item-dot { background: #f59e0b; }
.list-item[data-level="abschnitt"] .item-dot { background: #9ca3af; }

.list-item .item-title {
  font-size: var(--text-sm);
  color: var(--text);
  line-height: 1.35;
}
.list-item.active .item-title { color: #1d4ed8; font-weight: 500; }

.list-item .item-badge {
  margin-left: auto;
  font-size: 10px;
  color: var(--text-sec);
  flex-shrink: 0;
}

/* Einrückung nach Level */
.list-item[data-level="kapitel"]   { padding-left: 18px; }
.list-item[data-level="teil"]      { padding-left: 26px; }
.list-item[data-level="abschnitt"] { padding-left: 34px; }

.list-item[data-node-level="2"] { padding-left: 18px; }
.list-item[data-node-level="3"] { padding-left: 26px; }
.list-item[data-node-level="4"] { padding-left: 34px; }

/* ── BLOCK LIST ITEMS ── */
.block-item {
  padding: 8px 12px;
  cursor: pointer;
  border-left: 3px solid transparent;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s, border-color 0.15s;
}

.block-item:hover  { background: #f0f2f5; }
.block-item.active {
  background: #eff6ff;
  border-left-color: var(--btn-blue);
}

.block-aspekt {
  font-size: 11px;
  font-weight: 600;
  color: #d97706;
  margin-bottom: 2px;
}
.block-aspekt.empty {
  color: #9ca3af;
  font-weight: 400;
  font-style: italic;
}

.block-preview {
  font-size: var(--text-sm);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.block-meta {
  font-size: 10px;
  color: var(--text-sec);
  margin-top: 3px;
}

/* ============================================================
   EDITOR PANEL
   ============================================================ */

#editor-panel {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#editor-topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

#editor-topbar .editor-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
}

#editor-topbar .editor-id {
  font-size: 11px;
  color: var(--text-sec);
}

#editor-context {
  background: #eff6ff;
  border-bottom: 1px solid #dbeafe;
  padding: 7px 16px;
  flex-shrink: 0;
  display: none;
}

#editor-context .ctx-breadcrumb {
  font-size: 11px;
  color: #6b7280;
}
#editor-context .ctx-node {
  font-size: var(--text-sm);
  font-weight: 500;
  color: #1d4ed8;
  margin-top: 1px;
}

#editor-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 20px;
}
#editor-body::-webkit-scrollbar { width: 4px; }
#editor-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── EMPTY STATE ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 10px;
  color: var(--text-sec);
}
.empty-state i { color: #d1d5db; }
.empty-state .empty-msg {
  font-size: var(--text-sm);
  color: var(--text-sec);
}

/* ── LOADING ── */
.loading {
  padding: 16px 12px;
  font-size: var(--text-sm);
  color: var(--text-sec);
  text-align: center;
}

/* ── FIELDS ── */
.field-group { margin-bottom: 16px; }

.field-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-sec);
  margin-bottom: 5px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.field-label .hint {
  font-size: 10px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: #9ca3af;
}

input[type="text"],
input[type="number"],
textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  color: var(--text);
  font-family: inherit;
  font-size: var(--text-base);
  padding: 8px 10px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="text"]:focus,
input[type="number"]:focus,
textarea:focus {
  border-color: var(--btn-blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}

input[type="number"] { width: 80px; }

textarea#content-field {
  min-height: 300px;
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 12px;
  line-height: 1.7;
  resize: vertical;
}

.editor-row {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.editor-row .field-group       { flex: 1; }
.editor-row .field-group.narrow { flex: 0 0 80px; }

/* ── BUTTONS ── */
.btn-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  align-items: center;
}

.btn {
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  padding: 7px 14px;
  border-radius: var(--radius-btn);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  line-height: 1;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: var(--btn-primary);
  color: #fff;
  border-color: var(--btn-primary);
}
.btn-primary:hover:not(:disabled) { background: #2d3340; }

.btn-green {
  background: var(--btn-green);
  color: #fff;
  border-color: var(--btn-green);
}
.btn-green:hover:not(:disabled) { background: #059669; }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) { background: #f0f2f5; }

.btn-danger {
  background: transparent;
  color: var(--btn-red);
  border-color: var(--border);
  margin-left: auto;
}
.btn-danger:hover:not(:disabled) {
  background: #fef2f2;
  border-color: var(--btn-red);
}

/* ── DIVIDER ── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

/* ── TOAST ── */
#toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  padding: 10px 16px;
  font-size: var(--text-sm);
  color: var(--text);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 999;
}
#toast.show    { opacity: 1; transform: translateY(0); }
#toast.success { border-color: var(--btn-green); color: var(--btn-green); }
#toast.error   { border-color: var(--btn-red);   color: var(--btn-red); }

/* ── DOT ANIMATION ── */
.dot-anim::after {
  content: '...';
  animation: dots 1.2s steps(4, end) infinite;
}
@keyframes dots {
  0%, 20%  { content: '.';   }
  40%      { content: '..';  }
  60%,100% { content: '...'; }
}
