/* planplace — base stylesheet. Team/project theme CSS loads after this. */

@font-face {
  font-family: "Geist Mono";
  src: url("/static/fonts/GeistMono-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #fafafa;
  --bg-raised: #ffffff;
  --bg-sunken: #f0f0f0;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --border: #e2e2e2;
  --accent: #4f46e5;
  --accent-fg: #ffffff;
  --danger: #b91c1c;
  --s-draft: #8a8a8a;
  --s-in_review: #b45309;
  --s-approved: #15803d;
  --s-in_progress: #1d4ed8;
  --s-implemented: #7c3aed;
  --radius: 6px;
  --font: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111113;
    --bg-raised: #1a1a1e;
    --bg-sunken: #0c0c0e;
    --fg: #e6e6e6;
    --muted: #8f8f96;
    --border: #2a2a30;
    --accent: #818cf8;
    --accent-fg: #111113;
    --danger: #f87171;
    --s-draft: #7d7d85;
    --s-in_review: #d97706;
    --s-approved: #22c55e;
    --s-in_progress: #60a5fa;
    --s-implemented: #a78bfa;
  }
}

:root[data-theme="dark"] {
  --bg: #111113;
  --bg-raised: #1a1a1e;
  --bg-sunken: #0c0c0e;
  --fg: #e6e6e6;
  --muted: #8f8f96;
  --border: #2a2a30;
  --accent: #818cf8;
  --accent-fg: #111113;
  --danger: #f87171;
  --s-draft: #7d7d85;
  --s-in_review: #d97706;
  --s-approved: #22c55e;
  --s-in_progress: #60a5fa;
  --s-implemented: #a78bfa;
}

/* author display rules must never defeat the hidden attribute */
[hidden] {
  display: none !important;
}

* {
  box-sizing: border-box;
  /* smooth theme switches; no effect on initial paint */
  transition:
    background-color 0.25s ease,
    border-color 0.25s ease,
    color 0.15s ease;
}

/* gentle cross-document fade between pages (Chrome/Safari; no-op elsewhere) */
@view-transition {
  navigation: auto;
}
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.1s;
}
@media (prefers-reduced-motion: reduce) {
  @view-transition {
    navigation: none;
  }
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--fg);
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* text hierarchy: page title > section label > body > meta */
h1 { font-size: 20px; font-weight: 650; margin: 0 0 8px; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 8px; }
h3 { font-size: 13px; font-weight: 600; margin: 16px 0 8px; }
.card > h2 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 12px;
}

code {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: inherit;
  font-size: 0.92em;
}

.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); }

/* ---------- shell ---------- */

.shell { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 48px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
  flex-shrink: 0;
}

.topbar-left { display: flex; align-items: center; gap: 8px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.icon { width: 15px; height: 15px; flex-shrink: 0; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: var(--radius);
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--bg-sunken); color: var(--fg); }

.logo {
  font-weight: 700;
  font-size: 15px;
  color: var(--fg);
  letter-spacing: -0.02em;
}
.logo:hover { text-decoration: none; }
.logo-accent { color: var(--accent); }
.logo-large { font-size: 26px; }

/* user dropdown */
.user-menu { position: relative; }
.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
  padding: 4px 10px;
  border-radius: var(--radius);
}
.user-chip::-webkit-details-marker { display: none; }
.user-chip:hover { background: var(--bg-sunken); color: var(--fg); }
.user-menu[open] .user-chip { background: var(--bg-sunken); color: var(--fg); }
.caret { font-size: 10px; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 180px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  padding: 4px;
  z-index: 20;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border: none;
  background: none;
  border-radius: var(--radius);
  color: var(--fg);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
}
.menu-item:hover { background: var(--bg-sunken); text-decoration: none; }
.menu-item[aria-selected="true"] {
  color: var(--accent);
  background: var(--bg-sunken);
}

/* ---------- custom dropdown (styled <select> replacement) ---------- */

