:root {
  --navy: #3d3429;
  --blue: #e8792f;
  --blue-dark: #d4651f;
  --accent: #e8792f;
  --accent-dark: #d4651f;
  --accent-soft: #fff4e6;
  --accent-wash: #faf0e4;
  --ice: #f6f4f1;
  --white: #ffffff;
  --border: #e8e2d9;
  --inner-border: #efe9e0;
  --text: #2f2a24;
  --muted: #8a8176;
  --danger: #dc2626;
  --danger-dark: #b91c1c;
  --header-from: #2f2a24;
  --header-to: #3d3429;
  --chip-bg: rgba(232, 121, 47, 0.18);
  --chip-text: #ffd7b5;
  --chip-border: rgba(232, 121, 47, 0.35);
  --btn-primary-from: #f08a45;
  --subtitle: #c4b8a8;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--ice);
}

.hidden { display: none !important; }

.desktop-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 680px;
}

/* ---- Header ---- */
.header-bar { flex-shrink: 0; }

.header-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
  background: linear-gradient(90deg, var(--header-from), var(--header-to));
}

.brand-mark {
  width: 40px;
  height: 40px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 20px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  border-radius: 10px;
}

.app-title {
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.3px;
}

.app-subtitle {
  font-size: 12px;
  color: var(--subtitle);
  margin-top: 2px;
}

.header-spacer { flex: 1; }

.stat-chip {
  background: var(--chip-bg);
  color: var(--chip-text);
  border: 1px solid var(--chip-border);
  border-radius: 14px;
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.accent-stripe {
  height: 3px;
  background: var(--accent);
}

/* ---- Main split ---- */
.main-split {
  flex: 1;
  display: flex;
  gap: 0;
  padding: 14px;
  min-height: 0;
  overflow: hidden;
  --right-panel-width: 560px;
}

.left-panel {
  flex: 1 1 0;
  min-width: 360px;
  display: flex;
  flex-direction: column;
}

.split-handle {
  flex: 0 0 6px;
  margin: 0 4px;
  cursor: col-resize;
  border-radius: 4px;
  position: relative;
  align-self: stretch;
  touch-action: none;
}

.split-handle:hover,
body.split-dragging .split-handle {
  background: var(--accent-wash);
}

.split-handle::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 4px;
  height: 48px;
  border-radius: 2px;
  background: #c4b8a8;
  opacity: 0.55;
}

.split-handle:hover::after,
body.split-dragging .split-handle::after {
  opacity: 1;
  background: var(--accent);
}

.right-panel {
  flex: 0 0 var(--right-panel-width);
  width: var(--right-panel-width);
  min-width: 280px;
  display: flex;
  flex-direction: column;
}

body.split-dragging {
  cursor: col-resize;
  user-select: none;
}

body.split-dragging iframe {
  pointer-events: none;
}

.panel-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(47, 42, 36, 0.04);
}

/* ---- Tabs ---- */
.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  background: var(--accent-wash);
  flex-shrink: 0;
}

.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  margin-bottom: -1px;
}

.tab-btn:hover { color: var(--text); background: #fff; }

.tab-btn.active {
  color: var(--accent-dark);
  border-bottom-color: var(--accent);
  background: var(--white);
}

.tab-panel {
  display: none;
  flex: 1;
  flex-direction: column;
  padding: 12px 16px 16px;
  min-height: 0;
  overflow: auto;
}

.tab-panel.active { display: flex; }

.right-content.tab-panel { padding: 12px; }

/* ---- Groups ---- */
.group-box {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px 14px;
  margin-bottom: 12px;
  background: #fff;
}

.group-box.flex-grow {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.group-title {
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 12px;
  font-size: 13px;
}

.section-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.inner-panel {
  background: var(--accent-wash);
  border: 1px solid var(--inner-border);
  border-radius: 10px;
  padding: 10px;
  margin: 10px 0;
}

.config-pre {
  display: none;
}

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

/* ---- Fields ---- */
.field-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.field-row.compact { margin-bottom: 8px; }

.api-row .inbox-connect-btn {
  flex: 1;
  text-align: center;
  padding: 8px 12px;
}

.inbox-api-status {
  margin: 0 0 10px;
  white-space: pre-wrap;
  line-height: 1.45;
}

.inbox-multi {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  margin-bottom: 8px;
  resize: vertical;
  min-height: 72px;
  background: #fff;
}

.threshold-row select,
.threshold-row .threshold-count {
  flex: 0 0 auto;
  width: 80px;
}

.threshold-row .threshold-hint {
  flex: 1;
  margin: 0;
}

.field-label {
  font-weight: 600;
  color: #5c5349;
  min-width: 90px;
  flex-shrink: 0;
}

.field-row input[type="text"],
.field-row input[type="email"],
.field-row input[type="number"],
.field-row input[type="search"],
.field-row select,
.group-box > input,
.group-box > textarea,
.tools-panel input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 10px;
  font: inherit;
  background: #fff;
}

.field-row input:focus,
.field-row select:focus,
.inbox-multi:focus,
.group-box > input:focus,
.group-box > textarea:focus,
.tools-panel input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(232, 121, 47, 0.15);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
  font-size: 13px;
  cursor: pointer;
}

