/* Controls: buttons, segmented switch, chips, menus, popovers, History, ⌘K,
   notices, toasts, and dialogs. */

button {
  font: inherit;
  color: inherit;
}

kbd {
  font: 500 10.5px/1 var(--font-ui);
  color: var(--text-faint);
  letter-spacing: 0.02em;
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

.icon {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon.tiny {
  width: 12px;
  height: 12px;
}

.tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tool);
  height: var(--tool);
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  touch-action: manipulation;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

.tool:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.tool:active {
  background: var(--surface-active);
}

.tool:disabled,
.button:disabled {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}

.button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: var(--tool);
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

.button:hover {
  background: var(--surface-hover);
}

.button.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-muted);
}

.button.ghost:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.button.primary {
  border-color: transparent;
  background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 100%, black 8%));
  color: var(--accent-text);
  font-weight: 600;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.2), 0 1px 2px rgb(0 0 0 / 0.22);
}

.button.primary:hover {
  filter: brightness(1.06);
}

.button.danger {
  color: var(--danger);
  border-color: var(--danger);
  background: transparent;
}

.button.danger:hover {
  background: var(--danger-soft);
}

/* Segmented control (Design | Split | Code) */

.seg {
  display: inline-flex;
  padding: 2px;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.seg button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 9px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text-faint);
  font-weight: 500;
  cursor: pointer;
}

.seg button .icon {
  width: 14px;
  height: 14px;
}

.seg button:hover {
  color: var(--text);
}

.seg button[aria-checked="true"] {
  background: var(--surface-active);
  color: var(--text);
  box-shadow: var(--shadow-1);
}

.zoom-btn {
  font-variant-numeric: tabular-nums;
  min-width: 60px;
  justify-content: space-between;
}

/* Menus & popovers */

.menu-wrap {
  position: relative;
}

.menu,
.popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 50;
  min-width: 220px;
  padding: 5px;
  background: var(--raised);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
}

.menu.right {
  left: auto;
  right: 0;
}

.ctx-menu {
  position: fixed;
  z-index: 60;
  top: 0;
  left: 0;
}

/* New Document & Export dialogs */

.newdoc-dlg,
.export-dlg {
  width: min(460px, calc(100vw - 24px));
}

.newdoc-dims {
  display: flex;
  align-items: center;
  gap: 6px;
}

.newdoc-dlg .edit-input {
  background: var(--surface);
  border: 1px solid var(--border);
}

.newdoc-actions {
  gap: 8px;
}

.bg-swatches {
  display: flex;
  align-items: center;
  gap: 6px;
}

.bg-swatch-btn {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.bg-swatch-btn:hover {
  border-color: var(--accent);
}

.export-body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.fmt-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.fmt-pill {
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-muted);
  font-size: var(--t-12);
  font-weight: 600;
  cursor: pointer;
}

.fmt-pill:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.fmt-pill.on {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.exp-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
}

.exp-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.exp-lbl {
  min-width: 72px;
  font-size: var(--t-12);
  font-weight: 600;
  color: var(--text-muted);
}

.exp-meta {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: var(--t-11);
  color: var(--text-faint);
}

.exp-note {
  margin: 0;
  font-size: var(--t-12);
  color: var(--text-muted);
}

.exp-actions {
  display: flex;
  justify-content: flex-end;
}

/* Color & Token popover */

