/* Auto Post Mini App — same Obsidian language as the SaveContent hub:
   dark surfaces, multi-hue accents, tab panels + bottom nav + slide-up overlays.
   Light values follow Telegram's scheme through <html data-theme>. */

:root {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-card-2: #1c2230;
  --bg-elev: #20283a;
  --border: rgba(255,255,255,0.07);
  --text: #f5f7fa;
  --text-dim: #c6cbd4;
  --hint: #7a8494;

  --blue: #4ea6ec;
  --blue-2: #2b85d6;
  --gold: #f0b62a;
  --green: #2ecc71;
  --purple: #8b5cf6;
  --red: #ef4444;

  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 22px; --r-full: 999px;
  --safe-top: 0px; --safe-bottom: 0px;
}
html[data-theme="light"] {
  --bg: #f2f4f7;
  --bg-card: #ffffff;
  --bg-card-2: #f6f8fb;
  --bg-elev: #e9edf3;
  --border: rgba(15,23,42,0.09);
  --text: #111827;
  --text-dim: #374151;
  --hint: #6b7280;
  --blue: #2b85d6;
  --blue-2: #1f6fb8;
  --gold: #b7791f;
  --green: #17914d;
  --red: #d92d20;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: "Tajawal", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overscroll-behavior-y: none;
}
button, input, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes slideUp { from { transform: translateY(100%); opacity: .6; } to { transform: none; opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }

#app {
  max-width: 480px; margin: 0 auto;
  padding: calc(14px + var(--safe-top)) 14px calc(92px + var(--safe-bottom) + env(safe-area-inset-bottom));
}
.tab-panel { animation: fadeIn .2s ease; display: flex; flex-direction: column; gap: 12px; }

/* ───────── Loading + gates ───────── */
.center-view {
  min-height: 70vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; text-align: center; padding: 0 18px;
}
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--blue);
  animation: spin .8s linear infinite;
}
.gate-title { font-size: 18px; font-weight: 800; margin: 0; }
.gate-text { color: var(--text-dim); margin: 0; white-space: pre-wrap; }

/* ───────── Top bar ───────── */
.topbar { display: flex; align-items: center; gap: 10px; padding: 2px 2px 4px; }
.topbar-title { font-size: 19px; font-weight: 800; margin: 0; flex: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--bg-card-2); border: 1px solid var(--border);
  border-radius: var(--r-full); padding: 4px 10px; font-size: 12px; font-weight: 700; color: var(--text-dim);
  white-space: nowrap;
}
.chip.blue { color: var(--blue); border-color: rgba(78,166,236,.35); background: rgba(78,166,236,.10); }
.chip.gold { color: var(--gold); border-color: rgba(240,182,42,.35); background: rgba(240,182,42,.10); }
.chip.green { color: var(--green); border-color: rgba(46,204,113,.35); background: rgba(46,204,113,.10); }
.chip.red { color: var(--red); border-color: rgba(239,68,68,.35); background: rgba(239,68,68,.10); }

/* ───────── Cards ───────── */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 14px;
}
.card-title { font-size: 13px; font-weight: 700; color: var(--hint); margin: 0 0 10px; }
.card-row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--hint); font-size: 13px; }
.dim { color: var(--text-dim); }

