/* ── Design tokens ─────────────────────────────────────────── */

:root {
  /* Palette — deep blue accent, cool blue-tinted neutrals */
  --color-bg: oklch(0.97 0.006 250);
  --color-surface: oklch(0.993 0.004 250);
  --color-text: oklch(0.18 0.02 250);
  --color-text-secondary: oklch(0.44 0.015 250);
  --color-text-tertiary: oklch(0.58 0.01 250);
  --color-border: oklch(0.88 0.01 250);
  --color-border-subtle: oklch(0.92 0.007 250);

  --color-accent: oklch(0.48 0.16 260);
  --color-accent-hover: oklch(0.42 0.17 260);
  --color-accent-subtle: oklch(0.94 0.03 260);
  --color-accent-text: oklch(0.98 0.005 260);

  --color-success: oklch(0.52 0.11 160);
  --color-success-hover: oklch(0.46 0.12 160);
  --color-success-bg: oklch(0.95 0.02 160);
  --color-success-text: oklch(0.32 0.06 160);

  --color-error: oklch(0.56 0.16 18);
  --color-error-hover: oklch(0.49 0.17 18);
  --color-error-bg: oklch(0.95 0.02 18);
  --color-error-text: oklch(0.36 0.07 18);

  --color-warning-bg: oklch(0.95 0.03 85);
  --color-warning-text: oklch(0.40 0.09 85);

  --color-info-bg: oklch(0.95 0.02 250);
  --color-info-text: oklch(0.40 0.08 250);

  --color-proposed-bg: oklch(0.94 0.025 275);
  --color-proposed-text: oklch(0.38 0.09 275);

  /* Spacing — 4pt scale */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --space-3xl: 64px;

  /* Typography */
  --font-display: 'Bricolage Grotesque', system-ui, sans-serif;
  --font-body: 'Figtree', system-ui, sans-serif;
  --font-mono: 'Source Code Pro', ui-monospace, SFMono-Regular, monospace;

  --text-xs: 0.8125rem;  /* 13px */
  --text-sm: 0.875rem;   /* 14px */
  --text-base: 1rem;     /* 16px */
  --text-lg: 1.375rem;   /* 22px */
  --text-xl: 1.75rem;    /* 28px */

  /* Motion */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --duration-fast: 100ms;
  --duration-normal: 180ms;
}

/* ── Reset & base ─────────────────────────────────────────── */

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

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.55;
  color: var(--color-text);
  background: var(--color-bg);
  max-width: min(1400px, 95vw);
  margin: 0 auto;
  padding: var(--space-lg) var(--space-lg) var(--space-3xl);
  -webkit-font-smoothing: antialiased;
}

/* ── Page header ──────────────────────────────────────────── */

.page-header {
  display: flex;
  align-items: baseline;
  gap: var(--space-xl);
  margin-bottom: var(--space-xl);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--color-border);
}

h1 {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

h2 {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text);
  margin: var(--space-2xl) 0 var(--space-md);
  letter-spacing: -0.01em;
}

h2 .muted {
  font-family: var(--font-body);
  font-weight: 400;
}

h3 {
  font-family: var(--font-display);
  font-size: 1.125rem; /* 18px — between sm and lg for clear card heading hierarchy */
  font-weight: 600;
  margin: 0 0 var(--space-xs);
  letter-spacing: -0.01em;
}

/* ── Navigation ───────────────────────────────────────────── */

nav.tabs {
  display: flex;
  gap: var(--space-xs);
}

nav.tabs a {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: none;
  padding: var(--space-sm) var(--space-md);
  border-radius: 6px;
  color: var(--color-text-secondary);
  transition: color var(--duration-fast) var(--ease-out),
              background var(--duration-fast) var(--ease-out);
}

nav.tabs a:hover {
  color: var(--color-text);
  background: var(--color-border-subtle);
}

nav.tabs a.active {
  color: var(--color-accent);
  background: var(--color-accent-subtle);
  font-weight: 600;
}

/* ── Logout corner ────────────────────────────────────────── */

