:root {
  --bg: #0c0d10;
  --panel: #14161c;
  --panel2: #1a1d26;
  --border: #2a2e3a;
  --text: #f2f3f5;
  --muted: #9aa3b5;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.18);
  --warn: #f59e0b;
  --danger: #ef4444;
  --ok: #22c55e;
  --side-w: 220px;
  --herald-h: 36px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text);
  font-family: "Segoe UI", "IBM Plex Sans", "Trebuchet MS", sans-serif; }

.app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.35rem 1rem; border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #12141a, #0e1015);
  position: sticky; top: 0; z-index: 40;
}
.topbar-toolbar {
  display: flex; align-items: center; justify-content: center;
  gap: 1.1rem; flex: 1; flex-wrap: nowrap; padding: 0.3rem 0;
}
.mascot {
  flex: none; width: clamp(80px, 7.5vw, 112px); height: clamp(80px, 7.5vw, 112px);
  border: 0; padding: 0; background: transparent; cursor: pointer; border-radius: 50%;
  overflow: hidden;
}

.head-search {
  position: relative; flex: 0 1 28rem; width: min(36rem, 52vw); min-width: 12rem;
  display: flex; align-items: center; gap: 0.4rem;
  background: var(--panel2); border: 1px solid var(--border); border-radius: 10px;
  padding: 0 0.75rem; height: 40px;
}
.head-search input {
  flex: 1; border: 0; outline: 0; background: transparent; color: var(--text);
  font-size: 0.95rem;
}
.head-search-icon { color: var(--muted); flex: none; }

.lang-switch { flex: 0 0 auto; position: relative; }
.lang-current {
  height: 34px; min-width: 48px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel2); color: var(--text); cursor: pointer;
}
.lang-menu {
  position: absolute; right: 0; top: calc(100% + 4px); background: var(--panel);
  border: 1px solid var(--border); border-radius: 8px; min-width: 120px; z-index: 50;
}
.lang-menu button {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  color: var(--text); padding: 0.5rem 0.75rem; cursor: pointer;
}
.lang-menu button:hover { background: var(--accent-soft); }

.nav-burger {
  display: none; border: 1px solid var(--border); background: var(--panel2);
  color: var(--text); width: 36px; height: 36px; border-radius: 8px; cursor: pointer;
}

body.guest .sidebar,
body.guest .bottom-nav,
body.guest .nav-burger,
body.guest .gate { display: none !important; }
body.guest .layout { justify-content: center; }
body.guest .main { padding-bottom: 1.25rem; min-height: 40vh; }

.mascot img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}

.bottom-art[hidden] {
  display: none !important;
}
body.authed .bottom-art,
body.authed #bottomArt {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}
body.guest .bottom-art:not([hidden]) {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  justify-content: center;
  pointer-events: none;
  padding-bottom: env(safe-area-inset-bottom);
}
body.guest .bottom-art img {
  display: block;
  max-height: min(28vh, 220px);
  width: auto;
  max-width: min(90vw, 420px);
  object-fit: contain;
}
body.guest .main {
  padding-bottom: calc(1.25rem + min(28vh, 220px));
}
body.authed .main {
  padding-bottom: 4.5rem;
}

.layout { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: var(--side-w); flex: none; border-right: 1px solid var(--border);
  background: #101218; padding: 1rem 0.75rem; overflow-y: auto;
}
.side-section {
  font-size: 0.68rem; letter-spacing: 0.08em; color: var(--muted);
  padding: 0.4rem 0.65rem; text-transform: uppercase;
}
.side-link {
  display: block; width: 100%; text-align: left; border: 0; cursor: pointer;
  background: transparent; color: var(--muted); padding: 0.55rem 0.75rem;
  border-radius: 8px; margin-bottom: 2px; font-size: 0.92rem;
}
.side-link:hover { background: var(--panel2); color: var(--text); }
.side-link.active { background: var(--accent); color: #fff; }

.main { flex: 1; padding: 1.1rem 1.25rem 4.5rem; overflow: auto; }
.gate {
  max-width: 28rem; margin: 3rem auto; text-align: center; color: var(--muted);
  border: 1px dashed var(--border); border-radius: 12px; padding: 2rem;
}

.stats {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.75rem;
  margin-bottom: 1rem;
}
.stat-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 1rem 1.1rem;
}
.stat-card .n { font-size: 1.6rem; font-weight: 700; }
.stat-card .l { color: var(--muted); font-size: 0.85rem; margin-top: 0.2rem; }

.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 1rem; margin-bottom: 1rem;
}
.panel h2 { margin: 0 0 0.75rem; font-size: 1.05rem; font-weight: 600; }

