:root {
  --bg: #0a0d13;
  --bg-soft: #111723;
  --card: rgba(24, 32, 46, 0.82);
  --card-2: rgba(31, 41, 59, 0.68);
  --line: rgba(148, 163, 184, 0.16);
  --text: #eef3fb;
  --muted: #93a0b5;
  --accent: var(--tg-theme-button-color, #4f8cff);
  --accent-2: #7c5cff;
  --danger: #ff5d6c;
  --ok: #39d98a;
  --warn: #ffc857;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.36);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
  background:
    radial-gradient(1100px 520px at 10% -10%, rgba(79, 140, 255, 0.18), transparent 60%),
    radial-gradient(900px 500px at 105% 5%, rgba(124, 92, 255, 0.16), transparent 55%),
    var(--bg);
}

#app { max-width: 760px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(92px + var(--safe-bottom)); }

#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px;
  background: rgba(10, 13, 19, 0.78);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line);
}
#topbar-title { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-user { font-size: 12px; color: var(--muted); max-width: 34%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#screen { padding: 16px 16px 8px; }

h1, h2, h3, h4 { margin: 0; letter-spacing: -0.015em; }
h1 { font-size: 26px; line-height: 1.15; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.hidden { display: none !important; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
}
.card.soft { background: var(--card-2); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-title { font-weight: 650; font-size: 14px; }
.card-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.hero {
  padding: 22px 18px;
  border-radius: 24px;
  background:
    radial-gradient(420px 200px at 85% 0%, rgba(124, 92, 255, 0.32), transparent 60%),
    linear-gradient(135deg, rgba(79, 140, 255, 0.24), rgba(24, 32, 46, 0.86));
  border: 1px solid rgba(124, 92, 255, 0.25);
  box-shadow: var(--shadow);
}
.hero h1 { margin-bottom: 6px; }
.hero .sub { color: #c9d5e8; font-size: 13px; }

.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.mode-card {
  display: flex; flex-direction: column; gap: 8px;
  padding: 15px;
  border-radius: 16px;
  background: linear-gradient(160deg, rgba(43, 56, 80, 0.72), rgba(20, 27, 40, 0.86));
  border: 1px solid var(--line);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.14s ease;
}
.mode-card:active { transform: scale(0.98); }
.mode-card:hover { border-color: rgba(79, 140, 255, 0.45); }
.mode-card .m-title { font-weight: 650; font-size: 14px; }
.mode-card .m-sub { font-size: 11px; color: var(--muted); }
.mode-card.wide { grid-column: span 2; }
.mode-card.admin { border-color: rgba(124, 92, 255, 0.28); }

button, .btn {
  appearance: none; border: 0; border-radius: 13px; padding: 12px 16px;
  font: inherit; font-weight: 600; font-size: 14px;
  color: var(--text); background: rgba(148, 163, 184, 0.14);
  cursor: pointer; transition: transform 0.12s ease, filter 0.12s ease;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
button:active { transform: scale(0.985); }
button:disabled { opacity: 0.45; pointer-events: none; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; box-shadow: 0 10px 26px rgba(79, 140, 255, 0.32); }
.btn-ghost { background: rgba(148, 163, 184, 0.1); }
.btn-danger { background: rgba(255, 93, 108, 0.15); color: #ffb3ba; }
.btn-ok { background: rgba(57, 217, 138, 0.16); color: #9bf1c5; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 12px; border-radius: 10px; }
.btn-icon { padding: 9px; width: 40px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 12px; padding: 0;
  background: rgba(148, 163, 184, 0.12); color: var(--text);
}

label.field { display: flex; flex-direction: column; gap: 7px; font-size: 12px; color: var(--muted); font-weight: 600; }
input[type="text"], input[type="number"], input[type="url"], textarea, select {
  width: 100%; border: 1px solid var(--line); border-radius: 13px;
  background: rgba(9, 13, 20, 0.55); color: var(--text);
  padding: 12px 13px; font: inherit; font-size: 14px;
  outline: none; transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, textarea:focus, select:focus { border-color: rgba(79, 140, 255, 0.65); box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.14); }
textarea { resize: vertical; min-height: 108px; line-height: 1.5; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.seg { display: inline-flex; padding: 3px; border-radius: 12px; background: rgba(148, 163, 184, 0.1); gap: 3px; }
.seg button { padding: 8px 12px; border-radius: 9px; font-size: 12px; background: transparent; color: var(--muted); }
.seg button.active { background: rgba(79, 140, 255, 0.22); color: #fff; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 11px; border-radius: 999px; font-size: 12px;
  background: rgba(148, 163, 184, 0.12); color: var(--muted);
  border: 1px solid transparent; cursor: pointer;
}
.chip.active { color: #cfe0ff; background: rgba(79, 140, 255, 0.16); border-color: rgba(79, 140, 255, 0.35); }

.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  border-radius: 14px; background: rgba(148, 163, 184, 0.07);
  border: 1px solid transparent;
}
.list-item.active { border-color: rgba(57, 217, 138, 0.35); background: rgba(57, 217, 138, 0.08); }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-title { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .li-sub { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.thumb-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.thumb {
  position: relative; border-radius: 13px; overflow: hidden;
  aspect-ratio: 1 / 1; background: #0b1018; border: 1px solid var(--line);
}
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .badge {
  position: absolute; left: 6px; bottom: 6px; right: 6px;
  font-size: 9px; padding: 3px 6px; border-radius: 7px;
  background: rgba(5, 8, 13, 0.72); color: #d7e2f3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.thumb .badge.top { top: 6px; bottom: auto; }
.thumb.sel { outline: 2px solid var(--ok); }

.media-full { width: 100%; border-radius: 16px; display: block; background: #070a10; }
.ref-box { display: flex; gap: 12px; align-items: center; }
.ref-thumb { width: 78px; height: 78px; border-radius: 13px; object-fit: cover; background: #0b1018; border: 1px solid var(--line); flex: 0 0 auto; }
.ref-thumb.empty { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 10px; text-align: center; }

.result-card { overflow: hidden; padding: 0; display: block; width: 100%; text-align: left; }
.result-card .thumb { border-radius: 0; aspect-ratio: 4 / 3; border: 0; width: 100%; }
.active-job-card { border-color: rgba(255, 200, 87, 0.38); background: linear-gradient(135deg, rgba(255, 200, 87, 0.08), var(--card)); }
.active-job-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.result-card .rc-body { padding: 11px 13px 13px; }
.result-card .rc-title { font-size: 12px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 34px; }

.meta-table { display: flex; flex-direction: column; gap: 7px; }
.meta-row { display: flex; gap: 10px; font-size: 12px; }
.meta-row .k { color: var(--muted); min-width: 112px; flex: 0 0 112px; }
.meta-row .v { flex: 1; word-break: break-word; }

#tabbar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(12px + var(--safe-bottom)); z-index: 30;
  width: calc(100% - 24px); max-width: 736px;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 7px; border-radius: 20px;
  background: rgba(15, 21, 32, 0.82);
  border: 1px solid var(--line);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 8px 4px; border-radius: 14px; background: transparent;
  color: var(--muted); font-size: 10px; font-weight: 600;
}
.tab svg { width: 21px; height: 21px; }
.tab.active { color: #dce8ff; background: rgba(79, 140, 255, 0.14); }

.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(4, 7, 12, 0.68);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 12px 12px calc(12px + var(--safe-bottom));
}
.sheet {
  width: 100%; max-width: 720px; max-height: 92vh; overflow: auto;
  background: linear-gradient(180deg, rgba(23, 31, 46, 0.98), rgba(13, 18, 28, 0.99));
  border: 1px solid var(--line); border-radius: 22px;
  box-shadow: var(--shadow); padding: 16px;
  animation: sheetIn 0.2s ease;
}
@keyframes sheetIn { from { transform: translateY(14px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.sheet-head h2 { flex: 1; font-size: 17px; }

.progress-track { height: 9px; border-radius: 99px; background: rgba(148, 163, 184, 0.14); overflow: hidden; }
.progress-bar { height: 100%; width: 0%; border-radius: 99px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.35s ease; }
.progress-bar.indeterminate { width: 38% !important; animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-120%); } 100% { transform: translateX(330%); } }

.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid rgba(148, 163, 184, 0.2); border-top-color: var(--accent); animation: spin 0.8s linear infinite; margin: 0 auto 10px; }
@keyframes spin { to { transform: rotate(360deg); } }
.boot { text-align: center; padding: 80px 20px; color: var(--muted); }
.center { text-align: center; }
.error-box { padding: 16px; border-radius: 14px; background: rgba(255, 93, 108, 0.1); border: 1px solid rgba(255, 93, 108, 0.25); color: #ffc5cb; font-size: 13px; }

#toasts { position: fixed; z-index: 200; left: 50%; transform: translateX(-50%); bottom: calc(96px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 8px; width: calc(100% - 32px); max-width: 520px; pointer-events: none; }
.toast {
  padding: 12px 14px; border-radius: 14px; font-size: 13px;
  background: rgba(24, 34, 50, 0.96); border: 1px solid var(--line);
  box-shadow: var(--shadow); animation: toastIn 0.18s ease;
}
.toast.ok { border-color: rgba(57, 217, 138, 0.35); }
.toast.err { border-color: rgba(255, 93, 108, 0.4); }
@keyframes toastIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.divider { height: 1px; background: var(--line); margin: 4px 0; }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px; border-radius: 999px; font-size: 10px; font-weight: 600; background: rgba(148, 163, 184, 0.14); color: var(--muted); }
.pill.ok { background: rgba(57, 217, 138, 0.14); color: #a9f3ce; }
.pill.warn { background: rgba(255, 200, 87, 0.14); color: #ffe0a1; }

@media (max-width: 380px) {
  .mode-grid { grid-template-columns: 1fr; }
  .mode-card.wide { grid-column: span 1; }
  .thumb-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 620px) {
  .mode-grid { grid-template-columns: repeat(3, 1fr); }
  .mode-card.wide { grid-column: span 2; }
  .thumb-grid { grid-template-columns: repeat(4, 1fr); }
}