.logout-corner {
  position: fixed;
  bottom: var(--space-md);
  right: var(--space-md);
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text-tertiary);
  text-decoration: none;
  padding: var(--space-xs) var(--space-sm);
  border-radius: 4px;
  opacity: 0.5;
  transition: opacity var(--duration-fast) var(--ease-out),
              color var(--duration-fast) var(--ease-out);
}

.logout-corner:hover {
  opacity: 1;
  color: var(--color-text-secondary);
}

/* ── Controls ─────────────────────────────────────────────── */

.bar {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: var(--space-lg);
}

select {
  font: inherit;
  font-size: var(--text-sm);
  padding: var(--space-sm) var(--space-md);
  padding-right: var(--space-xl);
  border-radius: 6px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%23888' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-sm) center;
  transition: border-color var(--duration-fast) var(--ease-out);
}

select:hover { border-color: var(--color-text-tertiary); }
select:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
  border-color: transparent;
}

label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
}

button, input[type=submit] {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 500;
  padding: var(--space-sm) var(--space-md);
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
}

button:active, input[type=submit]:active {
  transform: scale(0.97);
}

/* Primary — accent */
button.primary, input[type=submit].primary {
  background: var(--color-accent);
  color: var(--color-accent-text);
  border-color: var(--color-accent);
}
button.primary:hover, input[type=submit].primary:hover {
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
}

/* Approve — green */
button.approve {
  background: var(--color-success);
  color: oklch(0.98 0.005 155);
  border-color: var(--color-success);
}
button.approve:hover {
  background: var(--color-success-hover);
  border-color: var(--color-success-hover);
}

/* Reject — outlined red */
button.reject {
  background: transparent;
  color: var(--color-error);
  border-color: var(--color-error);
}
button.reject:hover {
  background: var(--color-error-bg);
}

/* Secondary/undo — ghost */
button.undo {
  background: transparent;
  color: var(--color-text-secondary);
  border-color: var(--color-border);
}
button.undo:hover {
  background: var(--color-border-subtle);
  border-color: var(--color-border);
}

button:focus-visible, input[type=submit]:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

/* ── Editor (CodeMirror — styled via JS theme in editor.html) ── */

/* ── Save bar ─────────────────────────────────────────────── */

.save-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: var(--space-sm);
  align-items: center;
  flex-wrap: wrap;
  padding: var(--space-sm) var(--space-md);
  margin-top: -1px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0 0 8px 8px;
  box-shadow: 0 -2px 8px oklch(0.18 0.02 250 / 0.06);
  z-index: 10;
}

.bar + .bar { margin-top: 0; margin-bottom: var(--space-lg); }

.meta {
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
}

.shortcut {
  margin-left: auto;
  font-family: var(--font-mono);
  padding: 2px 6px;
  background: var(--color-border-subtle);
  border-radius: 4px;
}

.meta code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--color-accent-subtle);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--color-text-secondary);
}

/* ── Flash messages ───────────────────────────────────────── */

.flash {
  font-size: var(--text-sm);
  padding: var(--space-sm) var(--space-md);
  border-radius: 8px;
  margin-bottom: var(--space-lg);
  background: var(--color-success-bg);
  color: var(--color-success-text);
}

.flash.error {
  background: var(--color-error-bg);
  color: var(--color-error-text);
}

/* ── Backups ──────────────────────────────────────────────── */

.backups {
  margin-top: var(--space-xl);
  font-size: var(--text-sm);
  color: var(--color-text-tertiary);
}

.backups summary {
  cursor: pointer;
  font-weight: 500;
  color: var(--color-text-secondary);
  list-style: none;
}

.backups summary::before {
  content: '>';
  display: inline-block;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  margin-right: var(--space-sm);
  transition: transform var(--duration-fast) var(--ease-out);
}

.backups[open] summary::before {
  transform: rotate(90deg);
}

.backups ul {
  margin: var(--space-sm) 0 0;
  padding-left: var(--space-lg);
}

.backups li {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
  padding: var(--space-xs) 0;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.backup-name {
  flex-shrink: 0;
}

.backup-actions {
  display: flex;
  gap: var(--space-xs);
  align-items: center;
}

.backup-actions .inline {
  display: inline;
}

.backup-btn {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 500;
  padding: 2px var(--space-sm);
  border-radius: 4px;
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-accent);
  cursor: pointer;
  text-decoration: none;
  transition: background var(--duration-fast) var(--ease-out);
}

