:root {
  --bg: #0f1115;
  --card: #171a21;
  --card-2: #1e222b;
  --line: #2a2f3a;
  --text: #eef1f6;
  --muted: #8d96a7;
  --accent: #d22027;
  --accent-2: #ff3b42;
  --ok: #22c55e;
  --warn: #f59e0b;
  --info: #3b82f6;
  --err: #ef4444;
  --ig: linear-gradient(135deg, #f58529, #dd2a7b 50%, #8134af);
  --tt: linear-gradient(135deg, #25f4ee, #111 45%, #fe2c55);
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f4f7; --card: #fff; --card-2: #f6f7f9; --line: #e3e6ec;
    --text: #12151b; --muted: #687285; color-scheme: light;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  min-height: 100dvh; padding-bottom: calc(24px + var(--safe-b));
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
code { background: var(--card-2); padding: 1px 6px; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.mt { margin-top: 10px; }
[hidden] { display: none !important; }

/* top bar */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-size: 17px; }
.brand b, h1 b { color: var(--accent-2); }
.logo {
  width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 800; font-size: 18px;
  box-shadow: 0 4px 14px rgba(210, 32, 39, .35);
}
.logo.big { width: 64px; height: 64px; border-radius: 18px; font-size: 34px; }
.top-actions { display: flex; gap: 6px; align-items: center; }
.top-actions form { margin: 0; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: var(--card); border: 1px solid var(--line); color: var(--text); text-decoration: none;
}
.icon-btn:active { transform: scale(.95); }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.wrap { max-width: 560px; margin: 0 auto; padding: 16px; }
.page-title { font-size: 24px; margin: 4px 0 14px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px;
}
.card h2 { font-size: 17px; margin: 0 0 12px; }
.card h3 { font-size: 15px; margin: 18px 0 8px; }

/* services */
.svc-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.svc {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 14px 6px 12px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--card-2); transition: border-color .15s, transform .1s, box-shadow .15s;
}
.svc:active { transform: scale(.97); }
.svc-ic { width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; color: #fff; }
.svc-instagram .svc-ic { background: var(--ig); }
.svc-tiktok .svc-ic { background: var(--tt); }
.svc-name { font-size: 12px; color: var(--muted); text-align: center; line-height: 1.25; }
.svc-name b { display: block; font-size: 15px; color: var(--text); }
.svc[aria-checked="true"] {
  border-color: var(--accent); box-shadow: 0 0 0 4px rgba(210, 32, 39, .18);
}

/* fields */
.fld { display: block; margin-bottom: 12px; }
.fld > span, label.fld[for] span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.fld em { font-style: normal; font-weight: 500; float: right; }
input[type=text], input[type=url], input[type=password], input:not([type]), input[inputmode] {
  width: 100%; height: 50px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card-2); font-size: 16px; outline: none;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(210, 32, 39, .18); }
.input-row { display: flex; gap: 8px; margin-bottom: 12px; }
.input-row input { flex: 1; min-width: 0; }
.chips { display: flex; gap: 8px; margin: 10px 0 14px; overflow-x: auto; scrollbar-width: none; }
.chips button {
  flex: 1; min-width: 56px; height: 36px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card-2); font-size: 14px; font-weight: 600;
}
.chips button:disabled { opacity: .35; }
.check { display: flex; gap: 10px; align-items: center; margin: 4px 0 14px; font-size: 14px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

/* buttons */
.btn-primary {
  width: 100%; height: 52px; border: 0; border-radius: 14px; background: var(--accent);
  color: #fff; font-weight: 700; font-size: 17px; letter-spacing: .2px;
  box-shadow: 0 6px 18px rgba(210, 32, 39, .3);
}
.btn-primary:active { transform: scale(.985); }
.btn-link { display: grid; place-items: center; text-decoration: none; }
.btn-primary:disabled { opacity: .55; }
.btn-ghost {
  height: 50px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card-2); font-weight: 600;
}
.btn-ghost.wide { width: 100%; height: 46px; }
.btn-danger {
  height: 42px; padding: 0 14px; border-radius: 10px; border: 1px solid rgba(239, 68, 68, .4);
  background: rgba(239, 68, 68, .1); color: var(--err); font-weight: 600;
}
.form-err { color: var(--err); font-size: 14px; margin: -4px 0 12px; }

.alert { padding: 12px 14px; border-radius: 12px; margin-bottom: 14px; font-size: 14px; }
.alert.err { background: rgba(239, 68, 68, .12); color: #fca5a5; border: 1px solid rgba(239, 68, 68, .35); }
.alert.ok { background: rgba(34, 197, 94, .12); color: #86efac; border: 1px solid rgba(34, 197, 94, .35); }
@media (prefers-color-scheme: light) {
  .alert.err { color: #b91c1c; } .alert.ok { color: #15803d; }
}

.banner {
  display: flex; flex-direction: column; gap: 2px;
  padding: 14px 16px; margin-bottom: 16px; border-radius: var(--radius);
  background: rgba(239, 68, 68, .12); border: 1px solid rgba(239, 68, 68, .45);
}
.banner strong { color: var(--err); font-size: 16px; }
.banner span { font-size: 14px; }

/* history */
.hist-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 2px 10px; }
.hist-head h2 { margin: 0; font-size: 18px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 4px 9px; border-radius: 14px; background: var(--card); border: 1px solid var(--line);
  min-width: 0;
}
.stat-ic { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; color: #fff; margin-bottom: 4px; }
.stat-ic svg { width: 14px; height: 14px; }
.stat-instagram .stat-ic { background: var(--ig); }
.stat-tiktok .stat-ic { background: var(--tt); }
.stat b { font-size: 19px; font-weight: 800; letter-spacing: -.2px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat small { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.history { display: flex; flex-direction: column; gap: 10px; }
.empty { text-align: center; color: var(--muted); padding: 28px 0; font-size: 14px; }
.item {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px;
  display: grid; grid-template-columns: 38px 1fr auto; gap: 4px 12px; align-items: center;
}
.item.new { animation: pop .4s ease-out; }
@keyframes pop { from { transform: translateY(-6px); opacity: 0; } }
.item .ic { grid-row: span 2; width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; color: #fff; }
.item .ic svg { width: 18px; height: 18px; }
.item .ic.instagram { background: var(--ig); }
.item .ic.tiktok { background: var(--tt); }
.item .t { font-weight: 650; font-size: 15px; }
.item .t small { color: var(--muted); font-weight: 500; }
.item .l { grid-column: 2 / 4; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: none; }
.item .m { grid-column: 1 / 4; display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.item .bar { grid-column: 1 / 4; height: 4px; border-radius: 4px; background: var(--card-2); overflow: hidden; margin-top: 6px; }
.item .bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.item .er { grid-column: 1 / 4; font-size: 13px; color: var(--err); margin-top: 4px; }
.retry-btn {
  grid-column: 1 / 4; margin-top: 10px; height: 42px; border-radius: 11px;
  border: 1px solid rgba(210, 32, 39, .5); background: rgba(210, 32, 39, .12);
  color: var(--accent-2); font-weight: 700; font-size: 15px;
}
.retry-btn:active { transform: scale(.98); }
.btn-primary.loading { opacity: .85; display: flex; align-items: center; justify-content: center; gap: 10px; }
.btn-primary.loading::before {
  content: ""; width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, .35); border-top-color: #fff; animation: spin .8s linear infinite;
}
.badge {
  font-size: 11.5px; font-weight: 700; padding: 4px 9px; border-radius: 999px; white-space: nowrap;
  background: var(--card-2); color: var(--muted); border: 1px solid var(--line);
}
.badge.completed { color: var(--ok); border-color: rgba(34, 197, 94, .4); background: rgba(34, 197, 94, .1); }
.badge.progress { color: var(--info); border-color: rgba(59, 130, 246, .4); background: rgba(59, 130, 246, .1); }
.badge.pending { color: var(--warn); border-color: rgba(245, 158, 11, .4); background: rgba(245, 158, 11, .1); }
.badge.bad { color: var(--err); border-color: rgba(239, 68, 68, .4); background: rgba(239, 68, 68, .1); }
.badge.partial { color: #a78bfa; border-color: rgba(167, 139, 250, .4); background: rgba(167, 139, 250, .1); }
#moreBtn { margin-top: 12px; }

/* dialogs */
.dlg {
  width: min(92vw, 420px); border: 1px solid var(--line); border-radius: 20px;
  background: var(--card); color: var(--text); padding: 20px;
}
.dlg::backdrop { background: rgba(0, 0, 0, .55); backdrop-filter: blur(3px); }
.dlg[open] { animation: dlgIn .18s ease-out; }
@keyframes dlgIn { from { transform: translateY(10px) scale(.98); opacity: 0; } }
.dlg h3 { margin: 0 0 14px; font-size: 19px; }
.summary { display: grid; grid-template-columns: auto 1fr; gap: 10px 14px; margin: 0 0 18px; font-size: 15px; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; font-weight: 600; }
.break { word-break: break-all; font-weight: 500 !important; font-size: 13.5px; }
.dlg-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }
.dlg-actions.one { grid-template-columns: 1fr; }
.dlg-actions .btn-ghost { height: 52px; }
.dlg-err { text-align: center; }
.dlg-err p { margin: 0 0 18px; font-size: 16px; }
.dlg-icon {
  width: 56px; height: 56px; margin: 4px auto 12px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(239, 68, 68, .15); color: var(--err); font-weight: 800; font-size: 30px;
}
.dlg-err h3 { color: var(--err); }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + var(--safe-b)); transform: translate(-50%, 30px);
  background: #111; color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: .25s; max-width: 90vw; z-index: 50;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { background: #15803d; }
.toast.err { background: #b91c1c; }

/* auth */
.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-logo { display: flex; justify-content: center; margin-bottom: 14px; }
.auth-card h1 { text-align: center; margin: 0; font-size: 26px; }
.auth-card > p { text-align: center; margin: 4px 0 22px; }

/* settings */
.users { list-style: none; margin: 0; padding: 0; }
.users li { border-bottom: 1px solid var(--line); padding: 10px 0; }
.u-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.tag { font-size: 11px; background: var(--accent); color: #fff; padding: 2px 7px; border-radius: 999px; margin-left: 4px; }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-top: 6px; }
.inline-form { display: flex; gap: 8px; margin: 10px 0; }
.inline-form input { flex: 1; min-width: 0; }
.del-form { margin-bottom: 6px; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