.dropdown { position: relative; }
.dropdown-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--fg);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  list-style: none;
  white-space: nowrap;
}
.dropdown-btn::-webkit-details-marker { display: none; }
.dropdown-btn:hover { border-color: var(--accent); }
.dropdown[open] > .dropdown-btn { border-color: var(--accent); }
.dropdown-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dropdown-menu {
  left: 0;
  right: auto;
  max-height: 320px;
  overflow-y: auto;
}
.status-dropdown .dropdown-btn,
.rev-dropdown .dropdown-btn { font-size: 12px; padding: 4px 10px; }
.user-menu .menu { left: auto; right: 0; }
.theme-icon { width: 14px; height: 14px; }
.icon-sun { display: none; }
:root[data-theme="dark"] .icon-sun { display: inline; }
:root[data-theme="dark"] .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: inline; }
  :root:not([data-theme="light"]) .icon-moon { display: none; }
}
.avatar { width: 22px; height: 22px; border-radius: 50%; }

.workspace { display: flex; flex: 1; min-height: 0; }

.sidebar {
  width: 260px;
  flex-shrink: 0;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--bg-raised);
  padding: 10px;
}
.shell.nosidebar .sidebar { display: none; }

.sidebar-top {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 14px;
}
.sidebar-top .team-select { flex: 1; min-width: 0; }
.sidebar-top .team-select .dropdown-btn {
  width: 100%;
  justify-content: space-between;
  font-weight: 600;
  font-size: 13px;
}

.tree-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 0 8px;
  margin-bottom: 4px;
}

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.pane { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 24px 32px 64px; max-width: 980px; }

/* ---------- file tree ---------- */

.tree-project { margin-bottom: 2px; }
.tree-project > summary {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius);
  list-style: none;
  font-size: 13px;
  font-weight: 600;
}
.tree-project > summary::-webkit-details-marker { display: none; }
.tree-project > summary::before {
  content: "▸";
  color: var(--muted);
  font-size: 9px;
  width: 10px;
  flex-shrink: 0;
  transition: transform 0.12s ease;
}
.tree-project[open] > summary::before { transform: rotate(90deg); }
.tree-project > summary:hover { background: var(--bg-sunken); }
.tree a { color: var(--fg); }
.tree a:hover { text-decoration: none; }
.tree a.active { color: var(--accent); }
.tree-plans { list-style: none; margin: 0 0 4px; padding: 0; }
.tree-plans a {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 3px 8px 3px 22px;
  border-radius: var(--radius);
  font-size: 12.5px;
  color: var(--muted);
}
.tree-plans a:hover { background: var(--bg-sunken); color: var(--fg); }
.tree-plans a.active { color: var(--accent); background: var(--bg-sunken); }
.tree-plan-title {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.tree-empty {
  padding: 2px 8px 2px 22px;
  font-size: 12px;
  color: var(--muted);
  opacity: 0.7;
}
.tree-new {
  display: block;
  margin-top: 8px;
  padding: 3px 8px;
  font-size: 12px;
  color: var(--muted);
}
.tree-new:hover { color: var(--fg); text-decoration: none; }

.dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.dot-draft { background: var(--s-draft); }
.dot-in_review { background: var(--s-in_review); }
.dot-approved { background: var(--s-approved); }
.dot-in_progress { background: var(--s-in_progress); }
.dot-implemented { background: var(--s-implemented); }

/* ---------- tabs ---------- */

.tabbar {
  display: flex;
  gap: 2px;
  padding: 6px 12px 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
  overflow-x: auto;
  flex-shrink: 0;
}
.tab {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 4px 4px 4px 12px;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--bg);
  max-width: 220px;
  white-space: nowrap;
  font-size: 12px;
  flex-shrink: 0;
}
.tab.active { background: var(--bg-sunken); }
.tab-link {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
}
.tab.active .tab-link { color: var(--fg); }
.tab-link:hover { text-decoration: none; color: var(--fg); }
.tab-close {
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 2px 5px;
  border-radius: var(--radius);
}
.tab-close:hover { color: var(--danger); background: var(--bg-raised); }

