*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --fg: #0a0a0a;
  --muted: #6b7280;
  --border: #e5e7eb;
  --bg: #ffffff;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

html, body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }

/* ── Nav ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 48px;
}

.brand-link {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--fg);
}

.user-menu { position: relative; }
.user-menu summary {
  list-style: none;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: #f3f4f6;
  color: var(--fg);
  font-weight: 600;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  border: 1px solid var(--border);
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary::marker { content: ""; }
.user-menu summary:hover { background: #e5e7eb; }
.user-menu[open] summary { background: #e5e7eb; }

.user-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  min-width: 220px;
  padding: 12px 14px;
  z-index: 10;
}
.user-menu-email {
  font-size: 16px;
  color: var(--muted);
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid #f3f4f6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-menu-logout {
  background: none;
  border: none;
  font: inherit;
  font-size: 17px;
  cursor: pointer;
  padding: 6px 0;
  width: 100%;
  text-align: left;
  color: #dc2626;
}
.user-menu-logout:hover { color: #991b1b; opacity: 1; }

/* ── Content ── */
.content {
  max-width: 900px;
  margin: 56px auto 120px;
  padding: 0 48px;
}
.content-narrow { max-width: 560px; margin-top: 64px; }

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.page-header > :first-child { min-width: 0; }
.page-header h1 { overflow-wrap: anywhere; }
.page-header-actions {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.page-header-actions button { white-space: nowrap; }

h1 {
  font-size: clamp(28px, 3vw, 42px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
  margin-bottom: 6px;
}
.content-narrow h1 { font-size: clamp(28px, 3vw, 38px); margin-bottom: 24px; }
h2 { font-size: 1rem; font-weight: 600; }
.muted { color: var(--muted); font-size: 17px; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 17px;
  font-weight: 500;
}
.back-link:hover { color: var(--fg); }

/* ── Inputs ── */
.workspace-name-input,
.login-form input[type="email"] {
  padding: 10px 14px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 17px;
  font-family: inherit;
  color: var(--fg);
  background: var(--bg);
}
.workspace-name-input { width: min(420px, 100%); }
.workspace-name-input:focus,
.login-form input[type="email"]:focus {
  outline: none;
  border-color: var(--fg);
  box-shadow: 0 0 0 3px rgba(10,10,10,0.08);
}

/* ── Login form ── */
.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 28px;
}
.login-form button[type="submit"] { align-self: flex-start; }

/* ── Workspace cards ── */
.workspace-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 24px;
}
.workspace-card {
  display: block;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  background: var(--bg);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.workspace-card:hover {
  border-color: #d1d5db;
  box-shadow: 0 8px 24px rgba(0,0,0,0.06);
  transform: translateY(-1px);
}
.workspace-card-name { font-size: 20px; font-weight: 600; margin-bottom: 4px; }
.workspace-card-meta { font-size: 16px; color: var(--muted); }

.empty-state { margin-top: 24px; }

/* First-login hero — replaces the page-header on the very first visit
   to a workspace, so the user's eye lands on the welcome message rather
   than the auto-generated workspace name. */
.welcome-hero {
  margin-top: 8px;
  margin-bottom: 32px;
}
.welcome-hero h1 {
  font-size: clamp(36px, 4vw, 52px);
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin-bottom: 16px;
}
.welcome-hero p {
  font-size: 20px;
  line-height: 1.5;
  color: var(--fg);
  max-width: 56ch;
}


/* ── Keys ── */
.keys-section {
  margin-top: 28px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  padding: 14px 16px 16px;
}
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.key-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}
.key-main { flex: 1; min-width: 0; }
.key-value {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 16px;
  line-height: 1.5;
  color: var(--fg);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* ── Buttons ── */
button, .btn {
  padding: 9px 16px;
  background: var(--fg);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  font-size: 17px;
  font-family: inherit;
  cursor: pointer;
  font-weight: 500;
  transition: opacity 0.15s;
}
button:hover { opacity: 0.8; }
button:disabled { opacity: 0.55; cursor: default; }
button[aria-busy="true"] { cursor: progress; opacity: 1; }
button[aria-busy="true"]::after {
  content: "";
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  margin-left: 0.55em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -0.10em;
  animation: btn-spin 0.7s linear infinite;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }

.secondary-btn {
  padding: 9px 16px;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 17px;
  font-family: inherit;
  cursor: pointer;
  font-weight: 500;
}
.secondary-btn:hover { background: #f9fafb; border-color: #9ca3af; opacity: 1; }

.danger-btn {
  padding: 9px 16px;
  background: var(--bg);
  color: #b91c1c;
  border: 1px solid #fecaca;
  border-radius: 8px;
  font-size: 17px;
  font-family: inherit;
  cursor: pointer;
  font-weight: 500;
}
.danger-btn:hover { background: #fef2f2; border-color: #fca5a5; opacity: 1; }

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #9ca3af;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.icon-btn:hover { color: var(--fg); background: #f3f4f6; opacity: 1; }


/* ── Banners ── */
.err {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 16px;
}
.err-stacked { margin-bottom: 20px; }
.err-trailing { margin-top: 12px; }

/* ── Bootstrap section (collapsible <details>) ── */
details.bootstrap-section {
  margin-top: 28px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  overflow: hidden;
}

details.bootstrap-section summary {
  cursor: pointer;
  list-style: none;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  transition: background 0.12s;
}
details.bootstrap-section summary::-webkit-details-marker { display: none; }
details.bootstrap-section summary::marker { content: ""; }
details.bootstrap-section summary:hover { background: #f9fafb; }
details.bootstrap-section summary h2 { margin: 0; }

.disclosure-chevron {
  color: var(--muted);
  flex-shrink: 0;
  transition: transform 0.15s, color 0.12s;
}
details.bootstrap-section[open] .disclosure-chevron { transform: rotate(90deg); }
details.bootstrap-section summary:hover .disclosure-chevron { color: var(--fg); }

/* Padding is scoped to the disclosure case so the body sits inside
   the <details> border. On first login the body renders standalone
   (no border) and inherits page-level alignment instead. */
details.bootstrap-section .bootstrap-body { padding: 0 16px 16px; }
.bootstrap-body > p { margin-bottom: 14px; }
.bootstrap-body .agent-message { margin-top: 0; }

.just-minted-banner {
  background: #fef3c7;
  border: 1px solid #fde68a;
  color: #92400e;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  margin-top: 28px;
  margin-bottom: 16px;
}
.just-minted-banner + details.bootstrap-section { margin-top: 16px; }

.agent-message {
  margin: 0 0 12px;
  padding: 14px 16px;
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 15px;
  line-height: 1.6;
  color: var(--fg);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* ── Agent message collapsible preview ── */
.agent-message-wrap {
  position: relative;
  overflow: hidden;
  max-height: 148px; /* ~5 lines at 15px/1.6 + 14px top padding */
  margin-bottom: 12px;
}
.agent-message-wrap.expanded {
  max-height: none;
}
.agent-message-wrap .agent-message {
  margin: 0;
}
.agent-message-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 80px;
  background: linear-gradient(to bottom, transparent, #f9fafb 65%);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 10px;
}
.agent-message-wrap.expanded .agent-message-overlay {
  display: none;
}
.agent-message-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  padding: 2px 8px;
  border-radius: 4px;
}
.agent-message-toggle:hover { color: var(--fg); }
.agent-message-copy {
  display: block;
  width: fit-content;
  margin: 0 auto;
}

.btn.copied { background: #059669; color: #ffffff; opacity: 1; }
.secondary-btn.copied { background: #059669; color: #ffffff; border-color: #059669; opacity: 1; }
.text-btn.copied { color: #059669; }

/* Inline flow rather than flex so the copy button trails the key
   value as if it were the next word — when the key wraps over
   multiple lines on narrow viewports, the button follows the last
   wrapped line instead of dropping onto a new row. */
.key-value-row {
  margin-bottom: 4px;
  line-height: 1.6;
}
.text-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
  font-family: var(--font);
}
.text-btn:hover { color: var(--fg); opacity: 1; }

/* Copy-key chip: small bordered button that trails the key value
   inline. Border + padding override .text-btn's borderless defaults
   (placed after .text-btn so source order wins on equal specificity). */
.key-copy {
  margin-left: 14px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  white-space: nowrap;
}
.key-copy:hover { border-color: #c9cdd2; }
.key-copy.copied { border-color: #059669; }

/* ── Modals ── */
body.modal-open { overflow: hidden; }
.modal { position: fixed; inset: 0; z-index: 40; overflow-y: auto; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.4); }
.modal-card {
  position: relative;
  z-index: 1;
  width: min(560px, calc(100vw - 32px));
  margin: 5vh auto;
  background: var(--bg);
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 24px 48px rgba(0,0,0,0.12);
  padding: 24px;
}
.modal-card h2 { margin-bottom: 8px; }
.modal-copy { margin-bottom: 16px; color: var(--muted); font-size: 17px; }

/* Destructive-action warning card — used in the rotate-key modal so
   the user understands the current key stops working before they
   confirm. Red triangle icon + tinted background read as urgent
   without shouting. */
.warning {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 18px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 6px;
}
.warning-icon { color: #dc2626; flex-shrink: 0; margin-top: 2px; }
.warning-copy { margin: 0; color: #7f1d1d; font-size: 16px; line-height: 1.45; }
.warning-copy strong { color: #7f1d1d; font-weight: 700; }
.modal-form { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-meta { font-size: 16px; margin-bottom: 0; }
.id-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 16px;
  color: var(--fg);
  padding: 1px 5px;
  background: #f3f4f6;
  border-radius: 3px;
}

/* ── Mobile ── */
@media (max-width: 768px) {
  .topbar { padding: 16px 20px; }
  .content { margin-top: 40px; padding: 0 20px; }
  .content-narrow { margin-top: 48px; }
}
