:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-2: #374151;
  --muted: #6b7280;
  --brand: #f8161d;
  --brand-hover: #d90f16;
  --brand-soft: #fdecee;
  --brand-ring: rgba(248,22,29,0.18);
  --ok: #059669;
  --ok-soft: #ecfdf5;
  --ok-border: #a7f3d0;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --warn-border: #fde68a;
  --danger: #dc2626;
  --row-hover: #f9fafb;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16,24,40,0.04), 0 1px 3px rgba(16,24,40,0.06);
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; }
button { cursor: pointer; font-family: inherit; }
a { color: var(--brand); text-decoration: none; font-weight: 600; }
a:hover { text-decoration: underline; }

.container { max-width: 1180px; margin: 0 auto; padding: 32px 24px 24px; }

/* Header */
.app-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 24px; flex-wrap: wrap; }
.app-title { display: flex; align-items: center; gap: 12px; }
.app-icon { width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0; }
h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.local-badge {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--card); border: 1px solid var(--border);
  color: var(--text-2); font-size: 12px; font-weight: 500;
  padding: 6px 12px; border-radius: 99px;
}
.local-badge::before { content: ''; width: 7px; height: 7px; background: var(--ok); border-radius: 50%; }
.local-badge:hover { border-color: var(--ok-border); background: var(--ok-soft); }
.local-badge:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--brand-ring); }

