:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --text: #1f2328;
    --muted: #656d76;
    --border: #d8dde3;
    --accent: #2f6fdf;
    --accent-hover: #2459b8;
    --danger: #c23b3b;
    --ok-bg: #e7f5ea;
    --ok-text: #1d6b33;
    --err-bg: #fbeaea;
    --err-text: #9b2525;
    --info-bg: #eaf1fc;
    --info-text: #1f4d99;
    --warn-bg: #fdf3dc;
    --warn-text: #7a5300;
    --radius: 6px;
}

* { box-sizing: border-box; }

html { font-size: 15px; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .75rem; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
code { font-family: ui-monospace, Consolas, monospace; font-size: .9em; background: var(--bg); padding: 0 .25rem; border-radius: 3px; }
.nowrap { white-space: nowrap; }

/* Top bar and shell */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .6rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 600; color: var(--text); }
.topbar .user-box { display: flex; align-items: center; gap: .75rem; }
.topbar form { margin: 0; }

.shell { display: flex; min-height: calc(100vh - 50px); }

.sidenav {
    flex: 0 0 210px;
    padding: 1rem .75rem;
    background: var(--surface);
    border-right: 1px solid var(--border);
}
.sidenav ul { list-style: none; margin: 0 0 1rem; padding: 0; }
.sidenav a {
    display: block;
    padding: .4rem .6rem;
    border-radius: var(--radius);
    color: var(--text);
}
.sidenav a:hover { background: var(--bg); text-decoration: none; }
.sidenav a.active { background: var(--info-bg); color: var(--info-text); font-weight: 600; }
.sidenav .nav-section {
    margin: .5rem .6rem .25rem;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
}

.main { flex: 1; min-width: 0; padding: 1.5rem; }
.main-narrow { max-width: 420px; margin: 4rem auto; padding: 0 1rem; }

/* Cards and flashes */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
    max-width: 640px;
}
.card-wide { max-width: none; }

.flash { padding: .6rem .9rem; border-radius: var(--radius); margin-bottom: 1rem; }
.flash-success { background: var(--ok-bg); color: var(--ok-text); }
.flash-error { background: var(--err-bg); color: var(--err-text); }
.flash-info { background: var(--info-bg); color: var(--info-text); }
.flash-warning { background: var(--warn-bg); color: var(--warn-text); }
.field .flash { margin: .5rem 0 0; }

/* Forms */
.field { margin-bottom: 1rem; }
.field label, .field .label { display: block; font-weight: 600; margin-bottom: .3rem; }
.field .hint { font-size: .85rem; color: var(--muted); margin-top: .2rem; }
.field-error { color: var(--danger); font-size: .875rem; margin-top: .25rem; }

input[type=text], input[type=password], input[type=number], input[type=date], input[type=datetime-local], input[type=search], select, textarea {
    width: 100%;
    max-width: 100%;
    padding: .45rem .6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    font: inherit;
    color: inherit;
}
textarea { resize: vertical; min-height: 4.5rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.checkbox { display: flex; align-items: center; gap: .45rem; margin-bottom: .35rem; font-weight: normal; }
.checkbox input { margin: 0; }

.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

.btn {
    display: inline-block;
    padding: .45rem 1rem;
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    background: var(--accent);
    color: #fff;
    font: inherit;
    cursor: pointer;
}
.btn:hover { background: var(--accent-hover); text-decoration: none; }
.btn-secondary { background: var(--surface); color: var(--accent); }
.btn-secondary:hover { background: var(--info-bg); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--err-bg); }
.btn-link { background: none; border: none; color: var(--accent); padding: 0; cursor: pointer; font: inherit; }
.btn-link:hover { text-decoration: underline; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { text-align: left; padding: .5rem .7rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .85rem; color: var(--muted); font-weight: 600; }
tr.row-disabled td { color: var(--muted); }

.badge {
    display: inline-block;
    padding: .05rem .5rem;
    border-radius: 999px;
    font-size: .8rem;
    background: var(--bg);
    border: 1px solid var(--border);
}
.badge-ok { background: var(--ok-bg); color: var(--ok-text); border-color: transparent; }
.badge-off { background: var(--err-bg); color: var(--err-text); border-color: transparent; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }

.filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; margin-bottom: 1rem; }
.filters .field { margin: 0; min-width: 160px; }

.pager { display: flex; gap: .75rem; align-items: center; margin-top: 1rem; }

.details { font-family: ui-monospace, Consolas, monospace; font-size: .8rem; word-break: break-word; max-width: 480px; }

.sort-link { color: inherit; }
.inline-form { display: inline; margin-left: .5rem; }

