:root {
  --bg: #e9ebf4;
  --card: #ffffff;
  --ink: #1c1e2b;
  --ink2: #6b6e85;
  --ink3: #9fa2b8;
  --line: #eceef6;
  --orange: #ff7a35;
  --orange-soft: #fff0e6;
  --purple: #a76bff;
  --indigo: #4f5bf0;
  --soft: #f3f1ff;
  --good: #1f9d68;
  --bad: #e5484d;
  --shadow: 0 1px 2px rgba(40, 44, 90, .04), 0 14px 34px rgba(40, 44, 90, .07);
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-height: 100vh; font: 14px/1.45 'Segoe UI Variable Text', 'Segoe UI', system-ui, -apple-system, Roboto, Arial, sans-serif; color: var(--ink); font-variant-numeric: tabular-nums; background: linear-gradient(160deg, #eef0f9 0%, #e4e6f1 100%) fixed; }
button, input, select { font: inherit; color: inherit; }
svg { display: block; }
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.spacer { flex: 1; }

/* кнопки */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 20px; border: 0; background: var(--ink); color: #fff; border-radius: 999px; cursor: pointer; font-weight: 600; transition: transform .12s, box-shadow .12s; }
.btn:hover { transform: translateY(-1px); box-shadow: 0 8px 18px rgba(28, 30, 43, .22); }
.btn.ghost { background: #fff; color: var(--ink); box-shadow: var(--shadow); font-weight: 500; }
.btn.ghost:hover { box-shadow: 0 8px 22px rgba(40, 44, 90, .14); }
.btn.sm { padding: 7px 14px; font-size: 13px; }
.btn.danger { background: #fff; color: var(--bad); box-shadow: var(--shadow); font-weight: 500; }

/* вход */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login > form, .login > div { width: 100%; max-width: 380px; background: #fff; border-radius: 28px; padding: 38px 34px 30px; box-shadow: var(--shadow); }
.login h1 { font-size: 30px; line-height: 1.1; margin: 0 0 6px; font-weight: 800; letter-spacing: -.02em; }
.login p { margin: 0 0 22px; color: var(--ink2); }
.login input { width: 100%; padding: 13px 16px; border: 1px solid var(--line); background: #f7f8fc; border-radius: 14px; margin-bottom: 12px; outline: none; }
.login input:focus { border-color: var(--purple); background: #fff; }
.login .btn { width: 100%; padding: 13px; }
.login .err { color: var(--bad); min-height: 22px; font-size: 14px; margin-top: 8px; }

/* каркас */
.layout { display: flex; min-height: 100vh; }
.side { width: 244px; flex: none; background: #fff; box-shadow: var(--shadow); padding: 22px 16px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; z-index: 10; }
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 0 8px; }
.logo { display: block; height: 30px; width: auto; }
.brand .prod { font-size: 12.5px; font-weight: 600; color: var(--ink3); letter-spacing: .02em; }
.login .logo { height: 32px; margin-bottom: 22px; }
.side select.site { width: 100%; padding: 11px 34px 11px 14px; border: 0; background: #f4f5fb url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%231c1e2b' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 14px center / 10px; appearance: none; border-radius: 14px; font-weight: 600; cursor: pointer; }
.side .site-name { padding: 11px 14px; font-weight: 700; background: #f4f5fb; border-radius: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side nav { display: flex; flex-direction: column; gap: 4px; }
.side nav button { display: flex; align-items: center; gap: 12px; border: 0; background: transparent; padding: 11px 14px; border-radius: 14px; cursor: pointer; text-align: left; color: var(--ink2); font-size: 14.5px; font-weight: 500; transition: background .12s, color .12s; }
.side nav button .ic { color: var(--ink3); }
.side nav button:hover { background: #f6f7fc; color: var(--ink); }
.side nav button.on { background: var(--soft); color: var(--indigo); font-weight: 700; }
.side nav button.on .ic { color: var(--indigo); }
.live-dot { display: inline-flex; align-items: center; gap: 9px; font-size: 13.5px; color: var(--ink2); padding: 0 10px; }
.live-dot i { width: 9px; height: 9px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 0 rgba(31, 157, 104, .5); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(31, 157, 104, 0); } 100% { box-shadow: 0 0 0 0 rgba(31, 157, 104, 0); } }

.content { flex: 1; min-width: 0; }
.bar { display: flex; align-items: flex-end; gap: 14px; padding: 26px 34px 0; flex-wrap: wrap; }
.bar .date { color: var(--ink3); font-size: 13.5px; margin-bottom: 2px; }
.bar h1 { margin: 0; font-size: 30px; line-height: 1.1; font-weight: 800; letter-spacing: -.02em; }
.periods { display: flex; background: #fff; border-radius: 999px; padding: 4px; box-shadow: var(--shadow); }
.periods button { border: 0; background: transparent; padding: 8px 15px; border-radius: 999px; cursor: pointer; font-size: 13.5px; color: var(--ink2); white-space: nowrap; }
.periods button:hover { color: var(--ink); }
.periods button.on { background: var(--ink); color: #fff; font-weight: 600; }
.range { display: none; align-items: center; gap: 8px; }
.range.show { display: flex; }
.range input { padding: 8px 12px; border: 0; background: #fff; border-radius: 999px; box-shadow: var(--shadow); }
main { padding: 20px 34px 70px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 8px 6px 14px; background: #fff; border-radius: 999px; box-shadow: var(--shadow); font-size: 13.5px; }
.chip b { font-weight: 700; }
.chip button { border: 0; background: var(--soft); border-radius: 50%; cursor: pointer; padding: 4px; display: grid; place-items: center; color: var(--indigo); }
.chip button .ic { width: 13px; height: 13px; }

/* показатели */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(235px, 1fr)); gap: 16px; margin-bottom: 18px; }
.kc { background: #fff; border-radius: 22px; padding: 20px 22px 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; justify-content: space-between; min-height: 142px; }
.kc-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.kc .l { color: var(--ink2); font-size: 13.5px; margin-bottom: 6px; }
.kc .v { font-size: 32px; font-weight: 800; letter-spacing: -.03em; line-height: 1.05; }
.kc .d { font-size: 12.5px; color: var(--ink3); margin-top: 12px; }
.kc .d.up { color: var(--good); }
.kc .d.down { color: var(--bad); }
.sp rect { fill: var(--orange); }
.sp.p rect { fill: var(--purple); }
.ring .tr { fill: none; stroke: #eef0f9; stroke-width: 8; }
.ring .ar { fill: none; stroke: var(--purple); stroke-width: 8; stroke-linecap: round; }
.ring.o .ar { stroke: var(--orange); }
.ring text { font-size: 15px; font-weight: 800; fill: var(--ink); }

/* карточки */
.card { background: #fff; border-radius: 22px; box-shadow: var(--shadow); overflow: hidden; }
.card h3 { margin: 0; padding: 20px 22px 12px; font-size: 16px; font-weight: 700; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card h3 small { font-weight: 400; color: var(--ink3); font-size: 13px; }
.chart { margin-bottom: 18px; }
.chart .hd { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px 0; flex-wrap: wrap; gap: 10px; }
.legend { display: flex; gap: 8px; flex-wrap: wrap; }
.legend label { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; user-select: none; padding: 6px 13px 6px 10px; background: #f6f7fc; border-radius: 999px; color: var(--ink2); }
.legend label:has(input:checked) { color: var(--ink); background: var(--soft); }
.legend input { position: absolute; opacity: 0; pointer-events: none; }
.legend i { width: 11px; height: 11px; border-radius: 50%; display: inline-block; border: 2px solid transparent; }
.legend input:not(:checked) + i { background: #fff !important; border-color: #c9cbdc; }
.plot { position: relative; padding: 8px 14px 14px; }
.plot svg { width: 100%; height: 290px; overflow: visible; }
.plot .tip { position: absolute; pointer-events: none; background: var(--ink); color: #fff; padding: 10px 14px; font-size: 13px; line-height: 1.6; border-radius: 14px; transform: translate(-50%, -100%); white-space: nowrap; display: none; z-index: 5; box-shadow: 0 10px 26px rgba(28, 30, 43, .3); }
.plot .tip b { font-weight: 700; }
.empty { padding: 8px 22px 26px; color: var(--ink3); font-size: 14px; max-width: 520px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 430px), 1fr)); gap: 18px; }
.grid .wide { grid-column: 1 / -1; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th { font-weight: 500; font-size: 12px; color: var(--ink3); text-align: right; padding: 0 22px 8px 6px; white-space: nowrap; }
th:first-child { text-align: left; padding-left: 22px; }
th:not(:first-child) { width: 86px; }
td { padding: 0; font-size: 14px; text-align: right; white-space: nowrap; }
td.k { text-align: left; position: relative; }
td.n { padding: 8px 22px 8px 6px; width: 86px; overflow: hidden; }
tr.dr td { border-top: 1px solid var(--line); }
td.k .bar { position: absolute; left: 12px; top: 3px; bottom: 3px; background: var(--orange-soft); border-radius: 10px; z-index: 0; }
td.k .t { position: relative; z-index: 1; display: block; padding: 8px 22px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.k a { color: inherit; text-decoration: none; cursor: pointer; }
td.k a:hover { color: var(--indigo); text-decoration: underline; text-underline-offset: 3px; }
td.k .sub { display: block; font-size: 12px; color: var(--ink3); overflow: hidden; text-overflow: ellipsis; }
.more { display: block; width: 100%; border: 0; border-top: 1px solid var(--line); background: transparent; padding: 12px; cursor: pointer; color: var(--indigo); font-size: 13px; font-weight: 600; }
.more:hover { background: var(--soft); }
.sub-row td { background: #f8f8fd; border-top: 1px solid var(--line); }
.sub-row .inner { padding: 10px 22px 12px; text-align: left; white-space: normal; font-size: 13px; color: var(--ink2); }
.sub-row .inner div { display: flex; justify-content: space-between; gap: 16px; padding: 2px 0; }

.hours { display: flex; align-items: flex-end; gap: 4px; height: 150px; padding: 6px 22px 0; }
.hours i { flex: 1; background: var(--orange); border-radius: 6px; min-height: 3px; }
.hours i:nth-child(3n) { background: var(--purple); }
.hours i:hover { filter: brightness(.9); }
.hours-l { display: flex; gap: 4px; padding: 6px 22px 18px; font-size: 11px; color: var(--ink3); }
.hours-l span { flex: 1; text-align: center; }

/* сейчас */
.now-top { display: flex; align-items: flex-end; gap: 40px; flex-wrap: wrap; margin-bottom: 18px; background: #fff; border-radius: 22px; box-shadow: var(--shadow); padding: 26px 28px; }
.now-top .big { font-size: 84px; font-weight: 800; line-height: .9; letter-spacing: -.04em; }
.now-top .cap { color: var(--ink2); margin-top: 8px; }
.spark { display: flex; align-items: flex-end; gap: 4px; height: 76px; flex: 1; min-width: 260px; }
.spark i { flex: 1; background: var(--orange); border-radius: 5px; min-height: 3px; }
.spark i:nth-child(3n) { background: var(--purple); }
.feed { font-size: 14px; }
.feed .r { display: grid; grid-template-columns: 70px 1fr auto; gap: 12px; padding: 10px 22px; border-top: 1px solid var(--line); align-items: baseline; }
.feed .tm { color: var(--ink3); }
.feed .p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed .m { color: var(--ink3); font-size: 13px; text-align: right; }
.tag { display: inline-block; padding: 2px 10px; background: var(--soft); color: var(--indigo); font-size: 12px; border-radius: 999px; margin-right: 10px; font-weight: 600; }
.tag.ev { background: var(--orange-soft); color: #d9531a; }

/* подключение */
.site-box { background: #fff; border-radius: 22px; box-shadow: var(--shadow); padding: 24px; margin-bottom: 18px; }
.site-box h3 { margin: 0 0 4px; font-size: 18px; }
.site-box .meta { color: var(--ink2); font-size: 14px; margin-bottom: 12px; }
.code { position: relative; background: #1c1e2b; color: #e7e8f5; padding: 16px 58px 16px 18px; font: 13px/1.5 Consolas, 'Courier New', monospace; overflow-x: auto; white-space: pre; border-radius: 16px; }
.code .btn { position: absolute; right: 8px; top: 8px; padding: 8px 10px; background: #353852; box-shadow: none; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 14px; }
.row input { padding: 10px 16px; border: 1px solid var(--line); background: #f7f8fc; border-radius: 999px; min-width: 220px; flex: 1; max-width: 420px; outline: none; }
.row input:focus { border-color: var(--purple); background: #fff; }
.how { max-width: 820px; color: var(--ink2); }
.how h3 { color: var(--ink); margin: 24px 0 6px; font-size: 16px; }
.how code { background: #fff; padding: 2px 8px; font: 13px Consolas, monospace; border-radius: 8px; color: var(--ink); }
.how li { margin: 3px 0; }

.content[data-tab=setup] .periods, .content[data-tab=log] .periods, .content[data-tab=now] .periods, .content[data-tab=setup] .range, .content[data-tab=log] .range, .content[data-tab=now] .range { display: none; }

@media (max-width: 860px) {
  body { padding-bottom: 76px; }
  .layout { flex-direction: column; }
  .side { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 14px 16px 12px; gap: 10px 12px; border-radius: 0 0 24px 24px; }
  .brand { order: 1; flex: 1; flex-direction: row; align-items: center; gap: 10px; padding: 0; min-width: 0; }
  .logo { height: 26px; }
  .brand .prod { display: none; }
  .live-dot { order: 2; padding: 0; font-size: 12.5px; }
  .side .btn.ghost.sm { order: 3; padding: 7px 12px; }
  .side select.site, .side .site-name { order: 4; flex-basis: 100%; }
  .side .spacer { display: none; }
  .side nav { position: fixed; left: 10px; right: 10px; bottom: 10px; z-index: 30; flex-direction: row; gap: 2px; padding: 6px; background: #fff; border-radius: 22px; box-shadow: 0 8px 30px rgba(40, 44, 90, .22); padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  .side nav button { flex: 1; flex-direction: column; gap: 3px; padding: 8px 4px 7px; font-size: 11.5px; text-align: center; border-radius: 16px; min-width: 0; }
  .side nav button .ic { width: 22px; height: 22px; }
  .bar { padding: 18px 16px 0; gap: 12px; }
  .bar h1 { font-size: 26px; }
  .bar > div:first-child { flex: 1 1 100%; }
  .periods { max-width: 100%; overflow-x: auto; scrollbar-width: none; flex: 1 1 100%; }
  .periods::-webkit-scrollbar { display: none; }
  .periods button { padding: 8px 13px; flex: none; }
  .range { flex: 1 1 100%; }
  .range input { flex: 1; min-width: 0; }
  main { padding: 14px 16px 24px; }
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .grid { gap: 14px; }
  .card, .kc, .site-box, .now-top { border-radius: 20px; }
  .plot svg { height: 230px; }
  .now-top .big { font-size: 64px; }
  .now-top { gap: 20px; padding: 20px; }
}

@media (max-width: 560px) {
  .kc { padding: 15px 15px 13px; min-height: 0; }
  .kc-top { flex-direction: column-reverse; align-items: flex-start; gap: 10px; }
  .kc .l { font-size: 12.5px; margin-bottom: 4px; }
  .kc .v { font-size: 25px; }
  .kc .d { margin-top: 8px; font-size: 12px; }
  .kc .d .dt { display: none; }
  .sp { width: auto; height: 30px; }
  .ring { width: 54px; height: 54px; }
  .ring text { font-size: 17px; }
  .card h3 { padding: 16px 16px 10px; font-size: 15px; }
  .chart .hd { padding: 16px 16px 0; }
  .legend label { padding: 5px 11px 5px 8px; font-size: 12.5px; }
  .plot { padding: 6px 4px 10px; }
  th, th:first-child { font-size: 11.5px; }
  th:first-child { padding-left: 16px; }
  th { padding-right: 12px; }
  th:not(:first-child), td.n { width: 58px; }
  td.n { padding: 8px 12px 8px 4px; font-size: 13px; }
  td.k .t { padding: 8px 16px; font-size: 13.5px; }
  td.k .bar { left: 8px; }
  th:nth-child(5), td:nth-child(5) { display: none; }
  .hours { padding: 6px 16px 0; gap: 3px; }
  .hours-l { padding: 6px 16px 16px; gap: 3px; }
  .empty { padding: 4px 16px 20px; }
  .feed .r { grid-template-columns: 56px 1fr; padding: 9px 16px; }
  .feed .m { grid-column: 2; text-align: left; font-size: 12px; }
  .site-box { padding: 18px 16px; }
  .code { white-space: pre-wrap; word-break: break-all; font-size: 12px; padding-right: 54px; }
  .row input { min-width: 0; max-width: none; flex: 1 1 100%; }
  .row .btn { flex: 1 1 auto; }
  .chip { font-size: 13px; }
  .login > form, .login > div { padding: 30px 22px 24px; border-radius: 24px; }
}
