/* FlowMap — shared styles for the home page and the editor. */

:root {
  color-scheme: light;
  --accent: #006FFF;
  --accent-hover: #005ce0;
  --accent-active: #004fc4;
  --accent-soft: rgba(0, 111, 255, 0.10);
  --text: #1f2430;
  --text-muted: #667085;
  --panel: #f7f8fa;
  --border: #e3e6ea;
  --border-hover: #d4d9df;
  --canvas-bg: #fbfbfc;
  --white: #ffffff;
  --surface: #ffffff;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --danger-border: #f4c7c3;
  --warn: #b54708;
  --btn-bg: #f2f4f7;
  --btn-hover: #e7eaee;
  --btn-active: #dde1e7;
  --grid-dot: #dcdfe4;
  --ok: #12b76a;
  /* Background for accent-filled controls with white text (kept ≥4.5:1). */
  --accent-fill: var(--accent);
  --accent-fill-hover: var(--accent-hover);
  --accent-fill-active: var(--accent-active);
  --radius: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-lift: 0 2px 4px rgba(16, 24, 40, 0.06), 0 6px 16px rgba(16, 24, 40, 0.10);
  --menu-shadow: 0 4px 16px rgba(16, 24, 40, 0.12);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --accent: #2f80ff;
  --accent-hover: #4a8dff;
  --accent-active: #1f6fea;
  --accent-soft: rgba(64, 140, 255, 0.16);
  --text: #e6e9ef;
  --text-muted: #9aa3b2;
  --panel: #17191e;
  --border: #2a2e37;
  --border-hover: #3a4049;
  --canvas-bg: #101216;
  --surface: #1e2127;
  --danger: #f97066;
  --danger-soft: rgba(249, 112, 102, 0.12);
  --danger-border: rgba(249, 112, 102, 0.35);
  --warn: #f5a860;
  --btn-bg: #262a32;
  --btn-hover: #2e333c;
  --btn-active: #363c46;
  --grid-dot: #23262d;
  --ok: #3fcb7e;
  /* Dark --accent (#2f80ff) is only 3.5:1 against white text; filled
     controls use a darker blue so their labels stay WCAG AA readable. */
  --accent-fill: #0f62e6;
  --accent-fill-hover: #1a6cf0;
  --accent-fill-active: #0b53c7;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.45);
  --shadow-lift: 0 2px 4px rgba(0, 0, 0, 0.4), 0 8px 20px rgba(0, 0, 0, 0.5);
  --menu-shadow: 0 4px 16px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  color: var(--text);
  font-size: 14px;
}

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

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

/* Keyboard focus rings (mouse focus keeps the quieter :focus styles). */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

/* Slim, theme-aware scrollbars for the side panels and page. */
body, #palette, #props {
  scrollbar-width: thin;
  scrollbar-color: var(--border-hover) transparent;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--btn-bg);
  color: var(--text);
  cursor: pointer;
  line-height: 1.2;
  transition: background 0.12s ease, border-color 0.12s ease;
  user-select: none;
}
.btn:hover { background: var(--btn-hover); border-color: var(--border-hover); }
.btn:active { background: var(--btn-active); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:disabled:hover { background: var(--btn-bg); border-color: var(--border); }

.btn-primary {
  background: var(--accent-fill);
  border-color: var(--accent-fill);
  color: var(--white);
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-fill-hover); border-color: var(--accent-fill-hover); }
.btn-primary:active { background: var(--accent-fill-active); }

.btn-small { min-height: 28px; padding: 3px 10px; font-size: 13px; }

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

/* ------------------------------------------------------------ home page */

.home-page { background: var(--panel); min-height: 100vh; }

.home-wrap {
  max-width: 860px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

.home-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}
.home-title {
  display: flex;
  align-items: center;
  gap: 10px;
}
.home-logo { color: var(--accent); flex-shrink: 0; display: block; }
.home-header h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: -0.02em;
}
.home-sub {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

.home-header-actions { display: flex; gap: 8px; align-items: center; }

.home-list { display: flex; flex-direction: column; gap: 10px; }

.diagram-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.diagram-card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-lift);
  transform: translateY(-1px);
}

