/* Studio Mapa v5.6.0 — Design System Studio Apps V5 (100% tokenized, zero hex solto) */
*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100dvh;
  overflow: hidden;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  line-height: 1.45;
  background: var(--kf-surface-canvas);
  color: var(--kf-text-primary);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--kf-border-focus) transparent;
}
*::-webkit-scrollbar {
  width: 3px;
  height: 3px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background: var(--kf-border-focus);
  border-radius: 3px;
}

.kf-header {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 56px;
  flex: 0 0 56px;
  padding: 0 14px;
  background: var(--kf-surface-card);
  border-bottom: 0.8px solid var(--kf-border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: nowrap;
}

.kf-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-shrink: 0;
  cursor: pointer;
  user-select: none;
}

.kf-squircle {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--kf-app-brand);
  color: var(--kf-brand-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.kf-brand-title {
  font-size: 14px;
  letter-spacing: -0.02em;
  color: var(--kf-text-primary);
  white-space: nowrap;
}

.kf-brand-title strong { font-weight: 900; }
.kf-brand-title span { font-weight: 300; margin-left: 2px; }

.kf-nav-tabs {
  display: flex;
  align-items: stretch;
  gap: 4px;
  height: 56px;
  min-width: 0;
}

.kf-nav-tab {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--kf-text-secondary);
  font-size: 12.5px;
  font-weight: 500;
  padding: 0 12px;
  height: 56px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.16s ease, border-color 0.16s ease;
  white-space: nowrap;
}

.kf-nav-tab:hover { color: var(--kf-text-primary); }
.kf-nav-tab.active {
  color: var(--kf-app-brand-text);
  border-bottom-color: var(--kf-app-brand);
  font-weight: 600;
}

.kf-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 6px;
  border: 0.8px solid var(--kf-border-subtle);
  background: var(--kf-surface-card);
  color: var(--kf-text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease;
  flex-shrink: 0;
}

.icon-btn:hover {
  border-color: var(--kf-app-brand);
  background: var(--kf-surface-subtle);
}

.icon-btn-theme { width: 32px; height: 32px; }

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 30px;
  padding: 0 10px;
  border-radius: 6px;
  border: 0.8px solid var(--kf-border-subtle);
  background: var(--kf-surface-card);
  color: var(--kf-text-primary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

a.btn { text-decoration: none; }
.btn:hover { border-color: var(--kf-app-brand); background: var(--kf-surface-subtle); }
.btn-sm { height: 28px; padding: 0 8px; font-size: 12px; }

.btn-primary {
  background: var(--kf-border-strong);
  border-color: var(--kf-border-strong);
  color: var(--kf-surface-card);
}
.btn-primary:hover {
  background: var(--kf-app-brand);
  border-color: var(--kf-app-brand);
  color: var(--kf-brand-ink);
}

.btn-danger {
  background: var(--kf-status-crit-bg);
  border-color: var(--kf-status-crit-border);
  color: var(--kf-status-crit-text);
}
.btn-danger:hover {
  background: var(--kf-danger-hover-bg);
  border-color: var(--kf-danger-hover-bg);
  color: var(--kf-danger-hover-text);
}

.btn-accent-soft {
  background: var(--kf-app-brand-soft);
  border-color: var(--kf-app-brand);
  color: var(--kf-app-brand-text);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 0.8px solid var(--kf-border-subtle);
  background: var(--kf-surface-subtle);
  color: var(--kf-text-secondary);
  white-space: nowrap;
}
.badge-ok { background: var(--kf-status-ok-bg); color: var(--kf-status-ok-text); border-color: var(--kf-status-ok-border); }
.badge-warn { background: var(--kf-status-warn-bg); color: var(--kf-status-warn-text); border-color: var(--kf-status-warn-border); }
.badge-crit { background: var(--kf-status-crit-bg); color: var(--kf-status-crit-text); border-color: var(--kf-status-crit-border); }
.badge-brand { background: var(--kf-app-brand-soft); color: var(--kf-app-brand-text); border-color: var(--kf-app-brand); }

.kf-main {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 10px 14px;
}

.tab-panel { display: none; flex: 1 1 auto; min-height: 0; overflow: hidden; }
.tab-panel.active { display: flex; flex-direction: column; gap: 8px; }

.studio-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
  padding: 6px 10px;
  background: var(--kf-surface-card);
  border: 0.8px solid var(--kf-border-subtle);
  border-radius: 8px;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  min-width: 0;
}

