:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #16191d;
  --muted: #6b7280;
  --line: #e4e7eb;
  --accent: #128c4a;
  --accent-ink: #ffffff;
  --danger: #c0392b;
  --warn: #b26a00;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 19, 24, .06), 0 8px 24px rgba(16, 19, 24, .06);
}

* { box-sizing: border-box; }

/* class-based display rules outrank the UA [hidden] rule, so force it */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  padding-bottom: 40vh;
}

h2 { font-size: 15px; margin: 0; }
h3 { font-size: 13px; margin: 0; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.tiny { font-size: 11px; line-height: 1.4; }

/* topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  background: rgba(255,255,255,.88);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 650; display: flex; align-items: center; gap: 8px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.conn { display: flex; align-items: center; gap: 10px; }

.pill { font-size: 12px; padding: 4px 10px; border-radius: 999px; font-weight: 600; }
.pill--ok   { background: #e3f4ea; color: #0f7a41; }
.pill--idle { background: #eceef1; color: var(--muted); }
.pill--warn { background: #fdf0da; color: var(--warn); }
.pill--bad  { background: #fbe6e3; color: var(--danger); }

/* gate */
.gate { display: grid; place-items: center; padding: 56px 20px; }
.gate__card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 32px; max-width: 420px; text-align: center; box-shadow: var(--shadow);
}
.gate__card h2 { font-size: 18px; margin-bottom: 8px; }
.qr { width: 260px; height: 260px; margin: 20px auto 4px; display: block; border-radius: 8px; }
.spinner {
  width: 26px; height: 26px; margin: 24px auto 4px;
  border: 3px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* layout */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px;
  padding: 16px 20px; max-width: 1180px; margin: 0 auto; align-items: start;
}
@media (max-width: 900px) { .layout { grid-template-columns: minmax(0, 1fr); } }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow);
}
.card__head { display: flex; align-items: center; justify-content: space-between; }
.card__head--sub { margin-top: 6px; padding-top: 12px; border-top: 1px solid var(--line); }

.row { display: flex; align-items: center; gap: 10px; }
.row--between { justify-content: space-between; }
.row--tight { gap: 6px; }
.row--wrap { flex-wrap: wrap; }

/* inputs */
.input, .textarea {
  width: 100%; font: inherit; color: inherit;
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; background: #fff;
}
.input:focus, .textarea:focus { outline: 2px solid rgba(18,140,74,.28); border-color: var(--accent); }
.input--sm { padding: 7px 10px; font-size: 13px; }
.input--tiny { width: 58px; padding: 5px 7px; font-size: 12px; text-align: center; }
.textarea { min-height: 240px; resize: vertical; font-family: inherit; line-height: 1.55; }