.diagram-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.diagram-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.diagram-name:hover { color: var(--accent); text-decoration: none; }
.diagram-meta { color: var(--text-muted); font-size: 12px; }

.diagram-actions { display: flex; gap: 6px; flex-shrink: 0; }

.home-message {
  color: var(--text-muted);
  padding: 24px 4px;
}
.home-error { color: var(--danger); }

.home-empty {
  text-align: center;
  padding: 72px 16px;
  background: var(--surface);
  border: 1px dashed var(--border-hover);
  border-radius: 10px;
}
.home-empty-icon { color: var(--text-muted); opacity: 0.7; margin-bottom: 14px; }
.home-empty-icon svg { display: inline-block; }
.home-empty-title { margin: 0 0 6px; font-size: 16px; font-weight: 600; }
.home-empty-sub { margin: 0 auto; max-width: 380px; color: var(--text-muted); line-height: 1.5; }

/* ----------------------------------------------------------- editor page */

.editor-page {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--panel);
}

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

/* toolbar */

#toolbar {
  height: 48px;
  flex: 0 0 48px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  user-select: none;
  z-index: 20;
}

.tb-home {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  color: var(--text);
  padding: 4px 8px;
  border-radius: var(--radius);
}
.tb-home-logo { color: var(--accent); flex-shrink: 0; display: block; }
.tb-home:hover { color: var(--accent); text-decoration: none; background: var(--accent-soft); }

.tb-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 5px;
  flex-shrink: 0;
}

.tb-name {
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  font-weight: 600;
  font-size: 14px;
  height: 30px;
  padding: 4px 8px;
  width: 200px;
  min-width: 80px;
}
.tb-name:hover { border-color: var(--border); background: var(--panel); }
.tb-name:focus { border-color: var(--accent); background: var(--surface); }

.tb-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 10px 0 8px;
  margin-left: 2px;
  border-radius: 999px;
  background: var(--btn-bg);
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}
.tb-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background 0.15s ease;
}
.tb-status.is-saved .tb-status-dot { background: var(--ok); }
.tb-status.is-saving .tb-status-dot {
  background: var(--accent);
  animation: fm-pulse 1s ease-in-out infinite;
}
.tb-status.is-dirty { color: var(--warn); }
.tb-status.is-dirty .tb-status-dot { background: var(--warn); }

@keyframes fm-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.tb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--btn-bg);
  cursor: pointer;
  line-height: 1.2;
  min-width: 30px;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.tb-btn:hover { background: var(--btn-hover); border-color: var(--border-hover); }
.tb-btn:active { background: var(--btn-active); }
.tb-btn:disabled { opacity: 0.4; cursor: default; }
.tb-btn:disabled:hover { background: var(--btn-bg); border-color: var(--border); }
.tb-btn.active {
  background: var(--accent-fill);
  border-color: var(--accent-fill);
  color: var(--white);
}
.tb-btn.active:hover { background: var(--accent-fill-hover); }

.tb-zoom { min-width: 52px; text-align: center; font-variant-numeric: tabular-nums; }

.tb-label { color: var(--text-muted); font-size: 12px; margin-left: 4px; }

.tb-select {
  height: 30px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--btn-bg);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.tb-select:hover { background: var(--btn-hover); border-color: var(--border-hover); }
.tb-select:focus { border-color: var(--accent); }

.tb-spacer { flex: 1; }

.tb-menu { position: relative; }
.tb-menu-list {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 170px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--menu-shadow);
  padding: 4px;
  z-index: 50;
}
.tb-menu-list.open { display: block; }
.tb-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
}
.tb-menu-item:hover { background: var(--accent-soft); color: var(--accent); }
.tb-menu-sep { height: 1px; background: var(--border); margin: 4px 6px; }

.hidden-file { display: none; }

/* palette */

#palette {
  flex: 0 0 200px;
  width: 200px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 10px 8px;
  user-select: none;
}