.media-layout { display: grid; grid-template-columns: 180px 1fr; gap: 1rem; }
.preset-list { display: flex; flex-direction: column; gap: 0.35rem; }
.preset-btn {
  border: 1px solid var(--border); background: var(--panel2); color: var(--text);
  border-radius: 8px; padding: 0.55rem 0.65rem; text-align: left; cursor: pointer;
}
.preset-btn.active { border-color: var(--accent); background: var(--accent-soft); }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem;
}
.media-card {
  background: var(--panel2); border: 1px solid var(--border); border-radius: 12px;
  padding: 1rem 0.75rem 0.85rem; cursor: pointer; position: relative;
  min-height: 140px; display: flex; flex-direction: column; align-items: center;
}
.media-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.media-emblem {
  width: 56px; height: 56px; border-radius: 12px;
  border: 2px solid #e11d48; display: grid; place-items: center;
  font-size: 0.7rem; font-weight: 700; margin-bottom: 0.55rem; color: #fecaca;
}
.media-card h3 { margin: 0; font-size: 0.92rem; text-align: center; }
.media-card p { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.75rem; text-align: center; }

.wizard-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 0.75rem; }
.btn {
  border: 1px solid var(--border); background: var(--panel2); color: var(--text);
  border-radius: 8px; padding: 0.55rem 1rem; cursor: pointer; font-size: 0.9rem;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.form-row { margin-bottom: 0.75rem; }
.form-row label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.3rem; }
.form-row input, .form-row textarea, .form-row select {
  width: 100%; background: #0f1117; border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: 0.55rem 0.7rem; font: inherit;
}
.form-row textarea { min-height: 120px; resize: vertical; }

.ads-split { display: grid; grid-template-columns: 1fr 320px; gap: 1rem; }
.tg-preview {
  background: #0e1621; border-radius: 12px; padding: 1rem; border: 1px solid #1c2a3a;
  min-height: 280px;
}
.tg-bubble {
  background: #182533; border-radius: 12px; padding: 0.75rem; max-width: 100%;
}
.tg-bubble img { max-width: 100%; border-radius: 8px; display: block; margin-bottom: 0.5rem; }
.tg-bubble .body { white-space: pre-wrap; font-size: 0.92rem; line-height: 1.4; }
.tg-btns { display: flex; flex-direction: column; gap: 0.35rem; margin-top: 0.6rem; }
.tg-btn {
  display: block; text-align: center; background: #2b5278; color: #fff;
  border-radius: 6px; padding: 0.4rem; font-size: 0.85rem; text-decoration: none;
}

.table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.table th, .table td { text-align: left; padding: 0.5rem 0.4rem; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 500; }
.badge {
  display: inline-block; padding: 0.15rem 0.45rem; border-radius: 999px;
  font-size: 0.72rem; background: var(--panel2); border: 1px solid var(--border);
}
.badge.pending { border-color: var(--warn); color: var(--warn); }
.badge.awaiting_payment { border-color: var(--accent); color: var(--accent); }
.badge.approved, .badge.scheduled, .badge.running, .badge.done { border-color: var(--ok); color: var(--ok); }
.badge.rejected, .badge.failed, .badge.rework { border-color: var(--danger); color: var(--danger); }

.ctx-menu {
  position: fixed; z-index: 80; background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; min-width: 160px; padding: 0.35rem;
}
.ctx-menu button {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  color: var(--text); padding: 0.45rem 0.65rem; cursor: pointer; border-radius: 6px;
}
.ctx-menu button:hover { background: var(--accent-soft); }
.ctx-menu .ctx-version { color: var(--muted); font-variant-numeric: tabular-nums; }
.ctx-sep { height: 1px; background: var(--border); margin: 0.25rem 0; }

.bottom-nav {
  display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: #101218; border-top: 1px solid var(--border);
  padding: 0.35rem 0.5rem calc(0.35rem + env(safe-area-inset-bottom));
  justify-content: space-around;
}
.bottom-nav button {
  border: 0; background: transparent; color: var(--muted); padding: 0.5rem;
  font-size: 0.78rem; cursor: pointer;
}
.bottom-nav button.active { color: var(--accent); }

.hh-herald-host { min-height: 0; }
@media (max-width: 767px) {
  .nav-burger { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 50; transform: translateX(-105%);
    transition: transform 0.2s ease; width: min(80vw, 260px);
  }
  .sidebar.open { transform: translateX(0); }
  .bottom-nav { display: flex; }
  .stats { grid-template-columns: 1fr; }
  .media-layout, .ads-split { grid-template-columns: 1fr; }
  .topbar-toolbar { gap: 0.55rem; }
  .head-search { min-width: 8rem; width: min(42vw, 16rem); }
  .hh-herald-host, #hh-herald-root { display: none !important; }
}

/* Herald strip: built-in collapse tab (chevron). Don't hide on mobile for ads. */
body.herald-on .app { padding-top: 0; }
body.herald-on #herald-bar-root { display: block; }
