:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --text: #17171a;
  --muted: #6b6b73;
  --border: #e3e3e0;
  --accent: #2357d9;
  --accent-text: #ffffff;
  --danger: #c4361e;
  --ok: #1d8a4e;
  --warn: #a86a00;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --surface: #1b1b1f;
    --text: #ececef;
    --muted: #9a9aa3;
    --border: #2c2c32;
    --accent: #5b86f0;
    --accent-text: #0b0b0d;
    --danger: #f0735c;
    --ok: #4cc287;
    --warn: #e0a53a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  white-space: nowrap;
  min-height: 40px;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.danger { color: var(--danger); }
#refreshBtn.danger { border-color: var(--danger); font-weight: 600; min-width: 96px; }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: 14px; }

input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 9px 11px;
  min-height: 40px;
}
textarea { min-height: 120px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
label { display: block; font-weight: 600; margin: 14px 0 6px; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 0; }

/* Cabeçalho */
header.top {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
}
.top-row { display: flex; align-items: center; gap: 8px; max-width: 1200px; margin: 0 auto; }
.top-row h1 { font-size: 18px; margin: 0; flex: 1; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; max-width: 1200px; margin: 10px auto 0; }
.controls select { width: auto; flex: 1 1 140px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }

.status {
  max-width: 1200px; margin: 8px auto 0; font-size: 13px; color: var(--muted);
  display: flex; gap: 8px; align-items: center;
}
.status.running { color: var(--accent); }
.status.error { color: var(--danger); }
.spinner { width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

main { max-width: 1200px; margin: 0 auto; padding: 16px 16px 120px; }
.empty { text-align: center; color: var(--muted); padding: 60px 10px; }

.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; } }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column; position: relative;
}
.card.selected { outline: 3px solid var(--accent); outline-offset: -1px; }
.thumb {
  aspect-ratio: 9 / 16; background: var(--border); position: relative; cursor: pointer; display: block; width: 100%; border: 0; padding: 0;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .dur { position: absolute; right: 6px; bottom: 6px; background: rgba(0,0,0,.65); color: #fff; font-size: 12px; padding: 1px 6px; border-radius: 6px; }
.thumb .badge { position: absolute; left: 6px; bottom: 6px; background: rgba(0,0,0,.65); color: #fff; font-size: 12px; padding: 1px 6px; border-radius: 6px; }
.thumb .placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; padding: 10px; text-align: center; }
.sel {
  position: absolute; top: 8px; left: 8px; z-index: 2; width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid #fff; background: rgba(0,0,0,.35); color: #fff; display: grid; place-items: center; cursor: pointer; padding: 0;
}
.card.selected .sel { background: var(--accent); border-color: var(--accent); }
.meta { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.meta .user { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta .nums { display: flex; gap: 10px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.meta .nums b { color: var(--text); font-weight: 600; }
.meta .cap { font-size: 12px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.meta .err { font-size: 12px; color: var(--danger); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.meta .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; padding-top: 6px; }
.meta .actions .btn { flex: 1; }
.saved-tag { color: var(--ok); font-size: 12px; font-weight: 600; }

/* Barra de seleção */
.selbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  display: none;
}
.selbar.show { display: block; }
.selbar-inner { max-width: 1200px; margin: 0 auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.selbar-inner .count { flex: 1; font-weight: 600; min-width: 100px; }

/* Modais */
dialog {
  border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text);
  padding: 0; width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
}
dialog::backdrop { background: rgba(0,0,0,.5); }
.dlg-head { display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); gap: 8px; }
.dlg-head h2 { font-size: 17px; margin: 0; flex: 1; }
.dlg-body { padding: 4px 16px 18px; overflow: auto; }
.tabs { display: flex; gap: 4px; padding: 8px 12px 0; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab { border: 0; background: none; padding: 9px 12px; border-bottom: 2px solid transparent; color: var(--muted); cursor: pointer; white-space: nowrap; font-weight: 600; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.status .btn { margin-left: auto; }
.thumb:disabled { cursor: default; }
.player { width: min(440px, calc(100vw - 32px)); }
.player video { width: 100%; max-height: 75vh; display: block; background: #000; }
.player .dlg-body { padding: 12px 16px 16px; }

.profiles { list-style: none; margin: 8px 0 0; padding: 0; border: 1px solid var(--border); border-radius: 10px; }
.profiles li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-top: 1px solid var(--border); }
.profiles li:first-child { border-top: 0; }
.profiles li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.profiles li .small { color: var(--muted); font-size: 12px; }
.profiles li { flex-wrap: wrap; }
.profiles li .name { flex-basis: 100%; }
.profiles li input.mini { width: 80px; min-height: 32px; padding: 4px 8px; flex: none; }
.profiles li [data-remove] { margin-left: auto; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.row > .btn { flex: none; }
.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--border); }
.pill.ok { color: var(--ok); border-color: currentColor; }
.pill.no { color: var(--warn); border-color: currentColor; }
.logbox { font: 12px/1.5 ui-monospace, Menlo, monospace; white-space: pre-wrap; background: var(--bg); border-radius: 8px; padding: 10px; max-height: 50vh; overflow: auto; }

/* Login */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 22px; }
.auth-card h1 { font-size: 20px; margin: 0 0 4px; }
.auth-card .btn { width: 100%; margin-top: 16px; }
.msg { margin-top: 10px; font-size: 14px; color: var(--danger); min-height: 1em; }
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  max-width: calc(100vw - 32px); box-shadow: 0 4px 20px rgba(0,0,0,.2);
}
