/* Model Waygate styles */

:root {
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary-color: #64748b;
  --success-color: #22c55e;
  --danger-color: #ef4444;
  --warning-color: #f59e0b;
  --bg-color: #f8fafc;
  --card-bg: #ffffff;
  --text-color: #1e293b;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --code-bg: #1e293b;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  line-height: 1.6;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* Header */
.site-header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 0;
}

.site-header .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary-color);
  text-decoration: none;
}

.site-nav a {
  margin-left: 1.5rem;
  color: var(--text-muted);
  text-decoration: none;
}

.site-nav a:hover,
.site-nav a:focus-visible {
  color: var(--primary-color);
}

/* Main content */
main {
  padding: 2rem 0;
  min-height: calc(100vh - 200px);
}

/* Hero section */
.hero {
  text-align: center;
  padding: 4rem 0;
}

.hero h1 {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.tagline {
  font-size: 1.25rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
}

/* The landing page's one paragraph: measured, centred under the tagline. */
.hero .pitch {
  max-width: 44rem;
  margin: -1rem auto 2rem;
  color: var(--text-color);
}

.cta-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  border-radius: 0.5rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  border: none;
  font-size: 1rem;
}

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

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

.btn-secondary {
  background: transparent;
  color: var(--text-color);
  border: 1px solid var(--border-color);
}

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

.btn-danger {
  background: var(--danger-color);
  color: white;
}

.btn-sm {
  padding: 0.25rem 0.75rem;
  font-size: 0.875rem;
}

/* Features section */
.features {
  padding: 4rem 0;
}

.features h2 {
  text-align: center;
  margin-bottom: 2rem;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.5rem;
}

.feature-card {
  background: var(--card-bg);
  padding: 1.5rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border-color);
}

.feature-card h3 {
  margin-bottom: 0.5rem;
}

.feature-card p {
  color: var(--text-muted);
}

/* Dashboard */
.dashboard-nav {
  display: flex;
  gap: 1rem;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1rem;
}

.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.5rem 1rem;
}

.nav-link:hover, .nav-link.active {
  color: var(--primary-color);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--card-bg);
  padding: 1.5rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border-color);
  text-align: center;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary-color);
}

.stat-label {
  color: var(--text-muted);
}

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

/* Usage: the month against the cap, in words and as a bar. */
.cap-bar {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.cap-line {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.cap-bar progress {
  width: 100%;
  height: 0.75rem;
  accent-color: var(--primary-color);
}

/* Code blocks */
.code-block {
  background: var(--code-bg);
  color: #e2e8f0;
  padding: 1rem;
  border-radius: 0.5rem;
  overflow-x: auto;
  font-family: "Fira Code", "Consolas", monospace;
}

/* Dashboard tables: providers and keys */
.dash-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card-bg);
  border-radius: 0.5rem;
  overflow: hidden;
  margin-bottom: 2rem;
}

.dash-table th, .dash-table td {
  padding: 0.75rem 1rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border-color);
}

.dash-table th {
  background: var(--bg-color);
  font-weight: 600;
}

.dash-table input {
  width: 100%;
  min-width: 6rem;
  padding: 0.375rem 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: 0.375rem;
  font-size: 0.95rem;
}

/* The row's forms sit side by side; each holds one button. */
.dash-actions {
  white-space: nowrap;
}

.dash-actions form {
  display: inline;
}

.dash-actions > * + * {
  margin-left: 0.5rem;
}

.status-active, .status-ok {
  color: var(--success-color);
}

.status-disabled, .status-error {
  color: var(--danger-color);
}

/* Dashboard forms: add a provider, mint a key */
.dash-form {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 1.5rem;
  margin-bottom: 2rem;
  max-width: 640px;
}

.dash-form h2 {
  margin-bottom: 1rem;
}

.dash-form select {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  font-size: 1rem;
  background: var(--bg-color);
  color: var(--text-color);
}

.hidden {
  display: none;
}

/* The one-time key: a monospace box with the plaintext and a copy button. */
.secret-once {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin: 1rem 0 1.5rem;
}