/* Knowledge Base */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .75rem; }
.tile {
    display: flex; flex-direction: column; gap: .25rem;
    padding: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text);
}
.tile:hover { border-color: var(--accent); text-decoration: none; }
.tile-title { font-weight: 600; }
.tile-accent { border-color: var(--accent); }
.card-toolbar { display: flex; justify-content: flex-end; gap: .5rem; margin-bottom: .5rem; }
.btn-copy {
    padding: .15rem .6rem; border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); color: var(--accent); font: inherit; font-size: .8rem; cursor: pointer;
}
.btn-copy:hover { background: var(--info-bg); }
.copy-block { position: relative; }
.copy-block .btn-copy { position: absolute; top: .4rem; right: .4rem; }
.copy-buffer { position: fixed; left: -9999px; top: 0; }
.template { padding: .75rem 0; border-top: 1px solid var(--border); }
.template:first-of-type { border-top: none; }
.template-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .4rem; }
.template details, .template-new { margin-top: .5rem; }
.template summary, .template-new summary { cursor: pointer; color: var(--accent); }
.template-form { margin: .75rem 0; max-width: 640px; }
.badge-publication-live { background: var(--ok-bg); color: var(--ok-text); border-color: transparent; }
.badge-publication-removed { background: var(--err-bg); color: var(--err-text); border-color: transparent; }
.badge-strategy-active { background: var(--ok-bg); color: var(--ok-text); border-color: transparent; }
.badge-strategy-draft { background: var(--info-bg); color: var(--info-text); border-color: transparent; }
/* Matrix */
.matrix-summary { font-weight: 600; margin: .5rem 0; }
.matrix-legend { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-bottom: 1rem; }
.matrix-wrap { overflow: auto; max-height: 75vh; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.matrix { border-collapse: separate; border-spacing: 0; width: auto; min-width: 100%; }
table.matrix th, table.matrix td { padding: .25rem; border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); }
table.matrix thead th { position: sticky; top: 0; z-index: 2; background: var(--surface); vertical-align: bottom; }
table.matrix .matrix-strategy { min-width: 110px; max-width: 150px; font-size: .8rem; font-weight: 600; color: var(--text); }
table.matrix .matrix-venue { position: sticky; left: 0; z-index: 1; background: var(--surface); min-width: 200px; max-width: 260px; font-weight: normal; color: var(--text); }
table.matrix .matrix-corner { left: 0; z-index: 3; }
.cell {
    display: block; min-width: 96px; padding: .3rem .4rem; border-radius: 4px; font-size: .8rem; text-align: center;
    white-space: nowrap; color: var(--text); border: 1px solid transparent;
}
.matrix-legend .cell, .matrix-panel .cell { display: inline-block; min-width: 0; }
a.cell:hover { text-decoration: none; border-color: var(--accent); }
.cell-na { background: var(--bg); color: var(--muted); }
.cell-forbidden { background: var(--err-bg); color: var(--err-text); }
.cell-blocked { background: var(--warn-bg); color: var(--warn-text); }
.cell-never { background: var(--surface); color: var(--info-text); border-color: var(--border); border-style: dashed; }
.cell-recent { background: var(--ok-bg); color: var(--ok-text); }
.cell-due { background: var(--accent); color: #fff; font-weight: 600; }
.cell-count { margin-left: .2rem; opacity: .8; }
.cell-removed { margin-left: .2rem; font-weight: 700; color: var(--danger); }
.cell-due .cell-removed { color: #fff; }
.matrix-panel { border-color: var(--accent); }
.matrix-actions { margin-top: .75rem; }
.matrix-forbid { display: flex; gap: .5rem; flex-wrap: wrap; }
.matrix-forbid input[type=text] { width: 320px; }
.today-date { font-size: 1rem; font-weight: normal; }
.today-summary { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; align-items: baseline; margin-bottom: 1rem; }
.today-counter { color: var(--text); }
.today-items { list-style: none; margin: 0; padding: 0; }
.today-item { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem 1rem; padding: .6rem 0; border-top: 1px solid var(--border); }
.today-item:first-child { border-top: none; }
.today-main { flex: 1 1 320px; min-width: 0; overflow-wrap: anywhere; }
.today-title { font-weight: 600; }
.today-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.today-actions .inline-form { margin-left: 0; }
/* Report */
.report-section > summary { cursor: pointer; list-style: none; }
.report-section > summary::-webkit-details-marker { display: none; }
.report-section > summary h2 { display: inline; margin: 0; }
.report-section > summary::before { content: '▾ '; color: var(--muted); }
.report-section:not([open]) > summary::before { content: '▸ '; }
.report-section h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
.report-kpis { display: flex; flex-wrap: wrap; gap: .75rem; margin: .75rem 0; }
.report-kpis > div { min-width: 120px; padding: .5rem .75rem; background: var(--bg); border-radius: var(--radius); }
.report-kpis strong { display: block; font-size: 1.3rem; }
.report-kpis small { font-size: .8rem; font-weight: normal; color: var(--muted); }
.report-kpis span { font-size: .8rem; color: var(--muted); }
.report-days { max-height: 360px; }
.report-days td { padding: .15rem .5rem; border-bottom: none; }
.report-bar-cell { width: 70%; }
.report-bar { display: block; height: .7rem; min-width: 1px; background: var(--accent); border-radius: 2px; }
.bar-0 { width: 0%; }
.bar-1 { width: 5%; }
.bar-2 { width: 10%; }
.bar-3 { width: 15%; }
.bar-4 { width: 20%; }
.bar-5 { width: 25%; }
.bar-6 { width: 30%; }
.bar-7 { width: 35%; }
.bar-8 { width: 40%; }
.bar-9 { width: 45%; }
.bar-10 { width: 50%; }
.bar-11 { width: 55%; }
.bar-12 { width: 60%; }
.bar-13 { width: 65%; }
.bar-14 { width: 70%; }
.bar-15 { width: 75%; }
.bar-16 { width: 80%; }
.bar-17 { width: 85%; }
.bar-18 { width: 90%; }
.bar-19 { width: 95%; }
.bar-20 { width: 100%; }
.report-breakdowns { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 0 1.5rem; }
.report-list { columns: 2 260px; margin: .25rem 0; padding-left: 1.1rem; }
.rule-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: baseline; padding: .35rem 0; }
.rule-form { margin-top: .75rem; max-width: 640px; }
.link-row { padding: .5rem 0; border-top: 1px solid var(--border); }
.link-row:first-of-type { border-top: none; }
.link-head { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.link-target { overflow-wrap: anywhere; margin-top: .2rem; }
.screenshots { display: flex; flex-wrap: wrap; gap: .75rem; }
.screenshot { margin: 0; width: 180px; }
.screenshot img { display: block; width: 100%; height: 120px; object-fit: cover; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); }
.screenshot figcaption { margin-top: .25rem; overflow-wrap: anywhere; }
.check-form { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; margin-top: 1rem; }
.check-form .field { margin: 0; width: 140px; }
.check-form .check-note { flex: 1 1 260px; width: auto; }
.check-form .actions { flex-basis: 100%; }
.file-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: .6rem; }
.file-row .inline-form { margin-left: 0; }
.upload-form { margin-top: .75rem; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.upload-form .hint { flex-basis: 100%; }
.markdown { overflow-wrap: anywhere; }
.markdown > :first-child { margin-top: 0; }
.markdown pre {
    white-space: pre-wrap; margin: .75rem 0; padding: .75rem 5.5rem .75rem .75rem;
    background: var(--bg); border-radius: var(--radius); font-family: ui-monospace, Consolas, monospace; font-size: .875rem;
}
.markdown code { font-family: ui-monospace, Consolas, monospace; }
.markdown blockquote { margin: .75rem 0; padding-left: .9rem; border-left: 3px solid var(--border); color: var(--muted); }
.markdown img { max-width: 100%; }
.plain-list { list-style: none; margin: 0; padding: 0; }
.plain-list li { padding: .25rem 0; }
.history { margin-top: 1rem; }
.badge-account-active { background: var(--ok-bg); color: var(--ok-text); border-color: transparent; }
.badge-account-warming { background: var(--info-bg); color: var(--info-text); border-color: transparent; }
.badge-account-restricted { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
.badge-account-banned { background: var(--err-bg); color: var(--err-text); border-color: transparent; }
.badge-warn { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
.badge-ads-yes { background: var(--ok-bg); color: var(--ok-text); border-color: transparent; }
.badge-ads-no { background: var(--err-bg); color: var(--err-text); border-color: transparent; }

.props { display: grid; grid-template-columns: minmax(140px, max-content) 1fr; gap: .45rem 1.25rem; margin: 0; }
.props dt { color: var(--muted); }
.props dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.pre-wrap { white-space: pre-wrap; }
pre.rules {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    margin: 0;
    padding: .75rem;
    background: var(--bg);
    border-radius: var(--radius);
    font-family: ui-monospace, Consolas, monospace;
    font-size: .875rem;
}
textarea.mono { font-family: ui-monospace, Consolas, monospace; font-size: .875rem; }
.flash ul { margin: .25rem 0 .5rem; padding-left: 1.25rem; }
.flash p { margin: 0; }

.error-page { text-align: center; padding-top: 2rem; }
.error-code { font-size: 3rem; font-weight: 700; color: var(--muted); margin: 0; }

/* Phone */
@media (max-width: 800px) {
    .shell { flex-direction: column; }
    .sidenav { flex: none; border-right: none; border-bottom: 1px solid var(--border); padding: .5rem; }
    .sidenav ul { display: flex; flex-wrap: wrap; gap: .25rem; margin: 0; }
    .sidenav .nav-section { display: none; }
    .main { padding: 1rem; }
    .main-narrow { margin: 2rem auto; }
    .topbar { padding: .5rem 1rem; }
    .props { grid-template-columns: 1fr; gap: .1rem; }
    .props dd { margin-bottom: .5rem; }
}
