:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1b1f24;
  --muted: #69707a;
  --accent: #2459d6;
  --accent-text: #ffffff;
  --error: #b42318;
  --error-bg: #fdecea;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1a1d22;
    --border: #2c3038;
    --text: #e7e9ec;
    --muted: #8d949e;
    --accent: #5b8cff;
    --accent-text: #0b0d10;
    --error: #ff8a80;
    --error-bg: #3a1d1b;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

h1, h2 { margin: 0; }
h1 { font-size: 18px; }
h2 { font-size: 16px; }
a { color: var(--accent); }
.muted { color: var(--muted); }

input, select, button {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
}

button { cursor: pointer; }
button[type="submit"], #refresh-btn {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}
button:disabled { opacity: .6; cursor: progress; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

#scrape-form { display: flex; gap: 8px; flex: 1; max-width: 560px; }
#domain-input { flex: 1; min-width: 0; }

.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: calc(100vh - 58px);
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 58px);
  position: sticky;
  top: 0;
}

.sidebar-head { padding: 16px; display: grid; gap: 8px; border-bottom: 1px solid var(--border); }
.refresh-box { display: flex; gap: 8px; align-items: center; justify-content: space-between; font-size: 12px; }
.refresh-box button { font-size: 12px; padding: 4px 8px; white-space: nowrap; }
#refresh-failed { font-size: 12px; color: var(--error); }
#refresh-failed ul { margin: 4px 0 0; padding-left: 16px; max-height: 120px; overflow-y: auto; word-break: break-all; }
#domain-list { list-style: none; margin: 0; padding: 4px 0; overflow-y: auto; }
#domain-list li button {
  display: flex;
  justify-content: space-between;
  width: 100%;
  border: 0;
  border-radius: 0;
  text-align: left;
  padding: 8px 16px;
  background: none;
}
#domain-list li button:hover { background: var(--bg); }
#domain-list li button.active { background: var(--bg); font-weight: 600; box-shadow: inset 3px 0 var(--accent); }

main { padding: 20px; min-width: 0; }

.status { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; background: var(--surface); border: 1px solid var(--border); }
.status.error { color: var(--error); background: var(--error-bg); border-color: transparent; }

.result-head {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}
.result-head p { margin: 2px 0 0; word-break: break-all; }
.actions { display: flex; gap: 12px; align-items: center; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.card .thumb {
  aspect-ratio: 16 / 9;
  background: var(--bg) center / cover no-repeat;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
}
.card .body { padding: 12px; display: grid; gap: 6px; }
.card h3 { margin: 0; font-size: 14px; line-height: 1.35; }
.card h3 a { color: inherit; text-decoration: none; }
.card h3 a:hover { text-decoration: underline; }
.card .url, .card .img-url { font-size: 12px; color: var(--muted); word-break: break-all; }
.card .img-url a { color: var(--muted); }

#errors { margin-top: 20px; color: var(--error); }
#errors li { word-break: break-all; }

.empty { margin-top: 40px; text-align: center; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: 240px; border-right: 0; border-bottom: 1px solid var(--border); }
  #scrape-form { max-width: none; flex-basis: 100%; }
  .topbar, main { padding-left: 16px; padding-right: 16px; }
}
