/* MarketMonster AI — responsive app styles. No inline styles anywhere (strict CSP). */
:root {
  --bg: #f5f6fa; --surface: #ffffff; --surface-2: #f0f1f7; --border: #e1e3ec;
  --text: #1c1d26; --muted: #646778; --brand: #5b4bdb; --brand-2: #4637c4; --brand-soft: #ecebfd;
  --ok: #18865a; --ok-soft: #e3f5ec; --warn: #a96500; --warn-soft: #fdf1dc; --bad: #c4314b; --bad-soft: #fbe6ea;
  --info: #1f6fb2; --info-soft: #e3effa;
  --radius: 12px; --shadow: 0 1px 2px rgba(20, 20, 40, .06), 0 4px 16px rgba(20, 20, 40, .05);
  --nav-w: 232px; --top-h: 56px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121319; --surface: #1b1c25; --surface-2: #23242f; --border: #2f3140;
    --text: #e9e9f1; --muted: #9a9cb0; --brand: #8b7ff5; --brand-2: #a69cf8; --brand-soft: #2a2747;
    --ok: #4cc690; --ok-soft: #173327; --warn: #f0b04a; --warn-soft: #3a2c12; --bad: #f2788c; --bad-soft: #3d1c24;
    --info: #6fb2ea; --info-soft: #162c40;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
p { margin: .25rem 0 .75rem; }
code, .mono { font-family: var(--mono); font-size: .88em; }
pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: .75rem; overflow: auto; max-height: 360px; font-size: .82rem; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.boot { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: var(--nav-w) 1fr; grid-template-rows: var(--top-h) 1fr; min-height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: .75rem; padding: 0 1rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); white-space: nowrap; }
.brand img { width: 28px; height: 28px; }
.topbar .spacer { flex: 1; }
.company-picker { min-width: 0; max-width: 280px; }
.nav { background: var(--surface); border-right: 1px solid var(--border); padding: .75rem .5rem; overflow-y: auto; position: sticky; top: var(--top-h); height: calc(100vh - var(--top-h)); }
.nav a { display: flex; align-items: center; gap: .6rem; padding: .55rem .75rem; border-radius: 8px; color: var(--text); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand); }
.nav .section { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: .9rem .75rem .3rem; }
.nav svg { width: 18px; height: 18px; flex: none; }
.main { padding: 1.25rem; min-width: 0; }
.menu-btn { display: none; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-bottom: 1rem; }
.page-head h1 { margin: 0; flex: 1; min-width: 200px; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: .5rem; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .nav { position: fixed; left: 0; top: var(--top-h); bottom: 0; width: min(80vw, 280px); z-index: 30; transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow); height: auto; }
  .nav.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .main { padding: 1rem .75rem; }
  .brand span { display: none; }
  .company-picker { max-width: 50vw; }
}

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem; min-width: 0; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .5rem; }
.card-head h2, .card-head h3 { margin: 0; flex: 1; }
.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }
.kpis { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 1rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; box-shadow: var(--shadow); }
.kpi .label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 1.5rem; font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.empty h3 { color: var(--text); }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; padding: .5rem .85rem; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; min-height: 38px; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--bad); border-color: var(--bad-soft); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: .25rem .6rem; min-height: 30px; font-size: .85rem; }
.btn[disabled], .btn.busy { opacity: .6; pointer-events: none; }
.btn.busy::after { content: ""; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { padding: .4rem; min-height: 36px; min-width: 36px; }

label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: .25rem; }
.field { margin-bottom: .85rem; min-width: 0; }
.field .hint { font-weight: 400; color: var(--muted); font-size: .8rem; margin-top: .2rem; }
input[type=text], input[type=url], input[type=number], input[type=password], input[type=date], input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; padding: .5rem .65rem; font: inherit; min-height: 38px;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.check input { width: 18px; height: 18px; }
.form-grid { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: flex-end; margin-top: .5rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; margin-bottom: 1rem; }
.toolbar .field { margin: 0; min-width: 140px; flex: 1 1 140px; }
.toolbar .field.grow { flex: 3 1 220px; }