/* ---------- badges & status ---------- */

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.badge-draft { color: var(--s-draft); border-color: var(--s-draft); }
.badge-in_review { color: var(--s-in_review); border-color: var(--s-in_review); }
.badge-approved { color: var(--s-approved); border-color: var(--s-approved); }
.badge-in_progress { color: var(--s-in_progress); border-color: var(--s-in_progress); }
.badge-implemented { color: var(--s-implemented); border-color: var(--s-implemented); }

/* ---------- cards, tables, forms ---------- */

.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 16px 0;
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
  margin: 16px 0;
}
.card-grid .card { margin: 0; }
.card-link { color: var(--fg); display: block; }
.card-link:hover { border-color: var(--accent); text-decoration: none; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.breadcrumb { color: var(--muted); margin: 0 0 2px; font-size: 12px; }
.breadcrumb a { color: var(--muted); }

.plan-table { width: 100%; border-collapse: collapse; margin: 12px 0; }
.plan-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}
.plan-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); }
.plan-table tr.archived { opacity: 0.5; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--fg);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn-primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn-ghost { border-color: transparent; background: none; color: var(--muted); }
.btn-ghost:hover { color: var(--fg); border-color: var(--border); }

.field { display: block; margin: 12px 0; }
.field-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 4px;
}
.field-hint { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }

input, select, textarea {
  font-family: inherit;
  font-size: 13px;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  width: 100%;
  max-width: 560px;
}
textarea { resize: vertical; }
select { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.code-line {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  overflow-x: auto;
}
.code-line code { background: none; border: none; padding: 0; }

/* ---------- copy buttons ---------- */

.copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: none;
  color: var(--muted);
  cursor: pointer;
  vertical-align: middle;
}
.copy-btn:hover { color: var(--fg); border-color: var(--border); background: var(--bg-raised); }
.copy-btn .icon { width: 13px; height: 13px; }
.code-line-wrap { position: relative; }
.code-line-wrap .copy-btn {
  position: absolute;
  top: 7px;
  right: 7px;
  background: var(--bg-sunken);
}

/* ---------- comments ---------- */

.comment-marker {
  position: absolute; /* in .plan-doc space; top/left set by the island */
  z-index: 29;
  min-width: 20px;
  height: 20px;
  border: 1px solid var(--s-in_progress);
  border-radius: 999px;
  background: var(--bg-raised);
  color: var(--s-in_progress);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  padding: 0 5px;
}
.comment-marker:hover { background: var(--s-in_progress); color: var(--bg); }
.comment-marker.resolved { border-color: var(--muted); color: var(--muted); }
.comment-marker.question { border-color: var(--s-in_review); color: var(--s-in_review); }
.comment-marker.question:hover { background: var(--s-in_review); color: var(--bg); }

.comment-fab {
  position: absolute;
  z-index: 30;
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius);
  background: var(--s-in_progress);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
}
.comment-fab svg { width: 14px; height: 14px; }
.comment-fab:hover { filter: brightness(1.12); }

.comment-popover {
  position: absolute;
  z-index: 31;
  width: 340px;
  max-height: 420px;
  overflow-y: auto;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
  padding: 10px 12px;
}
.comment { padding: 6px 0; }
.comment + .comment { border-top: 1px solid var(--border); }
.comment-resolved { opacity: 0.6; }
.comment-head { font-size: 11px; color: var(--muted); }
.comment-body { margin: 4px 0; font-size: 13px; white-space: pre-wrap; }
.comment-reply { margin-left: 14px; padding-left: 10px; border-left: 2px solid var(--border); margin-top: 6px; }
.comment-actions { display: flex; gap: 6px; margin-top: 6px; }
.comment-actions .btn { font-size: 12px; padding: 3px 10px; }
.comment-composer textarea { width: 100%; max-width: none; margin-bottom: 6px; }