.check-row input[type="checkbox"],
.radio-row input[type="radio"] {
  accent-color: var(--accent);
}

.radio-row {
  display: flex;
  gap: 16px;
  margin: 8px 0 12px;
  font-size: 13px;
}

/* ---- Buttons ---- */
.btn {
  border: none;
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.full { width: 100%; }

.btn.primary {
  background: linear-gradient(180deg, var(--btn-primary-from), var(--accent));
  border: 1px solid var(--accent-dark);
  color: #fff;
  font-weight: 700;
}

.btn.primary:hover { background: var(--accent-dark); }

.btn.danger {
  background: linear-gradient(180deg, #ef4444, var(--danger));
  border: 1px solid var(--danger-dark);
  color: #fff;
  font-weight: 700;
  padding: 10px 20px;
}

.btn.danger:hover { background: var(--danger-dark); }

.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: #5c5349;
}

.btn.ghost:hover { background: var(--accent-wash); border-color: #e0d5c8; }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-row, .action-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.action-bar {
  background: var(--accent-wash);
  border: 1px solid var(--inner-border);
  border-radius: 12px;
  padding: 12px;
  margin-top: 8px;
}

.flex-spacer { flex: 1; }
.file-btn { cursor: pointer; display: inline-flex; align-items: center; }

/* ---- Compose ---- */
.content-tab-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 10px 0 6px;
  border-bottom: 1px solid var(--border);
}

.content-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  margin-bottom: -1px;
}

.content-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.content-tab-actions {
  margin-left: auto;
  display: flex;
  gap: 4px;
}

.code-area {
  flex: 1;
  min-height: 200px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 12px;
  line-height: 1.5;
  resize: none;
  background: #fff;
}

.send-mode-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 4px;
}

.send-mode {
  background: var(--accent-wash);
  border: 1px solid var(--border);
  border-radius: 10px 10px 0 0;
  padding: 6px 16px;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
}

.send-mode.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ---- Scraper ---- */
.scraper-intro { margin-top: 0; }

.scraper-urls {
  width: 100%;
  min-height: 72px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  font: inherit;
  resize: vertical;
  margin-bottom: 8px;
}

.progress-wrap {
  height: 8px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
  margin: 8px 0;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.25s;
}

.scraper-split {
  display: flex;
  gap: 10px;
  flex: 1;
  min-height: 200px;
  margin-top: 8px;
}

.scraper-sites {
  flex: 0 0 240px;
  min-width: 200px;
  display: flex;
  flex-direction: column;
}

.scraper-result {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.site-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--inner-border);
  border-radius: 6px;
  overflow: auto;
  flex: 1;
}

.site-list li {
  padding: 8px 10px;
  border-bottom: 1px solid #f1f5f9;
  font-family: monospace;
  font-size: 11px;
  cursor: pointer;
}

.site-list li:hover { background: var(--accent-wash); }
.site-list li.active { background: var(--accent-soft); color: var(--accent-dark); font-weight: 600; }

.result-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 6px;
}

.result-tab {
  background: var(--accent-wash);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
}

.result-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.result-text {
  flex: 1;
  margin: 0;
  padding: 10px;
  border: 1px solid var(--inner-border);
  border-radius: 6px;
  background: var(--accent-wash);
  font-family: Consolas, monospace;
  font-size: 11px;
  white-space: pre-wrap;
  overflow: auto;
  min-height: 120px;
}