.palette-heading {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  padding: 4px 10px 8px;
}

.palette-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px 8px;
  margin-bottom: 3px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  text-align: left;
  cursor: grab;
  transition: background 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.palette-item:hover {
  background: var(--surface);
  border-color: var(--border);
  box-shadow: var(--shadow);
}
.palette-item:hover .palette-title { color: var(--text); }
.palette-item:active { cursor: grabbing; box-shadow: none; }

.palette-icon {
  flex: 0 0 48px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}
.palette-icon svg { display: block; }
.palette-icon-text { color: var(--text-muted); }
.palette-item:hover .palette-icon-text { color: var(--text); }

.palette-title { font-size: 13px; color: var(--text); transition: color 0.12s ease; }

/* canvas area */

#canvas {
  flex: 1;
  min-width: 0;
  position: relative;
  overflow: hidden;
  background: var(--canvas-bg);
}

#canvas svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* ------------------------------------------------------- assistant chat */

.chat-toggle {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 24;
  box-shadow: var(--shadow-lift);
}
.chat-toggle.hidden-while-open { display: none; }

.chat-panel {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 25;
  width: 360px;
  max-width: calc(100% - 32px);
  height: 420px;
  max-height: calc(100% - 32px);
  display: none;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--menu-shadow);
  overflow: hidden;
}
.chat-panel.open { display: flex; }

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 8px 8px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}
.chat-close {
  border: none;
  background: transparent;
  font-size: 18px;
  line-height: 1;
  padding: 2px 8px;
  cursor: pointer;
  color: var(--text-muted);
  border-radius: var(--radius);
}
.chat-close:hover { color: var(--text); background: var(--btn-hover); }

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-hover) transparent;
}

.chat-hint { color: var(--text-muted); font-size: 12.5px; line-height: 1.5; }
.chat-hint p { margin: 0 0 8px; }

.chat-msg {
  max-width: 85%;
  padding: 8px 11px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.chat-user {
  align-self: flex-end;
  background: var(--accent-fill);
  color: var(--white);
  border-bottom-right-radius: 3px;
}
.chat-assistant {
  align-self: flex-start;
  background: var(--btn-bg);
  color: var(--text);
  border-bottom-left-radius: 3px;
}
.chat-pending { color: var(--text-muted); font-style: italic; }
.chat-error { color: var(--danger); background: var(--danger-soft); }

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  align-items: flex-end;
}
.chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 7px 9px;
  font-size: 13px;
  line-height: 1.4;
}
.chat-input:focus { outline: none; border-color: var(--accent); }
.chat-send { flex-shrink: 0; }

/* canvas element classes (rendered by canvas.js / interact.js) */

.grid-dot { fill: var(--grid-dot); }

.node { cursor: move; }
.node text {
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none;
}

.edge { cursor: pointer; }
.edge:hover { filter: drop-shadow(0 0 3px var(--accent)); }
.edge.selected { filter: drop-shadow(0 0 2px var(--accent)); }
.edge text {
  user-select: none;
  -webkit-user-select: none;
}

.sel-outline { stroke: var(--accent); }

.handle { fill: var(--white); stroke: var(--accent); }
.handle[data-dir="nw"], .handle[data-dir="se"] { cursor: nwse-resize; }
.handle[data-dir="ne"], .handle[data-dir="sw"] { cursor: nesw-resize; }
.handle[data-dir="n"],  .handle[data-dir="s"]  { cursor: ns-resize; }
.handle[data-dir="e"],  .handle[data-dir="w"]  { cursor: ew-resize; }

.edge-end {
  fill: var(--white);
  stroke: var(--accent);
  cursor: crosshair;
}

.anchor, .anchor-dot {
  fill: var(--white);
  stroke: var(--accent);
  cursor: crosshair;
}
/* Hover must emphasise the affordance, not fade it (accent-soft is ~10% alpha). */
.anchor:hover, .anchor-dot:hover { fill: var(--accent); stroke: var(--white); }

/* stroke-width comes from canvas.js (zoom-compensated presentation attribute);
   setting it here would override that and break constant screen thickness. */