#detached-comments,
#newer-comments,
#plan-questions {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
}
#plan-questions { border-left: 3px solid var(--s-in_review); }
.comment-question > .comment-head { color: var(--s-in_review); }

/* ---------- question option chips ---------- */

.option-chips {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 8px 0;
}
.option-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}
.option-chip:hover:not(:disabled) { border-color: var(--accent); }
.option-chip:disabled { cursor: default; opacity: 0.7; }
.option-chip.chosen {
  border-color: var(--s-approved);
  background: var(--bg-sunken);
}
.option-chip.chosen .option-chip-label::after {
  content: " ✓";
  color: var(--s-approved);
}
.option-chip-label { font-weight: 600; }
.option-chip-rec {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
}
.option-chip-desc { font-size: 12px; color: var(--muted); }

/* ---------- connect-an-agent tabs ---------- */

.connect-tabs {
  display: flex;
  gap: 6px;
  margin: 12px 0;
  flex-wrap: wrap;
}
.connect-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}
.connect-tab:hover { color: var(--fg); }
.connect-tab.active {
  color: var(--fg);
  border-color: var(--accent);
  background: var(--bg-raised);
}
.brand-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  display: inline-block;
}
.brand-braces {
  font-size: 12px;
  font-weight: 700;
  width: auto;
}
.connect-panel .btn .brand-icon { width: 13px; height: 13px; }

/* ---------- plan viewer ---------- */

.plan-chrome { border-bottom: 1px solid var(--border); padding-bottom: 12px; margin-bottom: 24px; }
.plan-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.share-row { font-size: 12px; color: var(--muted); }
.notice {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 12px;
}

.meta-panel { font-size: 12px; color: var(--muted); margin-top: 8px; }
.meta-panel summary { cursor: pointer; }
.meta-panel table { margin-top: 6px; border-collapse: collapse; }
.meta-panel th { text-align: left; padding: 2px 16px 2px 0; font-weight: 600; }
.meta-panel td { padding: 2px 0; }

/* rendered plan document — positioning context for comment widgets */
.plan-doc { font-size: 14px; position: relative; }
.plan-doc h1 { font-size: 24px; margin: 28px 0 12px; }
.plan-doc h2 { font-size: 19px; margin: 24px 0 10px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.plan-doc h3 { font-size: 15px; margin: 20px 0 8px; }
.plan-doc p { margin: 10px 0; }
.plan-doc pre {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  overflow-x: auto;
}
.plan-doc pre code { background: none; border: none; padding: 0; }
.plan-doc blockquote {
  margin: 12px 0;
  padding: 4px 16px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}
.plan-doc table { border-collapse: collapse; margin: 12px 0; }
.plan-doc table th, .plan-doc table td { border: 1px solid var(--border); padding: 5px 12px; }
.plan-doc table th { background: var(--bg-sunken); }
.plan-doc img { max-width: 100%; border-radius: var(--radius); }
.plan-doc ul { padding-left: 24px; }
.plan-doc li:has(> .task-checkbox) { list-style: none; margin-left: -20px; }
.plan-doc .task-checkbox { width: auto; accent-color: var(--accent); cursor: pointer; }
body[data-readonly] .task-checkbox { pointer-events: none; }
.plan-doc figure { margin: 16px 0; }
.plan-doc figcaption { font-size: 12px; color: var(--muted); margin-top: 4px; }
.plan-doc .mermaid { display: flex; justify-content: center; background: var(--bg-raised); }
.block { margin: 0 0 8px; }

/* ---------- share page & login ---------- */

.share-shell { min-height: 100vh; display: flex; flex-direction: column; }
.share-main { max-width: 860px; margin: 0 auto; padding: 24px 32px 64px; width: 100%; }

.center-card {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.center-card .card { width: 380px; text-align: center; padding: 32px; }
.center-card .btn { margin-top: 12px; }

.invite-list { padding-left: 18px; }
.invite-list li { margin: 6px 0; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--fg);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  z-index: 10;
}
.toast.show { opacity: 1; }
.toast-error { background: var(--danger); color: #fff; }
