:root {
  --bg: #f3f1ea;
  --paper: #fffcf5;
  --ink: #181716;
  --muted: #6a645b;
  --line: #d6cfbe;
  --accent: #145c53;
  --accent-2: #9a3f16;
  --danger: #a12d2f;
  --ok: #1f7a4d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 6%, rgba(20, 92, 83, 0.09), transparent 40%),
    radial-gradient(circle at 90% 10%, rgba(154, 63, 22, 0.08), transparent 42%),
    var(--bg);
  font-family: Georgia, "Times New Roman", serif;
}

.page-shell {
  max-width: 1320px;
  margin: 0 auto;
  padding: 22px;
}

.top-nav { margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.top-nav a { color: var(--accent); text-decoration: none; font-family: ui-sans-serif, system-ui, sans-serif; font-weight: 600; }
.top-nav a:hover { text-decoration: underline; }

.user-nav { display: flex; align-items: center; gap: 12px; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 13px; }
.user-label { font-weight: 700; color: var(--accent); }
.user-profile-link { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.logout-form button { background: none; border: none; padding: 0; color: var(--danger); font-size: 13px; font-weight: 700; cursor: pointer; font-family: inherit; }
.logout-form button:hover { text-decoration: underline; }

.hero {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 14px;
  align-items: start;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0;
  color: var(--accent-2);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-size: 12px;
  font-weight: 700;
  font-family: ui-sans-serif, system-ui, sans-serif;
}

.hero h1,
.page-title {
  margin: 8px 0 8px;
  line-height: 1.05;
  font-size: clamp(28px, 4vw, 42px);
}

.sub {
  margin: 0;
  color: var(--muted);
  max-width: 80ch;
}

.hero-card,
.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.hero-card {
  padding: 14px;
  display: grid;
  gap: 10px;
}

.metric-chip {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 1px dashed var(--line);
  padding-bottom: 8px;
}
.metric-chip:last-child { border-bottom: none; padding-bottom: 0; }
.metric-chip span { color: var(--muted); font-family: ui-sans-serif, system-ui, sans-serif; }
.metric-chip strong { font-size: 22px; }
.metric-chip a { color: inherit; text-decoration: none; }
.metric-chip a:hover { text-decoration: underline; }

.flash {
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 14px;
  border: 1px solid #b6dfc4;
  color: var(--ok);
  background: #e9f7ef;
  font-family: ui-sans-serif, system-ui, sans-serif;
}
.flash.error {
  border-color: #e7b9bf;
  color: #7f1f29;
  background: #fff0f2;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.panel { padding: 16px; min-width: 0; }
.panel h2 { margin: 0 0 12px; font-size: 20px; }
.span-2 { grid-column: span 2; }
.why-flow-panel { margin-bottom: 14px; }

.panel-header-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.onboarding-list .button-link {
  justify-content: flex-start;
}

.onboarding-step {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.onboarding-step.onboarding-done {
  background: #ecf4ef;
  color: #4f6259;
  border: 1px solid #c6dfcf;
}

.onboarding-check {
  font-weight: 700;
}

.stack { display: grid; gap: 10px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
label { display: grid; gap: 6px; }
label > span { color: var(--muted); font-size: 13px; font-family: ui-sans-serif, system-ui, sans-serif; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }

input, textarea, select, button { font: inherit; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
}
textarea { resize: vertical; }

button,
.button-link {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #124a6c);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-weight: 600;
}
button:hover,
.button-link:hover { filter: brightness(1.06); }
.button-link.secondary {
  background: linear-gradient(135deg, #9a3f16, #7d2f11);
}
.button-link.ghost {
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--line);
}
button.small { padding: 7px 10px; font-size: 12px; }
button.danger { background: linear-gradient(135deg, var(--danger), #6d1d1f); }
button.accent { background: linear-gradient(135deg, #2f6f18, #1c7a57); }

.inline-form { display: inline-flex; gap: 6px; align-items: center; margin-right: 6px; }
.inline-form.compact input { min-width: 120px; padding: 7px 8px; }
.inline-form input { padding: 7px 8px; border-radius: 8px; }
.builder-hidden-markdown { display: none; }

.template-builder-shell {
  display: grid;
  gap: 10px;
}

.template-builder-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.builder-toolbar-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.inline-select {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: ui-sans-serif, system-ui, sans-serif;
  color: var(--muted);
  font-size: 12px;
}

.inline-select select {
  min-width: 190px;
  width: auto;
  padding: 7px 8px;
}

.template-builder-sections {
  display: grid;
  gap: 10px;
}

.builder-section-create {
  display: flex;
  justify-content: center;
}

.builder-section {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: #fff;
}

.builder-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.builder-section-header input {
  font-weight: 700;
  min-width: 220px;
}

.builder-section-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.builder-section > textarea[data-builder-field="section-description"] {
  margin-bottom: 8px;
}

.builder-steps {
  display: grid;
  gap: 8px;
}

.builder-step-row {
  display: grid;
  grid-template-columns: 2fr 190px auto;
  gap: 8px;
  align-items: start;
  padding-left: calc(var(--builder-depth, 0) * 20px);
}

.builder-step-content {
  display: grid;
  gap: 6px;
}

.builder-step-row textarea {
  min-height: 66px;
}

.builder-step-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.builder-preview-panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: #fff;
}

.builder-preview-panel h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.builder-mermaid {
  border: 1px dashed var(--line);
  border-radius: 10px;
  min-height: 140px;
  background: #fffdf7;
  padding: 8px;
  overflow-x: auto;
}

.builder-mermaid svg {
  min-width: 420px;
}

.builder-mermaid-source {
  margin-top: 10px;
  display: grid;
  gap: 6px;
}

.builder-mermaid-source details {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 8px;
  background: #fffdf7;
}

.builder-mermaid-source summary {
  cursor: pointer;
  font-family: ui-sans-serif, system-ui, sans-serif;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.builder-mermaid-actions {
  margin-top: 8px;
}

.builder-mermaid-source textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  min-height: 140px;
  background: #fff;
}

.toast-md-host {
  margin-top: 6px;
}

.toastui-editor-defaultUI {
  border-color: var(--line) !important;
  border-radius: 12px;
  overflow: hidden;
  background: #fffdf7;
}

.toastui-editor-toolbar {
  background: #f7f3ea !important;
  border-bottom-color: var(--line) !important;
}

.toastui-editor-toolbar-icons {
  border-color: var(--line) !important;
}

.toastui-editor-md-tab-container,
.toastui-editor-mode-switch {
  background: #f7f3ea !important;
  border-top-color: var(--line) !important;
}

.toastui-editor-md-tab-container .tab-item {
  color: var(--muted) !important;
}

.toastui-editor-md-tab-container .tab-item.active {
  color: var(--ink) !important;
  font-weight: 700;
}

.toastui-editor-contents,
.toastui-editor-md-preview,
.toastui-editor-md-container .ProseMirror,
.toastui-editor-md-container .CodeMirror {
  font-family: Georgia, "Times New Roman", serif;
}

.md-editor-shell {
  display: grid;
  gap: 8px;
}

.md-editor-tabs {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.md-editor-tab {
  border: 1px solid var(--line);
  background: #f7f3ea;
  color: var(--ink);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-weight: 700;
  cursor: pointer;
}

.md-editor-tab.is-active {
  background: #eef7fb;
  border-color: #c6dfec;
}

.md-editor-help {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-family: ui-sans-serif, system-ui, sans-serif;
}

.md-editor-help code {
  font-size: 11px;
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 4px;
}

.md-editor-preview {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffdf7;
  padding: 12px;
  min-height: 160px;
  line-height: 1.45;
}

.md-editor-preview[hidden] { display: none !important; }

.md-editor-preview-empty {
  color: var(--muted);
  font-style: italic;
}

.md-editor-preview h1,
.md-editor-preview h2,
.md-editor-preview h3,
.md-editor-preview h4,
.md-editor-preview h5,
.md-editor-preview h6 {
  margin: 0.6em 0 0.35em;
  line-height: 1.2;
}

.md-editor-preview h1:first-child,
.md-editor-preview h2:first-child,
.md-editor-preview h3:first-child,
.md-editor-preview h4:first-child,
.md-editor-preview h5:first-child,
.md-editor-preview h6:first-child { margin-top: 0; }

.md-editor-preview p {
  margin: 0 0 10px;
  white-space: pre-wrap;
}

.md-editor-preview code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: #f3efe5;
  border-radius: 4px;
  padding: 1px 4px;
}

.md-editor-preview-list {
  list-style: none;
  padding: 0;
  margin: 0 0 10px;
  display: grid;
  gap: 4px;
}

.md-editor-preview-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding-left: calc(var(--md-indent, 0) * 10px);
}

.md-editor-preview-item.is-done {
  color: #506d58;
}

.md-editor-preview-item.is-done .md-editor-preview-item-text {
  text-decoration: line-through;
}

.md-task-box {
  width: 14px;
  height: 14px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  line-height: 1;
  margin-top: 2px;
  color: var(--ok);
  flex: 0 0 auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 14px;
}

.landing-hero .sub {
  max-width: 62ch;
}

.landing-proof {
  margin: 14px 0 0;
  padding-left: 18px;
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.landing-proof li {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 13px;
}

.worker-table td[data-label] {
  word-break: break-word;
}
.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

.data-table tbody tr.row-complete td {
  background: linear-gradient(0deg, rgba(31, 122, 77, 0.06), rgba(31, 122, 77, 0.06));
}

.data-table tbody tr.row-complete:hover td {
  background: linear-gradient(0deg, rgba(31, 122, 77, 0.09), rgba(31, 122, 77, 0.09));
}

.data-table tbody tr.row-complete td:not(:first-child) {
  color: color-mix(in srgb, var(--ink) 78%, white);
}
.data-table th {
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-weight: 600;
}

.muted {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.muted-inline {
  color: var(--muted);
  font-size: 11px;
  margin-left: 8px;
  font-family: ui-sans-serif, system-ui, sans-serif;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  word-break: break-word;
}

.pill {
  display: inline-flex;
  border-radius: 999px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  background: #f7f3ea;
  font-size: 12px;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-weight: 700;
}
.pill.active, .pill.open { background: #eef7fb; border-color: #c6dfec; }
.pill.archived { background: #f3edf0; border-color: #e2d4db; }
.pill.done { background: #eaf7ed; border-color: #c6e4cf; }

.path {
  color: var(--accent-2);
  font-weight: 700;
  margin-right: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.checklist-preview {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.checklist-row {
  display: flex;
  align-items: baseline;
  gap: 2px;
  flex-wrap: wrap;
}

.run-sections {
  margin: 10px 0 14px;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: #fffdf7;
}

.run-sections h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.run-reference-preview {
  margin-top: 6px;
}

.run-reference-inline-item {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.done-text {
  text-decoration: line-through;
  color: #5a7563;
}

.progress-shell {
  height: 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f6f2e9;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #2a7b53, #3ca276);
  width: 0%;
}

.meta-list { margin: 0; }
.meta-list div {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px dashed var(--line);
}
.meta-list div:last-child { border-bottom: none; }
.meta-list dt {
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 12px;
}
.meta-list dd { margin: 0; word-break: break-word; }

.snippet {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 180px;
  overflow: auto;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid #eadfcb;
  background: #fbf7ee;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.mini-input {
  width: 140px;
  padding: 6px 8px;
  font-size: 12px;
}

.compact-stack {
  gap: 6px;
}

.compact-stack input {
  padding: 7px 8px;
}

.event-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #fbf8f0;
  margin-top: 10px;
}

.event-line {
  margin-bottom: 6px;
}

@media (max-width: 980px) {
  .hero { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .two-col { grid-template-columns: 1fr; }
  .panel-header-row { flex-direction: column; }
  .data-table { table-layout: auto; }
  .meta-list div { grid-template-columns: 1fr; gap: 4px; }
  .template-builder-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }
  .builder-step-row {
    grid-template-columns: 1fr;
    padding-left: calc(var(--builder-depth, 0) * 14px);
  }
}

@media (max-width: 768px) {
  .page-shell {
    padding: 14px;
  }
  .top-nav {
    align-items: flex-start;
  }
  .top-nav .user-nav:first-child {
    width: 100%;
    overflow-x: auto;
    white-space: nowrap;
    padding-bottom: 2px;
  }
  .top-nav .user-nav:first-child a {
    display: inline-block;
  }
}

@media (max-width: 640px) {
  .hero h1,
  .page-title {
    line-height: 1.12;
    font-size: clamp(24px, 8vw, 34px);
  }
  .landing-cta-row .button-link {
    width: 100%;
  }
  .worker-grid {
    gap: 10px;
  }
  .worker-grid .panel {
    padding: 12px;
  }
  .worker-table {
    table-layout: auto;
    border-collapse: separate;
    border-spacing: 0;
  }
  .worker-table thead {
    display: none;
  }
  .worker-table tbody,
  .worker-table tr,
  .worker-table td {
    display: block;
    width: 100%;
  }
  .worker-table tr {
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    margin-bottom: 10px;
    padding: 8px;
  }
  .worker-table td {
    border-bottom: 1px dashed var(--line);
    padding: 7px 6px;
  }
  .worker-table td:last-child {
    border-bottom: none;
  }
  .worker-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    color: var(--muted);
    font-size: 11px;
    font-family: ui-sans-serif, system-ui, sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 2px;
  }
  .worker-table td[data-label="Action"] .inline-form,
  .worker-table td[data-label="Resume"] a,
  .worker-table td[data-label="Open"] a {
    width: 100%;
    margin-right: 0;
  }
}