.studio-grid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 290px;
  gap: 10px;
}

.canvas-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: var(--kf-surface-card);
  border: 0.8px solid var(--kf-border-subtle);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#mapCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#mapCanvas.grabbing { cursor: grabbing; }
#mapCanvas.crosshair { cursor: crosshair; }

/* Miro-style left floating tool rail */
.miro-rail {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 6;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 5px;
  background: var(--kf-surface-card);
  border: 0.8px solid var(--kf-border-subtle);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

.rail-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 6px;
  border: 0.8px solid transparent;
  background: transparent;
  color: var(--kf-text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}

.rail-btn:hover {
  background: var(--kf-surface-subtle);
  color: var(--kf-text-primary);
  border-color: var(--kf-border-subtle);
}

.rail-btn.active {
  background: var(--kf-app-brand-soft);
  color: var(--kf-app-brand-text);
  border-color: var(--kf-app-brand);
}

.rail-btn.recording {
  background: var(--kf-status-crit-bg);
  color: var(--kf-status-crit-text);
  border-color: var(--kf-status-crit-border);
}

/* Inline floating editor over canvas node */
.inline-editor {
  position: absolute;
  z-index: 9;
  display: none;
  min-width: 150px;
  max-width: 240px;
  height: 30px;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1.5px solid var(--kf-app-brand);
  background: var(--kf-surface-card);
  color: var(--kf-text-primary);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  text-align: center;
  outline: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}

/* Minimap bottom-right */
.minimap-box {
  position: absolute;
  right: 10px;
  bottom: 44px;
  z-index: 6;
  width: 148px;
  height: 92px;
  background: var(--kf-surface-card);
  border: 0.8px solid var(--kf-border-subtle);
  border-radius: 7px;
  overflow: hidden;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.06);
  cursor: pointer;
}

#minimapCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Presentation Walkthrough HUD */
.present-bar {
  position: absolute;
  left: 50%;
  bottom: 46px;
  transform: translateX(-50%);
  z-index: 7;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  background: var(--kf-surface-card);
  border: 0.8px solid var(--kf-app-brand);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.09);
}
.present-bar.open { display: flex; }

.canvas-hud-top {
  position: absolute;
  top: 8px;
  left: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
  z-index: 5;
}
.canvas-hud-top > * { pointer-events: auto; }

.canvas-hud-bottom {
  position: absolute;
  bottom: 8px;
  left: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
  z-index: 5;
}
.canvas-hud-bottom > * { pointer-events: auto; }

.hud-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--kf-surface-card);
  border: 0.8px solid var(--kf-border-subtle);
  font-size: 11.5px;
  color: var(--kf-text-secondary);
}

.inspector-card {
  background: var(--kf-surface-card);
  border: 0.8px solid var(--kf-border-subtle);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--kf-text-primary);
  padding-bottom: 6px;
  border-bottom: 0.8px solid var(--kf-border-subtle);
}

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 11.5px; font-weight: 600; color: var(--kf-text-secondary); }

.input, .select, .textarea {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  border-radius: 6px;
  border: 0.8px solid var(--kf-border-subtle);
  background: var(--kf-surface-subtle);
  color: var(--kf-text-primary);
  font-family: inherit;
  font-size: 12.5px;
  padding: 5px 8px;
  outline: none;
  transition: border-color 0.16s ease, background 0.16s ease;
}
.input, .select { height: 30px; }
.select { overflow: hidden; text-overflow: ellipsis; }
.textarea { resize: vertical; min-height: 58px; }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--kf-app-brand);
  background: var(--kf-surface-card);
}

