:root {
  --bg:       #0d1117;
  --surface:  #161b22;
  --surface2: #21262d;
  --border:   #30363d;
  --text:     #e6edf3;
  --muted:    #7d8590;
  --blue:     #2f81f7;
  --green:    #3fb950;
  --yellow:   #d29922;
  --red:      #f85149;
  --r:        6px;
  --gap:      16px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Header ─────────────────────────────────── */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}
.logo {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  transition: background .3s;
  flex-shrink: 0;
}
.dot.on  { background: var(--green); }
.dot.err { background: var(--red);   }

.auth-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
#conn-label { font-size: 12px; color: var(--muted); }

/* ── Main ───────────────────────────────────── */
.main { padding: 20px 24px; max-width: 1400px; margin: 0 auto; }

/* ── Toolbar ────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 10px 14px;
}
.toolbar-label { color: var(--muted); font-size: 12px; white-space: nowrap; }
#project-select { flex: 1; min-width: 200px; max-width: 420px; }
.or-sep { color: var(--muted); font-size: 12px; }
#url-input { flex: 1; min-width: 200px; max-width: 360px; }
.host-chip {
  font-family: monospace;
  font-size: 11px;
  padding: 2px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--muted);
}

/* ── Grid ───────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: var(--gap);
  align-items: start;
}
@media (max-width: 880px) { .grid { grid-template-columns: 1fr; } }
.col-left, .col-right { display: flex; flex-direction: column; gap: var(--gap); }

/* ── Cards ──────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.card-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
}

/* ── Inputs / Selects / Textarea ────────────── */
input, select, textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--text);
  padding: 6px 10px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color .2s;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); }
input[type="password"] { letter-spacing: 2px; }
textarea { resize: vertical; min-height: 70px; width: 100%; }

/* ── Buttons ────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--r);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: opacity .15s, transform .1s;
  white-space: nowrap;
  font-family: inherit;
  text-decoration: none;
}
.btn:hover   { opacity: .82; }
.btn:active  { transform: scale(.97); }
.btn:disabled { opacity: .38; cursor: not-allowed; transform: none; }

.btn-primary   { background: var(--blue);    color: #fff; }
.btn-success   { background: var(--green);   color: #0d1117; }
.btn-warning   { background: #2d2a18; color: var(--yellow); border: 1px solid #5c4b0f; }
.btn-info      { background: #1a2533; color: var(--blue);   border: 1px solid #1e4080; }
.btn-danger    { background: #2d1a1a; color: var(--red);    border: 1px solid #6e2222; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost     { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-sm        { padding: 4px 10px; font-size: 12px; }
.btn-full      { width: 100%; justify-content: center; }

/* ── Action group ───────────────────────────── */
.agroup { display: flex; flex-direction: column; gap: 8px; }
.sep { height: 1px; background: var(--border); margin: 4px 0; }

/* ── Badges ─────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.b-green  { background: rgba(63,185,80,.14);  color: var(--green);  }
.b-yellow { background: rgba(210,153,34,.14); color: var(--yellow); }
.b-red    { background: rgba(248,81,73,.14);  color: var(--red);    }
.b-blue   { background: rgba(47,129,247,.14); color: var(--blue);   }
.b-gray   { background: rgba(125,133,144,.14);color: var(--muted);  }

/* ── Sheet fields ───────────────────────────── */
.field-grid {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 6px 10px;
  align-items: center;
}
.field-label { color: var(--muted); font-size: 12px; }
.field-val   { font-size: 13px; word-break: break-all; }
.field-val a { color: var(--blue); text-decoration: none; }
.field-val a:hover { text-decoration: underline; }
.field-divider {
  grid-column: 1 / -1;
  height: 1px;
  background: var(--border);
  margin: 6px 0;
}
.field-section-label {
  grid-column: 1 / -1;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  margin-bottom: -2px;
}
.field-grid input { width: 100%; }

