/* =====================================================================
   KITE.™ — main stylesheet
   Light "cream" design system inherited from ioio.reach. The only
   visual change for KITE is the accent (was neon yellow #E6FF8A,
   now neon orange #FF6B00). Code editors stay dark (CodePen-style)
   for contrast against the cream canvas.
   ===================================================================== */

/* ---------- Tokens ----------------------------------------------------- */
:root {
  /* Surfaces */
  --bg:             #f6f5f1;
  --surface:        #ffffff;
  --surface-muted:  #fafaf7;
  --surface-soft:   #f0efea;
  --border:         #ececec;
  --border-strong:  #d9d9d9;

  /* Text */
  --ink:        #121212;
  --ink-soft:   #2a2a2a;
  --ink-muted:  #6b6b6b;
  --ink-faint:  #a0a0a0;

  /* Accent — neon orange (the only branding change vs. the original) */
  --accent:        #FF6B00;
  --accent-hover:  #ff8126;
  --accent-soft:   rgba(255, 107, 0, 0.15);
  --accent-faint:  rgba(255, 107, 0, 0.06);
  --accent-ink:    #1a1d12;
  --accent-glow:   0 0 0 1px rgba(255, 107, 0, 0.35), 0 6px 18px rgba(255, 107, 0, 0.22);

  /* Status */
  --green:       #16a34a;
  --green-soft:  #e6f8ec;
  --red:         #d4365a;
  --red-soft:    #fde8ee;
  --yellow:      #d49b00;
  --yellow-soft: #fff5d6;

  /* Sizing */
  --sidebar-w:  260px;
  --topbar-h:   52px;
  --radius-sm:  10px;
  --radius:     14px;
  --radius-lg:  20px;

  /* Shadows */
  --shadow-soft: 0 1px 2px rgba(0,0,0,0.04), 0 6px 22px rgba(0,0,0,0.06);
  --shadow-pop:  0 20px 50px rgba(0,0,0,0.18);
}

/* ---------- Reset ------------------------------------------------------ */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* The [hidden] HTML attribute is the toggle of choice in app.js. Class
   selectors below set explicit `display:` values that would otherwise
   beat the UA stylesheet's `[hidden] { display: none }`, so we lock
   that down with !important here. */
[hidden] { display: none !important; }

button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

/* Subtle dotted backdrop on the canvas — the visual signature
   carried over from ioio.reach. */
.dot-grid {
  position: absolute; inset: 0;
  background-image: radial-gradient(circle, rgba(0,0,0,0.06) 1px, transparent 1px);
  background-size: 22px 22px;
  pointer-events: none;
  z-index: 0;
}

/* ---------- Layout shell ---------------------------------------------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  width: 100vw;
}
.app.collapsed { grid-template-columns: 0 1fr; }
.app.collapsed .sidebar { transform: translateX(-100%); }

/* ---------- Sidebar ---------------------------------------------------- */
.sidebar {
  position: relative;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 14px 14px;
  transition: transform .25s ease;
  z-index: 5;
  overflow: hidden;
}

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.sidebar-title {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 15px;
  letter-spacing: 0.5px;
}
.sidebar-title .logo-text { font-family: 'JetBrains Mono', monospace; }
.sidebar-title .logo-text sup { font-size: .55em; opacity: .65; }

/* The KITE logo mark — a dark "K" on a neon orange tile. */
.logo-mark {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  display: inline-flex;
  align-items: center; justify-content: center;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 14px;
  box-shadow: var(--accent-glow);
  flex-shrink: 0;
}
.logo-mark.sm  { width: 22px; height: 22px; font-size: 12px; border-radius: 7px; }
.logo-mark.big { width: 60px; height: 60px; font-size: 30px; border-radius: 16px; }

/* "+ New Workspace" CTA — solid neon orange pill at the top. */
.new-workspace-btn {
  display: flex; align-items: center; justify-content: center;
  gap: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: var(--radius);
  padding: 11px 12px;
  font-weight: 700;
  font-size: 13.5px;
  margin-bottom: 18px;
  transition: background .12s, transform .08s, box-shadow .12s;
  box-shadow: 0 4px 14px rgba(255, 107, 0, 0.25);
}
.new-workspace-btn:hover { background: var(--accent-hover); }
.new-workspace-btn:active { transform: translateY(1px); }
.new-workspace-btn svg { width: 16px; height: 16px; }

.sidebar-section-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  margin: 4px 6px 8px;
}

/* Scrollable workspace list. */
.workspace-list {
  flex: 1;
  overflow-y: auto;
  margin: 0 -6px;
  padding: 0 6px 8px;
}
.workspace-list::-webkit-scrollbar { width: 8px; }
.workspace-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
.workspace-list::-webkit-scrollbar-track { background: transparent; }

.workspace-list-empty {
  padding: 14px 8px;
  font-size: 12.5px;
  color: var(--ink-faint);
  font-style: italic;
}

