/* The authenticated workspace (/app). Square, warm, yellow — the same
   language as the marketing pages, at working density. */

html,
body {
  height: 100%;
}

body {
  overflow: hidden;
}

#app-root {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* -------------------------------------------------------------- topbar --- */

.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
  min-height: 52px;
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: var(--weight-bold);
  font-size: var(--text-base);
  letter-spacing: -0.01em;
  color: var(--color-ink);
}

.topbar .brand__mark {
  height: 1.15em;
  width: auto;
  flex: none;
  fill: currentColor;
}

.topbar .brand:hover {
  color: var(--color-ink);
}

.topbar .navlink {
  font-size: var(--text-sm);
  color: var(--color-muted);
}

.topbar .navlink:hover {
  color: var(--color-ink);
}

.topbar-spacer {
  flex: 1;
}

/* ------------------------------------------------------------ user menu --- */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.user-menu {
  position: relative;
}

.user-menu__trigger {
  display: flex;
  align-items: center;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
}

/* The one deliberate curve in an otherwise square system — an account avatar
   is a strong enough convention to earn the exception. --radius-full is
   otherwise reserved for window-chrome dots. */
.user-menu__avatar {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: var(--color-on-primary);
  font-family: var(--font-display);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  line-height: 1;
}

.user-menu__trigger:hover .user-menu__avatar {
  background: var(--color-primary-strong);
}

.user-menu__panel {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  z-index: 60;
  min-width: 15rem;
  padding: var(--space-2) 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-none);
  box-shadow: var(--shadow-lg);
}

.user-menu__identity {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-2) var(--space-4) var(--space-3);
}

.user-menu__name {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-ink);
}

.user-menu__email {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-muted);
  overflow-wrap: anywhere;
}

.user-menu__group {
  padding-top: var(--space-2);
  border-top: 1px solid var(--color-border);
}

.user-menu__submenu-host {
  position: relative;
}

/* Flies out to the LEFT. The parent panel is already flush with the right
   edge of the viewport, so the conventional right-hand flyout would open
   off-screen. */
.user-menu__panel--sub {
  top: calc(-1 * var(--space-2));
  /* Overlap by the border width so the two panels share one seam instead of
     showing a double rule or floating apart. */
  right: calc(100% - 1px);
  left: auto;
  min-width: 10rem;
}

.user-menu__item--parent[aria-expanded="true"] {
  background: var(--color-surface-sunken);
}

/* Chevron drawn from borders rather than set as a glyph — Space Grotesk has
   no reliable arrow, and this also lets it point left, at the side the
   submenu actually opens on. */
.user-menu__item--parent::after {
  content: "";
  flex: none;
  width: 6px;
  height: 6px;
  margin-left: auto;
  border-left: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  opacity: 0.55;
}

.user-menu__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-2) var(--space-4);
  border: none;
  border-radius: var(--radius-none);
  background: none;
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
}

.user-menu__item:hover {
  background: var(--color-surface-sunken);
}

/* The selected marker is a swatch, not a tick: it reuses the square-chip
   language the product is built on, and sidesteps Space Grotesk having no
   check glyph — a ✓ here falls back to something resembling a square root. */
.user-menu__item--choice::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  background: transparent;
}

.user-menu__item--choice[aria-checked="true"]::before {
  background: var(--color-primary);
}

.user-menu__item--choice[aria-checked="true"] {
  font-weight: var(--weight-medium);
}

main {
  flex: 1;
  min-height: 0;
  display: flex;
}

main > * {
  flex: 1;
  min-width: 0;
  display: block;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-none);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  background: none;
  color: var(--color-ink);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out),
              color var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out);
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-on-primary);
}

