:root {
  --bg: #f4f2ee; --card: #ffffff; --ink: #141414; --sub: #6b6b6b; --line: rgba(0, 0, 0, .1);
  --accent: #e0502a; --on-accent: #ffffff; --ok: #1f7a4d; --ok-bg: #e3f3ea; --off: #8a8a8a; --off-bg: #ececec; --danger: #b3261e;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121315; --card: #1c1d20; --ink: #f2f2f2; --sub: #a3a3a3; --line: rgba(255, 255, 255, .12);
    --ok: #6fd39d; --ok-bg: rgba(111, 211, 157, .14); --off: #a0a0a0; --off-bg: rgba(255, 255, 255, .08); --danger: #ff8a80;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--ink); font: 400 16px/1.5 Inter, system-ui, sans-serif; min-height: 100vh; }
button, input, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: baseline; gap: 10px; text-decoration: none; color: inherit; font: 800 18px Syne, sans-serif; letter-spacing: .02em; }
.brand b { color: var(--accent); font-weight: inherit; }
.brand span { font: 600 11px Inter, sans-serif; letter-spacing: .2em; text-transform: uppercase; color: var(--sub); }
.bar-links { display: flex; align-items: center; gap: 14px; }
.logout { border: 0; background: none; padding: 0; font-size: 14px; font-weight: 600; color: var(--sub); cursor: pointer; white-space: nowrap; }
.logout[hidden] { display: none; }
.login { max-width: 420px; margin: 12vh auto 0; padding: 28px 24px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.login h1 { font: 800 22px Syne, sans-serif; margin-bottom: 6px; }
.login h1 b { color: var(--accent); }
.login p { color: var(--sub); font-size: 15px; margin-bottom: 18px; }
.login form { display: grid; gap: 14px; }
.login form[hidden] { display: none; }
.login input { width: 100%; min-height: 48px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); font-size: 17px; }
.login input[name="code"] { letter-spacing: .4em; font-size: 22px; text-align: center; }
.login .link { border: 0; background: none; color: var(--accent); font-weight: 600; cursor: pointer; justify-self: start; padding: 0; }
.login .status { min-height: 1.5em; font-size: 14px; color: var(--sub); }
.login .status.bad { color: var(--danger); }
.site-link { font-size: 14px; font-weight: 600; color: var(--accent); text-decoration: none; white-space: nowrap; }