.marquee {
  fill: rgba(0, 111, 255, 0.08);
  stroke: var(--accent);
  stroke-dasharray: 4 3;
}

.temp-edge {
  stroke: var(--accent);
  stroke-dasharray: 5 4;
  fill: none;
  pointer-events: none;
}

/* pan cursor helpers */
#canvas.pan, #canvas .pan, #canvas svg.pan { cursor: grab; }
#canvas.panning, #canvas .panning, #canvas svg.panning { cursor: grabbing; }

/* inline label editor (textarea overlay created by interact.js) */
.label-editor {
  position: absolute;
  z-index: 30;
  box-sizing: border-box;
  resize: none;
  border: 1.5px solid var(--accent);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  padding: 4px 6px;
  text-align: center;
  line-height: 1.3;
  box-shadow: 0 2px 8px rgba(16, 24, 40, 0.15);
  overflow: hidden;
}
.label-editor:focus { outline: none; }

/* properties panel */

#props {
  flex: 0 0 240px;
  width: 240px;
  background: var(--panel);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 14px 14px 24px;
}

.props-hint { color: var(--text-muted); font-size: 13px; line-height: 1.5; }
.props-hint p { margin: 0 0 10px; }

.props-section { margin-bottom: 22px; }
.props-section + .props-section {
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.props-title {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.props-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 13px;
}
.props-field-label { color: var(--text); }

.props-field.props-stacked {
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
}
.props-stacked .props-field-label {
  font-size: 12px;
  color: var(--text-muted);
}

.props-input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.props-input:focus { border-color: var(--accent); }
textarea.props-input { resize: vertical; min-height: 56px; line-height: 1.35; }

.props-number { width: 76px; flex: 0 0 76px; }

.props-field input[type="color"] {
  width: 48px;
  height: 28px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.12s ease;
}
.props-field input[type="color"]:hover { border-color: var(--border-hover); }
.props-field input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.props-field input[type="color"]::-webkit-color-swatch {
  border: 1px solid var(--border);
  border-radius: 3px;
}

.props-check { justify-content: flex-start; }
.props-check input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
  margin: 0;
}

select.props-input { width: auto; flex: 0 0 auto; cursor: pointer; }

/* ------------------------------------------------------------- auth page */

.auth-page {
  background: var(--panel);
  min-height: 100vh;
}

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lift);
  padding: 28px 28px 30px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.auth-logo { color: var(--accent); flex-shrink: 0; display: block; }
.auth-brand h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.02em;
}
.auth-sub {
  margin: 6px 0 22px;
  color: var(--text-muted);
  font-size: 13px;
}