.workspace-row {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  text-align: left;
  font-size: 13.5px;
  color: var(--ink-soft);
  margin-bottom: 2px;
  position: relative;
  transition: background .1s, color .1s, border-color .1s;
}
.workspace-row:hover {
  background: var(--surface-muted);
  color: var(--ink);
}
.workspace-row.active {
  background: var(--accent-faint);
  color: var(--ink);
  border-color: rgba(255, 107, 0, 0.25);
}
.workspace-row.active::before {
  content: '';
  position: absolute;
  left: -6px; top: 6px; bottom: 6px;
  width: 3px;
  background: var(--accent);
  border-radius: 2px;
}

.workspace-icon {
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--accent);
  font-size: 14px;
  flex-shrink: 0;
}
.workspace-icon svg { width: 18px; height: 18px; }

.workspace-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace-badge {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
}

.workspace-actions {
  margin-left: auto;
  display: flex; align-items: center; gap: 4px;
  opacity: 0;
  transform: translateX(4px);
  transition: opacity .12s, transform .12s;
}
.workspace-row:hover .workspace-actions,
.workspace-row.active .workspace-actions {
  opacity: 1;
  transform: translateX(0);
}

/* Sidebar footer (user chip + admin/signout icons). */
.sidebar-footer {
  display: flex; align-items: center; gap: 6px;
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 4px;
  border-radius: 999px;
  flex: 1;
  min-width: 0;
}
.user-chip.compact {
  flex: 0 0 auto;
  padding: 4px 4px 4px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
}
.user-initials {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 11.5px;
  display: inline-flex;
  align-items: center; justify-content: center;
  flex-shrink: 0;
  border: 1px solid rgba(255, 107, 0, 0.25);
}
.user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-chip.compact .user-name { font-size: 12.5px; }

/* ---------- Icon buttons ---------------------------------------------- */
.icon-btn {
  width: 32px; height: 32px;
  display: inline-flex;
  align-items: center; justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--ink-muted);
  transition: background .12s, color .12s, border-color .12s;
  flex-shrink: 0;
}
.icon-btn:hover {
  background: var(--surface-muted);
  color: var(--ink);
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn--xs {
  width: 22px; height: 22px;
  border-radius: 6px;
}
.icon-btn--xs svg { width: 13px; height: 13px; }
.icon-btn--xs:hover { background: var(--red-soft); color: var(--red); }

/* ---------- Main area -------------------------------------------------- */
.main {
  position: relative;
  background: var(--bg);
  overflow: hidden;
  min-width: 0;
}

/* Floating top bar — white pill with a soft shadow, centered. */
.topbar {
  position: absolute;
  top: 16px; left: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center;
  gap: 10px;
  padding: 6px 8px 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-soft);
  z-index: 10;
  height: var(--topbar-h);
  max-width: calc(100% - 40px);
}
.topbar-logo {
  display: flex; align-items: center; justify-content: center;
}
.topbar-divider {
  width: 1px;
  height: 22px;
  background: var(--border);
}

.topbar-name {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  width: 240px;
  outline: none;
  transition: background .12s, border-color .12s;
}
.topbar-name:hover:not(:disabled) { background: var(--surface-muted); }
.topbar-name:focus { background: var(--surface-muted); border-color: var(--border-strong); }
.topbar-name:disabled { color: var(--ink-faint); cursor: default; }
.topbar-name::placeholder { color: var(--ink-faint); }

/* Save state pill, lives inside the topbar to the right of the name. */
.save-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px 4px 8px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--ink-muted);
  border: 1px solid var(--border);
  user-select: none;
}
.save-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--ink-faint);
  flex-shrink: 0;
}
.save-pill[data-state="saving"]   .save-dot { background: var(--yellow); animation: pulse 1.1s ease-in-out infinite; }
.save-pill[data-state="dirty"]    .save-dot { background: var(--accent); }
.save-pill[data-state="saved"]    .save-dot { background: var(--green); }
.save-pill[data-state="error"]    { color: var(--red); border-color: rgba(212, 54, 90, 0.3); }
.save-pill[data-state="error"]    .save-dot { background: var(--red); }
@keyframes pulse {
  0%, 100% { opacity: .35; }
  50%      { opacity: 1; }
}

/* Tab switch (Preview | Code) — inset segmented pill. */
.tab-switch {
  display: inline-flex;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
  margin-left: 6px;
}
.tab-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent;
  border: none;
  color: var(--ink-muted);
  padding: 6px 14px;
  font-size: 12.5px;
  font-weight: 600;
  border-radius: 999px;
  transition: background .12s, color .12s;
}
.tab-btn svg { width: 14px; height: 14px; }
.tab-btn:hover { color: var(--ink); }
.tab-btn.active {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 4px 12px rgba(255, 107, 0, 0.28);
}

/* Top-right user chip. */
.topbar-right {
  position: absolute;
  top: 16px; right: 18px;
  z-index: 10;
}

