:root {
  --brand: #d44a44;
  --brand-soft: #f8e3e2;
  --bg: #fafafa;
  --fg: #222;
  --muted: #777;
  --border: #e3e3e3;
  --warn: #c98c00;
  --warn-bg: #fff8e6;
  --error: #c0392b;
  --success: #2c8a4a;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--fg);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
}

#app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px solid var(--brand);
  padding-bottom: 12px;
  margin-bottom: 24px;
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

.badge {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
}

main > .card,
main > .action-bar,
main > .banner,
main > .preview-pane {
  margin-bottom: 16px;
}

/* ---------- card ---------- */
.card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}

.card h2 {
  margin: 0 0 12px;
  font-size: 16px;
}

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

/* ---------- form ---------- */
.form-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.form-row label {
  flex: 0 0 80px;
  padding-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.form-row input[type="text"],
.form-row input[type="password"],
.form-row textarea,
#src-url,
#src-file {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: white;
}

.form-row textarea {
  resize: vertical;
  font-family: inherit;
}

.form-row .base-url-fields {
  flex: 1;
  min-width: 0;  /* let flex item shrink below its content size — needed
                    so the input below fills the available width instead
                    of staying at its default browser-determined width */
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-row .base-url-fields input[type="text"] {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
}

.form-row input:focus,
.form-row textarea:focus,
#src-url:focus,
#src-file:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 2px var(--brand-soft);
}

.form-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 8px;
}

.input-eye {
  flex: 1;
  display: flex;
  gap: 6px;
}

.input-eye input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
}

.eye {
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: white;
  cursor: pointer;
}

.feedback { font-size: 13px; }
.feedback.error { color: var(--error); }
.feedback.success { color: var(--success); }

/* ---------- buttons ---------- */
button.primary,
button.secondary {
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  border: 1px solid transparent;
}

button.primary {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
}

button.primary:hover { background: #b53e39; }

button.secondary {
  background: white;
  color: var(--brand);
  border-color: var(--brand);
}

button.primary:disabled,
button.secondary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- source radios ---------- */
.source-radios {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
}

.radio {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.source-card input[type="text"],
.source-card input[type="file"] {
  display: block;
  width: 100%;
  margin-top: 8px;
}

/* ---------- metadata details ---------- */
.metadata-card summary {
  cursor: pointer;
  user-select: none;
  list-style: none;
}

.metadata-card summary::-webkit-details-marker { display: none; }
.metadata-card summary::before {
  content: '▸ ';
  color: var(--muted);
}

.metadata-card[open] summary::before {
  content: '▾ ';
}

.thumb-preview {
  margin-top: 8px;
  max-width: 160px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ---------- credentials ok state ---------- */
.credentials-ok {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--success);
  background: #f0f8f3;
  border-color: #c9e7d3;
}

.credentials-ok .link-btn {
  background: none;
  border: none;
  color: var(--brand);
  cursor: pointer;
  text-decoration: underline;
  padding: 0 4px;
  font-size: 13px;
}

.ok-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--success);
}

/* ---------- action bar ---------- */
.action-bar {
  display: flex;
  gap: 12px;
  padding: 16px 0;
}

/* ---------- banners ---------- */
.banner {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
}

.banner.error {
  background: #fdecea;
  color: var(--error);
  border: 1px solid #f5c6c2;
}

.banner.success {
  background: #f0f8f3;
  color: var(--success);
  border: 1px solid #c9e7d3;
}

.banner a { color: inherit; text-decoration: underline; }

.synced-preview {
  margin: 12px 0 0;
  border: 1px solid #e0d6c4;
  border-radius: 6px;
  padding: 8px 12px;
  background: #faf6ef;
}
.synced-preview summary {
  cursor: pointer;
  font-size: 13px;
  color: #6a4a30;
}
.synced-preview iframe {
  display: block;
  width: 100%;
  height: 480px;
  margin-top: 10px;
  border: 1px solid #d6c8b0;
  border-radius: 4px;
  background: #fff;
}
.muted { color: #8a7a64; font-size: 13px; margin: 8px 0 0; }

/* ---------- preview pane ---------- */
.preview-pane h2 {
  margin: 0 0 12px;
  font-size: 16px;
}

.preview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

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

.preview-cell {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.preview-cell iframe {
  width: 100%;
  height: 70vh;
  border: 1px dashed var(--border);
  display: block;
}

.preview-meta { padding: 16px; }

.meta-block > div {
  margin-bottom: 6px;
  word-break: break-all;
}

.warnings {
  margin: 12px 0;
}

.warning-chip {
  background: var(--warn-bg);
  color: var(--warn);
  border: 1px solid #f3e2a8;
  border-radius: var(--radius);
  padding: 4px 8px;
  margin-bottom: 6px;
  font-size: 13px;
}

.preview-meta details {
  margin-top: 12px;
  border-top: 1px dashed var(--border);
  padding-top: 8px;
}

.preview-meta pre {
  max-height: 300px;
  overflow: auto;
  background: #f5f5f5;
  padding: 8px;
  border-radius: var(--radius);
  font-size: 12px;
}

/* ---------- preview tabs ---------- */
.preview-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.preview-tabs .tab {
  padding: 6px 14px;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: -1px;
}

.preview-tabs .tab:hover { color: var(--fg); }

.preview-tabs .tab.active {
  background: white;
  border-color: var(--border);
  color: var(--brand);
  font-weight: 600;
}

.preview-tabs .tab-spacer { flex: 1; }

.preview-tabs .link-btn {
  background: none;
  border: none;
  color: var(--brand);
  cursor: pointer;
  font-size: 13px;
  text-decoration: underline;
  padding: 4px 8px;
}

/* ---------- source editor ---------- */
.source-editor {
  width: 100%;
  height: 70vh;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.5;
  background: #fbfbfb;
  resize: vertical;
  white-space: pre;
  overflow: auto;
}

.source-editor:focus {
  outline: none;
  border-color: var(--brand);
  background: white;
  box-shadow: 0 0 0 2px var(--brand-soft);
}