/* Hero: the one big action */
.hero {
  background: var(--bg-card);
  border: 1px solid var(--border); border-inline-start: 4px solid var(--hint);
  border-radius: var(--r-lg); padding: 18px 16px;
  display: flex; flex-direction: column; gap: 14px;
}
.hero.on { border-inline-start-color: var(--green); }
.hero-status { display: flex; align-items: center; gap: 10px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #6b7280; flex: none; }
.dot.on { background: #32cd64; box-shadow: 0 0 8px rgba(50,205,100,.7); animation: pulse 1.8s ease-in-out infinite; }
.hero-state { font-size: 20px; font-weight: 800; }
.hero-sub { color: var(--text-dim); font-size: 13px; margin-top: -6px; }
.hero-times { color: var(--hint); font-size: 12.5px; margin-top: -8px; }

.btn {
  border: 0; border-radius: var(--r-md); padding: 13px 16px;
  font-weight: 800; font-size: 15px; cursor: pointer; width: 100%;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .08s ease, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-go { background: var(--green); color: #06240f; }
.btn-stop { background: transparent; color: var(--red); border: 1.5px solid var(--red); }
.btn-ghost { background: var(--bg-card-2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: transparent; color: var(--red); border: 1px solid rgba(239,68,68,.5); }
.btn-sm { padding: 8px 12px; font-size: 13px; width: auto; border-radius: var(--r-sm); }
.btn.busy { pointer-events: none; opacity: .7; }

/* Segmented control: the two systems */
.seg { display: flex; background: var(--bg-card-2); border: 1px solid var(--border); border-radius: var(--r-md); padding: 4px; gap: 4px; }
.seg button {
  flex: 1; border: 0; background: transparent; border-radius: 9px; padding: 9px 6px;
  font-weight: 700; font-size: 14px; color: var(--hint); cursor: pointer;
}
.seg button.active { background: var(--bg-elev); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.seg.locked { opacity: .55; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stats.three { grid-template-columns: repeat(3, 1fr); }
.stat { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--r-md); padding: 10px 6px; text-align: center; min-width: 0; }
.stat-num { font-size: 19px; font-weight: 800; }
.stat-label { font-size: 11px; color: var(--hint); font-weight: 700; margin-top: 2px; }
.stat.warn .stat-num { color: var(--gold); }
.stat.bad .stat-num { color: var(--red); }

/* Setup checklist */
.step { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); cursor: pointer; }
.step:first-of-type { border-top: 0; }
.step-num {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 13px; background: var(--bg-elev); color: var(--text-dim);
}
.step.done .step-num { background: var(--green); color: #06240f; }
.step.done .step-label { color: var(--hint); text-decoration: line-through; }
.step-label { flex: 1; font-weight: 700; }
.chev { color: var(--hint); font-size: 18px; }
[dir="rtl"] .chev { transform: scaleX(-1); }

/* ───────── Messages ───────── */
.msg-card { cursor: pointer; }
.msg-text {
  white-space: pre-wrap; overflow: hidden; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; margin: 0 0 10px; font-weight: 500;
  word-break: break-word;
}
.msg-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.msg-card.off { opacity: .6; }
.empty { text-align: center; color: var(--hint); padding: 30px 12px; }

/* Switch */
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span {
  position: absolute; inset: 0; background: var(--bg-elev); border-radius: 999px;
  transition: background .18s; cursor: pointer; border: 1px solid var(--border);
}
.switch span::after {
  content: ""; position: absolute; top: 2px; inset-inline-start: 2px;
  width: 22px; height: 22px; border-radius: 50%; background: #fff;
  transition: transform .18s; box-shadow: 0 1px 3px rgba(0,0,0,.35);
}
.switch input:checked + span { background: var(--green); border-color: transparent; }
.switch input:checked + span::after { transform: translateX(18px); }
[dir="rtl"] .switch input:checked + span::after { transform: translateX(-18px); }

/* Setting rows */
.row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.row:first-child { border-top: 0; padding-top: 2px; }
.row:last-child { padding-bottom: 2px; }
.row-icon { width: 24px; height: 24px; flex: none; color: var(--hint); display: inline-flex; }
.row-icon svg { width: 24px; height: 24px; }
.row-title { font-weight: 700; }
.row-desc { color: var(--hint); font-size: 12.5px; margin-top: 1px; }
.row.tap { cursor: pointer; }

/* Stepper (➖ value ➕) */
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button {
  width: 44px; height: 44px; border-radius: var(--r-md); border: 1px solid var(--border);
  background: var(--bg-card-2); font-size: 22px; font-weight: 800; cursor: pointer; flex: none;
}
.stepper button:active { background: var(--bg-elev); }
.stepper input {
  flex: 1; min-width: 0; height: 44px; text-align: center; font-size: 19px; font-weight: 800;
  background: var(--bg-card-2); border: 1px solid var(--border); border-radius: var(--r-md);
  direction: ltr;
}

/* Fields */
.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: 13px; font-weight: 700; color: var(--text-dim); }
.input, .textarea {
  width: 100%; background: var(--bg-card-2); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 12px; outline: none;
}
.input:focus, .textarea:focus, .stepper input:focus { border-color: var(--blue); }
.textarea { min-height: 130px; resize: vertical; line-height: 1.6; }
.input.ltr { direction: ltr; text-align: left; font-size: 18px; letter-spacing: .5px; }
.input.code { text-align: center; letter-spacing: 8px; font-size: 24px; font-weight: 800; }
.hintline { font-size: 12.5px; color: var(--hint); }
.hintline.err { color: var(--red); }
.note {
  background: rgba(240,182,42,.10); border: 1px dashed rgba(240,182,42,.4); color: var(--gold);
  border-radius: var(--r-md); padding: 10px 12px; font-size: 13px; white-space: pre-wrap;
}
.note.info { background: rgba(78,166,236,.10); border-color: rgba(78,166,236,.4); color: var(--blue); }

/* ───────── Overlays ───────── */
.overlay {
  position: fixed; inset: 0; background: var(--bg); z-index: 200;
  display: flex; flex-direction: column; animation: slideUp .2s ease;
}
.overlay-header {
  background: var(--bg-card); padding: calc(12px + var(--safe-top)) 14px 12px;
  display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border);
}
.overlay-back { background: transparent; border: 0; font-size: 28px; line-height: 1; color: var(--blue); cursor: pointer; padding: 0 6px; }
[dir="rtl"] .overlay-back { transform: scaleX(-1); }
.overlay-title { margin: 0; font-size: 16px; font-weight: 800; flex: 1; }
.overlay-body {
  padding: 16px 14px calc(30px + var(--safe-bottom) + env(safe-area-inset-bottom));
  overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 14px;
  max-width: 480px; width: 100%; margin: 0 auto;
}
.overlay-foot {
  padding: 10px 14px calc(12px + var(--safe-bottom) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); background: var(--bg-card);
}
.overlay-foot .inner { max-width: 452px; margin: 0 auto; display: flex; gap: 8px; }

/* Group picker */
.pick { display: flex; align-items: center; gap: 12px; padding: 11px 2px; border-top: 1px solid var(--border); cursor: pointer; }
.pick:first-child { border-top: 0; }
.pick-box {
  width: 24px; height: 24px; border-radius: 7px; border: 2px solid var(--hint); flex: none;
  display: flex; align-items: center; justify-content: center; font-size: 15px; color: transparent;
}
.pick.sel .pick-box { background: var(--blue); border-color: var(--blue); color: #fff; }
.pick-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-meta { font-size: 12.5px; color: var(--hint); margin-top: 1px; }
.pick.locked { opacity: .5; cursor: default; }
.pick.locked .pick-box { border-style: dashed; }
.pick-head { font-size: 12.5px; font-weight: 700; color: var(--hint); padding: 14px 2px 6px; border-top: 1px solid var(--border); }
.pick-sub { font-size: 12px; color: var(--hint); direction: ltr; text-align: left; }
[dir="rtl"] .pick-sub { text-align: right; }

/* Accounts */
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  background: linear-gradient(135deg, #5b8bd0, #355686); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 800;
}

/* ───────── Bottom nav ───────── */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex;
  background: var(--bg); border-top: 1px solid var(--border);
  padding: 8px 0 calc(8px + var(--safe-bottom) + env(safe-area-inset-bottom));
  z-index: 100; box-shadow: 0 -4px 20px rgba(0,0,0,.28);
}
.nav-tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 4px; color: var(--hint); cursor: pointer; background: none; border: 0;
}
.nav-tab svg { width: 23px; height: 23px; }
.nav-label { font-size: 11px; font-weight: 700; }
.nav-tab.active { color: var(--blue); }

/* ───────── Toast + confirm sheet ───────── */
#toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); transform: translateX(-50%);
  background: var(--bg-elev); color: var(--text); border: 1px solid var(--border);
  padding: 10px 16px; border-radius: var(--r-full); font-weight: 700; font-size: 14px;
  z-index: 400; max-width: 88vw; text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.35);
  animation: fadeIn .18s ease;
}
#toast.err { border-color: rgba(239,68,68,.6); color: var(--red); }
.sheet-back { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 300; display: flex; align-items: flex-end; }
.sheet {
  width: 100%; max-width: 480px; margin: 0 auto; background: var(--bg-card);
  border-radius: var(--r-xl) var(--r-xl) 0 0; padding: 18px 16px calc(18px + var(--safe-bottom) + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px; animation: slideUp .2s ease;
}
.sheet-title { font-size: 17px; font-weight: 800; margin: 0; }
.sheet-text { color: var(--text-dim); margin: 0; white-space: pre-wrap; }
.sheet-actions { display: flex; gap: 8px; }

/* Activity */
.event { padding: 10px 0; border-top: 1px solid var(--border); }
.event:first-child { border-top: 0; padding-top: 2px; }
.event-top { display: flex; gap: 8px; align-items: baseline; }
.event-title { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.event-time { color: var(--hint); font-size: 12px; direction: ltr; flex: none; }
.event-reason { color: var(--text-dim); font-size: 12.5px; margin-top: 2px; }

/* A newer page exists on the server */
#update-bar {
  position: fixed; top: calc(8px + var(--safe-top)); left: 12px; right: 12px; z-index: 350;
  background: var(--blue); color: #fff; border-radius: var(--r-md); padding: 10px 12px;
  display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(0,0,0,.3);
}
#update-bar span { flex: 1; }
#update-bar .btn { background: #fff; color: var(--blue-2); }

/* Admin */
.person { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); cursor: pointer; }
.person:first-child { border-top: 0; }
.funnel { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; font-size: 13.5px; border-top: 1px solid var(--border); }
.funnel:first-child { border-top: 0; }
.audit { font-size: 12.5px; padding: 7px 0; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.audit:first-child { border-top: 0; }
.audit time { color: var(--hint); direction: ltr; flex: none; }

@media (max-width: 340px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
