:root {
  font: 16px/1.45 system-ui,sans-serif;
  color-scheme: light dark;
  --bg: light-dark(#f8f6f3,#1c1d20);
  --ink: light-dark(#20242a,#f4efe9);
  --paper: light-dark(#fff,#25272a);
  --muted: light-dark(#635750,#d2c6bd);
  --border: light-dark(#e3dcd4,#48464a);
  --accent: light-dark(#963a0b,#ffab75);
  background: var(--bg);
  color: var(--ink);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none!important;
}

body {
  margin: 0;
}

a {
  color: var(--accent);
}

h1,h2,p {
  margin: 0;
}

h1 {
  font-size: clamp(1.45rem,5vw,2rem);
  line-height: 1.18;
}

h2 {
  font-size: 1.25rem;
}

.brand {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem max(1rem,env(safe-area-inset-left));
  background: #20242a;
  color: #fff;
}

.brand div {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand button {
  background: transparent;
  color: #fff;
  border-color: #716863;
}

main {
  max-width: 44rem;
  margin: auto;
  padding: 1.25rem 1rem 2rem;
}

.secondary,#status {
  color: var(--muted);
  margin: 0.375rem 0;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 0.5rem;
  margin: 1rem 0;
}

.toolbar span {
  padding-bottom: 0.5rem;
  color: var(--accent);
}

label, .field {
  display: grid;
  gap: 0.25rem;
}

input,textarea,select,button {
  color: inherit;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  min-height: 44px;
  font: inherit;
  padding: 0.45rem 0.65rem;
  max-width: 100%;
}

input[type=checkbox] {
  width: 1.2rem;
  min-height: 1.2rem;
  accent-color: var(--accent);
}

.check {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 44px;
  white-space: nowrap;
}

button:disabled {
  opacity: .6;
}

.primary {
  color: #fff;
  background: #963a0b;
  border-color: #963a0b;
}

.list {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  overflow: hidden;
}

.rule {
  padding: 0.7rem;
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  align-items: center;
  gap: 0.35rem 0.5rem;
}

.rule+.rule {
  border-top: 1px solid var(--border);
}

.rule strong,.rule small {
  display: block;
  overflow-wrap: anywhere;
}

.rule small {
  color: var(--muted);
}

.rule .meta {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

#actions {
  margin-bottom: 0.75rem;
}

dialog {
  width: min(100% - 1.5rem,30rem);
  max-height: 90dvh;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--paper);
  color: var(--ink);
  padding: 1rem;
}

dialog::backdrop {
  background: #20242aa8;
}

dialog form,.bounds {
  display: grid;
  gap: 0.6rem;
}

.bounds {
  grid-template-columns: 1fr 1fr;
}

textarea {
  resize: vertical;
}

#test-details {
  margin: 0;
  padding-left: 1.25rem;
}

#test-details:empty {
  display: none;
}

@media(max-width:380px) {
  .rule .meta {
    grid-column: 1/-1;
    justify-content: space-between;
  }
}

.sign-in {
  max-width: 29rem;
  padding-top: clamp(1.5rem, 8vw, 3rem);
}

.sign-in form {
  display: grid;
  gap: 0.5rem;
  margin-top: 1.5rem;
  padding: 1.25rem;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
}

.sign-in label + input {
  margin-bottom: 0.5rem;
}

.sign-in button {
  margin-top: 0.25rem;
}

.sign-in [role=alert]:empty {
  display: none;
}

#global-loading {
  position: fixed;
  z-index: 100;
  top: 0;
  left: 0;
  width: 100%;
  border-top: 3px solid #ff883d;
  pointer-events: none;
  display: flex;
  justify-content: center;
}

#global-loading span {
  border-radius: 0 0 0.6rem 0.6rem;
  padding: 0.15rem 0.8rem;
  color: #fff;
  background: #20242a;
  font-size: 0.82rem;
}

.app-content {
  padding-bottom: calc(5.5rem + env(safe-area-inset-bottom));
}

.tab-bar {
  position: fixed;
  z-index: 5;
  bottom: 0;
  inset-inline: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding: 0.3rem max(0.2rem, calc((100% - 44rem) / 2)) calc(0.3rem + env(safe-area-inset-bottom));
  background: var(--paper);
  border-top: 1px solid var(--border);
}

.tab-bar a {
  display: grid;
  place-items: center;
  min-height: 48px;
  padding-inline: 0.2rem;
  color: var(--muted);
  text-decoration: none;
  border-radius: 0.5rem;
}

.tab-bar a[aria-current] {
  color: var(--accent);
  font-weight: 700;
  background: light-dark(#fff0e5, #442b22);
}

.screen-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.8rem;
}

.panel, .stat {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.85rem;
  margin-block: 0.75rem;
}

.panel > * + * {
  margin-top: 0.55rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.stat {
  margin-block: 0;
}

.stat strong {
  display: block;
  font-size: 1.55rem;
}

.compact-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.compact-list li {
  padding-block: 0.4rem;
  overflow-wrap: anywhere;
}

.compact-list li + li {
  border-top: 1px solid var(--border);
}

.funnel-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.18rem 0.5rem;
}

.funnel-row meter {
  grid-column: 1 / -1;
  width: 100%;
  height: 0.56rem;
  accent-color: var(--accent);
}

#settings-fields {
  display: grid;
  gap: 0.65rem;
}

