/* Учёт подписок: светлая спокойная тема, сначала телефон */
:root {
  --bg: #f5f4ef;
  --card: #ffffff;
  --ink: #1e2a2b;
  --ink-2: #55615f;
  --ink-3: #7d8785;
  --line: #e3e1d9;
  --accent: #1d5a4c;
  --accent-ink: #ffffff;
  --accent-soft: #e4efeb;
  --late: #a9412b;
  --late-soft: #f7e7e1;
  --now: #8a5a12;
  --now-soft: #f6ecd6;
  --series-margin: #12876a;
  --series-cost: #c47a1e;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(30, 42, 43, .06);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
h1 { font-size: 26px; line-height: 1.2; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 18px; margin: 28px 0 10px; display: flex; align-items: baseline; gap: 8px; }
h3 { font-size: 17px; margin: 0; }
p { margin: 0 0 10px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--ink-3); }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.r { text-align: right; }
.b { font-weight: 600; }
.offscreen { position: fixed; left: -999px; top: 0; }
.boot { padding: 40px 16px; color: var(--ink-2); }
.count { font-size: 14px; font-weight: 500; color: var(--ink-3); margin-left: 6px; }
.empty { color: var(--ink-3); padding: 18px 0; margin: 0; }
.hint { font-size: 13px; color: var(--ink-3); margin: 0; }
.err { color: var(--late); font-size: 14px; margin: 0; min-height: 0; }
.err:empty { display: none; }
.lead { font-weight: 600; margin: 0; }
.note { background: var(--now-soft); color: var(--now); border-radius: 8px; padding: 10px 12px; font-size: 14px; }