.btn-primary:hover {
  background: var(--color-ink);
  color: var(--color-bg);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn-ghost {
  border-color: var(--color-border-strong);
}

.btn-ghost:hover {
  border-color: var(--color-primary);
  color: var(--color-primary-text);
}

.btn-danger {
  color: var(--color-danger);
  border-color: var(--color-border-strong);
}

.btn-danger:hover {
  background: var(--color-danger-soft);
  border-color: var(--color-danger);
}

.btn-sm {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
}

/* -------------------------------------------------------- projects page --- */

.projects-page {
  padding: var(--space-7) var(--space-6);
  overflow-y: auto;
}

.projects-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  max-width: 64rem;
  margin: 0 auto var(--space-6);
}

.projects-header h1 {
  margin: 0;
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  letter-spacing: -0.02em;
}

.projects-grid {
  max-width: 64rem;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1px;
  background: var(--color-border);
  border: 1px solid var(--color-border);
}

.project-card {
  display: block;
  text-align: left;
  background: var(--color-bg);
  border: none;
  padding: var(--space-5);
  cursor: pointer;
  font-family: var(--font-body);
  color: var(--color-ink);
  transition: background var(--duration-fast) var(--ease-out);
}

.project-card:hover {
  background: var(--color-surface-sunken);
}

.project-card h3 {
  margin: 0 0 var(--space-1);
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
  letter-spacing: -0.01em;
}

.project-card p {
  margin: 0 0 var(--space-4);
  color: var(--color-muted);
  font-size: var(--text-sm);
}

.project-card .meta {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-muted);
}

.badge {
  display: inline-block;
  margin-left: var(--space-2);
  padding: 0 var(--space-2);
  background: var(--color-primary);
  color: var(--color-on-primary);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.empty-state {
  max-width: 64rem;
  margin: var(--space-9) auto;
  text-align: center;
  color: var(--color-muted);
}

.empty-state h2 {
  color: var(--color-ink);
  font-weight: var(--weight-bold);
  letter-spacing: -0.02em;
}

/* --------------------------------------------------------- project page --- */

.project-page {
  display: flex;
  height: 100%;
  min-height: 0;
}

.token-sidebar {
  width: 220px;
  flex-shrink: 0;
  border-right: 1px solid var(--color-border);
  background: var(--color-surface-sunken);
  padding: var(--space-4) 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.token-sidebar .sidebar-title {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  padding: 0 var(--space-5) var(--space-3);
}

.token-sidebar button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: 9px var(--space-5);
  border: none;
  border-left: 2px solid transparent;
  background: none;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--color-muted);
  cursor: pointer;
  text-transform: capitalize;
  text-align: left;
}

.token-sidebar button:hover {
  color: var(--color-ink);
  background: var(--color-bg);
}

.token-sidebar button.active {
  background: var(--color-primary);
  border-left-color: var(--color-primary);
  color: var(--color-on-primary);
  font-weight: var(--weight-medium);
}

.token-sidebar button .count {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  opacity: 0.7;
}

.token-sidebar .sidebar-footer {
  margin-top: auto;
  padding: var(--space-5) var(--space-5) 0;
}

/* ------------------------------------------------------------ token view --- */

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

.token-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--color-border);
  flex-wrap: wrap;
}

.token-toolbar input.project-name {
  font-family: var(--font-body);
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  letter-spacing: -0.02em;
  color: var(--color-ink);
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-none);
  padding: var(--space-1) var(--space-2);
  min-width: 0;
  width: 16rem;
}

.token-toolbar input.project-name:hover,
.token-toolbar input.project-name:focus {
  border-color: var(--color-border-strong);
  outline: none;
}

.dirty-dot {
  width: 8px;
  height: 8px;
  background: var(--color-primary);
  visibility: hidden;
}

.dirty-dot.visible {
  visibility: visible;
}

.token-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5);
}

.token-list h2 {
  margin: 0 0 var(--space-5);
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  letter-spacing: -0.02em;
  text-transform: capitalize;
}

.column-headers,
.token-row {
  display: grid;
  grid-template-columns: 28px minmax(8rem, 1fr) minmax(8rem, 1.2fr) minmax(8rem, 1.4fr) auto;
  gap: var(--space-3);
}

