/* Desktop: wallpaper, top bar, dock, and the window look shared by tiled and floating modes.
   A theme may set --wallpaper (any CSS background) and --wallpaper-ink (text drawn straight on it);
   without one, the wallpaper is a sky that follows the local time (data-sky on #app). */

:root {
  --win-radius: 10px;
  --win-gap: 10px;
  --glass: color-mix(in srgb, var(--surface) 86%, transparent);
  --glass-line: color-mix(in srgb, var(--text) 14%, transparent);
}

#app { grid-template-rows: auto minmax(0, 1fr) var(--bar-h); }

#app[data-sky="dawn"] { --sky: linear-gradient(180deg, #3d4a7a 0%, #b77ea0 45%, #f2b48a 80%, #f7d7a8 100%); --sky-ink: #fbf6f0; }
#app[data-sky="day"] { --sky: linear-gradient(180deg, #3f7fc4 0%, #74aee0 45%, #b9d9f0 85%, #e3eef5 100%); --sky-ink: #ffffff; }
#app[data-sky="dusk"] { --sky: linear-gradient(180deg, #23284f 0%, #6a3f73 40%, #d0646a 75%, #f0a35e 100%); --sky-ink: #fbf3ec; }
#app[data-sky="night"] { --sky: linear-gradient(180deg, #05070f 0%, #0d1530 50%, #1c2648 85%, #2a3157 100%); --sky-ink: #e9ecf5; }
#app {
  background: var(--wallpaper, var(--sky, var(--bg)));
  background-size: cover;
  --ink: var(--wallpaper-ink, var(--sky-ink, var(--text)));
}
[data-theme="light"] #app[data-sky] { --sky-ink: #ffffff; }