/* Cards & layout */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.app-layout { display: grid; grid-template-columns: 320px 1fr; gap: 20px; align-items: start; }
.sidebar { display: flex; flex-direction: column; gap: 16px; }
.main-panel { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn-row.tight { gap: 6px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* Text */
.section-label { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 14px; letter-spacing: .02em; }
.hint { font-size: 12px; color: var(--muted); margin: 10px 0 0; line-height: 1.45; }
.flush { margin: 0; }
.brand-text { color: var(--brand); font-weight: 600; }
.notice { background: var(--warn-soft); border: 1px solid var(--warn-border); color: #92400e; padding: 9px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 16px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border-radius: var(--radius-sm); padding: 8px 14px;
  font-size: 13px; font-weight: 600;
  border: 1px solid var(--border-strong);
  background: var(--card); color: var(--text-2);
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { background: #f9fafb; border-color: #9ca3af; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--brand-ring); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn.ok { background: var(--text); border-color: var(--text); color: #fff; }
.btn.ok:hover { background: #1f2937; border-color: #1f2937; }
.btn.danger { color: var(--danger); border-color: #fecaca; background: #fff; }
.btn.danger:hover { background: #fef2f2; border-color: #fca5a5; }
.btn.danger-fill { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-fill:hover { background: #b91c1c; border-color: #b91c1c; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn svg { flex-shrink: 0; }

/* Fields */
.field { display: grid; gap: 6px; }
.field-label { font-size: 12px; font-weight: 600; color: var(--text-2); display: flex; align-items: center; gap: 5px; }
.field input, .field select {
  padding: 8px 10px; background: #fff;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  color: var(--text); font-family: inherit; font-size: 13px; outline: none;
  transition: border-color .15s, box-shadow .15s; width: 100%;
}
.field input:focus, .field select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.field input::placeholder { color: #9ca3af; }

/* Checkboxes */
.check-label { display: flex; align-items: center; gap: 9px; font-size: 13px; font-weight: 500; color: var(--text-2); cursor: pointer; }
.check-label.center { justify-content: center; }
.check-label input[type=checkbox] {
  appearance: none; -webkit-appearance: none;
  width: 16px; height: 16px; background: #fff;
  border: 1px solid var(--border-strong); border-radius: 4px;
  cursor: pointer; position: relative; transition: all .15s; flex-shrink: 0; margin: 0;
}
.check-label input[type=checkbox]:checked,
.check-label input[type=checkbox]:indeterminate { background: var(--brand); border-color: var(--brand); }
.check-label input[type=checkbox]:checked::after {
  content: ''; position: absolute; left: 4.5px; top: 1.5px; width: 4px; height: 8px;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.check-label input[type=checkbox]:indeterminate::after {
  content: ''; position: absolute; left: 3px; top: 6.5px; width: 8px; height: 2px; background: #fff;
}
.check-label input[type=checkbox]:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--brand-ring); }

/* Tooltips */
.tip {
  position: relative; display: inline-flex; width: 14px; height: 14px;
  background: #e5e7eb; color: var(--muted); border-radius: 50%;
  font-size: 9px; font-weight: 700; align-items: center; justify-content: center;
  cursor: help; flex-shrink: 0;
}
.tip::before { content: '?'; line-height: 1; }
.tip:hover { background: var(--text); color: #fff; }
.tip-text {
  display: none; position: absolute; bottom: calc(100% + 8px); left: 50%;
  transform: translateX(-50%); background: var(--text); color: #fff;
  font-size: 11px; font-weight: 500; line-height: 1.5; white-space: nowrap;
  padding: 7px 10px; border-radius: 6px; pointer-events: none; z-index: 100;
}
.tip-text::after {
  content: ''; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: var(--text);
}
.tip:hover .tip-text { display: block; }

/* Steps */
.pipeline { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.pipeline-empty { font-size: 12px; color: var(--muted); margin: 0; }
.step-card { border: 1px solid var(--border); border-radius: 10px; background: #fafafa; transition: border-color .15s, box-shadow .15s; }
.step-card:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.step-card.off .step-title, .step-card.off .step-body { opacity: .45; }
.step-header { display: flex; align-items: center; gap: 8px; padding: 9px 10px; cursor: pointer; user-select: none; }
.step-num {
  width: 22px; height: 22px; border-radius: 6px; background: #fff;
  border: 1px solid var(--border); color: var(--text-2); font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.step-title { font-size: 13px; font-weight: 600; flex: 1; }
.icon-btn {
  width: 24px; height: 24px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; color: var(--muted);
  font-size: 14px; line-height: 1; padding: 0; flex-shrink: 0;
}
.icon-btn:hover:not(:disabled) { background: #eef0f3; color: var(--text); }
.icon-btn.remove:hover { background: #fee2e2; color: var(--danger); }
.icon-btn:disabled { opacity: .3; cursor: default; }
.icon-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--brand-ring); }
.step-body { padding: 2px 12px 12px; display: flex; flex-direction: column; gap: 10px; }
.step-card.collapsed .step-body { display: none; }

.add-step-row { display: flex; flex-wrap: wrap; gap: 6px; }
.add-step-btn {
  padding: 6px 11px; border-radius: var(--radius-sm); font-size: 12px; font-weight: 600;
  border: 1px dashed var(--border-strong); background: transparent; color: var(--muted);
  transition: all .15s;
}
.add-step-btn:hover { border-color: var(--brand); border-style: solid; color: var(--brand); background: var(--brand-soft); }

.mode-toggle {
  display: inline-flex; align-items: center; padding: 6px 12px; border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 600; border: 1px solid var(--border-strong);
  background: #fff; color: var(--muted); cursor: pointer; transition: all .15s; user-select: none;
}
.mode-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.mode-toggle:has(input:checked) { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.mode-toggle:has(input:focus-visible) { box-shadow: 0 0 0 3px var(--brand-ring); }

/* Action bar */
.action-bar {
  position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.action-bar.ready { background: var(--ok-soft); border-color: var(--ok-border); }
.action-bar.problem { background: var(--warn-soft); border-color: var(--warn-border); }
.action-text { display: flex; flex-direction: column; gap: 2px; }
.status { font-size: 13px; font-weight: 600; color: var(--muted); }
.action-bar.ready .status { color: var(--ok); }
.action-bar.problem .status { color: var(--warn); }
.sub { font-size: 11.5px; color: var(--muted); }
.progress { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(0,0,0,.05); }
.progress-fill { height: 100%; width: 0; background: var(--brand); transition: width .15s; }

/* Preview */
.preview-card { padding: 16px; }
.preview-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.preview-wrap { border: 1px solid var(--border); border-radius: 10px; overflow: auto; max-height: calc(100vh - 270px); min-height: 320px; }
table { width: 100%; border-collapse: collapse; }
th {
  position: sticky; top: 0; z-index: 1; background: #f9fafb; text-align: left; padding: 10px 12px;
  font-size: 12px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--border);
}
th.col-check { width: 40px; text-align: center; }
td { padding: 8px 12px; border-bottom: 1px solid #f0f1f3; font-size: 13px; vertical-align: middle; word-break: break-all; }
td.col-check { text-align: center; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--row-hover); }
tr.row-dimmed td:not(.col-check) { opacity: .45; }
.mono { font-family: ui-monospace, 'SF Mono', 'Cascadia Mono', Consolas, monospace; font-size: 12px; }
.folder-cell { font-size: 12px; color: var(--muted); }
.new-name { color: var(--brand); font-weight: 500; cursor: text; }
.new-name.unselected { color: var(--muted); cursor: default; }
.new-name.edited::after { content: 'edited'; margin-left: 8px; font-family: system-ui, sans-serif; font-size: 10px; font-weight: 600; color: var(--muted); background: #f3f4f6; border-radius: 99px; padding: 1px 7px; }
tr.row-error td { background: #fff7ed; }
.badge-error { display: inline-block; margin-left: 8px; font-family: system-ui, sans-serif; font-size: 10.5px; font-weight: 700; color: #fff; background: var(--warn); border-radius: 99px; padding: 1px 8px; white-space: nowrap; }
.inline-wrap { display: flex; align-items: center; gap: 2px; }
.inline-edit {
  flex: 1; min-width: 60px; background: #fff; border: none; border-bottom: 1.5px solid var(--brand);
  font: inherit; color: var(--brand); outline: none; padding: 2px 0;
}
.inline-ext { color: var(--muted); }
.empty-state { padding: 56px 20px; text-align: center; color: var(--muted); font-size: 13px; }
.empty-state svg { display: block; margin: 0 auto 12px; opacity: .3; }

/* Drop overlay */
.drop-overlay {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: rgba(248,22,29,.06); border: 3px dashed var(--brand); pointer-events: none;
}
.drop-overlay div { background: #fff; color: var(--brand); font-weight: 700; padding: 14px 22px; border-radius: 12px; box-shadow: var(--shadow); }

/* Dialog */
dialog {
  border: none; border-radius: var(--radius); padding: 24px; width: min(520px, calc(100vw - 32px));
  box-shadow: 0 20px 50px rgba(16,24,40,.25); color: var(--text);
}
dialog::backdrop { background: rgba(17,24,39,.45); }
dialog h2 { font-size: 17px; margin-bottom: 10px; }
#dialogBody { font-size: 13.5px; line-height: 1.55; color: var(--text-2); }
#dialogBody p { margin: 0 0 10px; }
#dialogBody ul { margin: 0 0 10px; padding-left: 20px; }
#dialogBody li { margin-bottom: 6px; }
#dialogBody .file-list { max-height: 180px; overflow: auto; background: #f9fafb; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px 8px 28px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 99px; }

footer { text-align: center; margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
footer .heart { color: var(--brand); }

@media (max-width: 820px) {
  .app-layout { grid-template-columns: 1fr; }
  .preview-wrap { max-height: 420px; min-height: 200px; }
}

/* Web app only */
.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
