:root {
  --bg: #0c0c0f;
  --panel: #14141a;
  --panel-2: #1b1b23;
  --border: #272731;
  --text: #ececf1;
  --muted: #8b8b99;
  --accent: #ea580c;
  --accent-2: #fb923c;
  --danger: #ef4444;
  --ok: #22c55e;
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }

/* ---------- controls ---------- */
input, select, textarea {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 11px; font: inherit; outline: none; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(234 88 12 / 0.2); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 500;
  cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: #24242e; text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #f26a1f; }
.btn.danger { color: #fca5a5; border-color: #4b1f22; background: #1f1214; }
.btn.danger:hover { background: #2c1518; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stack > * + * { margin-top: 16px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; background: var(--panel-2);
  border: 1px solid var(--border); color: var(--muted); font-size: 12px; cursor: pointer; user-select: none;
}
.chip:hover { color: var(--text); }
.chip.active { background: rgb(234 88 12 / .15); border-color: var(--accent); color: var(--accent-2); }
.chip .n { opacity: .6; }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); }
.badge.ok { color: #86efac; border-color: #1f4d30; background: #0f2418; }
.badge.off { color: #fca5a5; border-color: #4b1f22; background: #1f1214; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(circle at 50% 0%, rgb(234 88 12 / .18), transparent 60%); }
.login-card { width: 340px; display: flex; flex-direction: column; gap: 12px; background: var(--panel); border: 1px solid var(--border); padding: 28px; border-radius: 16px; }
.login-card p { margin: 0; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; border-right: 1px solid var(--border); padding: 18px 12px; display: flex; flex-direction: column; gap: 22px; background: #0f0f13; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: var(--text); padding: 0 8px; }
.brand:hover { text-decoration: none; }
.brand.big { font-size: 22px; padding: 0; }
.logo { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 700; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--muted); font-weight: 500; }
nav a i { font-style: normal; width: 22px; text-align: center; font-size: 13px; }
nav a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
nav a.active { background: rgb(234 88 12 / .12); color: var(--accent-2); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding: 0 8px; }
.view { padding: 28px 32px 60px; max-width: 1400px; width: 100%; }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.view-head p { margin: 4px 0 0; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type=search] { flex: 1; min-width: 220px; }
.tagbar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }

/* ---------- gif grid ---------- */
.grid { columns: 5 200px; column-gap: 12px; }
.card {
  position: relative; break-inside: avoid; margin-bottom: 12px; border-radius: 10px; overflow: hidden; background: var(--panel-2);
  border: 1px solid var(--border); cursor: pointer; display: block;
}
.card img { display: block; width: 100%; height: auto; background: repeating-conic-gradient(#1c1c24 0 25%, #16161d 0 50%) 0 0 / 16px 16px; min-height: 60px; }
.card .overlay {
  position: absolute; inset: auto 0 0 0; padding: 22px 10px 8px; background: linear-gradient(transparent, rgb(0 0 0 / .85));
  font-size: 12px; opacity: 0; transition: opacity .15s; display: flex; justify-content: space-between; gap: 8px; align-items: flex-end;
}
.card:hover .overlay, .card.selected .overlay { opacity: 1; }
.card .overlay .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.card .check {
  position: absolute; top: 8px; left: 8px; width: 22px; height: 22px; border-radius: 6px; background: rgb(0 0 0 / .55);
  border: 1.5px solid rgb(255 255 255 / .6); display: grid; place-items: center; font-size: 13px; color: #fff;
}
.card.selected .check { background: var(--accent); border-color: var(--accent); }
.card .corner { position: absolute; top: 8px; right: 8px; }
.card.saved { cursor: default; }
.card.saved img { opacity: .55; }
.empty { text-align: center; padding: 70px 20px; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); }
.empty h2 { color: var(--text); }
.center { display: flex; justify-content: center; margin-top: 18px; }
.provider-tabs { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.provider-tabs .btn.active { border-color: var(--accent); color: var(--accent-2); background: rgb(234 88 12 / .1); }
.sticky-bar {
  position: sticky; bottom: 16px; margin-top: 16px; display: flex; gap: 12px; align-items: center; justify-content: space-between;
  background: #1d1d26ee; backdrop-filter: blur(8px); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px;
}

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 24px; }
.modal-backdrop { position: absolute; inset: 0; background: rgb(0 0 0 / .7); }
.modal-body { position: relative; width: min(1080px, 100%); max-height: calc(100vh - 48px); overflow: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; }
.detail { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); }
.detail-media { background: repeating-conic-gradient(#1c1c24 0 25%, #16161d 0 50%) 0 0 / 20px 20px; display: grid; place-items: center; padding: 20px; min-height: 320px; border-right: 1px solid var(--border); }
.detail-media img { max-width: 100%; max-height: 70vh; border-radius: 6px; }
.detail-info { padding: 22px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.close-x { position: absolute; top: 10px; right: 12px; z-index: 2; }
.meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.meta div { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.meta b { display: block; font-size: 13px; }
.meta span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.urls { display: flex; flex-direction: column; gap: 6px; }
.url-row { display: grid; grid-template-columns: 74px 1fr auto auto; gap: 6px; align-items: center; }
.url-row label { font-size: 12px; color: var(--muted); }
.url-row input { font-family: var(--mono); font-size: 12px; padding: 6px 9px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.tabs button { background: none; border: 0; color: var(--muted); padding: 6px 10px; cursor: pointer; font: inherit; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--text); border-color: var(--accent); }
pre.code { margin: 0; background: #0b0b0e; border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow: auto; white-space: pre; max-height: 360px; }
.code-wrap { position: relative; }
.code-wrap .btn { position: absolute; top: 6px; right: 6px; }

/* ---------- add page ---------- */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 44px 20px; text-align: center; color: var(--muted);
  cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone.drag, .dropzone:hover { border-color: var(--accent); background: rgb(234 88 12 / .06); color: var(--text); }
.dropzone .big { font-size: 34px; display: block; margin-bottom: 6px; }
.form { display: flex; flex-direction: column; gap: 10px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); }
.results-list { display: flex; flex-direction: column; gap: 8px; }
.result-item { display: flex; gap: 12px; align-items: center; padding: 8px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; }
.result-item img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; background: #000; }
.result-item .grow { min-width: 0; }
.result-item .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- tables & stats ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tr:last-child td { border-bottom: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stat span { color: var(--muted); font-size: 12px; }
.stat b { display: block; font-size: 24px; margin-top: 4px; letter-spacing: -0.02em; }
.chart { display: flex; align-items: flex-end; gap: 6px; height: 180px; padding-top: 10px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.chart .bars { display: flex; gap: 2px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.chart .bar { width: 45%; max-width: 16px; border-radius: 3px 3px 0 0; background: var(--accent); min-height: 2px; }
.chart .bar.api { background: #6366f1; }
.chart .lbl { font-size: 10px; color: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.top-list { display: flex; flex-direction: column; gap: 8px; }
.callout { border: 1px solid #5a2a0e; background: #1f130b; border-radius: 10px; padding: 14px; }
.callout.info { border-color: #2a2f5a; background: #11131f; }
.endpoint { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.endpoint header { display: flex; gap: 10px; align-items: center; padding: 10px 14px; background: var(--panel-2); }
.endpoint header code { font-size: 13px; }
.endpoint .body { padding: 12px 14px; }
.method { font-family: var(--mono); font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 5px; background: #0f2418; color: #86efac; }
.params td, .params th { padding: 6px 10px; font-size: 12.5px; }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #1f1f28; border: 1px solid var(--border); border-left: 3px solid var(--ok); padding: 10px 14px; border-radius: 8px; min-width: 240px; max-width: 380px; box-shadow: 0 8px 30px rgb(0 0 0 / .4); animation: pop .18s ease-out; }
.toast.error { border-left-color: var(--danger); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
.spinner { width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { margin: 0; flex-direction: row; }
  .view { padding: 20px 16px; }
  .detail, .two-col { grid-template-columns: 1fr; }
  .detail-media { border-right: 0; border-bottom: 1px solid var(--border); }
}

/* ---------- bulk scrape jobs ---------- */
.job { border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px; background: var(--panel-2); }
.job-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.job progress { width: 100%; height: 8px; margin: 10px 0 6px; accent-color: var(--accent); }
.job details pre { max-height: 180px; overflow: auto; }
