:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #14181d;
  --muted: #68707a;
  --border: #e3e6ea;
  --accent: #0e6fff;
  --accent-press: #0a58cc;
  --danger: #e5484d;
  --success: #2e7d32;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16, 20, 24, 0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101418;
    --surface: #1a2027;
    --text: #eceff2;
    --muted: #8b95a1;
    --border: #2a323c;
    --accent: #3b8bff;
    --accent-press: #2a6fd6;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

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

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); }

.view {
  min-height: 100dvh;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px calc(24px + var(--safe-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: var(--bg);
}

.topbar-title { font-size: 18px; font-weight: 700; }

.content {
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- upload ---------- */
#upload-view {
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
  padding-top: 6vh;
}

#drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 72px 24px;
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}

#drop-zone:hover, #drop-zone.dragging { border-color: var(--accent); }

/* ---------- editor ---------- */
.editor-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.section h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
}

.items {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item-row {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.item-label { font-weight: 600; overflow-wrap: anywhere; }

.badge {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
  flex-shrink: 0;
}

textarea, select, input[type="number"] {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}

textarea { resize: vertical; min-height: 44px; }

.slider-holder {
  display: flex;
  align-items: center;
  gap: 12px;
}

.slider-holder input[type="range"] { flex: 1; accent-color: var(--accent); }
.slider-holder input[type="number"] { width: 90px; flex-shrink: 0; }

.check-label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-label input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.replace-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.replace-status:empty { display: none; }
.replace-status { color: var(--success); }
.replace-status[data-warn] { color: var(--danger); }

/* ---------- batch mode ---------- */
.mode-toggle {
  display: inline-flex;
  align-self: flex-start;
  background: var(--surface);
  border-radius: 12px;
  padding: 3px;
  box-shadow: var(--shadow);
  gap: 2px;
}

.mode-btn {
  font: inherit;
  border: none;
  background: none;
  color: var(--muted);
  padding: 8px 16px;
  border-radius: 10px;
  cursor: pointer;
}

.mode-btn.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.batch-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.small-btn { padding: 8px 14px; font-size: 14px; }

.batch-table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 60vh;
  overflow-y: auto;
}

#batch-table {
  border-collapse: collapse;
  width: 100%;
}

#batch-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
  text-align: left;
  font-size: 13px;
  padding: 10px 8px 8px;
  border-bottom: 1px solid var(--border);
  min-width: 140px;
  vertical-align: top;
}

#batch-table th:last-child { min-width: 0; }

.col-hint { font-size: 11px; font-weight: 400; margin-top: 2px; }

#batch-table td {
  border-bottom: 1px solid var(--border);
  padding: 0;
}

#batch-table td.row-del { text-align: center; padding: 0 8px; }

#batch-table td input {
  width: 100%;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: none;
  border: none;
  border-radius: 0;
  padding: 10px 8px;
  outline-offset: -2px;
}

#batch-table td input:focus { outline: 2px solid var(--accent); }
#batch-table td input.invalid { outline: 2px solid var(--danger); background: rgba(229, 72, 77, 0.08); }

/* ---------- actions ---------- */
.actions {
  display: flex;
  gap: 12px;
  position: sticky;
  bottom: 0;
  padding: 12px 0 calc(4px + var(--safe-bottom));
  background: var(--bg);
}

.primary-btn, .secondary-btn, .link-btn {
  font: inherit;
  border-radius: 12px;
  cursor: pointer;
  border: none;
}

.primary-btn {
  flex: 1;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  padding: 14px;
}

.primary-btn:hover:not(:disabled), .primary-btn:active { background: var(--accent-press); }
.primary-btn:disabled { opacity: 0.5; cursor: default; }
.link-btn:hover { text-decoration: underline; }
.secondary-btn:hover { border: 1px solid var(--border); }

.secondary-btn {
  background: var(--surface);
  color: var(--text);
  padding: 14px 20px;
  box-shadow: var(--shadow);
}

.link-btn {
  background: none;
  color: var(--accent);
  padding: 4px 0;
  flex-shrink: 0;
}

/* desktop: two-column editor workspace */
@media (min-width: 960px) {
  #editor-view {
    display: grid;
    grid-template-columns: 1fr 1fr;
    /* the text/media row pair is sized so the tall published column stretches
       row "media", keeping media right below text instead of pushed down */
    grid-template-rows: auto auto auto 1fr auto auto;
    grid-template-areas:
      "head head"
      "toggle toggle"
      "text published"
      "media published"
      "batch batch"
      "actions actions";
    align-items: start;
    column-gap: 24px;
    row-gap: 20px;
  }

  .editor-head { grid-area: head; }
  .mode-toggle { grid-area: toggle; justify-self: start; }
  #text-section { grid-area: text; }
  #media-section { grid-area: media; }
  #published-section { grid-area: published; }
  #batch-section { grid-area: batch; }
  .actions { grid-area: actions; }

  .actions {
    justify-content: flex-end;
    position: static;
    padding: 8px 0 0;
  }

  .primary-btn { flex: 0 0 auto; min-width: 240px; }

  .topbar { padding-top: 24px; }
  .topbar-title { font-size: 22px; }
}