.column-headers {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}

.token-row {
  align-items: center;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-border);
}

.token-row input {
  width: 100%;
  padding: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-none);
  background: none;
  color: var(--color-ink);
  font-size: var(--text-sm);
}

.token-row input.token-name,
.token-row input.token-value {
  font-family: var(--font-mono);
}

.token-row input:hover {
  border-color: var(--color-border-strong);
}

.token-row input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: inset 0 0 0 1px var(--color-primary);
}

.token-row .swatch {
  width: 28px;
  height: 28px;
  border: 1px solid var(--color-border-strong);
  background:
    repeating-conic-gradient(var(--color-surface-sunken) 0% 25%, transparent 0% 50%) 50% / 12px 12px;
  position: relative;
  overflow: hidden;
}

.token-row .swatch::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--swatch-color, transparent);
}

.token-row .remove-token {
  border: none;
  background: none;
  color: var(--color-muted);
  cursor: pointer;
  font-size: var(--text-base);
  padding: var(--space-1) var(--space-2);
}

.token-row .remove-token:hover {
  color: var(--color-danger);
  background: var(--color-danger-soft);
}

.token-list-actions {
  padding: var(--space-5) 0;
  display: flex;
  gap: var(--space-3);
}

/* ---------------------------------------------------------- agent panel --- */

.agent-panel {
  width: 320px;
  flex-shrink: 0;
  border-left: 1px solid var(--color-border);
  background: var(--color-surface-sunken);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Collapsed keeps the element (and the conversation) in the DOM, so
   reopening restores the chat rather than starting over. */
.agent-panel.collapsed {
  display: none;
}

.agent-panel header {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--color-muted);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.agent-panel header::before {
  content: "";
  width: 8px;
  height: 8px;
  background: var(--color-success);
}

.agent-panel header .agent-close {
  margin-left: auto;
  border: none;
  background: none;
  color: var(--color-muted);
  font-size: var(--text-lg);
  line-height: 1;
  padding: 0 var(--space-1);
  cursor: pointer;
}

.agent-panel header .agent-close:hover {
  color: var(--color-ink);
  background: var(--color-bg);
}

/* Toolbar toggle reads as pressed while the panel is open */
.agent-toggle.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-on-primary);
}

.agent-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.agent-message {
  max-width: 100%;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.agent-message.user {
  align-self: flex-end;
  background: var(--color-primary);
  color: var(--color-on-primary);
}

.agent-message.assistant {
  align-self: flex-start;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
}

.agent-message.assistant pre {
  background: var(--color-surface-sunken);
  border: 1px solid var(--color-border);
  padding: var(--space-2);
  overflow-x: auto;
  max-height: 12rem;
  font-size: var(--text-xs);
}

.agent-message .apply-tokens {
  margin-top: var(--space-2);
}

.agent-message.thinking {
  color: var(--color-muted);
  font-style: italic;
}

.agent-form {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3);
  border-top: 1px solid var(--color-border);
}

.agent-form textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-none);
  background: var(--color-bg);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-3);
  min-height: 40px;
  max-height: 120px;
}

.agent-form textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: inset 0 0 0 1px var(--color-primary);
}

/* Dialogs live in <modal-ui>, whose styles are encapsulated in its shadow
   root (components/ui/modal/_styles.mjs) — nothing to style from here. */

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

#toast {
  position: fixed;
  bottom: var(--space-6);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-ink);
  color: var(--color-bg);
  padding: var(--space-3) var(--space-5);
  font-size: var(--text-sm);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-slow) var(--ease-out);
  z-index: 10;
}

#toast.visible {
  opacity: 1;
}

/* Too narrow for a 320px panel beside the editor: hide it, and hide the
   toggle too so there is no control that appears to do nothing. */
@media (max-width: 900px) {
  .agent-panel,
  .agent-toggle {
    display: none;
  }

  .token-sidebar {
    width: 170px;
  }
}
