:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --text: #1e2330;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #4f46e5;
  --accent-2: #6366f1;
  --accent-soft: #eef2ff;
  --ok: #059669;
  --ok-soft: #ecfdf5;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --err: #dc2626;
  --err-soft: #fef2f2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 4px 16px rgba(16,24,40,.06);
  color-scheme: light;
}
/* dark theme: chosen explicitly, or "auto" following the system setting */
:root[data-theme="dark"] {
  --bg: #0f1117; --card: #181b24; --text: #e7e9ef; --muted: #9aa1b2; --line: #2a2f3c;
  --accent: #818cf8; --accent-2: #a5b4fc; --accent-soft: #23264a;
  --ok: #34d399; --ok-soft: #10261f; --warn: #fbbf24; --warn-soft: #2a2312;
  --err: #f87171; --err-soft: #2c1517;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117; --card: #181b24; --text: #e7e9ef; --muted: #9aa1b2; --line: #2a2f3c;
    --accent: #818cf8; --accent-2: #a5b4fc; --accent-soft: #23264a;
    --ok: #34d399; --ok-soft: #10261f; --warn: #fbbf24; --warn-soft: #2a2312;
    --err: #f87171; --err-soft: #2c1517;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
.theme-switch { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.theme-switch button { border: 0; background: none; color: var(--muted); padding: 5px 8px; border-radius: 7px; cursor: pointer; display: grid; place-items: center; }
.theme-switch button:hover { color: var(--text); }
.theme-switch button.on { background: var(--card); color: var(--accent); box-shadow: var(--shadow); }
.theme-switch svg { width: 16px; height: 16px; }
.dropdown .theme-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 12px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; font-size: .85rem; color: var(--muted); }
.login-theme { position: fixed; top: 16px; right: 16px; }
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); min-height: 100vh;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* boot */
.boot { display: grid; place-items: center; min-height: 100vh; }
.spinner { width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* layout */
.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar-inner { max-width: 1100px; margin: 0 auto; padding: 0 16px; height: 60px; display: flex; align-items: center; gap: 20px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand img { width: 28px; height: 28px; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a svg { display: none; width: 22px; height: 22px; }
.nav a { padding: 8px 12px; border-radius: 9px; color: var(--muted); text-decoration: none; font-weight: 500; white-space: nowrap; }
.nav a:hover { background: var(--bg); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.usermenu { position: relative; }
.usermenu > button { display: flex; align-items: center; gap: 8px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: .8rem; }
.dropdown { position: absolute; right: 0; top: calc(100% + 6px); background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); min-width: 200px; padding: 6px; }
.dropdown button { width: 100%; text-align: left; background: none; border: 0; padding: 9px 12px; border-radius: 8px; color: var(--text); cursor: pointer; font: inherit; }
.dropdown button:hover { background: var(--bg); }
main { max-width: 1100px; margin: 0 auto; padding: 28px 16px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.card + .card { margin-top: 16px; }
.stack > * + * { margin-top: 16px; }

/* buttons & forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--bg); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--err); }
.btn.danger:hover { background: var(--err-soft); }
.btn.ghost { background: none; border-color: transparent; }
.btn.ghost:hover { background: var(--bg); }
.btn.sm { padding: 6px 10px; font-size: .85rem; border-radius: 8px; }
.btn.lg { padding: 14px 22px; font-size: 1.05rem; }
.btn.block { width: 100%; }
.btn.copied { background: var(--ok); border-color: var(--ok); color: #fff; }

label.field { display: block; }
label.field > span { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
label.field > small { display: block; color: var(--muted); margin-top: 5px; font-size: .82rem; }
input[type=text], input[type=password], input[type=number], input[type=url], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 80px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { margin-top: 4px; width: 17px; height: 17px; accent-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 700px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
details.advanced { border: 1px dashed var(--line); border-radius: 12px; padding: 12px 14px; }
details.advanced summary { cursor: pointer; font-weight: 600; color: var(--muted); }
details.advanced[open] summary { margin-bottom: 14px; }
input[type=range] { width: 100%; accent-color: var(--accent); }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(1200px 600px at 10% -10%, var(--accent-soft), transparent), var(--bg); }
.login { width: 100%; max-width: 380px; }
.login .brand { justify-content: center; font-size: 1.3rem; margin-bottom: 22px; }
.login .brand img { width: 40px; height: 40px; }
.alert { padding: 10px 14px; border-radius: 10px; font-size: .92rem; }
.alert.err { background: var(--err-soft); color: var(--err); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.info { background: var(--accent-soft); color: var(--accent); }

/* steps */
.step { display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 14px; }
.step-num { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; }
.step.done .step-num { background: var(--ok); color: #fff; }
.step h2 { margin-top: 5px; }

.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 38px 20px; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s; background: var(--bg);
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .big { font-size: 1.1rem; font-weight: 600; }
.dropzone svg { width: 44px; height: 44px; color: var(--accent); margin-bottom: 8px; }

.filelist { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.step > div:last-child { min-width: 0; } /* long file names must not widen the card */
.filelist + .dropzone, .filelist + p { margin-top: 12px; }
.dropzone.compact { padding: 16px; }
.dropzone.compact .big { font-size: 0.95rem; }
.filebox { display: flex; gap: 14px; align-items: center; padding: 14px; border: 1px solid var(--line); border-radius: 12px; }
.filebox .icon { width: 44px; height: 44px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.filebox .meta { flex: 1; min-width: 0; }
.filebox .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .4s ease; }
.progress.ok > div { background: var(--ok); }
.progress.err > div { background: var(--err); }
.progress.indet > div { width: 30% !important; animation: indet 1.2s ease-in-out infinite; }
@keyframes indet { 0% { margin-left: -30%; } 100% { margin-left: 100%; } }

.choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.choice {
  position: relative; border: 2px solid var(--line); border-radius: 12px; padding: 12px; cursor: pointer; background: var(--card);
  transition: border-color .15s, box-shadow .15s; display: block;
}
.choice:hover { border-color: var(--accent-2); }
.choice.selected { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.choice.disabled { opacity: .5; cursor: not-allowed; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice .title { font-weight: 600; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.choice .tick { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center; }
.choice.selected .tick { background: var(--accent); border-color: var(--accent); }
.choice.selected .tick::after { content: ""; width: 6px; height: 10px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg) translate(-1px, -1px); }
.choice.check-style .tick { border-radius: 6px; }
.wm-preview { aspect-ratio: 16/9; background: #111 repeating-conic-gradient(#1c1c1c 0 25%, #262626 0 50%) 50% / 20px 20px; border-radius: 8px; overflow: hidden; margin-bottom: 10px; display: grid; place-items: center; }
.wm-preview video, .wm-preview img { width: 100%; height: 100%; object-fit: contain; display: block; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: .78rem; font-weight: 600; background: var(--bg); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.run { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.run .dot { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* jobs */
.job { padding: 18px 20px; }
.job.highlight { animation: hl 2.5s ease-out; }
@keyframes hl { from { box-shadow: 0 0 0 4px var(--accent); } }
.job-head { display: flex; gap: 14px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.job-title { font-weight: 700; font-size: 1.02rem; word-break: break-all; }
.job-sub { color: var(--muted); font-size: .85rem; }
.job-stage { margin-top: 14px; }
.job-stage .row { margin-bottom: 6px; font-size: .9rem; }
.links { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; display: grid; gap: 10px; }
.link-row { display: grid; grid-template-columns: 140px 1fr auto; gap: 10px; align-items: center; }
.link-row .host { font-weight: 600; font-size: .9rem; display: flex; align-items: center; gap: 8px; overflow: hidden; }
.link-row .host span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-row input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; background: var(--bg); }
.link-row .status-text { font-size: .85rem; color: var(--muted); }
.link-row .status-text.err { color: var(--err); }
@media (max-width: 640px) { .link-row { grid-template-columns: 1fr auto; } .link-row .host { grid-column: 1 / -1; } }
.queue-box { display: flex; gap: 16px; align-items: center; background: var(--accent-soft); border-radius: 12px; padding: 14px 16px; }
.queue-pos { flex: none; width: 64px; height: 64px; border-radius: 14px; background: var(--card); display: grid; place-items: center; align-content: center; line-height: 1.1; color: var(--accent); box-shadow: var(--shadow); }
.queue-pos small { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.queue-pos b { font-size: 1.6rem; }
.queue-text { min-width: 0; }
.queue-times { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 4px; }
.queue-note { margin-bottom: 14px; }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty svg { width: 56px; height: 56px; opacity: .5; margin-bottom: 8px; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; white-space: nowrap; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tabs a { padding: 10px 14px; color: var(--muted); text-decoration: none; font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }

.wm-admin { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.wm-admin .card { padding: 14px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stat { background: var(--bg); border-radius: 12px; padding: 14px; }
.stat b { display: block; font-size: 1.3rem; }

/* modal */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 40px); background: var(--card); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(15, 17, 23, .5); backdrop-filter: blur(2px); }
#modal-body { padding: 24px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

/* toasts */
#toasts { position: fixed; bottom: 20px; right: 20px; display: grid; gap: 8px; z-index: 100; max-width: calc(100vw - 40px); }
.toast { background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); font-weight: 500; animation: tin .2s ease-out; max-width: 420px; }
.toast.err { background: var(--err); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
@keyframes tin { from { transform: translateY(10px); opacity: 0; } }

.help-list { margin: 0; padding-left: 18px; }
.help-list li + li { margin-top: 4px; }
code { background: var(--bg); padding: 1px 6px; border-radius: 5px; font-size: .88em; }

/* ---------- touch & phones ---------- */
.touch-only { display: none; }
.break { word-break: break-all; }
@media (hover: none) and (pointer: coarse) {
  .desk-only { display: none; }
  .touch-only { display: inline; }
}
@media (max-width: 720px) {
  /* iOS zooms into inputs below 16px */
  input[type=text], input[type=password], input[type=number], input[type=url], select, textarea { font-size: 16px; }
  .topbar-inner { height: 56px; gap: 10px; padding: 0 12px; }
  .um-name { display: none; }
  /* app-like tab bar at the bottom */
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; flex: none; overflow: visible;
    background: var(--card); border-top: 1px solid var(--line); gap: 0;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 16px rgba(16,24,40,.06);
  }
  .nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 4px; font-size: .72rem; border-radius: 10px; }
  .nav a svg { display: block; }
  .nav a.active { background: none; }
  .topbar-inner .brand { flex: 1; }
  main { padding: 18px 12px calc(92px + env(safe-area-inset-bottom)); }
  h1 { font-size: 1.35rem; }
  .card { padding: 16px; border-radius: 12px; }
  .page-head { margin-bottom: 14px; }
  .page-head .row { width: 100%; justify-content: space-between; }

  /* steps: number next to the heading instead of its own column */
  .step { display: block; }
  .step-num { float: left; width: 28px; height: 28px; font-size: .85rem; margin-right: 10px; }
  .step h2 { margin-top: 2px; line-height: 28px; }
  .dropzone { padding: 26px 14px; }

  .wm-choices { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .wm-choices .choice { padding: 8px; }
  .wm-choices .title { font-size: .9rem; }
  .choices:not(.wm-choices) { grid-template-columns: 1fr; }
  #start-btn { width: 100%; }

  /* bigger touch targets */
  .btn { min-height: 44px; }
  .btn.sm { min-height: 40px; padding: 8px 12px; }

  /* job links: name on top, link + buttons below */
  .link-row { grid-template-columns: minmax(0, 1fr) auto; }
  .link-row .host { grid-column: 1 / -1; }
  .btn-label { display: none; }
  .job { padding: 14px; }
  .job-stage .row.between { flex-direction: column; align-items: stretch; }
  .job-stage .row.between > .row { justify-content: flex-end; }
  .queue-box { gap: 12px; padding: 12px; }
  .queue-pos { width: 54px; height: 54px; }

  /* tables become cards */
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { padding: 12px 0; border-bottom: 1px solid var(--line); }
  table.responsive tr:last-child { border-bottom: 0; }
  table.responsive td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
  table.responsive td.cell-title { display: block; padding-bottom: 6px; }
  table.responsive td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .85rem; }
  table.responsive td.actions { justify-content: flex-end; padding-top: 8px; }
  .table-wrap { overflow: visible; }
  .card.table-wrap { padding-top: 4px; padding-bottom: 4px; }

  /* tabs scroll sideways without a visible scrollbar */
  .tabs { scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }

  /* dialogs as bottom sheets */
  dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 18px 18px 0 0; max-height: 92vh; }
  #modal-body { padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); }
  .modal-actions { position: sticky; bottom: 0; background: var(--card); padding-top: 12px; }
  .modal-actions .btn { flex: 1; }
  #toasts { left: 12px; right: 12px; bottom: calc(84px + env(safe-area-inset-bottom)); }
  .toast { max-width: none; }
  .login-theme { top: 12px; right: 12px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat b { font-size: 1.1rem; }
  .link-row input[readonly] { font-size: 13px; }
}


/* thumbnail collage */
.collage-opt { margin-top: 14px; }
.collage-thumb { display: block; justify-self: start; line-height: 0; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.collage-thumb img { display: block; height: 72px; width: auto; max-width: 100%; object-fit: cover; }

/* hoster order */
th.order-col, td.order-cell { width: 1%; padding-right: 4px; }
.order-btns { display: flex; flex-direction: column; gap: 2px; }
.icon-btn { padding: 4px 6px; line-height: 0; }
.icon-btn:disabled { opacity: .25; cursor: default; }
@media (max-width: 640px) {
  table.responsive td.order-cell { width: 100%; }
  .order-btns { flex-direction: row; }
}