.secret-once input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  background: var(--code-bg);
  color: #e2e8f0;
  font-family: "Fira Code", "Consolas", monospace;
  font-size: 0.95rem;
}

/* An endpoint's URL in the list: the read-only box and its copy button side by side. */
.endpoint-url {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.endpoint-url input {
  min-width: 20rem;
  font-family: "Fira Code", "Consolas", monospace;
  font-size: 0.85rem;
}

/* The route editor: the endpoint over the canvas Miso fills. */
.editor-head {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: baseline;
  margin-bottom: 1rem;
}

.endpoint-editor {
  position: relative;
  min-height: 60vh;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
}

/* The loading placeholder sits beside the EMPTY #miso mount, never inside it,
   and goes the moment Miso renders anything into the mount. */
.boot {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

#miso:not(:empty) + .boot {
  display: none;
}

.boot-spinner {
  width: 2rem;
  height: 2rem;
  border: 3px solid var(--border-color);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: boot-spin 0.8s linear infinite;
}

@keyframes boot-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .boot-spinner { animation: none; }
}

.boot-error {
  color: var(--danger-color);
  max-width: 32rem;
  text-align: center;
}

/* The editor Miso draws: toolbar, notice, then the canvas beside the panel. */
.route-editor {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.75rem;
}

.editor-loading,
.editor-unusable {
  color: var(--text-muted);
}