.wrap { max-width: 860px; margin: 0 auto; padding: 20px 16px 120px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.summary { color: var(--sub); font-size: 14px; }
.who { margin-top: 28px; color: var(--sub); font-size: 13px; text-align: center; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 18px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); font-weight: 600; font-size: 15px; cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.big { min-height: 50px; padding: 12px 22px; font-size: 16px; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .55; cursor: progress; }
.icon { width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; font-size: 28px; line-height: 1; cursor: pointer; }

.list { list-style: none; display: flex; flex-direction: column; gap: 12px; }
.loading, .empty { padding: 40px 16px; text-align: center; color: var(--sub); background: var(--card); border: 1px dashed var(--line); border-radius: 12px; }
.item { display: grid; grid-template-columns: 76px minmax(0, 1fr) auto; grid-template-areas: "pic info move" "pic status edit"; gap: 8px 14px; align-items: center; padding: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.item .pic { grid-area: pic; width: 76px; height: 96px; border-radius: 8px; object-fit: cover; background: var(--off-bg); }
.item .pic.none { display: grid; place-items: center; font-size: 11px; color: var(--sub); text-align: center; padding: 6px; }
.item .info { grid-area: info; min-width: 0; }
.item .info strong { display: block; font-size: 16px; line-height: 1.25; overflow-wrap: anywhere; }
.item .info span { display: block; font-size: 13px; color: var(--sub); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .info .warn { color: var(--danger); white-space: normal; }
.item .move { grid-area: move; display: flex; gap: 4px; justify-self: end; }
.item .move button { width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--line); background: transparent; cursor: pointer; font-size: 16px; }
.item .move button:disabled { opacity: .3; cursor: default; }
.item .edit { grid-area: edit; justify-self: end; }
.toggle { grid-area: status; justify-self: start; white-space: nowrap; display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 6px 14px 6px 10px; border-radius: 999px; border: 0; font-size: 13px; font-weight: 700; cursor: pointer; background: var(--ok-bg); color: var(--ok); }
.toggle::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: currentColor; }
.toggle.off { background: var(--off-bg); color: var(--off); }
.toggle:disabled { opacity: .6; cursor: progress; }

.editor { margin: auto; width: min(640px, 100vw); max-width: 100vw; max-height: 100dvh; border: 0; border-radius: 14px; background: var(--card); color: var(--ink); padding: 0; }
.editor::backdrop { background: rgba(0, 0, 0, .55); }
.editor form { display: flex; flex-direction: column; max-height: inherit; }
.ed-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 12px 10px 20px; border-bottom: 1px solid var(--line); }
.ed-head h2 { font-size: 20px; }
.ed-body { overflow: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 18px; }
.ed-photos h3 { font-size: 15px; }
.hint { color: var(--sub); font-size: 13px; margin: 2px 0 10px; }
.photos { list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; margin-bottom: 12px; }
.photos:empty { display: none; }
.photos li { position: relative; border-radius: 8px; overflow: hidden; background: var(--off-bg); aspect-ratio: 3 / 4; }
.photos li.first { outline: 3px solid var(--accent); outline-offset: -3px; }
.photos img { width: 100%; height: 100%; object-fit: cover; }
.photos .tag { position: absolute; top: 6px; left: 6px; padding: 2px 8px; border-radius: 999px; background: var(--accent); color: var(--on-accent); font-size: 11px; font-weight: 700; }
.photos .new { position: absolute; top: 6px; left: 6px; padding: 2px 8px; border-radius: 999px; background: rgba(0, 0, 0, .6); color: #fff; font-size: 11px; font-weight: 600; }
.photos .first .new { top: 30px; }
.photos .tools { position: absolute; inset: auto 0 0 0; display: flex; justify-content: space-between; padding: 6px; background: linear-gradient(transparent, rgba(0, 0, 0, .6)); }
.photos .tools button { width: 34px; height: 34px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .92); color: #111; font-size: 15px; cursor: pointer; }
.photos .tools button:disabled { visibility: hidden; }
.photos .tools .remove { color: var(--danger); }
.upload { width: 100%; border-style: dashed; cursor: pointer; }
.upload:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; border: 0; }
.field input, .field textarea { width: 100%; padding: 12px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); font-size: 16px; font-weight: 400; }
.field textarea { resize: vertical; min-height: 120px; }
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.status legend { margin-bottom: 6px; }
.status { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.status legend { grid-column: 1 / -1; }
.status label { position: relative; }
.status input { position: absolute; opacity: 0; }
.status span { display: flex; align-items: center; justify-content: center; min-height: 48px; border-radius: 8px; border: 1px solid var(--line); font-weight: 600; cursor: pointer; }
.status input:checked + span { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.status input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.error { padding: 10px 14px; border-radius: 8px; background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); font-size: 14px; }
.ed-foot { display: flex; justify-content: space-between; gap: 12px; padding: 12px 20px; padding-bottom: max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.ed-foot .primary { flex: 1; max-width: 260px; margin-left: auto; }

.toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50; max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 10px; background: var(--ink); color: var(--bg); font-size: 14px; font-weight: 600; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); }
.toast.bad { background: var(--danger); color: #fff; }

@media (max-width: 640px) {
  .brand span { display: none; }
  .toolbar .big { width: 100%; }
  .editor { width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
  .editor form { height: 100%; }
  .ed-body { flex: 1; }
}

.tabs { display: flex; gap: 4px; margin-right: auto; margin-left: 8px; }
.tabs a { padding: 8px 12px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--sub); text-decoration: none; white-space: nowrap; }
.tabs a[aria-current="true"] { background: var(--card); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }

.traffic { display: block; }
.traffic[hidden] { display: none; }
.messages[hidden] { display: none; }
.messages .toolbar h2 { font-size: 20px; }
.tabs .count { display: inline-block; min-width: 20px; margin-left: 4px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: var(--on-accent); font-size: 12px; line-height: 20px; text-align: center; }
.msg { background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.msg.unread { border-color: var(--accent); }
.msg summary { display: grid; grid-template-columns: minmax(0, auto) minmax(0, 1fr) auto; gap: 12px; align-items: baseline; padding: 14px 16px; cursor: pointer; list-style: none; }
.msg summary::-webkit-details-marker { display: none; }
.m-who { font-weight: 700; }
.msg.unread .m-who::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 8px; border-radius: 50%; background: var(--accent); vertical-align: middle; }
.m-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--sub); }
.m-when { font-size: 13px; color: var(--sub); white-space: nowrap; }
.m-body { display: grid; gap: 12px; padding: 0 16px 16px; }
.m-meta { font-size: 14px; }
.m-meta a { color: var(--accent); }
.m-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.m-note { font-size: 13px; color: var(--sub); }
.m-actions { display: flex; flex-wrap: wrap; gap: 8px; }
@media (max-width: 600px) {
  .msg summary { grid-template-columns: minmax(0, 1fr) auto; }
  .m-subject { grid-column: 1 / -1; grid-row: 2; }
}
.t-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.t-head h2 { font-size: 20px; }
.periods { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.periods button { min-height: 36px; padding: 6px 12px; border: 0; border-radius: 7px; background: transparent; font-size: 13px; font-weight: 600; color: var(--sub); cursor: pointer; }
.periods button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.t-body { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; transition: opacity .2s; }
.t-body.busy { opacity: .5; }
.t-body > .t-empty, .t-foot, .kpis, .t-card.wide { grid-column: 1 / -1; }
.t-empty { padding: 28px 16px; text-align: center; color: var(--sub); background: var(--card); border: 1px dashed var(--line); border-radius: 12px; font-size: 14px; }
.t-card .t-empty { padding: 12px 0; background: none; border: 0; text-align: left; }
.t-empty.bad { color: var(--danger); }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.kpi { padding: 14px 16px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.kpi span { display: block; font-size: 13px; color: var(--sub); }
.kpi strong { display: block; margin-top: 2px; font-size: 28px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.t-card { min-width: 0; padding: 16px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.t-card h3 { font-size: 15px; margin-bottom: 10px; }
.t-hint { margin: -4px 0 12px; font-size: 13px; color: var(--sub); }
.t-foot { font-size: 12px; color: var(--sub); line-height: 1.5; }

.rank, .sources { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.rank li, .sources summary { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: baseline; }
.rank-label { min-width: 0; font-size: 14px; font-weight: 500; overflow-wrap: anywhere; }
.rank-label small { display: block; font-size: 12px; font-weight: 400; color: var(--sub); }
.rank-value { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rank-value small { margin-left: 6px; font-size: 12px; font-weight: 400; color: var(--sub); }
.rank-track { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--off-bg); overflow: hidden; }
.rank-fill { display: block; height: 100%; border-radius: 3px; background: var(--accent); }

.sources > li { border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.sources > li:last-child { border-bottom: 0; padding-bottom: 0; }
.sources summary { list-style: none; cursor: pointer; padding: 4px 0; }
.sources summary::-webkit-details-marker { display: none; }
.sources summary .rank-label::before { content: "▸"; display: inline-block; width: 16px; color: var(--sub); transition: transform .15s; }
.sources details[open] summary .rank-label::before { transform: rotate(90deg); }
.source-detail { margin: 10px 0 4px 16px; padding-left: 12px; border-left: 2px solid var(--line); }
.source-detail h4 { margin: 6px 0 8px; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--sub); }
.source-detail .rank { margin-bottom: 10px; }
.source-detail .rank-fill { background: color-mix(in srgb, var(--accent) 55%, var(--card)); }

.chart-wrap { position: relative; }
.chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--sub); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .col { fill: var(--accent); }
.chart .hit { fill: transparent; }
.chart .day.on .hit { fill: color-mix(in srgb, var(--ink) 6%, transparent); }
.tip { position: absolute; top: 4px; transform: translateX(-50%); z-index: 2; display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; border-radius: 8px; background: var(--ink); color: var(--bg); font-size: 12px; white-space: nowrap; pointer-events: none; box-shadow: 0 6px 20px rgba(0, 0, 0, .2); }
.tip strong { font-size: 12px; }
.tip[hidden] { display: none; }

@media (max-width: 640px) {
  .bar { flex-wrap: wrap; row-gap: 8px; }
  .tabs { order: 3; width: 100%; margin: 0; }
  .tabs a { flex: 1; text-align: center; }
  .t-body { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi strong { font-size: 24px; }
}