#settings-fields label {
  font-size: 0.93rem;
}

/* Marketing follows the same mobile navigation and private-media layout. */
.tab-bar { grid-template-columns: repeat(5, minmax(0, 1fr)); }
#marketing-editor { max-width: 640px; width: calc(100% - 24px); }
#marketing-editor form { display:grid; gap:12px; }
#marketing-detail img { object-fit:contain; }
#marketing-list .panel, #marketing-detail .panel { overflow-wrap:anywhere; }

@media (max-width: 420px) { .tab-bar a { font-size: 12px; min-width: 0; padding-inline: 4px; } }

/* The brand stays above scrolling content, including on installed mobile PWAs. */
:root { --brand-height: calc(62px + env(safe-area-inset-top)); }
body { padding-top: var(--brand-height); }
.brand { position: fixed; inset: 0 0 auto; z-index: 30; height: var(--brand-height); padding-top: calc(.5rem + env(safe-area-inset-top)); }
.paid-kpi { border-color: light-dark(#96cfad,#3b7452); }
.paid-kpi > strong { display:block; margin:.5rem 0; color:light-dark(#13763d,#68dc98); font-size:clamp(2rem,8vw,3.25rem); line-height:1.12; overflow-wrap:anywhere; }
.product-cards { display:grid; gap:1rem; }
.principal-product { border-left:4px solid #e76217; }
#settings-fields fieldset { min-width:0; border:1px solid var(--border); border-radius:.75rem; margin:0 0 1rem; padding:1rem; display:grid; gap:.8rem; }
#product-maintenance { display:grid; gap:1rem; }
summary { cursor:pointer; font-weight:600; }
html { scroll-padding-top:calc(var(--brand-height) + 16px); }
#marketing-manual[open] { display:grid; gap:.8rem; }
#marketing-ai-preview { display:grid; gap:.7rem; }
#marketing-ai-fill { width:100%; }

/* Local Instagram emulator: every action stays inside this dialog. */
.instagram-preview { width:min(100% - 1rem, 48rem); max-height:94dvh; padding:1rem; }
.ig-preview-heading { display:flex; align-items:start; justify-content:space-between; gap:1rem; }
.ig-preview-heading h2 { font-size:1.25rem; }
.ig-preview-tabs { display:flex; gap:.5rem; margin:1rem 0; }
.ig-preview-tabs button[aria-pressed=true] { background:var(--ink); color:var(--bg); }
.ig-preview-viewport { padding:.8rem 0; display:flex; justify-content:center; background:light-dark(#eeecea,#18191b); border-radius:1rem; }
.ig-preview-note { font-size:.85rem; color:var(--muted); margin:.75rem 0 0; }
.ig-device { color:#101010; background:#fff; width:min(100%,360px); border:6px solid #171717; border-radius:30px; overflow:hidden; font:14px/1.4 system-ui,sans-serif; box-shadow:0 8px 24px #0002; }
.ig-device svg { width:24px; height:24px; flex-shrink:0; }
.ig-statusbar { display:flex; justify-content:space-between; padding:12px 20px 8px; font-size:12px; font-weight:650; background:#fff; color:#111; }
.ig-appbar { display:flex; align-items:center; gap:18px; padding:10px 12px; border-bottom:1px solid #eee; }
.ig-wordmark { margin-right:auto; font:italic 600 28px/1.2 Georgia,serif; letter-spacing:-1px; }
.ig-identity { display:flex; gap:9px; align-items:center; padding:11px 12px; }
.ig-identity > div { display:grid; gap:1px; }
.ig-identity strong { font-size:12px; font-weight:650; }
.ig-identity small { font-size:10px; }
.ig-more { margin-left:auto; font-size:24px; }
.ig-avatar { width:32px; height:32px; border:1px solid #ddd; border-radius:50%; padding:6px; background:#22262b; object-fit:contain; }
.ig-feed-picture { aspect-ratio:4/5; overflow:hidden; background:#eee; }
.ig-art { width:100%; height:100%; object-fit:cover; display:block; }
.ig-empty-media { width:100%; height:100%; min-height:160px; display:grid; place-content:center; padding:2rem; text-align:center; background:#f0ece8; color:#665b53; }
.ig-cta { width:100%; display:flex; justify-content:space-between; align-items:center; border:0; border-radius:0; min-height:42px; background:#eaf3ff; color:#1769b4; font-size:12px; font-weight:650; padding:8px 12px; }
.ig-post-actions { display:flex; gap:14px; align-items:center; padding:12px; }
.ig-post-actions svg:last-child { margin-left:auto; }
.ig-caption { padding:0 12px 14px; font-size:12px; overflow-wrap:anywhere; white-space:pre-wrap; }
.ig-caption-collapsed .ig-copy { display:-webkit-box; -webkit-line-clamp:3; -webkit-box-orient:vertical; overflow:hidden; }
.ig-caption-more { min-height:26px; padding:0; border:0; background:transparent; color:#777; font-size:12px; }
.ig-navigation { display:flex; justify-content:space-between; align-items:center; border-top:1px solid #eee; padding:12px 15px 18px; }
.ig-navigation .ig-avatar { width:24px; height:24px; padding:4px; }
.ig-story { aspect-ratio:9/16; position:relative; overflow:hidden; background:#20242a; color:#fff; }
.ig-story > .ig-art, .ig-story > .ig-empty-media { position:absolute; inset:0; }
.ig-story-header { position:absolute; inset:0 0 auto; padding:8px 6px 22px; background:linear-gradient(#0008,transparent); }
.ig-story-progress { margin:0 4px; height:2px; background:#ffffff7f; border-radius:4px; }
.ig-story-progress::before { content:''; display:block; width:40%; height:2px; background:#fff; }
.ig-story .ig-avatar { border-color:#fff; }
.ig-story .ig-cta { position:absolute; bottom:32px; left:14%; width:72%; border-radius:25px; justify-content:center; gap:8px; background:#fff; color:#151515; box-shadow:0 2px 16px #0003; }
.ig-story-home { position:absolute; bottom:10px; left:36%; width:28%; height:4px; background:#fff; border-radius:4px; }
@media(max-width:380px) { .instagram-preview { padding:.7rem; } .ig-preview-heading { gap:.5rem; } .ig-preview-heading h2 { font-size:1.1rem; } .ig-device { border-width:4px; } }
.ig-preview-heading { position:sticky; top:-1rem; background:var(--paper); z-index:2; padding:.5rem 0; }
