/* ---------- Shell ---------- */
.app {
  display: block;
  height: 100vh;
  position: relative;
  z-index: 1;
}

/* ---------- Left rail ---------- */
.rail {
  background: var(--bg-surface);
  border-right: 1px solid var(--bd-1);
  display: flex; flex-direction: column;
  padding: 20px 14px;
  gap: 8px;
  overflow-y: auto;
}
.rail-brand {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 6px 14px;
}
.rail-brand .logo { height: 22px; display: block; }
.rail-bell {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-pill);
  border: 1px solid var(--bd-1);
  color: var(--fg-default);
  background: var(--bg-surface);
  cursor: pointer;
  position: relative;
}
.rail-bell .badge {
  position: absolute; top: -3px; right: -3px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: var(--radius-pill);
  background: #EF4444; color: #fff;
  font-size: 10px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--bg-surface);
}

.rail-user {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--bd-1);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  margin-bottom: 16px;
  cursor: pointer;
  transition: background 150ms;
}
.rail-user:hover { background: var(--bg-surface-2); }
.rail-user .avatar {
  width: 28px; height: 28px; border-radius: var(--radius-pill);
  background: var(--bg-subtle);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--fg-muted);
  flex-shrink: 0;
}
.rail-user .who { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
.rail-user .who .name { font-size: 13px; font-weight: 600; color: var(--fg-strong); }
.rail-user .who .email { font-size: 11px; color: var(--fg-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail-user .chev { color: var(--fg-muted); }

.rail-section { margin-top: 14px; }
.rail-section:first-of-type { margin-top: 0; }
.rail-section .label {
  font-size: 11px; font-weight: 600;
  color: var(--fg-muted);
  letter-spacing: 0.2px;
  padding: 0 10px;
  margin-bottom: 6px;
}

.rail-link, .rail-section .header {
  display: flex; align-items: center; gap: 10px;
  height: 34px; padding: 0 10px;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500;
  color: var(--fg-default);
  cursor: pointer;
  border: 0; background: transparent; width: 100%;
  text-align: left;
  transition: background 150ms;
}
.rail-link:hover, .rail-section .header:hover { background: var(--bg-subtle); }
.rail-link.active {
  background: var(--bg-subtle);
  color: var(--fg-strong);
  font-weight: 600;
}
.rail-link.active::before {
  content: "";
  width: 3px; height: 16px;
  background: var(--accent-2);
  border-radius: 2px;
  margin-left: -10px;
  margin-right: 7px;
}
.rail-link svg, .rail-section .header svg {
  flex-shrink: 0;
  color: var(--fg-muted);
}
.rail-link.active svg { color: var(--fg-strong); }

.rail-spacer { flex: 1; min-height: 16px; }

.rail-theme {
  display: flex; align-items: center; gap: 4px;
  padding: 4px;
  border: 1px solid var(--bd-1);
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
}
.rail-theme button {
  flex: 1;
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  height: 28px; padding: 0 10px;
  border: 0; background: transparent;
  border-radius: var(--radius-pill);
  font-size: 12px; font-weight: 600;
  color: var(--fg-muted);
  cursor: pointer;
  transition: background 150ms, color 150ms;
}
.rail-theme button.on {
  background: var(--bg-subtle);
  color: var(--fg-strong);
}
[data-theme="dark"] .rail-theme button.on {
  background: rgba(255,255,255,0.10);
}

/* ---------- Workspace (right side) ---------- */
.work {
  display: grid;
  grid-template-rows: 56px 1fr;
  min-width: 0;
  min-height: 0;
  height: 100vh;
  position: relative; /* anchor for WelcomeScreen overlay covering topbar + stage */
}

.crumbs {
  display: flex; align-items: center;
  padding: 0 24px;
  gap: 16px;
  border-bottom: 1px solid var(--bd-2);
  background: transparent;
}
.crumbs .path {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--fg-muted);
}
.crumbs .path .sep { opacity: 0.5; }
.crumbs .path .current {
  color: var(--fg-strong); font-weight: 600;
  cursor: default;
  border-radius: 6px;
  padding: 2px 4px;
  margin: -2px -4px;
  transition: background 120ms;
}
.crumbs .path .current:hover { background: var(--bg-subtle); }

.crumb-name-input {
  height: 28px;
  padding: 0 8px;
  font-size: 13px; font-weight: 600;
  font-family: inherit;
  color: var(--fg-strong);
  background: var(--bg-subtle);
  border: 1px solid var(--accent-1);
  border-radius: 6px;
  outline: none;
  min-width: 140px;
  max-width: 260px;
}
.crumb-confirm-btn {
  height: 28px; padding: 0 12px;
  font-size: 12px; font-weight: 600;
  font-family: inherit;
  background: var(--accent-2);
  color: var(--cdn-ink, #0A0E1F);
  border: none;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: opacity 120ms;
}
.crumb-confirm-btn:hover { opacity: 0.85; }
.crumbs .spacer { flex: 1; }

.tb-group { display: inline-flex; align-items: center; gap: 6px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px;
  background: var(--bg-surface);
  border: 1px solid var(--bd-1);
  border-radius: var(--radius-pill);
  color: var(--fg-default);
  font-size: 13px; font-weight: 500; letter-spacing: -0.1px;
  cursor: pointer;
  transition: background 150ms, border-color 150ms, transform 100ms;
}
.btn:hover { background: var(--bg-surface-2); border-color: var(--bd-strong); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn.primary {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: var(--cdn-ink);
  box-shadow: 0 4px 12px var(--accent-2-glow);
}
.btn.primary:hover {
  background: #FFFAB4;
  border-color: #FFFAB4;
  box-shadow: 0 8px 24px var(--accent-2-glow);
}
.btn.ghost {
  background: transparent;
  border-color: transparent;
}
.btn.ghost:hover { background: var(--bg-subtle); }

/* ---------- Brand theme picker ---------- */
.brand-picker {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px;
  border: 1px solid var(--bd-1);
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
}
.brand-picker-btn {
  width: 28px; height: 28px; padding: 0;
  border: none; border-radius: 8px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: box-shadow 120ms;
  outline: none;
}
.brand-picker-btn.selected {
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px #0D5284;
}
.brand-picker-btn:disabled {
  opacity: 0.38; cursor: not-allowed;
}
.brand-picker-label {
  font-size: 12px; font-weight: 600; color: var(--fg-muted);
  padding: 0 6px 0 2px;
}

.btn .soon {
  font-size: 9px; font-weight: 700; letter-spacing: 0.4px;
  padding: 2px 5px;
  background: var(--accent-1-soft);
  color: var(--accent-1);
  border-radius: 4px;
  text-transform: uppercase;
}

.select {
  height: 32px; padding: 0 28px 0 12px;
  border: 1px solid var(--bd-1);
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  color: var(--fg-default);
  font-family: inherit; font-size: 13px;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  cursor: pointer;
}
[data-theme="dark"] .select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-color: var(--bg-surface);
}

/* ---------- Stage (sidebar + canvas + inspector) ---------- */
.stage {
  display: grid;
  grid-template-columns: 300px 1fr 300px;
  min-height: 0;
  padding: 0;
  gap: 0;
  position: relative; /* anchor for WelcomeScreen overlay */
}

/* ---------- Scrollbars (subtle) ---------- */
.panel::-webkit-scrollbar, .rail::-webkit-scrollbar { width: 8px; height: 8px; }
.panel::-webkit-scrollbar-thumb, .rail::-webkit-scrollbar-thumb {
  background: var(--bd-1); border-radius: 999px;
}
.panel::-webkit-scrollbar-track, .rail::-webkit-scrollbar-track { background: transparent; }

/* ---------- Topbar history group ---------- */
.tb-history-group {
  display: inline-flex; align-items: center; gap: 2px;
  margin-right: 4px;
}
.btn.btn-icon {
  padding: 0 8px;
  min-width: 32px;
  justify-content: center;
}
.btn.btn-icon.active {
  background: var(--accent-1-soft);
  border-color: var(--accent-1);
  color: var(--accent-1);
}
.tb-hist-wrap {
  position: relative;
}

/* ---------- History panel dropdown ---------- */
.history-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  width: 220px;
  background: var(--toolbar-bg, #fff);
  border: 1px solid var(--bd-1, #e0e1e6);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.13), 0 2px 8px rgba(0,0,0,0.07);
  z-index: 200;
  overflow: hidden;
}
[data-theme="dark"] .history-panel {
  box-shadow: 0 8px 28px rgba(0,0,0,0.55), 0 2px 8px rgba(0,0,0,0.35);
}
.history-panel-header {
  padding: 9px 12px 7px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--fg-muted, #888);
  border-bottom: 1px solid var(--bd-2, #e8e9ee);
  user-select: none;
}
.history-panel-list {
  max-height: 288px;
  overflow-y: auto;
  padding: 4px 0;
}
.history-panel-list::-webkit-scrollbar { width: 5px; }
.history-panel-list::-webkit-scrollbar-thumb { background: var(--bd-1); border-radius: 99px; }
.history-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 5px 12px;
  border: none;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-size: 12px;
  font-family: inherit;
  line-height: 1.4;
  color: var(--fg-default, #15171e);
  transition: background 70ms;
}
.history-item:hover:not(.active) { background: var(--bg-subtle, rgba(232,233,238,0.4)); }
.history-item.active {
  background: var(--accent-1-soft, rgba(59,89,206,0.08));
  color: var(--accent-1, #3B59CE);
  font-weight: 600;
  pointer-events: none;
}
.history-item.future { color: var(--fg-subtle, #96979c); }
.history-item-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--fg-subtle, #96979c);
  transition: background 70ms, box-shadow 70ms;
}
.history-item.active .history-item-dot {
  background: var(--accent-1, #3B59CE);
  box-shadow: 0 0 0 3px var(--accent-1-soft, rgba(59,89,206,0.18));
}
.history-item.future .history-item-dot {
  background: transparent;
  border: 1.5px solid var(--fg-subtle, #96979c);
}
.history-item-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-item-ts {
  font-size: 10px;
  color: var(--fg-subtle, #96979c);
  white-space: nowrap;
  flex-shrink: 0;
}
.history-item.active .history-item-ts {
  color: var(--accent-1, #3B59CE);
  opacity: 0.7;
}
.history-divider {
  height: 1px;
  background: var(--bd-2, #e8e9ee);
  margin: 4px 12px;
}