/* ---------- tables & lists ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: .55rem 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.kv { display: grid; grid-template-columns: minmax(110px, 30%) 1fr; gap: .35rem .75rem; margin: 0; }
.kv dt { color: var(--muted); font-size: .88rem; } .kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---------- chips & badges ---------- */
.badge { display: inline-flex; align-items: center; gap: .3rem; border-radius: 999px; padding: .1rem .55rem; font-size: .76rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); } .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); } .badge.info { background: var(--info-soft); color: var(--info); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }
.tags { display: flex; flex-wrap: wrap; gap: .3rem; }
.tag { font-size: .8rem; padding: .05rem .5rem; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); }
.pf { display: inline-flex; align-items: center; gap: .35rem; font-weight: 600; font-size: .85rem; }
.pf::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.pf.instagram::before { background: #d6249f; } .pf.facebook::before { background: #1877f2; } .pf.linkedin::before { background: #0a66c2; }
.pf.tiktok::before { background: #25f4ee; box-shadow: 2px 0 0 #fe2c55; } .pf.x::before { background: #888; } .pf.pinterest::before { background: #e60023; }
.pf.youtube::before { background: #ff0000; } .pf.threads::before { background: #666; }
.trend-up { color: var(--ok); } .trend-down { color: var(--bad); } .trend-flat { color: var(--muted); }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: .25rem; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 1rem; scrollbar-width: thin; }
.tabs button { border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; padding: .6rem .9rem; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ---------- posts ---------- */
.post-list { display: grid; gap: .75rem; }
.post-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem 1rem; box-shadow: var(--shadow); cursor: pointer; display: grid; gap: .4rem; }
.post-card:hover { border-color: var(--brand); }
.post-card .meta { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; font-size: .85rem; color: var(--muted); }
.post-card .text { display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; }
.day-group h3 { margin: 1rem 0 .5rem; font-size: .9rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.post-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.scene { border-left: 3px solid var(--brand); padding: .25rem .75rem; margin: .5rem 0; background: var(--surface-2); border-radius: 0 8px 8px 0; }

/* ---------- charts ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--border); stroke-width: 1; }
.chart .grid-line { stroke: var(--border); stroke-dasharray: 3 4; }
.chart .line { fill: none; stroke: var(--brand); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.second { stroke: var(--ok); }
.chart .area { fill: var(--brand-soft); opacity: .7; }
.chart .dot { fill: var(--brand); }
.chart .bar { fill: var(--brand); }
.chart .bar.low { fill: var(--muted); }
.chart text { fill: var(--muted); font-size: 14px; font-family: var(--font); }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .82rem; color: var(--muted); }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; background: var(--brand); margin-right: .35rem; }
.legend .sw.second { background: var(--ok); }

/* ---------- dialog, toasts ---------- */
.dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 0; width: min(560px, calc(100vw - 1.5rem)); max-height: calc(100vh - 2rem); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(10, 10, 25, .45); }
.dialog .d-head { padding: 1rem 1rem .5rem; } .dialog .d-body { padding: 0 1rem; overflow: auto; max-height: 65vh; }
.dialog .d-foot { padding: .75rem 1rem 1rem; display: flex; justify-content: flex-end; gap: .5rem; flex-wrap: wrap; }
.toasts { position: fixed; right: 1rem; bottom: 1rem; display: grid; gap: .5rem; z-index: 100; max-width: min(420px, calc(100vw - 2rem)); }
.toast { background: var(--text); color: var(--bg); padding: .7rem 1rem; border-radius: 10px; box-shadow: var(--shadow); font-weight: 500; animation: pop .15s ease-out; }
.toast.bad { background: var(--bad); color: #fff; } .toast.ok { background: var(--ok); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
.secret { display: flex; gap: .5rem; align-items: center; background: var(--warn-soft); border: 1px solid var(--warn); border-radius: 8px; padding: .6rem .75rem; }
.secret code { flex: 1; overflow-wrap: anywhere; }
.callout { border-radius: 10px; padding: .75rem 1rem; background: var(--info-soft); color: var(--text); border: 1px solid transparent; margin-bottom: 1rem; }
.callout.warn { background: var(--warn-soft); } .callout.bad { background: var(--bad-soft); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login .card { width: min(440px, 100%); padding: 1.5rem; }
.login .brand { justify-content: center; font-size: 1.3rem; margin-bottom: 1rem; }
.login .brand img { width: 40px; height: 40px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-bottom: 1rem; }
.seg button { border: 0; background: var(--surface); color: var(--muted); font: inherit; font-weight: 600; padding: .55rem; cursor: pointer; }
.seg button.active { background: var(--brand-soft); color: var(--brand); }

@media (max-width: 600px) {
  .kv { grid-template-columns: 1fr; } .kv dt { margin-top: .4rem; }
  .page-head .actions { width: 100%; } .page-head .actions .btn { flex: 1; }
  .hide-sm { display: none; }
  th, td { padding: .5rem; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.unstyled { border: 0; padding: 0; margin: 0; min-width: 0; }
details summary { cursor: pointer; margin: .5rem 0; }
select[multiple] { min-height: 110px; }


.page-head .actions select { width: auto; }

.input-row { display: flex; gap: .5rem; align-items: stretch; }
.input-row input { flex: 1; min-width: 0; }
@media (max-width: 600px) { .input-row { flex-direction: column; } }


.qr-row { display: flex; gap: .75rem; align-items: center; margin-top: .75rem; padding-top: .75rem; border-top: 1px solid var(--border); }
.qr { background: #fff; border-radius: 6px; padding: 4px; flex: none; }
h4 { margin: .6rem 0 .2rem; font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

.export-menu { position: relative; }
.export-menu summary { list-style: none; margin: 0; }
.export-menu summary::-webkit-details-marker { display: none; }
.export-menu-options { position: absolute; top: calc(100% + .35rem); right: 0; z-index: 5; display: grid; gap: .25rem; min-width: 130px; padding: .35rem; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); }
.export-menu-options .btn { justify-content: flex-start; border-color: transparent; }
.seo-card-summary { display: flex; align-items: center; gap: .6rem; list-style: none; margin: 0; }
.seo-card-summary::-webkit-details-marker { display: none; }
.seo-card-summary h2 { flex: 1; min-width: 0; margin: 0; }
.seo-card-toggle::before { content: '⌄'; display: inline-block; color: var(--muted); font-size: 1.2rem; transition: transform .15s ease; }
.seo-card[open] .seo-card-toggle::before { transform: rotate(180deg); }
.seo-card > .card-head { margin-top: .75rem; }