/* ── Jobs ───────────────────────────────────── */
.job-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 0;
  border-bottom: 1px solid var(--surface2);
  font-size: 12px;
  gap: 8px;
}
.job-row:last-child { border-bottom: none; }
.job-host {
  font-family: monospace;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.job-time { color: var(--muted); font-size: 11px; white-space: nowrap; }

/* ── Empty state ────────────────────────────── */
.empty { color: var(--muted); font-size: 12px; font-style: italic; text-align: center; padding: 12px 0; }

/* ── Screenshot ─────────────────────────────── */
.shot-placeholder {
  height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
  background: var(--surface2);
  border-radius: var(--r);
}
.shot-img { width: 100%; border-radius: var(--r); display: block; border: 1px solid var(--border); }

/* ── Payment result ─────────────────────────── */
.result-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 8px 10px;
  font-family: monospace;
  font-size: 12px;
  color: var(--blue);
  word-break: break-all;
  display: none;
}
.result-box.show { display: flex; align-items: flex-start; gap: 6px; }
.result-url { flex: 1; }

/* ── Run params ─────────────────────────────── */
.params-details { margin-top: 4px; }
.params-summary {
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  padding: 4px 2px;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.params-summary::-webkit-details-marker { display: none; }
.params-summary::before { content: '▶'; font-size: 9px; transition: transform .2s; }
details[open] .params-summary::before { transform: rotate(90deg); }
.params-content { margin-top: 10px; display: flex; flex-direction: column; gap: 5px; }
.param-section-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  margin-top: 8px;
  margin-bottom: 2px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}
.param-section-label:first-child { border-top: none; padding-top: 0; margin-top: 0; }
.param-row {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 6px;
  align-items: center;
}
.param-row label { font-size: 11px; color: var(--muted); text-align: right; }
.param-row input, .param-row select { width: 100%; font-size: 12px; padding: 4px 8px; }

/* ── Log ────────────────────────────────────── */
.log-panel { margin-top: var(--gap); }
.log-output {
  background: #010409;
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 10px 12px;
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 12px;
  height: 190px;
  overflow-y: auto;
}
.log-entry { line-height: 1.7; }
.log-req  { color: #555; }
.log-ok   { color: var(--green); }
.log-err  { color: var(--red); }
.log-info { color: var(--blue); }

/* ── Inline row ─────────────────────────────── */
.row2 { display: flex; gap: 8px; align-items: center; }
.row2 input { flex: 1; }
.row2 input.w-price { width: 110px; flex: none; }

/* ── Toast ──────────────────────────────────── */
#toasts {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}
.toast {
  padding: 10px 16px;
  border-radius: var(--r);
  font-size: 13px;
  font-weight: 500;
  max-width: 340px;
  animation: toastIn .22s ease;
}
.t-success { background: var(--green); color: #0d1117; }
.t-error   { background: var(--red);   color: #fff;    }
.t-info    { background: var(--blue);  color: #fff;    }
@keyframes toastIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Email Composer Modal ───────────────────── */
.email-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.email-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 100%;
  max-width: 1100px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.email-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}

.email-modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  transition: color .15s;
}
.email-modal-close:hover { color: var(--text); }

.email-modal-body {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 0;
  flex: 1;
  overflow: hidden;
}

.email-modal-left {
  border-right: 1px solid var(--border);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.email-modal-right {
  padding: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Cache Picker Modal ──────────────────────── */
.cache-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.cache-modal-body {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cache-modal-url {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
  word-break: break-all;
}

.cache-file-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cache-file-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.cache-file-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  text-align: left;
}
.cache-file-btn:hover {
  background: var(--surface-hover, rgba(255,255,255,.06));
  border-color: var(--warning, #e67e22);
}
.cache-file-btn--all {
  color: var(--danger, #e74c3c);
  border-color: var(--danger, #e74c3c);
  font-weight: 600;
}
.cache-file-btn--all:hover {
  background: rgba(231,76,60,.1);
  border-color: var(--danger, #e74c3c);
}
.cache-file-icon { font-size: 14px; flex-shrink: 0; }
.cache-file-name { font-family: monospace; font-size: 12px; }

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

.email-config-grid {
  display: grid;
  grid-template-columns: 90px 1fr;
  align-items: center;
  gap: 8px 10px;
}
.email-config-grid label {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.email-config-grid input,
.email-config-grid select {
  width: 100%;
}

.email-var-row {
  display: grid;
  grid-template-columns: 130px 1fr;
  align-items: center;
  gap: 6px 10px;
  margin-bottom: 6px;
}
.email-var-label {
  font-size: 12px;
  color: var(--muted);
  font-family: monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.email-var-input { width: 100%; }

.email-vars-empty {
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
}

#email-preview {
  flex: 1;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: #fff;
}