/* ---- Right panel users ---- */
.tools-panel { margin-bottom: 8px; }

.tools-panel input.full-width,
.tools-panel #userSearch {
  display: block;
  width: 100%;
  flex: none;
  margin-top: 4px;
}

.tools-header {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.tools-header .hint { flex: 1; min-width: 120px; margin: 0; }

.users-list {
  flex: 1;
  overflow: auto;
  border: 1px solid var(--inner-border);
  border-radius: 10px;
  min-height: 200px;
  margin-bottom: 10px;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--inner-border);
  cursor: pointer;
}

.user-row:hover { background: var(--accent-wash); }

.user-row label {
  font-family: Consolas, monospace;
  font-size: 12px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mono-path {
  font-family: Consolas, monospace;
  font-size: 11px;
  word-break: break-all;
  margin: 4px 0 6px;
}

.negative-files-list {
  flex: 1;
  overflow: auto;
  border: 1px solid var(--inner-border);
  border-radius: 10px;
  min-height: 180px;
  margin-bottom: 10px;
  background: #fff;
}

.negative-file-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--inner-border);
}

.negative-file-row:hover { background: var(--accent-wash); }

.negative-file-row.marked {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
}

.negative-file-row .neg-name {
  flex: 1;
  min-width: 0;
  font-family: Consolas, monospace;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.negative-file-row .neg-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.negative-preview {
  max-height: 160px;
  overflow: auto;
  border: 1px solid var(--inner-border);
  border-radius: 10px;
  padding: 10px;
  background: var(--accent-wash);
  white-space: pre-wrap;
  font-size: 11px;
  margin: 0;
}

.rand-panel {
  background: var(--accent-wash);
  border: 1px solid var(--inner-border);
  border-radius: 8px;
  padding: 10px;
  flex-shrink: 0;
}

.results-wrap {
  flex: 1;
  overflow: auto;
  margin-top: 12px;
  border: 1px solid var(--inner-border);
  border-radius: 6px;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.results-table th,
.results-table td {
  padding: 6px 8px;
  border-bottom: 1px solid #f1f5f9;
  text-align: left;
}

.results-table th {
  background: var(--accent-wash);
  font-weight: 700;
  color: var(--navy);
}

/* ---- Dialogs ---- */
dialog:not([open]) {
  display: none !important;
}

dialog {
  border: none;
  border-radius: 10px;
  padding: 16px 20px;
  max-width: 720px;
  width: 92vw;
  box-shadow: 0 20px 50px rgba(0,0,0,0.2);
}

dialog::backdrop { background: rgba(15,39,68,0.45); }

dialog.log-dialog[open] {
  display: flex;
  flex-direction: column;
  max-width: 800px;
  height: 70vh;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.dialog-header-actions {
  display: flex;
  gap: 8px;
}

.log-view {
  flex: 1;
  background: #0b1220;
  color: #e2e8f0;
  border-radius: 6px;
  padding: 12px;
  overflow: auto;
  font-family: Consolas, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  margin-bottom: 12px;
  min-height: 300px;
}

.tags-list {
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 10px 0;
}

.tag-group { padding: 8px 12px; border-bottom: 1px solid #f1f5f9; }
.tag-group h4 { margin: 0 0 6px; font-size: 11px; color: var(--muted); text-transform: uppercase; }

.tag-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 5px 4px;
  cursor: pointer;
  font-family: monospace;
  font-size: 12px;
}

.tag-item:hover, .tag-item.selected { background: var(--accent-soft); }

/* ---- Theme palettes ---- */
.theme-hint {
  margin: 0 0 12px;
  font-size: 12px;
}

.theme-groups {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.theme-group-label {
  grid-column: 1 / -1;
  margin: 6px 0 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.theme-group-label:first-child {
  margin-top: 0;
}

.theme-grid {
  display: contents;
}

.theme-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--white);
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.theme-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(47, 42, 36, 0.08);
}

.theme-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.theme-swatches {
  display: flex;
  height: 36px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--inner-border);
}

.theme-swatches span {
  flex: 1;
  min-width: 0;
}

.theme-card-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  padding: 0 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 960px) {
  .main-split { flex-direction: column; overflow: auto; }
  .split-handle { display: none; }
  .right-panel {
    flex: none;
    width: auto;
    min-width: 0;
    min-height: 400px;
  }
  .theme-groups { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

