:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #d8dde6;
  --text: #17202a;
  --muted: #617080;
  --accent: #0f766e;
  --accent-strong: #115e59;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #ffffff;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.brand {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 8px;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  height: 36px;
  padding: 0 14px;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

button.secondary {
  background: #e7eef2;
  color: var(--text);
}

button.danger {
  background: #b42318;
  color: #fff;
}

button.danger:hover {
  background: #912018;
}

nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.workflow-item {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px;
  display: grid;
  gap: 6px;
}

.workflow-item.active,
.workflow-item:hover {
  background: #e5f3f0;
  border-color: #c7e5df;
}

.workflow-open {
  background: transparent;
  color: var(--text);
  text-align: left;
  justify-content: flex-start;
  border-radius: 6px;
  width: 100%;
  height: auto;
  min-height: 30px;
  padding: 4px 6px;
  overflow-wrap: anywhere;
}

.workflow-open:hover {
  background: transparent;
  color: #0f4f49;
}

main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 24px;
}

.browser-overlay {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 1000;
  background: rgba(9, 14, 20, 0.88);
}

.browser-overlay.open {
  display: block;
}

.browser-overlay-shell {
  position: absolute;
  inset: 0;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.overlay-close {
  align-self: flex-end;
  background: #e7eef2;
  color: #17202a;
}

.browser-overlay iframe {
  flex: 1;
  width: 100%;
  border: 0;
  border-radius: 12px;
  background: #111;
  min-height: 0;
}

.toolbar {
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  padding: 14px 18px;
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.toolbar-title h1 {
  margin: 0;
  font-size: 19px;
}

.toolbar-title .muted {
  margin: 2px 0 0;
}

.toolbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.delay-control {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 6px;
  height: 36px;
}

.delay-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--muted);
  padding-left: 2px;
}

.delay-btn {
  height: 26px;
  width: 26px;
  padding: 0;
  border-radius: 4px;
  font-size: 16px;
  line-height: 1;
}

.delay-value {
  min-width: 46px;
  text-align: center;
  font-weight: 700;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

input {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  font: inherit;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

section.inputs-panel,
section.log-panel,
section.gallery-panel {
  margin: 0 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.inputs-panel h2,
.panel-head h2 {
  margin: 0 0 12px;
  font-size: 15px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.panel-head h2 {
  margin: 0;
}

.variable-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.variable-field {
  display: grid;
  gap: 6px;
}

.variable-field input {
  width: 100%;
}

.variable-field-checkbox {
  display: flex;
  flex-direction: row-reverse;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.variable-field-checkbox input {
  width: auto;
  height: auto;
}

#log {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
  max-height: 320px;
  min-height: 80px;
  padding: 14px;
  overflow: auto;
  white-space: pre-wrap;
  color: #24313d;
  font: 13px/1.45 Consolas, "Courier New", monospace;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}

.gallery-item {
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
  background: #fbfcfd;
}

.gallery-item:hover {
  border-color: var(--accent);
}

.gallery-item img {
  display: block;
  width: 100%;
  height: 120px;
  object-fit: cover;
  background: #eef1f4;
}

.gallery-pdf-icon {
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fdecea;
  color: #b3261e;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.06em;
}

.gallery-caption {
  padding: 8px 10px 0;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gallery-meta {
  padding: 2px 10px 10px;
  font-size: 11px;
  color: var(--muted);
}

.advanced-panel {
  margin: 0 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 16px 16px;
}

.advanced-panel summary {
  cursor: pointer;
  padding: 12px 0;
  font-weight: 700;
  font-size: 14px;
  color: var(--muted);
}

.advanced-body {
  display: grid;
  gap: 14px;
}

.filename-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.filename-row label {
  margin: 0;
}

.filename-row input {
  flex: 1;
  min-width: 220px;
}

.rule-panel {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: minmax(360px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.prompt-box {
  display: grid;
  gap: 6px;
}

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

.rule-panel textarea {
  min-height: 96px;
  max-height: 150px;
  resize: vertical;
}

#editor {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  min-height: 420px;
  padding: 14px;
  overflow: auto;
  font: 13px/1.45 Consolas, "Courier New", monospace;
  width: 100%;
}

@media (max-width: 900px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .rule-panel {
    grid-template-columns: 1fr;
  }

  input {
    width: 100%;
  }
}