/* кнопки и поля */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #c9c6ba; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #174a3e; }
.btn.danger { background: var(--late); border-color: var(--late); color: #fff; }
.btn.ghost-danger { color: var(--late); background: transparent; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: default; }
.link { background: none; border: 0; padding: 8px; color: var(--accent); font: inherit; cursor: pointer; }
.x { background: none; border: 0; width: 36px; height: 36px; font-size: 22px; line-height: 1; color: var(--ink-3); cursor: pointer; border-radius: 8px; flex: none; }
.x:hover { background: var(--bg); color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid #cfccc1; border-radius: 10px;
  background: #fff; color: var(--ink); font: inherit; font-size: 16px;
}
textarea { resize: vertical; min-height: 0; }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; flex: none; accent-color: var(--accent); }
input.masked { -webkit-text-security: disc; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-label { font-size: 13px; color: var(--ink-2); font-weight: 500; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.form { display: flex; flex-direction: column; gap: 14px; }
.grid2, .grid3 { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; align-items: start; }
.with-btn { display: flex; gap: 8px; align-items: center; }
.actions { display: flex; gap: 10px; justify-content: flex-end; align-items: center; }
.actions.start { justify-content: flex-start; }
.actions.wrap { flex-wrap: wrap; }
.actions select { width: auto; min-height: 36px; padding: 4px 10px; font-size: 14px; }
fieldset.secret-box { border: 1px dashed #b9c9c3; border-radius: 10px; padding: 12px; margin: 0; display: flex; flex-direction: column; gap: 12px; background: #fafcfb; min-width: 0; }
fieldset.secret-box legend { font-size: 13px; font-weight: 600; color: var(--accent); padding: 0 6px; }

/* вход */
.auth { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px 16px; }
.auth-card { width: 100%; max-width: 420px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 24px 20px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.auth-brand { font-weight: 700; color: var(--accent); letter-spacing: .02em; font-size: 14px; text-transform: uppercase; }
.auth-foot { margin: 0; text-align: center; }
.code { font: 600 20px/1.3 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .04em; background: var(--accent-soft); border-radius: 10px; padding: 14px 10px; text-align: center; overflow-wrap: anywhere; user-select: all; }

/* каркас */
.shell { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
.top { display: flex; align-items: center; gap: 18px; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; color: var(--ink); margin-right: auto; }
.nav { display: none; gap: 4px; }
.nav a { padding: 8px 12px; border-radius: 8px; color: var(--ink-2); font-weight: 500; position: relative; }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.nav a:hover { text-decoration: none; color: var(--ink); }
.lockbtn { display: inline-flex; align-items: center; gap: 6px; background: none; border: 1px solid var(--line); border-radius: 8px; min-height: 36px; padding: 0 10px; font: inherit; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.ico { width: 22px; height: 22px; flex: none; }
.lockbtn .ico { width: 18px; height: 18px; }
.badge { background: var(--late); color: #fff; border-radius: 10px; font-size: 11px; font-weight: 700; min-width: 18px; height: 18px; padding: 0 5px; display: inline-flex; align-items: center; justify-content: center; }
.nav .badge { margin-left: 6px; }
main { max-width: 920px; margin: 0 auto; padding: 18px 16px 24px; }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 7px; font-size: 11px; color: var(--ink-3); position: relative; min-width: 0; }
.tabs a.on { color: var(--accent); font-weight: 600; }
.tabs a:hover { text-decoration: none; }
.tabs .badge { position: absolute; top: 4px; left: calc(50% + 6px); }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 14px; }
.head h2 { margin: 0; }
h1 + .tiles, .back + .head { margin-top: 12px; }
main > h1 { margin-bottom: 14px; }
main > h2, main > .head:not(:first-child) { margin-top: 28px; }
.head { flex-wrap: wrap; }
.head select { width: auto; max-width: 100%; }
.back { display: inline-block; font-size: 14px; margin-bottom: 4px; }
.filters { display: grid; gap: 10px; margin-bottom: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 12px; display: flex; flex-direction: column; gap: 12px; }
.card p { margin: 0; }
.steps { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 6px; color: var(--ink-2); font-size: 15px; }

/* плитки */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 14px 0 6px; }
.tiles.four { grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-width: 0; }
.tile-num { font-size: 22px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile-label { font-size: 13px; color: var(--ink-2); }
.tile-extra { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.tiles.four .tile { padding: 10px 8px; text-align: center; }
.tiles.four .tile-label { font-size: 12px; }
.tiles.four .tile-num { color: var(--ink-3); }
.tile.late.has { background: var(--late-soft); border-color: #ebcfc5; }
.tile.late.has .tile-num { color: var(--late); }
.tile.now.has { background: var(--now-soft); border-color: #ead9b3; }
.tile.now.has .tile-num { color: var(--now); }
.tile.d3.has .tile-num, .tile.d7.has .tile-num { color: var(--accent); }

/* списки */
.group { margin-top: 18px; }
.group h2 { margin: 0 0 8px; }
.group.late h2 { color: var(--late); }
.group.now h2 { color: var(--now); }
.group-sum { margin-left: auto; font-size: 14px; font-weight: 500; color: var(--ink-2); }
details > summary { cursor: pointer; color: var(--ink-2); font-weight: 500; padding: 8px 0; }
.list, .group { display: flex; flex-direction: column; gap: 8px; }
.row { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; color: inherit; }
a.row:hover { text-decoration: none; border-color: #c9c6ba; }
.row-main { min-width: 0; }
.row .name { font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.row .sub { font-size: 14px; color: var(--ink-2); overflow-wrap: anywhere; }
.row-date { text-align: right; font-size: 13px; color: var(--ink-2); display: flex; flex-direction: column; font-variant-numeric: tabular-nums; }
.row-date b { color: var(--ink); font-size: 15px; }
.row-sum { font-variant-numeric: tabular-nums; font-weight: 600; }
.row.renew { grid-template-columns: 1fr auto; }
.row.renew .row-sum { grid-column: 1; }
.row.renew .btn { grid-column: 2; justify-self: end; }
.row.renew.late { border-left: 4px solid var(--late); }
.row.renew.late .row-date span { color: var(--late); font-weight: 600; }
.row.renew.now { border-left: 4px solid var(--now); }
.row.renew.now .row-date span { color: var(--now); font-weight: 600; }
.row.client .row-sum { grid-column: 1 / -1; font-weight: 500; color: var(--ink-2); font-size: 14px; }
.row.gone { grid-template-columns: 1fr auto; }
.row.gone .row-main { grid-column: 1 / -1; }
.row.gone .status { justify-self: start; }
.status { display: inline-block; font-size: 12px; font-weight: 600; border-radius: 20px; padding: 2px 10px; white-space: nowrap; }
.status.active { background: var(--accent-soft); color: var(--accent); }
.status.paused { background: var(--now-soft); color: var(--now); }
.status.cancelled { background: #ecebe6; color: var(--ink-2); }

/* карточка подписки */
.subcard.cancelled { background: #fbfaf7; }
.subcard-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 15px; }
.facts dt { color: var(--ink-3); font-size: 14px; }
.facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.pays { border-top: 1px solid var(--line); padding-top: 4px; }
.pay { display: grid; grid-template-columns: auto 1fr auto 36px; gap: 2px 10px; align-items: center; font-size: 14px; padding: 6px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.pay .muted { grid-column: 1 / 4; text-align: left; font-size: 13px; }
.pay .x { grid-row: 1; grid-column: 4; }
.danger-zone { margin-top: 26px; }
.noteform textarea { min-height: 60px; }

/* журнал */
.log { display: flex; flex-direction: column; }
.logrow { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.log-meta { grid-column: 1; font-size: 12px; color: var(--ink-3); display: flex; gap: 8px; align-items: center; font-variant-numeric: tabular-nums; }
.kind { background: #ecebe6; color: var(--ink-2); border-radius: 6px; padding: 1px 7px; font-weight: 600; }
.logrow.renew .kind { background: var(--accent-soft); color: var(--accent); }
.logrow.cancelled .kind, .logrow.deleted .kind, .logrow.payment_deleted .kind { background: var(--late-soft); color: var(--late); }
.logrow.price .kind, .logrow.paused .kind, .logrow.note .kind { background: var(--now-soft); color: var(--now); }
.log-text { grid-column: 1; font-size: 15px; overflow-wrap: anywhere; }
.logrow .x { grid-column: 2; grid-row: 1 / 3; align-self: center; }

/* окна */
dialog.modal { border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 20px)); max-height: calc(100dvh - 24px); background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(20, 30, 30, .25); }
dialog.modal::backdrop { background: rgba(30, 42, 43, .45); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 10px 6px 18px; position: sticky; top: 0; background: var(--card); z-index: 1; }
.modal-head h2 { margin: 0; font-size: 19px; }
dialog.modal > .form, dialog.modal > div:not(.modal-head) { padding: 8px 18px 18px; }
dialog.modal > div:not(.modal-head) > .form { padding: 0; }
.secret-row { display: grid; grid-template-columns: 1fr; gap: 6px 10px; align-items: center; padding: 10px 12px; background: var(--bg); border-radius: 10px; }
.secret-row.col { grid-template-columns: 1fr; }
.secret-val { overflow-wrap: anywhere; font-size: 16px; user-select: all; }
.btns { display: flex; gap: 6px; }

/* таблицы и график */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.card .table-wrap { border: 0; border-radius: 0; }
table { border-collapse: collapse; width: 100%; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th.r, td.r { text-align: right; }
th { font-size: 12px; color: var(--ink-3); font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
td:first-child { white-space: normal; min-width: 110px; }
th, td { padding-left: 8px; padding-right: 8px; }
th:first-child, td:first-child { padding-left: 14px; }
th:last-child, td:last-child { padding-right: 14px; }
.mini { display: block; height: 3px; border-radius: 2px; background: var(--series-margin); opacity: .55; margin-top: 4px; min-width: 2px; }
.chart { min-width: 0; }
.chart-body { position: relative; overflow: hidden; }
.chart svg { display: block; max-width: 100%; height: auto; }
.chart .grid { stroke: #ecebe5; stroke-width: 1; }
.chart .axis { stroke: #cfccc1; stroke-width: 1; }
.chart .tick { font-size: 11px; fill: var(--ink-3); font-variant-numeric: tabular-nums; }
.chart .bar-margin { fill: var(--series-margin); }
.chart .bar-cost { fill: var(--series-cost); }
.chart .hit { fill: transparent; cursor: default; outline: none; }
.chart .hit:hover, .chart .hit:focus { fill: rgba(30, 42, 43, .05); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.dot.margin { background: var(--series-margin); }
.dot.cost { background: var(--series-cost); }
.tip { position: absolute; width: 210px; white-space: nowrap; background: var(--ink); color: #fff; border-radius: 8px; padding: 8px 10px; font-size: 12px; display: flex; flex-direction: column; gap: 2px; pointer-events: none; font-variant-numeric: tabular-nums; }
.tip[hidden] { display: none; }
.tip b { font-size: 13px; text-transform: capitalize; }

#toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s; z-index: 2147483647; max-width: calc(100vw - 32px); text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--late); }

@media (min-width: 560px) {
  .grid3 { grid-template-columns: 1fr 1fr 1fr; }
  .filters { grid-template-columns: 1fr auto; }
  .filters select { width: auto; }
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .row.renew { grid-template-columns: 1fr 130px 100px auto; }
  .row.renew .row-sum, .row.renew .btn { grid-column: auto; }
  .row.renew .row-sum { text-align: right; }
  .row.client { grid-template-columns: 1fr 130px 100px; }
  .row.client .row-sum { grid-column: auto; text-align: right; }
  .row.gone { grid-template-columns: 1fr auto 100px; }
  .row.gone .row-main { grid-column: auto; }
  .pay { grid-template-columns: 90px 90px 1fr 1fr 36px; }
  .pay .muted { grid-column: auto; text-align: right; }
  .pay .x { grid-column: auto; }
  .logrow { grid-template-columns: 250px 1fr auto; align-items: baseline; }
  .log-meta, .log-text { grid-column: auto; }
  .logrow .x { grid-column: 3; grid-row: 1; }
  .secret-row { grid-template-columns: 110px 1fr auto; }
  .secret-row .field-label { grid-column: auto; }
  .secret-row.col { grid-template-columns: 110px 1fr; }
}
@media (min-width: 860px) {
  .shell { padding-bottom: 0; }
  .tabs { display: none; }
  .nav { display: flex; }
  .brand { margin-right: 12px; }
  .nav { margin-right: auto; }
  main { padding-top: 26px; }
  #toast { bottom: 28px; }
}
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