/* ---- top bar ---- */
#topbar {
  display: flex; align-items: center; gap: 10px; min-width: 0; padding: 8px var(--win-gap) 0;
  color: var(--ink); font-family: var(--font-prose); font-size: 13px;
}
.top-mark { font-weight: 750; font-size: 16px; letter-spacing: -0.01em; }
.top-clock { opacity: 0.8; font-variant-numeric: tabular-nums; }
.top-spacer { flex: 1; }
.top-pulse { display: inline-flex; align-items: center; gap: 6px; opacity: 0.9; white-space: nowrap; }
.top-pulse:not(:empty)::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: 0.5; }
.top-pulse.ok::before { background: #6fd08c; opacity: 1; box-shadow: 0 0 0 3px rgba(111, 208, 140, 0.25); }
.top-pulse.warn::before { background: #f2c14e; opacity: 1; }
.top-pulse.bad::before { background: #f07167; opacity: 1; }
.top-btn, .seg {
  font: inherit; border-radius: 999px; border: 1px solid color-mix(in srgb, var(--ink) 28%, transparent);
  background: color-mix(in srgb, var(--surface) 35%, transparent); color: var(--ink);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.top-btn { padding: 4px 12px; cursor: pointer; white-space: nowrap; }
.top-btn:hover { background: color-mix(in srgb, var(--surface) 60%, transparent); }
.plan-btn { font-weight: 600; }
.plan-btn.is-pro { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.seg { display: inline-flex; padding: 2px; }
.seg-btn { font: inherit; border: 0; background: transparent; color: inherit; padding: 2px 12px; border-radius: 999px; cursor: pointer; }
.seg-btn[aria-checked="true"] { background: var(--accent); color: var(--accent-fg); font-weight: 600; }

/* ---- windows (both modes) ---- */
#stage-wrap { position: relative; padding: var(--win-gap); }
#app.has-dock #stage-wrap { padding-bottom: calc(var(--win-gap) + 50px); }
#stage { --gap: var(--win-gap); }
.pane {
  border-radius: var(--win-radius); background: var(--glass); border: 1px solid var(--glass-line);
  backdrop-filter: blur(18px) saturate(1.15); -webkit-backdrop-filter: blur(18px) saturate(1.15);
}
.pane.is-focused { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.pane-head { background: color-mix(in srgb, var(--surface-2) 80%, transparent); }
.pane-idx { border-radius: var(--win-radius) 0 0 0; }
.pane-min, .pane-grip { display: none; }

/* ---- floating mode ---- */
#stage[data-mode="floating"] .pane { box-shadow: 0 14px 40px rgba(0, 0, 0, 0.32); }
#stage[data-mode="floating"] .pane.is-focused { box-shadow: 0 0 0 1px var(--accent), 0 18px 50px rgba(0, 0, 0, 0.4); }
#stage[data-mode="floating"] .pane-head { cursor: grab; }
#stage[data-mode="floating"] .pane-head :is(button, select, input) { cursor: pointer; }
#stage[data-mode="floating"] .pane-min { display: inline-block; }
#stage[data-mode="floating"] .pane-grip {
  display: block; position: absolute; right: 0; bottom: 0; width: 18px; height: 18px; cursor: nwse-resize; touch-action: none;
  background: linear-gradient(135deg, transparent 55%, var(--border-strong) 55%, var(--border-strong) 62%, transparent 62%, transparent 75%, var(--border-strong) 75%, var(--border-strong) 82%, transparent 82%);
}
#stage[data-mode="floating"] .pane.is-zoomed .pane-grip { display: none; }
#stage[data-mode="floating"] .pane.is-min { display: none; }
#stage.dragging { user-select: none; }
#stage.dragging .pane-body { pointer-events: none; }
#stage.dragging .pane-head { cursor: grabbing; }

/* ---- dock (floating only) ---- */
#dock {
  position: absolute; z-index: 950; left: 50%; bottom: var(--win-gap); transform: translateX(-50%);
  display: flex; gap: 4px; padding: 5px; border-radius: 16px; max-width: calc(100% - 40px); overflow-x: auto;
  background: color-mix(in srgb, var(--surface) 70%, transparent); border: 1px solid var(--glass-line);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  font-family: var(--font-prose);
}
.dock-btn {
  font: inherit; font-size: 12.5px; padding: 5px 12px; border-radius: 11px; border: 0; cursor: pointer; white-space: nowrap;
  background: transparent; color: var(--text); position: relative;
}
.dock-btn:hover { background: var(--surface-3); }
.dock-btn.is-focused { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.dock-btn.is-min { color: var(--text-faint); }
.dock-btn.is-min::after { content: ""; position: absolute; left: 50%; bottom: 2px; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: var(--text-faint); }
.dock-add { color: var(--text-dim); font-weight: 700; }

/* ---- shared bits for the Hark-style windows ---- */
.foryou, .panels { display: flex; flex-direction: column; min-height: 0; font-family: var(--font-prose); font-size: 13.5px; }
.feed, .panel-list { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 10px; }
.quiet { margin: 0; color: var(--text-dim); font-size: 12.5px; }
.card, .panel { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 11px 13px; }
.card { border-left: 4px solid var(--text-faint); }
.card.tone-accent { border-left-color: var(--accent); }
.card.tone-warn { border-left-color: var(--warn); }
.card.tone-err { border-left-color: var(--err); }
.card.tone-ok { border-left-color: var(--ok); }
.card.tone-info { border-left-color: var(--info); }
.card-title { margin: 0 0 3px; font-size: 14px; font-weight: 600; }
.card-detail { margin: 0; color: var(--text-dim); line-height: 1.45; }
.card-code { display: block; white-space: pre-wrap; margin-top: 7px; padding: 5px 9px; border-radius: 7px; font-size: 12px; background: var(--surface); user-select: all; overflow-wrap: anywhere; }
.acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.act {
  font: inherit; font-size: 12.5px; padding: 3px 11px; border-radius: 999px; cursor: pointer;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
}
.act:hover { background: var(--surface-3); }
.act.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
.act.ghost { background: transparent; border-color: transparent; color: var(--text-dim); }

.panel-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.panel-head h3 { margin: 0; flex: 1; font-size: 11.5px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-dim); }
.panel-tools { display: flex; gap: 4px; }
.icon-btn { width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font: inherit; line-height: 1; }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.panels.customizing .panel { outline: 2px dashed color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 1px; }
.panel-add { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 0 10px 10px; }
.panel-add:empty { display: none; }
.big { margin: 0 0 5px; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.big-of { font-size: 13px; font-weight: 400; color: var(--text-dim); letter-spacing: 0; }
.meter { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.meter .bar { flex: 1; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; margin: 0; }
.stats dt { font-size: 11.5px; color: var(--text-dim); }
.stats dd { margin: 0; font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; }
.last-model { margin: 0 0 5px; font-size: 14.5px; font-weight: 600; }
.live { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.live li { display: flex; align-items: center; gap: 6px; }
.live li.failed .live-model { color: var(--err); }
.live-model { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-mono); font-size: 12px; }

/* chat empty state: greeting and suggestions */
.chat-greet { margin: 6px 0 6px; font-family: var(--font-prose); font-size: clamp(24px, 3vw, 36px); font-weight: 650; letter-spacing: -0.02em; color: var(--text); }
.chat-empty .empty-detail { font-family: var(--font-prose); font-size: 14px; }
.suggest { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.suggest-btn {
  font-family: var(--font-prose); font-size: 13px; padding: 6px 13px; border-radius: 999px; cursor: pointer;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
}
.suggest-btn:hover { border-color: var(--accent); }

@media (max-width: 640px) {
  .top-clock, .top-pulse { display: none; }
  #topbar { flex-wrap: wrap; gap: 6px; padding: 8px 8px 0; }
  :root { --win-gap: 6px; }
}

/* connect window */
.connect { display: flex; flex-direction: column; min-height: 0; font-family: var(--font-prose); font-size: 13.5px; }
.connect-intro { margin: 0; padding: 10px 12px 0; color: var(--text-dim); }
.connect-list { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 10px 12px 12px; }
.connect-h { margin: 6px 0 0; font-size: 11.5px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-dim); }
.connect-row { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 5px; }
.connect-row.is-set { border-left: 4px solid var(--ok); }
.connect-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.connect-row .acts { margin-top: 2px; }
.connect-form { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 4px; }
.connect-input { flex: 1 1 220px; min-width: 0; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font-family: var(--font-mono); font-size: 12.5px; }
.connect-input:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.connect-note { flex-basis: 100%; }
.connect-note:empty { display: none; }
.btn.mic { font-family: var(--font-prose); }
.btn.mic.recording { background: var(--err); border-color: var(--err); color: var(--accent-fg); animation: mic-pulse 1.2s ease-in-out infinite; }
@keyframes mic-pulse { 50% { opacity: 0.65; } }
.connect-train { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; border: 1px dashed var(--border-strong); cursor: pointer; }
.connect-train input { margin-top: 3px; accent-color: var(--accent); }

/* Omarchy-style leader key pop-up */
.whichkey {
  position: fixed; z-index: 980; left: 50%; bottom: calc(var(--bar-h) + 14px); transform: translateX(-50%);
  width: min(880px, calc(100vw - 24px)); max-height: 60vh; overflow-y: auto; padding: 14px 16px;
  background: color-mix(in srgb, var(--surface) 92%, transparent); border: 1px solid var(--accent);
  border-radius: 14px; box-shadow: var(--shadow); font-size: 12.5px; pointer-events: none;
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.wk-title { display: flex; justify-content: space-between; margin-bottom: 10px; color: var(--accent); font-weight: 700; letter-spacing: 0.04em; }
.wk-esc { color: var(--text-faint); font-weight: 400; }
.wk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px 18px; }
.wk-group h4 { margin: 0 0 5px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); }
.wk-row { display: flex; gap: 10px; align-items: baseline; padding: 2px 0; }
.wk-row kbd { flex: none; min-width: 64px; text-align: center; }
.wk-row span { color: var(--text); }

/* team chat */
.team { display: flex; flex-direction: column; min-height: 0; }
.team-bots { flex: none; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.team-chip-wrap { display: inline-flex; align-items: center; gap: 2px; }
.team-chip { font: 600 12.5px var(--font-mono); padding: 3px 10px; border-radius: 999px; cursor: pointer; color: var(--bot, var(--accent)); background: color-mix(in srgb, var(--bot, var(--accent)) 14%, transparent); border: 1px solid color-mix(in srgb, var(--bot, var(--accent)) 45%, transparent); }
.team-chip-wrap .icon-btn { width: 22px; height: 22px; font-size: 11px; }
.msg.team-bot { border-left-color: var(--bot, var(--border-strong)); }
.msg.team-bot .msg-role { color: var(--bot, var(--text-faint)); }
.team-note { margin: 0; font-size: var(--fs-small); }
.team-editor { flex: 1; min-height: 0; overflow-y: auto; padding: 12px; font-family: var(--font-prose); }
.team-form { display: flex; flex-direction: column; gap: 10px; max-width: 560px; }
.team-field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--text-dim); }
.team-field .connect-input { flex: none; font-family: var(--font-prose); font-size: 13.5px; }
.team-instructions { resize: vertical; min-height: 90px; }
.team-row { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.bot-avatar { display: inline-grid; place-items: center; flex: none; border-radius: 50%; object-fit: cover; vertical-align: middle; }
.bot-avatar.initials { background: var(--bot, var(--accent)); color: #0b0d10; font: 700 10px/1 var(--font-prose); }
.bot-avatar.initials.big { width: 96px; height: 96px; font-size: 30px; }
.team-chip { display: inline-flex; align-items: center; gap: 6px; padding-left: 3px; }
.team-role { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.team-picture-block { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.team-picture img { width: 96px; height: 96px; border-radius: 50%; object-fit: cover; border: 2px solid var(--border-strong); }
.team-picture-tools { flex: 1 1 260px; display: flex; flex-direction: column; gap: 6px; }