.pw-wrap { position: relative; display: flex; align-items: center; }
.pw-wrap .input { padding-right: 34px; }
.kfw-eye {
  position: absolute;
  right: 4px;
  width: 26px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--kf-text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 4px;
}
.kfw-eye:hover { color: var(--kf-text-primary); background: var(--kf-surface-hover); }

.swatch-row { display: flex; align-items: center; gap: 6px; }
.swatch-btn {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  border: 0.8px solid var(--kf-border-subtle);
  background: var(--kf-surface-subtle);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--kf-text-primary);
}
.swatch-btn.active { border-color: var(--kf-border-strong); box-shadow: 0 0 0 1.5px var(--kf-app-brand); }

.recall-box {
  padding: 8px;
  border-radius: 6px;
  border: 0.8px solid var(--kf-border-subtle);
  background: var(--kf-surface-subtle);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stats-mini { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.stat-tile {
  padding: 5px;
  border-radius: 6px;
  background: var(--kf-surface-subtle);
  border: 0.8px solid var(--kf-border-subtle);
  text-align: center;
}
.stat-val { font-size: 13.5px; font-weight: 700; color: var(--kf-app-brand-text); }
.stat-lbl { font-size: 10.5px; color: var(--kf-text-tertiary); }

.split-two { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.card-pane {
  background: var(--kf-surface-card);
  border: 0.8px solid var(--kf-border-subtle);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  overflow: hidden;
}
.pane-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }

.code-editor {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  resize: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  padding: 10px;
  border-radius: 6px;
  border: 0.8px solid var(--kf-border-subtle);
  background: var(--kf-surface-subtle);
  color: var(--kf-text-primary);
  outline: none;
}
.code-editor:focus { border-color: var(--kf-app-brand); background: var(--kf-surface-card); }

.lib-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 10px;
  background: var(--kf-surface-card);
  border: 0.8px solid var(--kf-border-subtle);
  border-radius: 8px;
}
.lib-grid-wrap { flex: 1 1 auto; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.lib-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; align-content: start; }
.map-card {
  height: 152px;
  background: var(--kf-surface-card);
  border: 0.8px solid var(--kf-border-subtle);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: border-color 0.18s ease;
  overflow: hidden;
}
.map-card:hover { border-color: var(--kf-app-brand); }
.map-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.map-card-title { font-size: 13px; font-weight: 700; color: var(--kf-text-primary); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.map-card-meta { font-size: 11.5px; color: var(--kf-text-tertiary); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.map-card-actions { display: flex; align-items: center; justify-content: space-between; gap: 6px; }

.pagination-bar { flex: 0 0 36px; display: flex; align-items: center; justify-content: space-between; padding: 4px 2px; font-size: 12px; color: var(--kf-text-secondary); }

.ai-bubble { padding: 9px 10px; border-radius: 7px; border: 0.8px solid var(--kf-border-subtle); background: var(--kf-surface-subtle); font-size: 12.5px; white-space: pre-wrap; }
.citation-chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 5px; border: 0.8px solid var(--kf-border-subtle); background: var(--kf-surface-card); color: var(--kf-app-brand-text); font-size: 11.5px; font-weight: 600; cursor: pointer; }
.citation-chip:hover { border-color: var(--kf-app-brand); background: var(--kf-app-brand-soft); }
.quiz-card { padding: 10px; border-radius: 7px; border: 0.8px solid var(--kf-border-subtle); background: var(--kf-surface-subtle); display: flex; flex-direction: column; gap: 6px; }

.drawer-overlay { position: fixed; inset: 0; z-index: 60; background: var(--kf-overlay); backdrop-filter: blur(2px); display: none; justify-content: flex-end; }
.drawer-overlay.open { display: flex; }
.drawer { width: 440px; max-width: 100vw; height: 100%; padding: 16px 18px; overflow-y: auto; background: var(--kf-surface-card); border-left: 0.8px solid var(--kf-border-subtle); display: flex; flex-direction: column; gap: 12px; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding-bottom: 10px; border-bottom: 0.8px solid var(--kf-border-subtle); }
.drawer-tabs { display: flex; gap: 5px; flex-wrap: wrap; }
.drawer-pane { display: none; flex-direction: column; gap: 10px; }
.drawer-pane.active { display: flex; }
.admin-row { height: 112px; padding: 10px; border-radius: 7px; border: 0.8px solid var(--kf-border-subtle); background: var(--kf-surface-subtle); display: flex; flex-direction: column; justify-content: space-between; }

.kf-modal-overlay { position: fixed; inset: 0; z-index: 80; background: var(--kf-overlay); backdrop-filter: blur(2px); display: none; align-items: center; justify-content: center; padding: 14px; }
.kf-modal-overlay.open { display: flex; }
.kf-modal { width: 480px; max-width: 92vw; max-height: 88dvh; background: var(--kf-surface-card); border: 0.8px solid var(--kf-border-subtle); border-radius: 10px; display: flex; flex-direction: column; overflow: hidden; }
.kf-modal.kf-modal-wide { width: 780px; }
.kf-modal-head { padding: 12px 14px; border-bottom: 0.8px solid var(--kf-border-subtle); display: flex; align-items: center; justify-content: space-between; font-weight: 700; font-size: 13.5px; }
.kf-modal-body { padding: 14px; overflow-y: auto; scrollbar-width: none; display: flex; flex-direction: column; gap: 10px; }
.kf-modal-body::-webkit-scrollbar { display: none; }
.kf-modal-foot { padding: 10px 14px; border-top: 0.8px solid var(--kf-border-subtle); display: flex; align-items: center; justify-content: flex-end; gap: 8px; }

#pdfPreviewCanvas { width: 100%; height: auto; border-radius: 6px; border: 0.8px solid var(--kf-border-subtle); background: var(--kf-surface-subtle); }

.kf-toast-wrap { position: fixed; right: 14px; bottom: 42px; z-index: 95; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.kf-toast { pointer-events: auto; min-width: 220px; max-width: 360px; padding: 8px 11px; border-radius: 8px; border: 0.8px solid var(--kf-border-subtle); background: var(--kf-surface-card); color: var(--kf-text-primary); font-size: 12px; display: flex; align-items: center; gap: 8px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08); }

.public-banner { display: none; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 12px; background: var(--kf-app-brand-soft); border-bottom: 0.8px solid var(--kf-app-brand); color: var(--kf-app-brand-text); font-size: 12px; font-weight: 600; }
.public-banner.show { display: flex; }

.kf-footer { flex: 0 0 30px; height: 30px; padding: 0 14px; background: var(--kf-surface-card); border-top: 0.8px solid var(--kf-border-subtle); display: flex; align-items: center; justify-content: space-between; font-size: 11px; color: var(--kf-text-tertiary); }
.kf-mobile-nav { display: none; }

@media (max-width: 1024px) {
  .studio-grid { grid-template-columns: 1fr 248px; }
  .lib-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 767px) {
  .kf-nav-tabs { display: none; }
  .icon-btn { width: 40px; height: 40px; }
  .btn { height: 36px; padding: 0 10px; }
  .input, .select, .textarea { font-size: 16px; }
  .kf-main { padding: 8px; }
  .studio-grid { grid-template-columns: 1fr; grid-template-rows: 1fr 185px; }
  .minimap-box { display: none; }
  .split-two { grid-template-columns: 1fr; overflow-y: auto; }
  .lib-grid { grid-template-columns: 1fr; }
  .map-card { height: 136px; }
  .kf-footer { display: none; }
  .kf-mobile-nav { flex: 0 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); background: var(--kf-surface-card); border-top: 0.8px solid var(--kf-border-subtle); padding: 4px 6px calc(4px + env(safe-area-inset-bottom)); }
  .kf-mobile-btn { appearance: none; border: none; background: transparent; color: var(--kf-text-secondary); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 44px; font-size: 10.5px; font-weight: 500; cursor: pointer; }
  .kf-mobile-btn.active { color: var(--kf-app-brand-text); font-weight: 700; }
  .kf-toast-wrap { top: 62px; bottom: auto; left: 10px; right: 10px; }
}