.backup-btn:hover {
  background: var(--color-accent-subtle);
}

.backup-restore {
  color: var(--color-error);
  border-color: var(--color-error);
}

.backup-restore:hover {
  background: var(--color-error-bg);
}

/* ── Cards ────────────────────────────────────────────────── */

.card {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: var(--space-md) var(--space-lg);
  margin-bottom: var(--space-md);
  background: var(--color-surface);
}

.card .rule {
  background: var(--color-accent-subtle);
  padding: var(--space-sm) var(--space-md);
  margin: var(--space-sm) 0;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  color: var(--color-text);
}

.rule-editor {
  width: 100%;
  background: var(--color-accent-subtle);
  padding: var(--space-sm) var(--space-md);
  margin: var(--space-sm) 0;
  border: 1px solid transparent;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  color: var(--color-text);
  resize: vertical;
  box-sizing: border-box;
  field-sizing: content;
  min-height: 3lh;
}

.rule-editor:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-subtle);
  background: var(--color-surface);
}

.merge-controls {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.card dl {
  margin: var(--space-sm) 0;
  font-size: var(--text-sm);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-xs) var(--space-md);
  align-items: baseline;
}

.card dt {
  font-weight: 600;
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.card dd {
  margin: 0;
  color: var(--color-text);
  white-space: pre-wrap;
}

.card-details {
  margin: var(--space-sm) 0 0;
}

.card-details summary {
  cursor: pointer;
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text-tertiary);
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

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

.card-details summary::before {
  content: '>';
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  transition: transform var(--duration-fast) var(--ease-out);
}

.card-details[open] summary::before {
  transform: rotate(90deg);
}

.card-details summary:hover {
  color: var(--color-text-secondary);
}

.card-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-top: var(--space-sm);
}

.muted {
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
  line-height: 1.4;
}

/* ── Status badges ────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px var(--space-sm);
  border-radius: 4px;
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  vertical-align: middle;
  position: relative;
  top: -1px;
}

.badge-PENDING    { background: var(--color-warning-bg); color: var(--color-warning-text); }
.badge-PROPOSED   { background: var(--color-proposed-bg); color: var(--color-proposed-text); }
.badge-APPROVED   { background: var(--color-info-bg); color: var(--color-info-text); }
.badge-APPLYING   { background: var(--color-proposed-bg); color: var(--color-proposed-text); }
.badge-IMPLEMENTED { background: var(--color-success-bg); color: var(--color-success-text); }
.badge-REJECTED   { background: var(--color-error-bg); color: var(--color-error-text); }

/* ── Feedback sections (details/summary) ──────────────────── */

details.section {
  margin-top: var(--space-md);
}

details.section summary {
  cursor: pointer;
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  padding: var(--space-sm) 0;
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

details.section summary::before {
  content: '>';
  display: inline-block;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 400;
  transition: transform var(--duration-fast) var(--ease-out);
}

details.section[open] summary::before {
  transform: rotate(90deg);
}

/* Remove default marker in all browsers */
details.section summary::-webkit-details-marker { display: none; }

/* ── Zendesk link ─────────────────────────────────────────── */

a.zd {
  font-size: var(--text-xs);
  color: var(--color-accent);
  text-decoration: none;
  font-weight: 500;
}

a.zd:hover { text-decoration: underline; }

/* ── Diff link ────────────────────────────────────────────── */

a.diff-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-accent);
  text-decoration: none;
  padding: var(--space-sm) var(--space-md);
  border-radius: 6px;
  background: var(--color-accent-subtle);
  transition: background var(--duration-fast) var(--ease-out);
}

a.diff-link:hover {
  background: oklch(0.90 0.05 260);
}

/* ── Diff view ────────────────────────────────────────────── */

