:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --surface: #fffdf8;
  --surface-alt: #f0f7f4;
  --text: #27241f;
  --muted: #706a60;
  --line: #d9d2c4;
  --accent: #087f5b;
  --accent-dark: #056449;
  --accent-soft: #dff4eb;
  --danger: #b42318;
  --danger-soft: #fce8e6;
  --warning: #9a6700;
  --warning-soft: #fff4cf;
  --info: #2764a4;
  --info-soft: #e7f0fb;
  --shadow: 0 18px 48px rgba(47, 42, 34, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

button,
input,
select,
textarea {
  font: inherit;
}

code,
textarea {
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px clamp(16px, 4vw, 42px);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.15;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.5rem, 3vw, 2.1rem);
}

h2 {
  font-size: 1rem;
}

.header-status {
  min-width: 160px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  background: var(--surface-alt);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  min-height: calc(100vh - 98px);
}

.control-panel {
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.preview-panel {
  min-width: 0;
  padding: 22px clamp(14px, 3vw, 30px) 30px;
}

.tool-section {
  padding: 20px clamp(16px, 3vw, 26px);
  border-bottom: 1px solid var(--line);
}

.section-heading,
.preview-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.section-heading span,
.preview-toolbar p,
#planSummary {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.folder-row,
.button-row,
.split-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.button-row + .button-row {
  margin-top: 10px;
}

.button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 13px;
  font-weight: 700;
  cursor: pointer;
  transition:
    background-color 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.primary-button:hover:not(:disabled) {
  background: var(--accent-dark);
}

.secondary-button {
  border-color: var(--line);
  background: #fff;
  color: var(--text);
}

.secondary-button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.field-label,
.field-group span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.field-group {
  flex: 1 1 160px;
  min-width: 0;
}

.text-input,
select,
.script-preview {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

.text-input,
select {
  min-height: 42px;
  padding: 9px 11px;
}

.text-input {
  margin-bottom: 12px;
}

.text-input:focus,
select:focus,
.script-preview:focus {
  outline: 3px solid var(--accent-soft);
  border-color: var(--accent);
}

.notice {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.strong-notice {
  padding: 10px 12px;
  border: 1px solid #e1ca86;
  border-radius: 8px;
  background: var(--warning-soft);
  color: #5f4500;
}

.message-list {
  display: grid;
  gap: 8px;
}

.message {
  padding: 9px 11px;
  border-radius: 8px;
  font-size: 0.9rem;
}

.message.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.message.warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.message.info {
  background: var(--info-soft);
  color: var(--info);
}

.replacement-list {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.replacement-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr) auto auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.replacement-toggle {
  display: flex;
  gap: 6px;
  align-items: center;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.replacement-input {
  width: 100%;
  min-width: 0;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  background: #fff;
  color: var(--text);
}

.replacement-input:focus {
  outline: 3px solid var(--accent-soft);
  border-color: var(--accent);
}

.replacement-empty {
  padding: 10px 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fff;
}

.mini-button {
  min-width: 42px;
  min-height: 34px;
  padding: 6px 8px;
  font-size: 0.82rem;
}

.capture-list {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 6px 12px;
  margin: 0;
  font-size: 0.92rem;
}

.capture-list dt {
  color: var(--accent-dark);
  font-weight: 800;
}

.capture-list dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.script-preview {
  display: block;
  min-height: 230px;
  margin-top: 12px;
  padding: 12px;
  resize: vertical;
  white-space: pre;
}

.preview-toolbar {
  margin-bottom: 14px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 800;
}

.status-pill.ready {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.status-pill.blocked {
  background: var(--danger-soft);
  color: var(--danger);
}

.status-pill.warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  min-width: 940px;
  border-collapse: collapse;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #efe9dc;
  color: #463f35;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

td {
  max-width: 280px;
  overflow-wrap: anywhere;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr.row-ready {
  background: #fbfffd;
}

tbody tr.row-warning {
  background: #fffaf0;
}

tbody tr.row-blocked {
  background: #fff8f7;
}

.filename {
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.88rem;
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .control-panel {
    border-right: 0;
  }

  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-status {
    width: 100%;
    text-align: left;
  }
}

@media (max-width: 560px) {
  .tool-section,
  .preview-panel,
  .app-header {
    padding-left: 14px;
    padding-right: 14px;
  }

  .section-heading,
  .preview-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .button,
  .folder-row label,
  .button-row button {
    width: 100%;
  }

  .replacement-row {
    grid-template-columns: 1fr;
  }
}