.auth-tabs {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--btn-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 20px;
}
.auth-tab {
  flex: 1;
  min-height: 32px;
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.auth-tab:hover { color: var(--text); }
.auth-tab.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
/* The [hidden] attribute (login.js toggles it per tab) must win over the
   author display:flex above; without this both forms render at once. */
.auth-form[hidden] {
  display: none;
}
.auth-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.auth-field > span {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.auth-field > span em {
  font-style: normal;
  font-weight: 400;
  color: var(--text-muted);
}
.auth-field input {
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.auth-field input:hover { border-color: var(--border-hover); }
.auth-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.auth-field input:disabled { opacity: 0.55; cursor: default; }
.auth-hint { color: var(--text-muted); font-size: 12px; }

.auth-error {
  padding: 9px 12px;
  border: 1px solid var(--danger-border);
  border-radius: var(--radius);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  line-height: 1.4;
}

.auth-submit {
  margin-top: 4px;
  min-height: 40px;
  width: 100%;
}

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

.user-menu {
  display: flex;
  align-items: center;
  gap: 8px;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  padding: 4px 10px 4px 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
}
.user-avatar {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-fill);
  color: var(--white);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
}
.user-identity {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}
.user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
}
.user-email {
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
}

@media (max-width: 560px) {
  .user-identity { display: none; }
  .user-chip { padding: 4px; }
}

/* -------------------------------------------------- Phase 2: workspaces */

.home-workspace {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.ws-switch { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ws-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.ws-select {
  height: 32px;
  max-width: 260px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.ws-select:hover { border-color: var(--border-hover); }
.ws-select:focus { outline: none; border-color: var(--accent); }
.ws-actions { display: flex; gap: 8px; align-items: center; }
/* .btn sets display:inline-flex, which outranks the UA [hidden]{display:none}
   rule — so home.js's `.hidden = true` on these buttons wouldn't actually hide
   them. The id+attribute selector wins the specificity race and restores it
   (same gotcha the .auth-form[hidden] rule documents). */
#members-btn[hidden], #new-btn[hidden] { display: none; }
#members-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* members panel */

.members-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-bottom: 18px;
}

.members-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding-bottom: 12px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.members-ws-name { font-weight: 700; font-size: 15px; }
.members-role-you {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: auto;
}

.members-list { display: flex; flex-direction: column; }
.member-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}
.member-row:last-child { border-bottom: none; }
.member-identity { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.member-name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.member-email {
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.member-controls { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.member-role { height: 28px; }
.member-role-tag {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
}

/* invite block */

.invite-block { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.members-subtitle {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.invite-controls { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.invite-link-row { display: flex; gap: 8px; align-items: center; }
.invite-link {
  flex: 1;
  min-width: 0;
  height: 32px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.invite-link:focus { outline: none; border-color: var(--accent); }
.invite-hint { margin: 8px 0 0; font-size: 12px; color: var(--text-muted); line-height: 1.4; }

/* diagram card badges */

.diagram-namerow { display: flex; align-items: center; gap: 8px; min-width: 0; }
.card-badge {
  flex-shrink: 0;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-private {
  color: var(--text-muted);
  background: var(--btn-bg);
  border-color: var(--border);
}
.badge-shared {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: transparent;
}

/* join page */

.join-body { display: flex; flex-direction: column; gap: 6px; }
.join-lead { margin: 4px 0 8px; font-size: 15px; line-height: 1.5; color: var(--text); }
.join-actions { margin-top: 10px; }
.join-actions .btn, .join-actions .auth-submit { width: 100%; }
.join-decline {
  display: inline-block;
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 13px;
}
.join-decline:hover { color: var(--text); }

@media (max-width: 560px) {
  .home-workspace { align-items: flex-start; }
  .ws-select { max-width: 180px; }
}

/* ------------------------------------------------------------ AI settings */

/* Same [hidden] specificity fix the members/new buttons need (btn is
   inline-flex, which outranks the UA [hidden] rule). */
#ai-btn[hidden] { display: none; }
#ai-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.ai-form { display: flex; flex-direction: column; }
.ai-field { margin-top: 14px; }
.ai-field[hidden] { display: none; }
.ai-label {
  display: block;
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.ai-input {
  width: 100%;
  max-width: 420px;
}
.ai-text, .ai-num {
  height: 32px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  transition: border-color 0.12s ease;
}
.ai-text:focus, .ai-num:focus { outline: none; border-color: var(--accent); }
.ai-num { max-width: 140px; }
select.ai-input { max-width: 420px; }

.ai-key-wrap { max-width: 420px; }
.ai-key-row { display: flex; gap: 8px; align-items: center; }
.ai-key-row .ai-text { flex: 1; min-width: 0; }
.ai-key-status {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--warn);
  line-height: 1.4;
}
.ai-field-hint {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

.ai-usage {
  margin: 16px 0 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.ai-actions { margin-top: 16px; }

/* Admin read-only summary */
.ai-summary { display: flex; flex-direction: column; margin-top: 4px; }
.ai-sum-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.ai-sum-row:last-child { border-bottom: none; }
.ai-sum-key { color: var(--text-muted); }
.ai-sum-val { font-weight: 600; text-align: right; word-break: break-word; }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 12px);
  z-index: 60;
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--menu-shadow);
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-ok { border-color: var(--ok); }
.toast-error { border-color: var(--danger-border); color: var(--danger); }