.diff-view {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: var(--space-md) var(--space-lg);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.65;
  overflow-x: auto;
  max-height: 72vh;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.diff-section {
  display: block;
  margin-top: var(--space-md);
  font-weight: 600;
  color: var(--color-accent);
}

.diff-sep {
  display: block;
  color: var(--color-border);
  margin: var(--space-xs) 0;
  user-select: none;
}

.diff-add {
  display: block;
  background: var(--color-success-bg);
  color: var(--color-success-text);
  border-radius: 3px;
  padding: 0 var(--space-xs);
  margin: 0 calc(-1 * var(--space-xs));
}

.diff-del {
  display: block;
  background: var(--color-error-bg);
  color: var(--color-error-text);
  border-radius: 3px;
  padding: 0 var(--space-xs);
  margin: 0 calc(-1 * var(--space-xs));
}

/* ── Diff legend ──────────────────────────────────────────── */

.diff-legend {
  display: flex;
  gap: var(--space-md);
  font-size: var(--text-xs);
  font-weight: 500;
  margin-bottom: var(--space-sm);
}

.diff-legend-del,
.diff-legend-add {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.diff-legend-del::before,
.diff-legend-add::before {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.diff-legend-del::before {
  background: var(--color-error-bg);
  border: 1px solid var(--color-error);
}

.diff-legend-del {
  color: var(--color-error-text);
}

.diff-legend-add::before {
  background: var(--color-success-bg);
  border: 1px solid var(--color-success);
}

.diff-legend-add {
  color: var(--color-success-text);
}

/* ── Diff page action bar ─────────────────────────────────── */

.diff-actions {
  margin-top: var(--space-lg);
}

/* ── Back button ─────────────────────────────────────────── */

.btn-back {
  display: inline-block;
  padding: var(--space-sm) var(--space-md);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: none;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  transition: background var(--duration-fast) var(--ease-out);
}

.btn-back:hover {
  background: var(--color-border-subtle);
}

/* ── Responsive ───────────────────────────────────────────── */

@media (max-width: 640px) {
  body {
    padding: var(--space-md);
  }

  .page-header {
    flex-direction: column;
    gap: var(--space-sm);
  }

  .card dl {
    grid-template-columns: 1fr;
  }

  .card dt {
    margin-top: var(--space-sm);
  }
}

/* ── Login page ────────────────────────────────────────────── */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--space-lg);
}

.login-card {
  width: 100%;
  max-width: 360px;
}

.login-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  margin: 0 0 var(--space-xs);
  letter-spacing: -0.02em;
}

.login-subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-tertiary);
  margin: 0 0 var(--space-xl);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.login-field label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
}

.login-field input {
  font-family: var(--font-body);
  font-size: var(--text-base);
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color var(--duration-fast) var(--ease-out);
}

.login-field input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-subtle);
}

.login-submit {
  margin-top: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  font-size: var(--text-base);
  font-weight: 600;
  width: 100%;
}

/* ── Clarify section (diff page) ─────────────────────────── */

.clarify-section {
  margin-top: var(--space-md);
}

.btn-clarify {
  display: inline-block;
  padding: var(--space-xs) var(--space-md);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
  cursor: pointer;
  border-radius: 6px;
}

.btn-clarify:hover {
  color: var(--color-text);
  background: var(--color-border-subtle);
}

.clarify-form {
  margin-top: var(--space-sm);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.clarify-form textarea {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  padding: var(--space-sm);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  color: var(--color-text);
  resize: vertical;
}

.clarify-form textarea:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-subtle);
}

.clarify-form button {
  align-self: flex-start;
}

/* ── Target file selector (knowledge gap merge) ─────────── */

.merge-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.merge-targets {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
}

.target-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-body);
  font-size: var(--text-xs);
  padding: 4px 10px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  transition: border-color var(--motion-fast), background var(--motion-fast);
  user-select: none;
}

.target-option:has(input:checked) {
  border-color: var(--color-accent);
  background: var(--color-accent-subtle);
}

.target-option.disabled {
  opacity: 0.35;
  pointer-events: none;
}

.target-option input[type="radio"],
.target-option input[type="checkbox"] {
  accent-color: var(--color-accent);
  margin: 0;
}

.target-option--convert {
  border-style: dashed;
  margin-left: auto;
}

/* ── Reduced motion ───────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
  }
}
