:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --border: #2a2f3a;
  --text: #eef0f4;
  --muted: #8b93a3;
  --accent: #ffd60a;
  --accent-text: #111;
  --ok: #34c77b;
  --warn: #f5a524;
  --err: #ff5a5f;
  --info: #5aa9ff;
  --radius: 14px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --border: #e1e4ea;
    --text: #15181e;
    --muted: #677084;
    --accent: #f2c200;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 400; }
.small-text { font-size: 13px; }
.center { text-align: center; }
h2 { font-size: 18px; margin: 0 0 14px; }
h3 { font-size: 15px; margin: 0 0 10px; }

.container { max-width: 880px; margin: 0 auto; padding: 16px; display: grid; gap: 22px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card.inner { background: var(--surface-2); margin-top: 16px; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-right #me { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }
.logo { font-weight: 800; font-size: 17px; letter-spacing: .2px; }

label { display: grid; gap: 6px; font-weight: 600; font-size: 14px; margin-bottom: 12px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 12px; font-size: 16px; /* evita zoom no iPhone */
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .row { grid-template-columns: 1fr; gap: 0; } }

.btn {
  font: inherit; font-weight: 700; border-radius: 10px; border: 1px solid var(--border);
  padding: 11px 16px; cursor: pointer; background: var(--surface-2); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; width: 100%; }
.btn.ghost { background: transparent; }
.btn.small { padding: 7px 11px; font-size: 13px; }
.btn.danger { color: var(--err); }
.btn:disabled { opacity: .55; cursor: default; }

.file-drop {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 22px 14px;
  text-align: center; cursor: pointer; font-weight: 600; background: var(--surface-2);
}
.file-drop input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.file-drop.has-file { border-color: var(--accent); }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 14px; }

.upload-status { margin-top: 14px; }
.progress { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--border); }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .3s; }

.list-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 4px; }
.list-head select { width: auto; padding: 7px 10px; font-size: 14px; }
.list-head h2 { margin: 0; }

.jobs { margin-top: 12px; }
.job-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.job + .job { border-top: 1px solid var(--border); }
.job.open { background: color-mix(in srgb, var(--surface-2) 45%, var(--surface)); }
.job-head {
  all: unset; box-sizing: border-box; width: 100%; cursor: pointer;
  display: flex; gap: 10px; align-items: center; padding: 13px 14px;
}
.job-head:hover { background: var(--surface-2); }
.job-head:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.job-main { flex: 1; min-width: 0; }
.job-main .job-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job.open .job-main .job-title { white-space: normal; }
.job-sub { margin-top: 4px; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.chevron { flex: none; font-size: 22px; line-height: 1; color: var(--muted); transition: transform .2s; }
.job.open .chevron { transform: rotate(90deg); }
.job-detail { padding: 0 14px 16px; }
.job-title { font-weight: 700; font-size: 15px; word-break: break-word; }
.job-meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.badge { font-size: 12px; font-weight: 700; padding: 4px 9px; border-radius: 99px; white-space: nowrap; background: var(--surface-2); border: 1px solid var(--border); }
.badge.uploading, .badge.queued { color: var(--info); }
.badge.downloading, .badge.processing { color: var(--warn); }
.badge.done { color: var(--ok); }
.badge.error { color: var(--err); }
.badge.expired { color: var(--muted); }
.job-progress { margin-top: 10px; font-size: 14px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--warn); animation: spin 1s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.job-notes { margin-top: 8px; font-size: 13px; color: var(--muted); white-space: pre-wrap; }

.job-body { display: grid; grid-template-columns: 220px 1fr; gap: 16px; margin-top: 14px; }
.job-body.horizontal { grid-template-columns: 1fr; }
@media (max-width: 640px) { .job-body { grid-template-columns: 1fr; } }
.job video { width: 100%; border-radius: 10px; background: #000; max-height: 70vh; }
.post { display: grid; gap: 12px; align-content: start; min-width: 0; }
.post-block { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.post-block-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.post-line { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; padding: 4px 0; }
.post-line + .post-line { border-top: 1px solid var(--border); }
.post-text { white-space: pre-wrap; word-break: break-word; font-size: 14px; }
.copy { flex: none; font-size: 12px; padding: 4px 9px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font-weight: 600; }
.job-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.job-actions .btn { flex: 1 1 auto; }
.error-text { color: var(--err); font-size: 13px; white-space: pre-wrap; word-break: break-word; margin: 8px 0 0; }
details.error-details { margin-top: 8px; font-size: 12px; color: var(--muted); }
details.error-details pre { white-space: pre-wrap; word-break: break-word; max-height: 220px; overflow: auto; }

.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-card .logo { font-size: 22px; margin-bottom: 2px; }
.login-card p { margin: 0 0 18px; }

dialog {
  width: min(640px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
}
dialog::backdrop { background: rgba(0, 0, 0, .55); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.dialog-head h2 { margin: 0; }
.users-list { display: grid; gap: 8px; }
.user-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px; background: var(--surface-2); border-radius: 10px; border: 1px solid var(--border); }
.user-row div { min-width: 0; }
.user-row .muted { font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
fieldset { border: 1px solid var(--border); border-radius: 10px; margin: 0 0 14px; padding: 8px 12px; }
legend { font-weight: 600; font-size: 14px; padding: 0 4px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.checks label { display: flex; align-items: center; gap: 6px; font-weight: 500; margin: 0; }
.checks input { width: auto; }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(140%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 14px;
  transition: transform .25s, opacity .25s; z-index: 50; max-width: calc(100vw - 32px);
  opacity: 0; visibility: hidden;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; visibility: visible; }

.agent-status { margin: 10px 0 0; font-size: 13px; padding: 9px 12px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); color: var(--muted); }
.agent-status.off { border-color: color-mix(in srgb, var(--warn) 50%, var(--border)); }
.job:not(.open) .job-meta { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
