/* ============================================================
   Beany design tokens — light is the base, data-theme="dark"
   overrides. data-accent="pink|blue|violet|mint" swaps accent only.
   Workspace IDE semantics (--panel, --user, --tool, --ok, --error)
   are kept as legacy aliases that follow the active theme.
   ============================================================ */
:root {
  /* Brand palette */
  --pink: #FF5C93;
  --pink-2: #FF7AA8;
  --pink-soft: #FFE6EE;
  --pink-softer: #FFF1F6;

  --navy: #0B1F3A;
  --navy-2: #0E2647;
  --sky: #3B82F6;
  --deep-blue: #1E3A8A;

  /* Active accent — pink default */
  --accent: var(--pink);
  --accent-2: var(--pink-2);
  --accent-soft: var(--pink-soft);
  --accent-softer: var(--pink-softer);
  --accent-tint: rgba(255, 92, 147, 0.14);
  --accent-glow: rgba(255, 92, 147, 0.28);

  /* Surfaces — light theme defaults */
  --bg: #FFFFFF;
  --bg-soft: #F7F8FA;
  --bg-muted: #F0F2F6;
  --surface: #FFFFFF;
  --surface-2: #FBFBFD;
  --border: #E5E8EE;
  --border-strong: #D6DAE2;

  --text-strong: #0B1F3A;
  --text: #14181F;
  --text-muted: #6B7280;
  --text-faint: #A7AEBB;

  --shadow-card: 0 1px 2px rgba(11,31,58,0.04), 0 8px 24px rgba(11,31,58,0.06);
  --shadow-lift: 0 2px 4px rgba(11,31,58,0.04), 0 24px 48px rgba(11,31,58,0.10);

  /* Hero gradient (landing) */
  --hero-bg: linear-gradient(180deg, #0E2647 0%, #0B1F3A 100%);
  --hero-text: #FFFFFF;
  --hero-text-muted: rgba(255,255,255,0.78);

  /* Radii */
  --radius-pill: 999px;
  --radius-card: 22px;
  --radius-section: 36px;

  /* Legacy IDE semantics — alias to active theme tokens */
  --panel: var(--surface);
  --panel-2: var(--surface-2);
  --muted: var(--text-muted);
  --user: var(--accent-softer);
  --tool: #eaf3ec;
  --error: #d94545;
  --ok: #1f9d55;
}

/* Accent palettes */
html[data-accent="blue"] {
  --accent: var(--sky);
  --accent-2: #60A5FA;
  --accent-soft: #DCEBFF;
  --accent-softer: #EAF2FF;
  --accent-tint: rgba(59,130,246,0.14);
  --accent-glow: rgba(59,130,246,0.30);
}
html[data-accent="violet"] {
  --accent: #7A5AE0;
  --accent-2: #9B83F0;
  --accent-soft: #E6DEFA;
  --accent-softer: #F1ECFD;
  --accent-tint: rgba(122,90,224,0.14);
  --accent-glow: rgba(122,90,224,0.30);
}
html[data-accent="mint"] {
  --accent: #10B981;
  --accent-2: #34D9A4;
  --accent-soft: #D1FAE9;
  --accent-softer: #E8FBF2;
  --accent-tint: rgba(16,185,129,0.14);
  --accent-glow: rgba(16,185,129,0.30);
}

/* Dark theme — matches the original IDE palette (pre-Beany) for workspace surfaces */
html[data-theme="dark"] {
  --bg: #0e0f12;
  --bg-soft: #14161b;
  --bg-muted: #1d2026;
  --surface: #16181d;
  --surface-2: #1d2026;
  --border: #262a31;
  --border-strong: #353a45;

  --text-strong: #f4f7fb;
  --text: #e6e8ec;
  --text-muted: #8a8f99;
  --text-faint: #6a7282;

  --shadow-card: 0 1px 2px rgba(0,0,0,0.30), 0 8px 24px rgba(0,0,0,0.30);
  --shadow-lift: 0 2px 4px rgba(0,0,0,0.30), 0 24px 48px rgba(0,0,0,0.40);

  --hero-bg: radial-gradient(900px 540px at 20% -10%, rgba(59,130,246,0.18), transparent 60%),
             radial-gradient(700px 420px at 110% 110%, rgba(255,92,147,0.16), transparent 60%),
             linear-gradient(180deg, #0A1424 0%, #060E1C 100%);
  --hero-text: #FFFFFF;
  --hero-text-muted: rgba(255,255,255,0.74);

  /* IDE semantics in dark */
  --user: rgba(255, 92, 147, 0.16);
  --tool: #1f2a22;
  --error: #ff6b6b;
  --ok: #6bcf7f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", sans-serif;
  font-size: 14px;
  overflow: hidden;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}
button:hover { background: #252932; }
button.primary { background: var(--accent); border-color: var(--accent); color: white; }
button.primary:hover { background: var(--accent-2); }
button.cancel { background: #4a2828; border-color: #6a3434; color: #ffd0d0; }
button.cancel:hover { background: #5a3030; }
.hidden { display: none !important; }
.cursor {
  display: inline-block;
  width: 8px; height: 16px;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  border-radius: 1px;
  animation: blink 0.8s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* Rich "thinking" placeholder shown while the LLM hasn't sent a token yet,
 * or between tool calls. Includes label, elapsed timer, and time-gated hint. */
.msg.thinking {
  align-self: flex-start;
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: 10px;
  width: fit-content;
  min-width: 240px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.thinking-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
}
.thinking-icon {
  font-size: 14px;
  color: var(--accent);
  animation: thinking-pulse 1.4s ease-in-out infinite;
  display: inline-block;
}
.thinking-label { font-weight: 500; }
.thinking-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.thinking-elapsed { font-weight: 600; }
.thinking-hint { font-style: italic; opacity: 0.85; }
@keyframes thinking-pulse {
  0%, 100% { opacity: 0.5; transform: rotate(0deg) scale(1); }
  50%      { opacity: 1;   transform: rotate(180deg) scale(1.15); }
}

.dots { display: inline-flex; gap: 5px; align-items: center; }
.dots span {
  width: 6px; height: 6px;
  background: var(--accent);
  border-radius: 50%;
  display: inline-block;
  animation: dot-bounce 1.3s infinite ease-in-out both;
}
.dots span:nth-child(1) { animation-delay: -0.32s; }
.dots span:nth-child(2) { animation-delay: -0.16s; }
@keyframes dot-bounce {
  0%, 80%, 100% { transform: scale(0.3); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

input, select, textarea {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  width: 100%;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }

/* Top bar */
.topbar {
  position: relative; /* anchor for #loading-bar */
  height: 48px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  gap: 16px;
}

/* Global loading bar — sits at the very bottom edge of the topbar.
 * Active whenever any API call is in flight.                        */
#loading-bar {
  position: absolute;
  bottom: 0; left: 0;
  width: 100%;
  height: 2px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 10;
  background: transparent;
}
#loading-bar.active {
  opacity: 1;
  background: linear-gradient(
    90deg,
    transparent 0%,
    var(--accent) 25%,
    #5bffcf 50%,
    var(--accent) 75%,
    transparent 100%
  );
  background-size: 300% 100%;
  animation: lb-shimmer 1.3s ease-in-out infinite;
}
@keyframes lb-shimmer {
  0%   { background-position:  100% 0; }
  100% { background-position: -100% 0; }
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.brand-mark { color: var(--accent); }
.spacer { flex: 1; }

/* Workspace topbar elements */
.back-link {
  color: var(--muted);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
}
.back-link:hover { background: var(--panel-2); color: var(--text); }
.app-title { display: flex; align-items: center; min-width: 0; }
.app-name {
  font-weight: 600;
  font-size: 15px;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: text;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 360px;
}
.app-name:hover { background: var(--panel-2); }
.app-name-input {
  font-weight: 600;
  font-size: 15px;
  padding: 3px 8px;
  width: 280px;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 380px 240px 1fr;
  height: calc(100vh - 48px);
}
/* Files pane is hidden by default; toggle via #files-toggle button. */
body.files-hidden .layout { grid-template-columns: 380px 1fr; }
body.files-hidden .files-pane { display: none; }
#files-toggle.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
#files-toggle { position: relative; }
#files-toggle.has-new::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  background: var(--ok);
  border-radius: 50%;
  border: 1.5px solid var(--panel);
}

/* Pane tabs (used in chat-pane and files-pane) */
.pane-tabs {
  flex: none;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  height: 36px;
}
.pane-tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 4px 12px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 500;
}
.pane-tab:hover { background: var(--panel-2); color: var(--text); }
.pane-tab.active { background: var(--panel-2); color: var(--text); border-color: var(--border); }
.tab-badge {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  margin-left: 4px;
  background: var(--accent);
  color: white;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  text-align: center;
}

/* Chat */
.chat {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--panel);
  min-width: 0;
  min-height: 0; /* allow grid child to shrink so .messages can scroll */
  height: 100%;
}
.chat-body, .notes-body {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.messages {
  flex: 1 1 0;
  min-height: 0; /* unlock overflow inside the flex column */
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.msg {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
}
.msg.user { background: var(--user); border-color: #344056; align-self: flex-end; max-width: 90%; }
.msg.assistant { background: var(--panel-2); }
.msg.tool {
  background: var(--tool);
  border-color: #2a3a30;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: #c8d9c8;
}
.msg.error {
  background: #2a1a1a;
  border-color: #4a2a2a;
  color: var(--error);
}
.msg .role {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 4px;
}
.msg.tool .tool-name { color: var(--ok); font-weight: 600; }

.composer {
  border-top: 1px solid var(--border);
  padding: 10px;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.composer textarea {
  resize: none;
  min-height: 60px;
  max-height: 200px;
}
.composer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.hint { color: var(--muted); font-size: 12px; }

/* Files pane */
.files-pane {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
  min-height: 0;
  overflow: hidden;
}
.files-pane .pane-tabs .icon-btn {
  position: static;
  width: 24px;
  height: 24px;
  font-size: 12px;
  background: transparent;
  border-color: transparent;
}
.files-pane .pane-tabs .icon-btn:hover { background: var(--panel-2); border-color: var(--border); }

.files-body, .history-body, .console-body {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Preview console (errors / warnings forwarded from preview iframe) */
.console-list {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.console-list .empty {
  color: var(--muted); font-size: 12px; font-style: italic;
  text-align: center; padding: 30px 12px;
}
.console-item {
  display: flex;
  flex-direction: column;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--muted);
  cursor: default;
  position: relative;
}
.console-item:hover { border-color: var(--accent); }
.console-item.error,
.console-item.console-error,
.console-item.rejection { border-left-color: var(--error); }
.console-item.console-warn { border-left-color: #d4a955; }
.console-item .ci-row1 {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}
.console-item .ci-kind {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  font-weight: 600;
  flex: none;
}
.console-item .ci-time {
  font-size: 10px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.console-item .ci-loc {
  font-size: 10px;
  color: var(--muted);
  margin-left: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 50%;
}
.console-item .ci-msg {
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  line-height: 1.45;
}
.console-item .ci-stack {
  margin-top: 4px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10.5px;
  white-space: pre-wrap;
  max-height: 80px;
  overflow: auto;
}
.console-item .ci-actions {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s;
}
.console-item:hover .ci-actions { opacity: 1; }
.console-item .ci-actions button {
  padding: 2px 6px;
  font-size: 11px;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.console-item .ci-actions .send-btn:hover { color: var(--accent); border-color: var(--accent); background: var(--panel); }
.console-item .ci-actions .del-btn:hover  { color: var(--error); }
.console-item .ci-count {
  font-size: 10px;
  color: var(--muted);
  background: var(--panel);
  padding: 1px 6px;
  border-radius: 999px;
  margin-left: auto;
}

#files-toggle.has-console-error::before {
  content: '⚠';
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: 9px;
  color: var(--error);
}

.file-tree {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 4px 14px;
  font-size: 13px;
}
.file-tree .empty {
  padding: 14px 12px;
  color: var(--muted);
  font-size: 12px;
  font-style: italic;
}
.tree-node {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: none;
}
.tree-node:hover { background: var(--panel-2); }
.tree-node.active {
  background: rgba(91, 156, 255, 0.18);
  color: var(--accent);
}
.tree-node .twisty {
  width: 12px;
  display: inline-block;
  text-align: center;
  color: var(--muted);
  font-size: 10px;
  flex: none;
}
.tree-node .icon {
  flex: none;
  font-size: 12px;
  color: var(--muted);
}
.tree-node.dir > .icon { color: #d3b873; }
.tree-node .label {
  overflow: hidden;
  text-overflow: ellipsis;
}
.tree-children {
  display: flex;
  flex-direction: column;
}
.tree-children.collapsed { display: none; }

/* Preview */
.preview {
  position: relative;
  display: flex;
  flex-direction: column;
  background: white;
  min-width: 0;
}
.preview-toolbar {
  height: 36px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 10px;
}
.preview-tabs { display: flex; gap: 4px; align-items: center; }
.tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 5px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tab:hover { background: var(--panel-2); color: var(--text); }
.tab.active { background: var(--panel-2); color: var(--text); border-color: var(--border); }
.tab-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  font-size: 14px;
  line-height: 1;
  color: var(--muted);
}
.tab-close:hover { background: rgba(255,255,255,0.08); color: var(--text); }
.preview-url { color: var(--muted); font-family: ui-monospace, monospace; font-size: 12px; }
#preview-frame {
  flex: 1;
  border: none;
  width: 100%;
  background: white;
}

/* Visual editor (GrapesJS) — overlay layout inside the preview pane.
 * Canvas + property panel are split horizontally; toolbar sits on top. */
.visual-editor {
  position: absolute;
  top: 36px; /* below preview-toolbar */
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.visual-toolbar {
  flex: none;
  height: 34px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.visual-toolbar button { padding: 4px 10px; font-size: 12px; }
.visual-body {
  flex: 1 1 0;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 320px;
}
.visual-canvas {
  position: relative;
  background: white;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}
.props-pane {
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.props-tabs {
  flex: none;
  display: flex;
  gap: 2px;
  padding: 6px 6px 0;
  border-bottom: 1px solid var(--border);
}
.props-tab {
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 5px 5px 0 0;
  font-size: 12px;
}
.props-tab:hover { background: var(--panel-2); color: var(--text); }
.props-tab.active { background: var(--panel-2); color: var(--text); border-color: var(--border); }
.props-body {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
}

/* Hide GrapesJS's own panel chrome — we project its managers into our tabs.
 * Only the canvas itself stays visible inside #visual-canvas. */
.visual-canvas .gjs-pn-panels,
.visual-canvas .gjs-pn-views,
.visual-canvas .gjs-pn-views-container,
.props-pane .gjs-pn-panels { display: none; }
.props-body .gjs-sm-sectors,
.props-body .gjs-trt-traits,
.props-body .gjs-clm-tags,
.props-body .gjs-layer { color: var(--text); }
.props-body .gjs-mdl-dialog { color: var(--text); }
/* Soften GrapesJS dark theme to match ours where it leaks through. */
.props-pane .gjs-one-bg { background-color: var(--panel) !important; }
.props-pane .gjs-two-color { color: var(--text) !important; }
.props-pane .gjs-three-bg { background-color: var(--panel-2) !important; }
.props-pane .gjs-four-color, .props-pane .gjs-four-color-h:hover { color: var(--accent) !important; }

/* When Visual mode is active, hide the iframe and code viewer overlays. */
body.visual-mode .preview-frame,
body.visual-mode #preview-frame { display: none; }

@media (max-width: 1100px) {
  .visual-body { grid-template-columns: 1fr 280px; }
}

/* Code viewer overlay (sits above the iframe in the preview area) */
.code-viewer {
  position: absolute;
  top: 36px;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.code-toolbar {
  flex: none;
  height: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.code-path {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 50%;
}
.code-status { font-size: 12px; color: var(--muted); }
.code-toolbar button { padding: 4px 10px; font-size: 12px; }
.code-viewer pre {
  flex: 1;
  margin: 0;
  padding: 14px 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text);
  white-space: pre;
  tab-size: 2;
  overflow: auto;
}
#code-editor {
  flex: 1;
  width: 100%;
  margin: 0;
  padding: 14px 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  border: none;
  border-radius: 0;
  resize: none;
  outline: none;
  white-space: pre;
  tab-size: 2;
}
#code-editor:focus { border: none; }

/* Settings modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  width: 520px;
  max-width: 90vw;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal h2 { margin: 0 0 4px; }
.modal label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text);
}
.muted { color: var(--muted); font-weight: normal; font-size: 12px; }
.muted code { background: #2a2f38; padding: 1px 5px; border-radius: 3px; color: #cfd6e0; }

/* ============================================================
 * App list page
 * ============================================================ */

.page-list { overflow: auto; }
.page-list .topbar { position: sticky; top: 0; z-index: 10; }

.list-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 24px 80px;
}

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}
.list-header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
}
.list-header .count {
  color: var(--muted);
  font-weight: normal;
  font-size: 16px;
  margin-left: 6px;
}

button.big {
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
}

.empty-state {
  margin: 60px auto;
  max-width: 460px;
  text-align: center;
  padding: 40px 24px;
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: 14px;
}
.empty-state h2 { margin: 0 0 8px; font-size: 18px; font-weight: 600; }
.empty-state p { color: var(--muted); margin: 0 0 20px; }

.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
}

/* Card */
.card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
}
.card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Thumbnail iframe — shrink a desktop-sized iframe into the card. */
.card-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  background: white;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}
.card-thumb iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 1280px;
  height: 800px;
  border: none;
  transform: scale(0.25);
  transform-origin: top left;
  pointer-events: none;
}

.card-body {
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.card-name-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.card-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.card-meta { font-size: 12px; color: var(--muted); }
.card-snippet {
  font-size: 12px;
  color: #a8b0bd;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-top: 4px;
  font-style: italic;
}

/* Action icons (rename / delete) */
.card-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}
.card:hover .card-actions,
.card:focus-within .card-actions { opacity: 1; }

.icon-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 22, 28, 0.85);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  backdrop-filter: blur(6px);
}
.icon-btn:hover { background: var(--panel-2); border-color: var(--accent); }

/* Notes panel */
.notes-list {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.notes-list .empty {
  color: var(--muted);
  font-size: 12px;
  font-style: italic;
  text-align: center;
  padding: 30px 12px;
}
.note-item {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: 13px;
  line-height: 1.45;
}
.note-item.done { opacity: 0.55; }
.note-item.done .note-text { text-decoration: line-through; }
.note-item input[type="checkbox"] {
  flex: none;
  width: 14px;
  height: 14px;
  margin-top: 3px;
  cursor: pointer;
}
.note-item .note-text {
  flex: 1 1 0;
  word-break: break-word;
  cursor: text;
}
.note-item .note-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s;
}
.note-item:hover .note-actions { opacity: 1; }
.note-item .note-actions button {
  padding: 2px 6px;
  font-size: 11px;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.note-item .note-actions button:hover { background: var(--panel); color: var(--text); }
.note-item .note-actions .send-btn:hover { color: var(--accent); }
.note-item .note-actions .delete-btn:hover { color: var(--error); }

/* Sessions panel */
.sessions-body {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.sessions-toolbar {
  flex: none;
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.sessions-toolbar button { flex: 1; padding: 7px 0; font-size: 13px; }
.sessions-list {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sessions-list .empty {
  color: var(--muted); font-size: 12px; font-style: italic;
  text-align: center; padding: 24px 12px;
}
.session-item {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  cursor: default;
}
.session-item:hover { border-color: var(--accent); }
.session-item .body { flex: 1 1 0; min-width: 0; }
.session-item .label {
  font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.session-item .meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.session-item .actions {
  display: flex; gap: 4px; opacity: 0; transition: opacity 0.15s;
}
.session-item:hover .actions { opacity: 1; }
.session-item .actions button {
  padding: 3px 8px; font-size: 11px;
  background: transparent; border-color: transparent; color: var(--muted);
}
.session-item .actions .load-btn:hover { color: var(--accent); border-color: var(--accent); background: var(--panel); }
.session-item .actions .del-btn:hover { color: var(--error); }

.note-composer {
  flex: none;
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}
.note-composer input { flex: 1 1 0; padding: 6px 10px; font-size: 13px; }
.note-composer button {
  flex: none;
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 18px;
  font-weight: 600;
  line-height: 1;
}

/* History panel */
.history-list {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.history-list .empty {
  color: var(--muted);
  font-size: 12px;
  font-style: italic;
  text-align: center;
  padding: 30px 12px;
}
.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: default;
  position: relative;
}
.history-item:hover { background: var(--panel-2); }
.history-item .dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.history-item.manual    .dot { background: var(--accent); }
.history-item.llm-post  .dot { background: var(--ok); }
.history-item.llm-pre   .dot { background: #888; }
.history-item.pre-save  .dot { background: #555; }
.history-item .body {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.history-item .label {
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-item .meta {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.history-item .restore-btn {
  flex: none;
  padding: 2px 8px;
  font-size: 11px;
  opacity: 0;
  transition: opacity 0.15s;
}
.history-item:hover .restore-btn { opacity: 1; }
.history-item .restore-btn:hover { background: var(--accent); color: white; border-color: var(--accent); }

/* Toast (LLM-post notification, errors, status) */
.toast-container {
  position: fixed;
  top: 60px;
  right: 14px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: 360px;
}
.toast {
  pointer-events: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: toast-in 0.18s ease-out;
}
.toast.llm-post { border-left-color: var(--ok); }
.toast .toast-msg { line-height: 1.4; white-space: pre-line; }
.toast .toast-actions { display: flex; gap: 6px; justify-content: flex-end; }
.toast .toast-actions button { padding: 4px 10px; font-size: 12px; }
@keyframes toast-in {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* Profile switcher (topbar) */
.profile-switcher { position: relative; }
.profile-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  font-size: 12px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.profile-btn:hover { background: #252932; }
.profile-btn.active-profile { border-color: var(--accent); color: var(--accent); }
.profile-arrow { font-size: 10px; color: var(--muted); flex: none; }
.profile-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 260px;
  max-width: 340px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
  z-index: 150;
  overflow: hidden;
}
.profile-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.profile-dropdown-item:last-child { border-bottom: none; }
.profile-dropdown-item:hover { background: var(--panel-2); }
.profile-dropdown-item.is-active { color: var(--accent); font-weight: 600; }
.profile-dropdown-item .dot {
  flex: none; width: 7px; height: 7px;
  border-radius: 50%; background: var(--border);
}
.profile-dropdown-item.is-active .dot { background: var(--accent); }
.profile-dropdown-item .item-label { flex: 1 1 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-dropdown-item .no-key { font-size: 11px; color: var(--error); flex: none; }
.profile-dropdown-add {
  padding: 9px 14px;
  font-size: 12px;
  color: var(--accent);
  cursor: pointer;
  text-align: center;
}
.profile-dropdown-add:hover { background: var(--panel-2); }

/* Settings modal — profile row */
.settings-header { display: flex; flex-direction: column; gap: 10px; margin-bottom: 4px; }
.settings-profile-row { display: flex; align-items: center; gap: 6px; }
.cfg-profile-select { flex: 1 1 0; font-size: 13px; padding: 6px 8px; }
.danger-btn { background: #2a1a1a; border-color: #4a2a2a; color: var(--error); padding: 6px 10px; }
.danger-btn:hover { background: #3a2020; }
.cfg-label-preview {
  font-size: 12px;
  color: var(--muted);
  padding: 6px 10px;
  background: var(--panel-2);
  border-radius: 6px;
  border: 1px solid var(--border);
}
.cfg-label-preview strong { color: var(--text); }
.cfg-policy {
  margin: 0 0 4px;
  padding: 8px 12px;
  font-size: 12px;
  background: rgba(91, 156, 255, 0.07);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  color: var(--text);
  line-height: 1.5;
}
.cfg-policy code {
  background: var(--panel-2);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
}

/* Token usage pill in workspace topbar */
.usage-cluster {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.usage-pill {
  font-size: 12px;
  color: var(--muted);
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  cursor: default;
}
.usage-cluster:hover .usage-pill { border-color: var(--accent); color: var(--text); }
.usage-calc {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-decoration: none;
  background: var(--panel-2);
  cursor: pointer;
  user-select: none;
}
.usage-calc:hover { border-color: var(--accent); background: var(--panel); }

/* Hover popover with model breakdown */
.usage-tooltip {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 280px;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
  padding: 10px 12px;
  font-size: 12px;
  z-index: 150;
}
.usage-tooltip .ut-head {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin-bottom: 6px;
}
.usage-tooltip .ut-total {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.usage-tooltip .ut-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 3px 0;
  font-variant-numeric: tabular-nums;
}
.usage-tooltip .ut-row .ut-model {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text);
}
.usage-tooltip .ut-row .ut-tokens { color: var(--muted); }
.usage-tooltip .ut-row .ut-turns  { color: var(--muted); font-size: 11px; }
.usage-tooltip .ut-empty { color: var(--muted); font-style: italic; padding: 6px 0; }
.usage-tooltip .ut-archive {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
}

/* Per-message footer (model + tokens) shown under each assistant turn */
.msg-meta {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  gap: 8px;
}
.msg-meta .meta-tokens { color: var(--text); opacity: 0.85; }
.msg-meta .meta-model {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
}

/* Template picker modal */
.modal-wide { width: 720px; max-width: 92vw; }
.template-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 8px;
}
.template-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 18px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, transform 0.15s, background 0.15s;
  min-height: 110px;
}
.template-card:hover {
  border-color: var(--accent);
  background: #1f2530;
  transform: translateY(-2px);
}
.template-card .template-icon {
  font-size: 22px;
  color: var(--accent);
  margin-bottom: 4px;
}
.template-card .template-name {
  font-size: 14px;
  font-weight: 600;
}
.template-card .template-desc {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

@media (max-width: 640px) {
  .template-grid { grid-template-columns: repeat(2, 1fr); }
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}