/* ---------- Empty state ----------------------------------------------- */
.empty-state {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 1;
  padding: 24px;
}
.empty-card {
  text-align: center;
  max-width: 460px;
  padding: 36px 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
}
.empty-logo { margin-bottom: 18px; display: flex; justify-content: center; }
.empty-card h1 {
  font-family: 'JetBrains Mono', monospace;
  font-size: 26px;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  color: var(--ink);
}
.empty-card h1 sup { font-size: .5em; opacity: .55; }
.empty-card p {
  color: var(--ink-muted);
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 20px;
}

/* ---------- Buttons ---------------------------------------------------- */
.primary-btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 700;
  font-size: 13.5px;
  transition: background .12s, transform .08s, box-shadow .12s;
  box-shadow: 0 4px 14px rgba(255, 107, 0, 0.3);
}
.primary-btn:hover { background: var(--accent-hover); }
.primary-btn:active { transform: translateY(1px); }
.primary-btn svg { width: 16px; height: 16px; }

.ghost-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent;
  color: var(--ink-muted);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 7px 12px;
  font-weight: 500;
  font-size: 12.5px;
  transition: background .12s, color .12s, border-color .12s;
}
.ghost-btn:hover {
  background: var(--surface-muted);
  color: var(--ink);
}
.ghost-btn svg { width: 14px; height: 14px; }

.danger-btn {
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 18px;
  font-weight: 700;
  font-size: 13px;
  transition: background .12s, transform .08s;
}
.danger-btn:hover { background: #b9264a; }
.danger-btn:active { transform: translateY(1px); }

/* ---------- Views ------------------------------------------------------ */
.view {
  position: absolute;
  top: calc(var(--topbar-h) + 32px);
  left: 24px; right: 24px; bottom: 24px;
  z-index: 1;
  display: flex;
}

/* Preview view --------------------------------------------------------- */
.preview-view {
  flex-direction: column;
  background: transparent;
}
.preview-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 4px 10px;
  color: var(--ink-muted);
}
.preview-label {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
}
.preview-frame-wrap {
  flex: 1;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
}
.preview-frame {
  width: 100%; height: 100%;
  border: 0;
  background: var(--surface);
  display: block;
}

/* Code view (three CodeMirror columns) --------------------------------- */
/* Editors stay dark — same convention CodePen uses on light themes. */
.code-view {
  flex-direction: row;
  gap: 12px;
}
.code-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #282a36; /* dracula bg */
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-width: 0;
  box-shadow: var(--shadow-soft);
}
.code-pane-header {
  display: flex; align-items: baseline; gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(to bottom, rgba(255,255,255,0.03), rgba(0,0,0,0.18));
  border-bottom: 1px solid #1e1f29;
}
.pane-tag {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-transform: uppercase;
}
.code-pane[data-pane="css"] .pane-tag  { color: #50fa7b; }   /* dracula green */
.code-pane[data-pane="js"]  .pane-tag  { color: #f1fa8c; }   /* dracula yellow */
.pane-hint {
  font-size: 11px;
  color: #6b6d7d;
  letter-spacing: 0.02em;
}
.code-pane .CodeMirror {
  flex: 1;
  min-height: 0;
  height: auto !important;
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
  background: #282a36;
}
.code-pane .CodeMirror-gutters {
  background: #21222c;
  border-right: 1px solid #1e1f29;
}
.code-pane .CodeMirror-linenumber { color: #4b4d5a; }
.code-pane .CodeMirror-cursor { border-left: 2px solid var(--accent); }
.code-pane .CodeMirror-selected { background: rgba(255, 107, 0, 0.18) !important; }

/* ---------- Modal ----------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(18, 18, 18, 0.35);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  width: 420px;
  max-width: 100%;
  overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  font-size: 16px;
  font-weight: 700;
}
.modal-body { padding: 20px; }
.modal-text {
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 18px;
}
.modal-text strong { color: var(--ink); font-weight: 600; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px;
}

/* ---------- Floating sidebar menu (when collapsed) -------------------- */
#sidebarMenuBtn {
  position: fixed;
  top: 16px; left: 16px;
  z-index: 20;
  display: none;
}
.app.collapsed #sidebarMenuBtn { display: block; }
#sidebarMenuBtn button {
  width: 38px; height: 38px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-soft);
  transition: background .12s;
}
#sidebarMenuBtn button:hover { background: var(--surface-muted); }
#sidebarMenuBtn button svg { width: 18px; height: 18px; }

/* ---------- Responsive ------------------------------------------------- */
@media (max-width: 768px) {
  .app:not(.collapsed) {
    grid-template-columns: 0 1fr;
  }
  .app:not(.collapsed) .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    z-index: 30;
    box-shadow: var(--shadow-pop);
  }
  .app:not(.collapsed)::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 25;
  }
  .topbar {
    left: 50%;
    max-width: calc(100vw - 24px);
    flex-wrap: wrap;
  }
  .topbar-name { width: 140px; }
  .view {
    top: calc(var(--topbar-h) + 80px);
    left: 12px; right: 12px; bottom: 12px;
  }
  .code-view {
    flex-direction: column;
  }
}