.editor-unusable {
  color: var(--danger-color);
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.editor-palette {
  display: inline-flex;
  gap: 0.5rem;
  align-items: center;
}

.editor-spacer {
  flex: 1;
}

.route-editor .btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.save-state {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.save-state.dirty {
  color: var(--warning-color);
  font-weight: 600;
}

.editor-notice {
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
  font-size: 0.9rem;
}

.editor-notice.empty {
  display: none;
}

.editor-notice p {
  margin: 0 0 0.25rem;
}

.notice-ok {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.notice-error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.notice-hint {
  background: #fffbeb;
  color: #92400e;
  border: 1px solid #fde68a;
}

.problem-list {
  margin: 0;
  padding-left: 1.25rem;
}

.editor-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 20rem;
  gap: 0.75rem;
}

@media (max-width: 900px) {
  .editor-body {
    grid-template-columns: minmax(0, 1fr);
  }
}

.route-canvas {
  display: block;
  height: 65vh;
  min-height: 24rem;
  border: 1px solid var(--border-color);
  border-radius: 0.375rem;
  /* The same as the view box's own background, so the letterboxing that keeps
     its aspect ratio does not show. */
  background: var(--bg-color);
  /* Dragging is the canvas's own: no scrolling or zooming under a finger. */
  touch-action: none;
  user-select: none;
}

.canvas-bg {
  fill: var(--bg-color);
}

.node-box {
  fill: var(--card-bg);
  stroke: var(--border-color);
  stroke-width: 1.5;
}

.node-body {
  cursor: grab;
}

.node-Input .node-box { fill: #eff6ff; stroke: #93c5fd; }
.node-Output .node-box { fill: #f0fdf4; stroke: #86efac; }
.node-Fallback .node-box { fill: #fffbeb; stroke: #fcd34d; }
.node-Decision .node-box { fill: #faf5ff; stroke: #d8b4fe; }

.node.selected .node-box {
  stroke: var(--primary-color);
  stroke-width: 3;
}

.node.has-error .node-box {
  stroke: var(--danger-color);
  stroke-width: 3;
}

.node-title {
  font-weight: 600;
  font-size: 14px;
  fill: var(--text-color);
}

.node-summary,
.node-option {
  font-size: 12px;
  fill: var(--text-muted);
}

/* A node's text is part of its box: the box takes the pointer. */
.node-title,
.node-summary,
.node-option {
  pointer-events: none;
}

.node-option {
  text-anchor: end;
}

.port {
  fill: var(--card-bg);
  stroke: var(--secondary-color);
  stroke-width: 2;
}

.port-out {
  cursor: crosshair;
}

.port-out:hover {
  fill: var(--primary-color);
}

.edge-line,
.edge-draft {
  fill: none;
  stroke: var(--secondary-color);
  stroke-width: 2;
}

.edge-draft {
  stroke: var(--primary-color);
  stroke-dasharray: 6 4;
  pointer-events: none;
}

.default-edge .edge-line {
  stroke-dasharray: 4 4;
}

/* A wide invisible stroke so an edge is easy to click. */
.edge-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 14;
  cursor: pointer;
}

.edge.selected .edge-line {
  stroke: var(--primary-color);
  stroke-width: 3;
}

.edge.has-error .edge-line {
  stroke: var(--danger-color);
  stroke-width: 3;
}

.edge-label {
  font-size: 12px;
  fill: var(--text-color);
  text-anchor: middle;
  pointer-events: none;
}

.editor-panel {
  border: 1px solid var(--border-color);
  border-radius: 0.375rem;
  padding: 0.75rem;
  font-size: 0.9rem;
}

.editor-panel h3 {
  margin: 0 0 0.25rem;
}

.editor-panel h4 {
  margin: 1rem 0 0.25rem;
  font-size: 0.95rem;
}

.editor-panel .form-control {
  width: 100%;
  margin-bottom: 0.5rem;
}

.editor-panel .node-id {
  font-family: "Fira Code", "Consolas", monospace;
  font-size: 0.8rem;
}

.editor-help {
  padding-left: 1.25rem;
}

.option-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.25rem 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-color);
}

.option-row .option-label,
.option-row .option-description,
.option-row .option-route {
  grid-column: 1;
}

.option-row button {
  grid-column: 2;
  grid-row: 1;
}

.fallback-children {
  padding-left: 1.25rem;
}

.fallback-child {
  display: flex;
  gap: 0.25rem;
  align-items: center;
  margin-bottom: 0.25rem;
}

.fallback-child .child-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Sign in page */
.sign-in-page {
  max-width: 400px;
  margin: 0 auto;
  text-align: center;
}

.sign-in-page h1 {
  margin-bottom: 1rem;
}

.sign-in-page p {
  color: var(--text-muted);
  margin-bottom: 2rem;
}

.auth-buttons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Settings */
.settings-section {
  background: var(--card-bg);
  padding: 1.5rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border-color);
  margin-bottom: 1.5rem;
}

.settings-section h2 {
  margin-bottom: 1rem;
}

/* Footer */
.site-footer {
  background: var(--card-bg);
  border-top: 1px solid var(--border-color);
  padding: 2rem 0;
  text-align: center;
  color: var(--text-muted);
}

.footer-tagline {
  margin-bottom: 0.5rem;
}

/* The shared policy links bring their own bullet separators (span.link-sep),
   so the row only spaces and wraps them. */
.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: baseline;
  column-gap: 0.5rem;
  row-gap: 0.25rem;
  font-size: 0.875rem;
}

.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
}

.footer-links a:hover,
.footer-links a:focus-visible {
  color: var(--primary-color);
}

/* Policy pages (privacy, cookies, terms): the shared prose on a card. */
.policy-page {
  max-width: 56rem;
  margin: 2rem auto 3rem;
  padding: 2rem 3rem;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
}

