* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 13px;
  color: #222;
  background: #f6f6f5;
}

header {
  padding: 16px 24px;
  background: #fff;
  border-bottom: 1px solid #d8d8d6;
  display: flex;
  align-items: center;
  gap: 24px;
}
.header-main { flex: 1; min-width: 0; }

.auth-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.auth-signin-label { color: #888; }
.auth-provider-btn {
  display: inline-block;
  padding: 5px 10px;
  background: #fff;
  border: 1px solid #c8c8c6;
  border-radius: 3px;
  font-size: 12px;
  color: #222;
  text-decoration: none;
  cursor: pointer;
}
.auth-provider-btn:hover { background: #f0f0ee; border-color: #a8a8a6; }

.auth-user { position: relative; display: inline-flex; align-items: center; gap: 8px; }
.auth-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
}
.auth-name { color: #444; }
.auth-user-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  background: #fff;
  border: 1px solid #c8c8c6;
  border-radius: 3px;
  font-size: 12px;
  cursor: pointer;
}
.auth-user-btn:hover { background: #f0f0ee; border-color: #a8a8a6; }
.auth-caret { color: #888; font-size: 10px; }
.auth-menu {
  min-width: 160px;
}
.auth-menu a, .auth-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 6px 10px;
  font-size: 12px;
  color: #222;
  text-decoration: none;
  cursor: pointer;
  font-family: inherit;
}
.auth-menu a:hover, .auth-menu button:hover { background: #eef3f0; }
.auth-menu a#auth-menu-billing {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.auth-menu-balance {
  font-size: 11px;
  font-weight: 600;
  color: #155e34;
  background: #e6f2eb;
  border-radius: 10px;
  padding: 1px 7px;
  white-space: nowrap;
}
.auth-logout { margin: 0; }
header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.home-link, .home-link:visited {
  color: inherit;
  text-decoration: none;
}
.subtitle {
  color: #888;
  margin-top: 2px;
  font-size: 12px;
}

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px 24px 64px;
}

.step {
  background: #fff;
  border: 1px solid #d8d8d6;
  border-radius: 4px;
  margin-bottom: 16px;
  overflow: hidden;
}
.step-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid #e8e8e6;
  background: #fafafa;
}
.step-num {
  width: 22px;
  height: 22px;
  background: #1a7a43;
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
}
.step-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.file-btn {
  display: inline-block;
  cursor: pointer;
}
.file-btn input[type=file] { display: none; }
.file-btn span, button, select, input[type=number] {
  display: inline-block;
  padding: 5px 10px;
  background: #fff;
  border: 1px solid #c8c8c6;
  border-radius: 3px;
  font-size: 12px;
  font-family: inherit;
  color: #222;
  cursor: pointer;
}
button:hover:not(:disabled), .file-btn span:hover {
  background: #f0f0ee;
  border-color: #a8a8a6;
}
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
button.primary {
  background: #1a7a43;
  border-color: #155e34;
  color: #fff;
}
button.primary:hover:not(:disabled) { background: #155e34; }
input[type=number] { width: 52px; cursor: text; }
.sample-size {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #666;
  font-size: 12px;
  margin-left: auto;
}

.status {
  color: #666;
  font-size: 12px;
  margin-left: auto;
}
.status.error { color: #c23c2c; }
.status.success { color: #1a7a43; }

.info {
  padding: 6px 14px;
  color: #666;
  font-size: 12px;
  background: #fafafa;
  border-bottom: 1px solid #e8e8e6;
}
.info:empty { display: none; }

.undo-toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: #2a2a2a;
  color: #f5f5f5;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  font-size: 13px;
  z-index: 100;
}
.undo-toast button {
  background: transparent;
  color: #ffce5c;
  border: none;
  padding: 0;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.undo-toast button:hover { text-decoration: underline; }

.grid-wrap {
  overflow: auto;
  max-height: 320px;
  border-top: 1px solid #e8e8e6;
}
.grid-wrap:empty { display: none; }

table.grid {
  border-collapse: collapse;
  font-size: 12px;
  width: max-content;
  min-width: 100%;
}
table.grid th, table.grid td {
  border: 1px solid #d8d8d6;
  padding: 4px 8px;
  min-width: 80px;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: #fff;
}
table.grid th {
  background: #eef1ef;
  font-weight: 600;
  position: sticky;
  top: -2px;
  z-index: 1;
  text-align: left;
}
table.grid th.row-num, table.grid td.row-num {
  background: #eef1ef;
  color: #888;
  text-align: right;
  position: sticky;
  left: 0;
  min-width: 36px;
  font-variant-numeric: tabular-nums;
}
table.grid tr:nth-child(even) td { background: #fafafa; }
table.grid td.blank { color: #bbb; }

#transformations {
  padding: 0;
}
#transformations:empty { display: none; }
#transformations:empty ~ .refine-all { display: none; }

.xform {
  border-bottom: 1px solid #e8e8e6;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 10px 14px;
}
.xform:last-child { border-bottom: none; }
.xform-title {
  font-weight: 600;
  font-size: 13px;
}
.xform-title .empty-hint {
  font-weight: 400;
  color: #c23c2c;
  font-size: 11px;
  margin-left: 6px;
}
.xform-notes {
  color: #666;
  font-size: 12px;
  margin-top: 4px;
  white-space: pre-wrap;
}
.xform-body { display: flex; flex-direction: column; gap: 8px; }
.xform textarea.code {
  width: 100%;
  min-height: 60px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  padding: 6px 8px;
  border: 1px solid #d8d8d6;
  border-radius: 3px;
  resize: vertical;
  background: #fafafa;
}
.xform-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.xform-actions .preview {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: #444;
  background: #f0f3f0;
  padding: 3px 6px;
  border-radius: 2px;
  max-width: 400px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.xform-actions .preview.err { background: #fbecea; color: #c23c2c; }

.xform-refine {
  display: flex;
  gap: 6px;
}
.xform-refine textarea {
  flex: 1;
  min-height: 30px;
  padding: 5px 8px;
  border: 1px solid #d8d8d6;
  border-radius: 3px;
  font-family: inherit;
  font-size: 12px;
  resize: vertical;
}

.preview-bar {
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-top: 1px solid #e8e8e6;
  background: #fafafa;
}
.preview-label {
  font-weight: 600;
  font-size: 12px;
  color: #444;
}

table.grid td.cell-err {
  background: #fbecea;
  color: #c23c2c;
}

.refine-all {
  padding: 12px 14px;
  display: flex;
  gap: 8px;
  border-top: 1px solid #e8e8e6;
  background: #fafafa;
}
.refine-all textarea {
  flex: 1;
  min-height: 36px;
  padding: 6px 8px;
  border: 1px solid #d8d8d6;
  border-radius: 3px;
  font-family: inherit;
  font-size: 12px;
  resize: vertical;
}

/* Conflict resolution dialog */
.cf-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 20, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
}
.cf-dialog {
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  width: min(800px, 100%);
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.cf-title {
  padding: 14px 18px;
  font-weight: 600;
  font-size: 14px;
  border-bottom: 1px solid #e8e8e6;
}
.cf-blurb {
  padding: 10px 18px;
  font-size: 12px;
  color: #555;
  background: #fafafa;
  border-bottom: 1px solid #e8e8e6;
}
.cf-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  padding: 0;
  overflow: auto;
}
.cf-panel {
  padding: 12px 16px;
  border-right: 1px solid #e8e8e6;
}
.cf-panel:last-child { border-right: none; }
.cf-panel-head {
  font-weight: 600;
  font-size: 12px;
  color: #444;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.cf-panel-body {
  font-size: 12px;
  color: #222;
  line-height: 1.6;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.cf-panel-raw {
  margin-top: 10px;
  font-size: 11px;
}
.cf-panel-raw summary {
  cursor: pointer;
  color: #666;
  user-select: none;
}
.cf-panel-raw pre {
  background: #fafafa;
  padding: 8px;
  border: 1px solid #e8e8e6;
  border-radius: 3px;
  margin-top: 6px;
  max-height: 240px;
  overflow: auto;
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-word;
}
.cf-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid #e8e8e6;
  background: #fafafa;
}
.cf-spacer { flex: 1; }

/* Project list (home page) */
.project-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid #e8e8e6;
}
.project-row:last-child { border-bottom: none; }
.project-main {
  flex: 1;
  text-decoration: none;
  color: inherit;
  min-width: 0;
}
.project-main:hover .project-name { color: #1a7a43; }
.project-name {
  font-weight: 600;
  font-size: 13px;
}
.project-meta {
  color: #888;
  font-size: 12px;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.project-meta.save-error { color: #b3261e; }

/* Project bar (transform page) */
.project-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: #fff;
  border: 1px solid #d8d8d6;
  border-radius: 4px;
  margin-bottom: 16px;
}
.project-name-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #666;
  font-size: 12px;
  flex: 1;
}
.project-name-field input {
  flex: 1;
  padding: 5px 8px;
  border: 1px solid #d8d8d6;
  border-radius: 3px;
  font-family: inherit;
  font-size: 13px;
  background: #fafafa;
}
.back-link {
  color: #1a7a43;
  font-size: 12px;
  text-decoration: none;
}
.back-link:hover { text-decoration: underline; }

/* Locked step (e.g. Destination hydrated from saved project) */
.step.locked .info,
.step.locked .grid-wrap,
.step.locked table.grid th,
.step.locked table.grid td {
  color: #888;
  background: #f6f6f5;
}
.step.locked .step-head { background: #f3f3f1; }
#target-locked-note { color: #888; font-style: italic; margin-left: 0; }

/* New-project cards on home page */
.new-project-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid #e8e8e6;
  background: #fafafa;
}
@media (max-width: 600px) {
  .new-project-cards { grid-template-columns: 1fr; }
}
.project-card {
  display: block;
  text-align: left;
  background: #fff;
  border: 1px solid #d8d8d6;
  border-radius: 4px;
  padding: 16px 18px;
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s, transform 0.12s;
  font: inherit;
  color: inherit;
  width: 100%;
}
.project-card:hover {
  background: #fff;
  border-color: #1a7a43;
  box-shadow: 0 2px 8px rgba(26, 122, 67, 0.1);
}
.project-card:focus-visible {
  outline: 2px solid #1a7a43;
  outline-offset: 2px;
}
.project-card h3 {
  margin: 0 0 6px 0;
  font-size: 15px;
  font-weight: 600;
  color: #1a7a43;
}
.project-card p {
  margin: 0;
  font-size: 13px;
  color: #555;
  line-height: 1.4;
}

.menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: #fff;
  border: 1px solid #c8c8c6;
  border-radius: 3px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  min-width: 180px;
  z-index: 10;
  padding: 4px;
}
.menu button {
  border: none;
  background: transparent;
  text-align: left;
  padding: 6px 10px;
  font-size: 12px;
  width: 100%;
}
.menu button:hover { background: #eef3f0; }

/* Project-type badge */
.project-type {
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: #e8efe8;
  color: #4a6a4a;
  padding: 1px 6px;
  border-radius: 2px;
  font-weight: 600;
  vertical-align: middle;
}
.project-type.merge { background: #eaeaf4; color: #525288; }

/* Priority radios on merge page */
.priority-group {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  color: #666;
  font-size: 12px;
}
.priority-group label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

/* Match editor on merge page */
.match-editor {
  border-bottom: 1px solid #e8e8e6;
}
.match-editor:empty { display: none; }

.join-section {
  padding: 12px 14px;
  border-bottom: 1px solid #e8e8e6;
  background: #fafafa;
}
.join-head {
  font-weight: 600;
  font-size: 12px;
  color: #444;
  margin-bottom: 8px;
}
.match-columns-display {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.match-columns-display:empty { display: none; }
.match-col-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 4px 8px;
  background: #fff;
  border: 1px solid #d8d8d6;
  border-radius: 3px;
}
.match-col-side {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: #222;
}
.match-col-arrow { color: #888; }
.match-col-strategy {
  color: #666;
  font-style: italic;
  border-left: 1px solid #e0e0de;
  padding-left: 8px;
}
.match-notes-text {
  color: #666;
  font-size: 12px;
  margin-bottom: 10px;
}
.match-notes-text:empty { display: none; }
.join-refine {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.join-refine textarea {
  flex: 1;
  min-height: 30px;
  padding: 5px 8px;
  border: 1px solid #d8d8d6;
  border-radius: 3px;
  font-family: inherit;
  font-size: 12px;
  resize: vertical;
}
.match-code-details summary {
  cursor: pointer;
  color: #666;
  font-size: 11px;
  user-select: none;
  padding: 2px 0;
}
.match-code-details[open] summary { color: #444; }
.match-code-details textarea.code {
  width: 100%;
  min-height: 50px;
  margin-top: 6px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  padding: 6px 8px;
  border: 1px solid #d8d8d6;
  border-radius: 3px;
  resize: vertical;
  background: #fff;
}

/* Settings page */
.settings-form { padding: 16px 18px; }
.settings-row {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 12px 16px;
  align-items: start;
  padding: 10px 0;
  border-bottom: 1px solid #f0f0ee;
}
.settings-row:last-of-type { border-bottom: none; }
.settings-row label {
  font-weight: 600;
  font-size: 13px;
  padding-top: 6px;
  color: #222;
}
.settings-control { display: flex; flex-direction: column; gap: 6px; }
.settings-control input[type=password],
.settings-control select {
  padding: 6px 8px;
  border: 1px solid #d8d8d6;
  border-radius: 3px;
  font-family: inherit;
  font-size: 13px;
  background: #fafafa;
  width: 100%;
  max-width: 420px;
}
.settings-hint {
  color: #666;
  font-size: 12px;
  line-height: 1.5;
}
.settings-hint a {
  color: #c23c2c;
  text-decoration: none;
  margin-left: 6px;
}
.settings-hint a:hover { text-decoration: underline; }
.settings-actions {
  padding-top: 12px;
  display: flex;
  gap: 8px;
}

.api-key-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.api-key-badge {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 10px;
  border: 1px solid transparent;
}
.api-key-state[data-state="stored"] .api-key-badge {
  background: #e6f3ec;
  color: #1a7a43;
  border-color: #b9dec8;
}
.api-key-state[data-state="empty"] .api-key-badge {
  background: #f1f1ef;
  color: #777;
  border-color: #ddd;
}
.api-key-state[data-state="loading"] .api-key-badge {
  background: #f1f1ef;
  color: #888;
  border-color: #ddd;
}
.api-key-remove {
  font-size: 12px;
  padding: 3px 10px;
  background: #fff;
  border: 1px solid #d8b4ad;
  color: #c23c2c;
  border-radius: 3px;
  cursor: pointer;
}
.api-key-remove:hover:not(:disabled) {
  background: #fbecea;
  border-color: #c23c2c;
}

.billing-section {
  margin: 4px 18px 18px;
  padding: 14px 16px;
  border: 1px solid #e8e8e6;
  border-radius: 4px;
  background: #fafafa;
}
.billing-section h3 {
  margin: 0 0 6px;
  font-size: 14px;
  color: #155e34;
}
.billing-section .settings-hint { margin: 0 0 10px; }
.billing-balance {
  font-size: 13px;
  font-weight: 600;
  color: #155e34;
  margin-bottom: 10px;
}
.billing-chart {
  margin: 0 0 12px;
}
.billing-chart h4 {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 600;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.billing-chart svg {
  display: block;
  width: 100%;
  height: 80px;
  background: #fff;
  border: 1px solid #e0e0de;
  border-radius: 3px;
}
.billing-chart-meta {
  margin-top: 6px;
  font-size: 11px;
  color: #666;
  font-variant-numeric: tabular-nums;
}

.billing-packs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}
.billing-pack {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid #e0e0de;
  border-radius: 4px;
}
.billing-pack-label { font-weight: 600; font-size: 13px; }
.billing-pack-tokens { font-size: 12px; color: #555; }
.billing-pack-price { font-size: 12px; color: #155e34; margin-bottom: 4px; }
.billing-pack button { align-self: flex-start; padding: 4px 14px; font-size: 12px; }
.billing-status {
  margin-top: 10px;
  font-size: 12px;
  color: #444;
}
.billing-status.success { color: #155e34; }
.billing-status.error { color: #b13727; }
.billing-transactions {
  margin-top: 18px;
}
.billing-transactions-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 6px;
}
.billing-transactions-head h4 {
  margin: 0;
  font-size: 13px;
}
.billing-transactions-head a {
  font-size: 12px;
  color: #1a7a43;
}
.billing-transactions table.grid td.num,
.billing-transactions table.grid th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.billing-transactions table.grid td.credit { color: #155e34; }
.billing-transactions table.grid td.debit  { color: #666; }
.billing-transactions .settings-hint { margin-top: 6px; }

.settings-help {
  margin: 4px 18px 18px;
  border-top: 1px solid #e8e8e6;
  padding-top: 12px;
}
.settings-help summary {
  cursor: pointer;
  color: #1a7a43;
  font-size: 12px;
  font-weight: 600;
  user-select: none;
  padding: 4px 0;
}
.settings-help summary:hover { text-decoration: underline; }
.settings-help[open] summary { color: #155e34; }
.settings-help-body {
  margin-top: 10px;
  padding: 12px 14px;
  background: #fafafa;
  border: 1px solid #e8e8e6;
  border-radius: 4px;
  font-size: 12px;
  color: #444;
  line-height: 1.55;
}
.settings-help-body p { margin: 0 0 10px; }
.settings-help-body ol {
  margin: 0;
  padding-left: 18px;
}
.settings-help-body li { margin-bottom: 6px; }
.settings-help-body li:last-child { margin-bottom: 0; }
.settings-help-body a {
  color: #1a7a43;
  text-decoration: none;
}
.settings-help-body a:hover { text-decoration: underline; }
.settings-help-body code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  background: #eef1ef;
  padding: 1px 4px;
  border-radius: 2px;
  font-size: 11px;
}