/* buttons */
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border-radius: 9px; border: 1px solid transparent; padding: 9px 14px;
  white-space: nowrap; flex-shrink: 0;
  transition: filter .12s ease, background .12s ease;
}
.btn:hover:not(:disabled) { filter: brightness(.96); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn--sm { padding: 5px 10px; font-size: 12px; }
.btn--ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--danger { background: #fbe6e3; color: var(--danger); border-color: #f3cdc7; }
.btn--blast {
  background: var(--accent); color: var(--accent-ink);
  width: 100%; padding: 14px; font-size: 15px; letter-spacing: .01em;
}

.chip {
  font: inherit; font-size: 12px; cursor: pointer;
  background: #f1f3f5; border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 11px; color: var(--muted);
}
.chip:hover { background: #e9ecef; color: var(--ink); }
.chip--on, .chip--on:hover { background: #e3f4ea; border-color: #b9e2ca; color: #0f7a41; }
.chip__x { margin-left: 6px; opacity: .5; }
.chip__x:hover { opacity: 1; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.list--groups, .list--listings {
  max-height: 300px; overflow-y: auto;
  border: 1px solid var(--line); border-radius: 9px;
}
.list--groups li, .list--listings li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.list li:last-child { border-bottom: none; }
.list--groups li:hover, .list--listings li:hover { background: #f8f9fa; }
.list--groups li.on { background: #f0faf4; }
.list--groups input { accent-color: var(--accent); width: 16px; height: 16px; }
.gname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gmeta { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.list--groups li.locked { opacity: .5; cursor: not-allowed; }
.list--groups li.locked .gmeta { color: var(--warn); }
.warn { color: var(--warn); font-weight: 600; }
#groupHint { margin: 2px 0 0; }

.list--listings li { flex-direction: column; align-items: stretch; gap: 3px; }
.ltitle { font-weight: 600; font-size: 13px; }
.lprev { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lrow { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.del { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 15px; padding: 0 4px; line-height: 1; }
.del:hover { color: var(--danger); }
.empty { padding: 18px; text-align: center; color: var(--muted); font-size: 12px; }

.badge {
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: #e3f4ea; color: #0f7a41;
}
.badge--bad { background: #fbe6e3; color: var(--danger); }

.list--queue { border: 1px solid var(--line); border-radius: 9px; margin-top: 8px; }
.list--queue li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-bottom: 1px solid var(--line);
}
.list--queue li:last-child { border-bottom: none; }
.qnum {
  flex-shrink: 0; width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
  display: grid; place-items: center;
}
.qmove {
  background: none; border: 1px solid var(--line); border-radius: 6px;
  cursor: pointer; font-size: 11px; line-height: 1; padding: 3px 6px; color: var(--muted);
}
.qmove:hover:not(:disabled) { background: #f1f3f5; color: var(--ink); }
.qmove:disabled { opacity: .3; cursor: not-allowed; }
.list--queue li.editing { align-items: flex-start; background: #f8faf9; }
.list--queue li.editing .qnum { margin-top: 3px; }
.qactions { flex-shrink: 0; }
.qedit { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.textarea--q { min-height: 90px; font-size: 13px; line-height: 1.5; }
.textarea--lib { min-height: 140px; font-size: 13px; line-height: 1.5; margin-top: 6px; }
.list--listings li.editing { background: #f8faf9; gap: 6px; }
.badge--edit { background: #fdf0da; color: var(--warn); }
.list--queue .lprev { cursor: pointer; }
.list--queue .lprev:hover { color: var(--ink); }
#queueBox { padding-top: 12px; }
.list--listings .ltitle, .list--listings .lprev { cursor: pointer; }

/* listing groups */
#lgBox { padding-top: 12px; }
.lg { margin: 8px 0 2px; }
.lgchip { display: inline-flex; align-items: center; gap: 6px; background: #eef7f1; border-color: #cfe9d9; color: #0f7a41; font-weight: 600; }
.lgchip:hover { background: #e3f4ea; color: #0a5c30; }
.lgcount { background: #0f7a41; color: #fff; border-radius: 999px; padding: 0 6px; font-size: 10px; line-height: 16px; }
.lpick { accent-color: var(--accent); width: 15px; height: 15px; flex-shrink: 0; cursor: pointer; }
.lhead { min-width: 0; flex: 1; flex-wrap: wrap; }
.gtag { font-size: 10px; font-weight: 600; color: #0f7a41; background: #eef7f1; border-radius: 4px; padding: 1px 5px; }
.list--listings li.picked { background: #f0faf4; }
#pickBar .input { flex: 1; min-width: 0; }

.sets:empty { display: none; }

/* schedule */
.card--wide { grid-column: 1 / -1; }
.sched { border-top: 1px solid var(--line); padding-top: 10px; }
.sched summary { cursor: pointer; font-size: 12px; color: var(--muted); font-weight: 600; }
.sched summary:hover { color: var(--ink); }
.sched__row { margin: 10px 0 8px; }
.sched__row .input { flex: 1; min-width: 0; }
.sched #schedBtn { width: 100%; }
.list--sched { border: 1px solid var(--line); border-radius: 9px; max-height: 260px; overflow-y: auto; }
.list--sched li {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.list--sched li:last-child { border-bottom: none; }
.list--sched li.paused { opacity: .55; }
.sched__main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sched__last { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.st--missed { background: #fdf0da; color: var(--warn); }
.sendbar { margin-top: 4px; padding-top: 12px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 9px; }

/* drawer */
.drawer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--card); border-top: 1px solid var(--line);
  box-shadow: 0 -8px 32px rgba(16,19,24,.12);
  max-height: 46vh; display: flex; flex-direction: column;
}
.drawer__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--line);
}
.progress { height: 3px; background: var(--line); }
.progress__bar { height: 100%; width: 0; background: var(--accent); transition: width .3s ease; }
.list--job { overflow-y: auto; padding: 4px 0; }
.list--job li {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 20px; font-size: 13px; border-bottom: 1px solid #f2f4f6;
}
.st { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; flex-shrink: 0; min-width: 64px; text-align: center; }
.st--pending { background: #eceef1; color: var(--muted); }
.st--sending { background: #fdf0da; color: var(--warn); }
.st--sent    { background: #e3f4ea; color: #0f7a41; }
.st--failed  { background: #fbe6e3; color: var(--danger); }
.st--skipped { background: #eceef1; color: var(--muted); }
.jerr { font-size: 11px; color: var(--danger); }

.crash {
  position: fixed; top: 0; left: 0; right: 0; z-index: 60;
  background: #fbe6e3; color: var(--danger); border-bottom: 1px solid #f3cdc7;
  padding: 10px 20px; font-size: 13px; font-weight: 600;
}

/* toast */
.toast {
  position: fixed; bottom: 50vh; left: 50%; transform: translateX(-50%); z-index: 50;
  background: #16191d; color: #fff; padding: 10px 18px; border-radius: 9px;
  font-size: 13px; box-shadow: var(--shadow);
}

/* scheduling: rotation + specific days */
.sched__mode { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; font-size: 13px; }
.sched__mode label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.sched__mode input { accent-color: var(--accent); }
.sched__rotate { margin-top: 8px; }
.sched__rotate .chip { display: inline-flex; align-items: center; gap: 6px; }
.sched__days { margin: -2px 0 8px; }
.st--running { background: #fdf0da; color: var(--warn); }
.st--stopped { background: #eceef1; color: var(--muted); }
#notifySelf { accent-color: var(--accent); }

/* sign-in page */
.login { display: flex; flex-direction: column; gap: 12px; width: 100%; }
.login .btn { width: 100%; }
.body--login { padding-bottom: 0; }

/* phones */
@media (max-width: 600px) {
  .topbar { padding: 10px 16px; }
  .layout { padding: 12px 16px; }
  .conn { gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
  .brand, .pill { white-space: nowrap; }
  .conn .btn { padding: 5px 8px; font-size: 12px; }
  .list--sched li { flex-direction: column; align-items: stretch; }
}