.policy-content {
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.policy-page h1 {
  font-size: 2.25rem;
  margin-bottom: 0.25rem;
}

.policy-page h1 + p {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding-bottom: 1.25rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.policy-page h2 {
  font-size: 1.25rem;
  margin: 2rem 0 0.5rem;
}

.policy-page p {
  margin-bottom: 1rem;
}

.policy-page a {
  color: var(--primary-color);
}

.policy-page a:hover {
  color: var(--primary-hover);
}

.policy-page hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 2rem 0 1rem;
}

.policy-page hr + p {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Documentation Page */
.docs-page {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 2rem;
  max-width: 1200px;
  margin: 0 auto;
}

.docs-sidebar {
  position: sticky;
  top: 2rem;
  height: fit-content;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 1rem;
}

.docs-sidebar h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.docs-sidebar ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.docs-sidebar li {
  margin-bottom: 0.25rem;
}

.docs-sidebar a {
  display: block;
  padding: 0.5rem 0.75rem;
  color: var(--text-color);
  text-decoration: none;
  border-radius: 0.25rem;
  font-size: 0.9rem;
}

.docs-sidebar a:hover {
  background: var(--bg-color);
  color: var(--primary-color);
}

.docs-content {
  min-width: 0;
}

.docs-hero {
  margin-bottom: 2rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border-color);
}

.docs-hero h1 {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.docs-hero .tagline {
  margin-bottom: 0;
}

.docs-section {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.docs-section h2 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-color);
}

.docs-section h3 {
  font-size: 1.1rem;
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
  color: var(--text-color);
}

.docs-section h3:first-of-type {
  margin-top: 1rem;
}

.docs-section p {
  margin-bottom: 1rem;
  color: var(--text-muted);
}

.docs-section ul {
  margin-bottom: 1rem;
  padding-left: 1.5rem;
}

.docs-section li {
  margin-bottom: 0.5rem;
  color: var(--text-muted);
}

.docs-section .code-block {
  margin-bottom: 1rem;
}

.docs-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card-bg);
  border-radius: 0.5rem;
  overflow: hidden;
  margin-bottom: 1rem;
}

.docs-table th,
.docs-table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.docs-table th {
  background: var(--bg-color);
  font-weight: 600;
  font-size: 0.875rem;
}

.docs-table td {
  font-size: 0.9rem;
}

.docs-table code {
  background: var(--code-bg);
  color: #e2e8f0;
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  font-size: 0.85rem;
}

.docs-cta {
  background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
  color: white;
  border-radius: 0.5rem;
  padding: 2rem;
  text-align: center;
  margin-top: 2rem;
}

.docs-cta h2 {
  color: white;
  margin-bottom: 1rem;
  border-bottom: none;
  padding-bottom: 0;
}

.docs-cta .btn-primary {
  background: white;
  color: var(--primary-color);
}

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

/* Code Tabs */
.code-tabs {
  margin-top: 1rem;
}

.code-tabs-nav {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 0;
}

.code-tab {
  padding: 0.5rem 1rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.15s ease;
}

.code-tab:hover {
  color: var(--text-color);
  background: var(--bg-color);
}

.code-tab.active {
  color: var(--primary-color);
  border-bottom-color: var(--primary-color);
}

.code-tabs-content {
  background: var(--code-bg);
  border-radius: 0 0 0.5rem 0.5rem;
}

.code-tab-panel {
  display: none;
}

.code-tab-panel.active {
  display: block;
}

.code-tab-panel .code-block {
  margin: 0;
  border-radius: 0 0 0.5rem 0.5rem;
}

/* Forms */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group:last-of-type {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.375rem;
  font-weight: 600;
  font-size: 0.95rem;
}

.form-help {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  font-size: 1rem;
  font-family: inherit;
  background: var(--bg-color);
  color: var(--text-color);
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group textarea {
  resize: vertical;
  min-height: 100px;
}

.error-message {
  background: #fef2f2;
  color: #991b1b;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  margin-bottom: 1.5rem;
  border-left: 3px solid var(--danger-color);
  font-size: 0.95rem;
}

/* Responsive: collapse sidebar on smaller screens */
@media (max-width: 768px) {
  .docs-page {
    grid-template-columns: 1fr;
  }

  .docs-sidebar {
    position: static;
    margin-bottom: 1rem;
  }

  .docs-sidebar ul {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    list-style: none;
  }

  .docs-sidebar li {
    margin-bottom: 0;
  }

  .docs-sidebar a {
    padding: 0.375rem 0.75rem;
    background: var(--bg-color);
  }

  .docs-hero h1 {
    font-size: 2rem;
  }

  .policy-page {
    padding: 2rem 1rem;
  }

  .policy-page h1 {
    font-size: 1.75rem;
  }
}

/* Once the policy links wrap, a bullet would dangle at a line end, so drop
   the separators and space the links by the gap alone. */
@media (max-width: 600px) {
  .footer-links {
    column-gap: 1rem;
  }

  .footer-links .link-sep {
    display: none;
  }
}