.color-pop {
  position: fixed;
  z-index: 70;
  width: 236px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cp-sec-title {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 6px;
}

.cp-swatches {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}

.cp-tile {
  width: 24px;
  height: 24px;
  border-radius: 5px;
  border: 1px solid rgb(11 26 46 / 0.18);
  cursor: pointer;
  padding: 0;
}

.cp-tile.on {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.cp-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.cp-spectrum {
  width: 32px;
  height: 28px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  flex: none;
}

.cp-hex {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--font-mono);
}

.cp-lbl {
  font-size: var(--t-11);
  color: var(--text-muted);
  min-width: 34px;
}

.cp-alpha {
  flex: 1 1 auto;
  min-width: 0;
}

.cp-alpha-val {
  font-family: var(--font-mono);
  font-size: var(--t-11);
  color: var(--text-faint);
  min-width: 32px;
  text-align: right;
}

.cp-save-tok {
  width: 100%;
  justify-content: center;
}

.swatch-btn {
  padding: 0;
  cursor: pointer;
  width: 16px;
  height: 16px;
}

.menu-wrap.up .popover {
  top: auto;
  bottom: calc(100% + 8px);
}

.menu button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  height: 30px;
  padding: 0 8px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.menu button .icon {
  color: var(--text-faint);
}

.menu button:hover {
  background: var(--accent);
  color: var(--accent-text);
}

.menu button:hover .icon,
.menu button:hover kbd {
  color: inherit;
}

.menu kbd {
  margin-left: auto;
}

.menu .check.on::after {
  content: "✓";
  margin-left: auto;
  color: var(--accent);
  font-weight: 600;
}

.menu .check.on:hover::after {
  color: inherit;
}

/* History popover */

.popover.history {
  width: 300px;
  padding: 0;
}

.pop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.history-list {
  max-height: 320px;
  overflow: auto;
  padding: 4px;
}

.h-step {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 30px;
  padding: 0 8px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  text-align: left;
  color: var(--text);
  position: relative;
  cursor: pointer;
}

.h-step .icon {
  width: 14px;
  height: 14px;
  color: var(--text-faint);
}

.h-step:hover {
  background: var(--surface-hover);
}

.h-step.cur {
  background: var(--accent-soft);
}

.h-step.cur::before {
  content: "";
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 2px;
  border-radius: 2px;
  background: var(--accent);
}

.h-step.cur .icon {
  color: var(--accent);
}

.h-step.ahead {
  color: var(--text-faint);
}

.h-step.ahead .h-label {
  font-style: italic;
}

.h-label {
  font-weight: 500;
}

.h-detail {
  margin-left: auto;
  color: var(--text-faint);
  font-size: var(--t-11);
  max-width: 50%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-foot {
  margin: 0;
  padding: 8px 12px 10px;
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  font-size: var(--t-11);
  line-height: 1.45;
}

/* Problems popover & status chips */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text-faint);
  font-size: var(--t-11);
  font-weight: 500;
  cursor: pointer;
}

.chip:hover {
  background: var(--surface-hover);
  color: var(--text-muted);
}

.chip.ok {
  color: var(--ok);
}

.chip.err {
  color: var(--danger);
  background: var(--danger-soft);
}

.popover.problems-pop {
  width: min(440px, calc(100vw - 16px));
  padding: 0;
}

.problems-pop .diag-list {
  max-height: 280px;
}

/* Stale & render badges on canvas */

.stale-badge {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 0;
  border-radius: 99px;
  background: color-mix(in srgb, var(--warning) 14%, var(--surface));
  color: var(--warning);
  font-size: var(--t-11);
  font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--shadow-1);
  cursor: pointer;
}

.stale-badge .icon {
  width: 13px;
  height: 13px;
}

.badge.render-badge {
  position: absolute;
  right: 12px;
  top: 12px;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 99px;
  background: var(--raised);
  color: var(--text-muted);
  font-size: var(--t-11);
  font-weight: 500;
  box-shadow: var(--shadow-1);
}

/* Export dropdown */

.export-tools {
  position: relative;
  z-index: 5;
}

.export-tools summary {
  list-style: none;
}

.export-tools summary::-webkit-details-marker {
  display: none;
}

.export-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  display: grid;
  width: max-content;
  max-width: min(220px, 80vw);
  padding: 5px;
  border-radius: var(--radius-lg);
  background: var(--raised);
  box-shadow: var(--shadow-pop);
}

.export-menu .button {
  min-height: 30px;
  border-color: transparent;
  background: transparent;
}

.export-menu .button:hover {
  background: var(--surface-hover);
}

.export-menu p {
  margin: 0;
  padding: 4px 10px 6px;
  color: var(--text-muted);
  font-size: var(--t-11);
}

.example-link {
  display: block;
  width: 100%;
  margin-top: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

/* Command palette (⌘K) */

.modal {
  border: 0;
  padding: 0;
  border-radius: var(--radius-xl);
  background: var(--raised);
  color: var(--text);
  box-shadow: var(--shadow-pop);
}

.modal::backdrop {
  background: rgb(3 8 16 / 0.55);
  backdrop-filter: blur(3px);
}

.cmdk {
  width: min(560px, 100vw - 24px);
  margin-top: 14vh;
}

.cmdk-input {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  height: 46px;
  border-bottom: 1px solid var(--border);
  color: var(--text-faint);
}

.cmdk-input input {
  flex: 1;
  background: none;
  border: 0;
  outline: none;
  font-size: var(--t-15);
  color: var(--text);
}

.cmdk-list {
  max-height: 360px;
  overflow: auto;
  padding: 6px;
}

.cmdk-group {
  font-size: var(--t-11);
  color: var(--text-faint);
  padding: 8px 8px 4px;
  font-weight: 600;
}

.cmdk-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-size: var(--t-13);
  cursor: pointer;
}

.cmdk-item .icon {
  color: var(--text-faint);
}

.cmdk-item kbd {
  margin-left: auto;
}

.cmdk-item:hover,
.cmdk-item.on {
  background: var(--accent-soft);
}

.cmdk-item.on {
  box-shadow: inset 2px 0 0 var(--accent);
}

.empty-pop {
  padding: 20px 12px;
  text-align: center;
  color: var(--text-faint);
}

/* Notices & toasts */

.notice {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-3);
  min-width: 0;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--info-soft);
}

.notice.error {
  background: var(--danger-soft);
}

.notice.warning {
  background: var(--warning-soft);
}

.notice-icon {
  display: flex;
  color: var(--info);
}

.notice.error .notice-icon {
  color: var(--danger);
}

.notice.warning .notice-icon {
  color: var(--warning);
}

.notice-text {
  flex: 1 1 260px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.notice-text strong {
  font-weight: 600;
}

.notice-code {
  font-family: var(--font-mono);
  font-size: var(--t-11);
  color: var(--text-muted);
  margin-right: 6px;
}

.notice-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.notice-detail {
  flex: 1 0 100%;
  max-height: 140px;
  margin: 0;
  padding: 6px 10px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: var(--t-11);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--status-h) + 12px);
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-width: calc(100vw - 24px);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-radius: var(--radius-lg);
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow-pop);
  font-weight: 500;
  pointer-events: auto;
}

.toast .icon {
  width: 14px;
  height: 14px;
  color: inherit;
}

body:has(dialog[open]) .toasts {
  visibility: hidden;
}

/* Recent & browser drafts / Project document chooser modals */

.doc-dialog {
  width: min(440px, calc(100vw - 24px));
  max-height: min(72vh, 560px);
}

.doc-dialog[open] {
  display: flex;
  flex-direction: column;
}

.doc-dialog-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px 14px;
  min-height: 0;
  overflow: hidden;
}

.doc-dialog-note {
  margin: 0;
  font-size: var(--t-12);
  color: var(--text-muted);
}

.doc-dialog-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
}

#draft-message:empty {
  display: none;
}

.draft-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px;
  border-radius: var(--radius);
  transition: background var(--dur) var(--ease);
}

.draft-row:hover {
  background: var(--surface-hover);
}

.draft-row-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 6px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.draft-row-main .icon {
  color: var(--text-faint);
}

.draft-name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: var(--t-13);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.draft-time {
  flex: none;
  font-size: var(--t-11);
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.draft-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: none;
}

.draft-act {
  width: 28px;
  height: 28px;
  color: var(--text-faint);
}

.draft-act:hover {
  color: var(--text);
}

.draft-act.danger:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

.doc-dialog-list .project-document {
  display: grid;
  justify-items: start;
  gap: 1px;
  width: 100%;
  min-height: 40px;
  height: auto;
  padding: 6px 10px;
  text-align: start;
  white-space: normal;
  overflow-wrap: anywhere;
}

.project-document small {
  color: var(--text-muted);
}

/* Settings modal */

.settings-dlg {
  width: min(560px, calc(100vw - 24px));
  max-height: min(76vh, 520px);
}

.settings-body {
  display: grid;
  grid-template-columns: 156px minmax(0, 1fr);
  min-height: 280px;
}

.settings-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px;
  border-right: 1px solid var(--border);
  background: var(--surface-2);
}

.settings-nav button {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: var(--t-12);
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.settings-nav button:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.settings-nav button.on {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.settings-panes {
  padding: 14px 16px;
  overflow: auto;
}

.settings-pane {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-pane h3 {
  margin: 0;
  font-size: var(--t-13);
  font-weight: 600;
}

.set-diag-pre {
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 160px;
  overflow: auto;
}

.zoom-input-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
}

.zoom-input-row .edit-input {
  width: 100%;
  height: 26px;
}
