:root {
  --bg: #f2f5f8;
  --surface: #ffffff;
  --border: #e3e8ef;
  --text: #17212b;
  --muted: #687788;
  --accent: #0b93ab;
  --accent-strong: #087a8f;
  --accent-soft: #e3f5f8;
  --good: #138a63;
  --good-soft: #e3f6ee;
  --warn: #b26b00;
  --warn-soft: #fff4e0;
  --bad: #c43b3b;
  --bad-soft: #fdeaea;
  --neutral-soft: #edf0f4;
  --tg: #1f6fb2; --tg-soft: #e5f1fb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --surface-2: #f8fafc;
  --border-strong: #c9d5e1;
  --nav-text: #3b4856;
  --input-bg: #ffffff;
  --focus-ring: rgba(11, 147, 171, .15);
  --row-alert: #fff8f8;
  --alert-ok-border: #bfe8d6; --alert-ok-text: #0e6a4c;
  --alert-warn-border: #f5d9a8; --alert-warn-text: #7a4a00;
  --alert-error-border: #f2c4c4; --alert-error-text: #9b2c2c;
  --danger-border: #f0caca;
  --suspended-text: #4b5866;
  --popover-shadow: 0 10px 30px rgba(16, 24, 40, .12);
  color-scheme: light;
}

/* Ночная тема: выбрана вручную или системная + тёмная тема в ОС */
:root[data-theme="dark"] { 
  --bg: #0e1318; --surface: #161d24; --surface-2: #1b232c;
  --border: #26303b; --border-strong: #354352;
  --text: #e5ebf1; --muted: #8d9aa8; --nav-text: #c3cdd7;
  --accent: #22b4cf; --accent-strong: #4cc8df; --accent-soft: #133a44;
  --good: #3cc791; --good-soft: #143528;
  --warn: #f0a93b; --warn-soft: #3a2a10;
  --bad: #f07272; --bad-soft: #3d1b1d;
  --neutral-soft: #222b35;
  --tg: #6cb6f0; --tg-soft: #12304a;
  --input-bg: #11171d; --focus-ring: rgba(34, 180, 207, .25);
  --row-alert: #2a1618;
  --alert-ok-border: #1f5a43; --alert-ok-text: #6fe0b3;
  --alert-warn-border: #6b4a14; --alert-warn-text: #f5c26e;
  --alert-error-border: #6e2a2d; --alert-error-text: #ff9c9c;
  --danger-border: #6e2a2d;
  --suspended-text: #a9b4c0;
  --shadow: none;
  --popover-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  color-scheme: dark;
 }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { 
  --bg: #0e1318; --surface: #161d24; --surface-2: #1b232c;
  --border: #26303b; --border-strong: #354352;
  --text: #e5ebf1; --muted: #8d9aa8; --nav-text: #c3cdd7;
  --accent: #22b4cf; --accent-strong: #4cc8df; --accent-soft: #133a44;
  --good: #3cc791; --good-soft: #143528;
  --warn: #f0a93b; --warn-soft: #3a2a10;
  --bad: #f07272; --bad-soft: #3d1b1d;
  --neutral-soft: #222b35;
  --tg: #6cb6f0; --tg-soft: #12304a;
  --input-bg: #11171d; --focus-ring: rgba(34, 180, 207, .25);
  --row-alert: #2a1618;
  --alert-ok-border: #1f5a43; --alert-ok-text: #6fe0b3;
  --alert-warn-border: #6b4a14; --alert-warn-text: #f5c26e;
  --alert-error-border: #6e2a2d; --alert-error-text: #ff9c9c;
  --danger-border: #6e2a2d;
  --suspended-text: #a9b4c0;
  --shadow: none;
  --popover-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  color-scheme: dark;
 }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }
h1, h2 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }

/* ---------- раскладка ---------- */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex; flex-direction: column; gap: 24px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center;
  color: #fff; background: linear-gradient(135deg, #12a9c2, #0b7f94);
  flex: none;
}
.brand-text { display: flex; flex-direction: column; font-weight: 700; font-size: 15px; line-height: 1.15; }
.brand-text small { font-weight: 500; font-size: 12px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 9px;
  color: var(--nav-text); font-weight: 500;
}
.nav a svg { width: 18px; height: 18px; fill: currentColor; opacity: .75; flex: none; }
.nav a:hover { background: var(--bg); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent-strong); }
.nav a.active svg { opacity: 1; }
.sidebar-foot { margin-top: auto; padding: 0 10px; color: var(--muted); font-size: 12px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.card { min-width: 0; }
.table td.muted { overflow-wrap: anywhere; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-user { display: flex; align-items: center; gap: 12px; }
.user-chip {
  display: flex; align-items: center; gap: 10px; padding: 4px 14px 4px 4px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  display: grid; place-items: center; background: var(--accent); color: #fff;
}
.avatar svg { width: 17px; height: 17px; fill: currentColor; }
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-meta strong { font-size: 13px; }
.user-meta small { color: var(--muted); font-size: 11.5px; }

/* выбор темы */
.theme { position: relative; }
.theme-button {
  width: 38px; height: 38px; border-radius: 11px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; display: grid; place-items: center;
}
.theme-button:hover { border-color: var(--border-strong); }
.theme-button svg { width: 18px; height: 18px; fill: currentColor; display: none; }
.theme[data-mode="light"] .ic-light, .theme[data-mode="dark"] .ic-dark, .theme[data-mode="system"] .ic-system { display: block; }
.theme-menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 20; min-width: 190px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--popover-shadow); padding: 6px; display: none;
}
.theme.open .theme-menu { display: block; }
.theme-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px;
  border: 0; border-radius: 8px; background: transparent; color: var(--text);
  font: inherit; cursor: pointer; text-align: left;
}
.theme-menu button svg { width: 17px; height: 17px; fill: currentColor; opacity: .75; }
.theme-menu button:hover { background: var(--surface-2); }
.theme-menu button[aria-checked="true"] { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.theme-menu button[aria-checked="true"] svg { opacity: 1; }

/* быстрая смена даты окончания */
.inline-edit summary {
  list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  border-bottom: 1px dashed var(--border-strong); padding-bottom: 1px;
}
.inline-edit summary::-webkit-details-marker { display: none; }
.inline-edit summary svg { width: 14px; height: 14px; fill: var(--muted); }
.inline-edit summary:hover { color: var(--accent); border-color: var(--accent); }
.inline-edit summary:hover svg { fill: var(--accent); }
.inline-edit[open] summary { display: none; }
.inline-edit form { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 2px; }
.inline-edit input[type=date] { width: auto; height: 34px; }
.crumb { color: var(--muted); font-weight: 500; }
.content { padding: 24px 28px 48px; display: flex; flex-direction: column; gap: 20px; max-width: 1240px; width: 100%; }

/* ---------- карточки ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 12px;
  align-items: center;
}
a.stat:hover { border-color: var(--border-strong); color: inherit; }
.stat-icon {
  grid-row: span 2; width: 38px; height: 38px; border-radius: 10px;
  display: grid; place-items: center;
}
.stat-icon svg { width: 19px; height: 19px; fill: currentColor; }
.stat-value { font-size: 24px; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: 12.5px; }
.tone-good { background: var(--good-soft); color: var(--good); }
.tone-warn { background: var(--warn-soft); color: var(--warn); }
.tone-bad { background: var(--bad-soft); color: var(--bad); }
.tone-muted { background: var(--neutral-soft); color: var(--muted); }
.tone-accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- таблицы ---------- */
.table-wrap { overflow-x: auto; position: relative; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-weight: 600; font-size: 12px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
  padding: 0 10px 10px; border-bottom: 1px solid var(--border);
}
.table td { padding: 11px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table a:not(.btn) { color: var(--text); }
.table a:not(.btn):hover { color: var(--accent); }
.row-link { cursor: pointer; }
.row-link:hover td { background: var(--surface-2); }
.row-alert td { background: var(--row-alert); }

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge-active { background: var(--good-soft); color: var(--good); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-expired { background: var(--bad-soft); color: var(--bad); }
.badge-suspended { background: var(--neutral-soft); color: var(--suspended-text); }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 9px;
  border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn-sm { height: 30px; padding: 0 11px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); color: #fff; }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--border-strong); color: var(--text); background: var(--surface-2); }
.btn-danger-ghost { background: var(--surface); border-color: var(--danger-border); color: var(--bad); }
.btn-danger-ghost:hover { background: var(--bad-soft); color: var(--bad); }
.btn-logout { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn-logout:hover { background: var(--bad-soft); color: var(--bad); }
.link { color: var(--accent); font-weight: 500; }

/* ---------- формы ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-weight: 600; font-size: 13px; }
.field small { color: var(--muted); font-size: 12px; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=search], select, textarea {
  font: inherit; color: var(--text);
  height: 38px; padding: 0 11px;
  border: 1px solid var(--border); border-radius: 9px; background: var(--input-bg);
  width: 100%;
}
textarea { height: auto; padding: 9px 11px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring);
}
.form { display: flex; flex-direction: column; gap: 4px; }
.form.narrow { max-width: 420px; gap: 14px; }
.form-section { border: 0; margin: 0; padding: 14px 0 18px; border-top: 1px solid var(--border); }
.form-section:first-of-type { border-top: 0; padding-top: 0; }
.card-head ~ .form-section:first-of-type { border-top: 1px solid var(--border); padding-top: 14px; }
.form-section legend { font-weight: 700; font-size: 14px; padding: 0; margin-bottom: 12px; float: left; width: 100%; }
.form-section legend small { color: var(--muted); font-weight: 500; margin-left: 6px; }
.form-section > *:not(legend) { clear: both; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.form-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.checks { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 18px; }
.check { display: flex; align-items: center; gap: 9px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }
.form-actions { display: flex; align-items: center; gap: 12px; padding-top: 14px; border-top: 1px solid var(--border); }

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .search { max-width: 340px; }
.toolbar select { width: auto; }
.spacer { flex: 1; }

/* ---------- карточка лицензии ---------- */
.summary { display: grid; grid-template-columns: 1fr 230px; gap: 24px; }
.summary-title { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.summary-title h2 { font-size: 18px; }
.summary-actions { display: flex; flex-direction: column; gap: 8px; }
.summary-actions form { margin: 0; }
.key-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 4px 0 16px; }
.key {
  display: inline-block; padding: 8px 12px; border-radius: 9px;
  background: var(--bg); border: 1px dashed var(--border-strong);
  font-size: 15px; letter-spacing: .04em; user-select: all;
}
.key-wide { font-size: 13px; letter-spacing: 0; word-break: break-all; }
.facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 20px; margin: 0; }
.facts dt { color: var(--muted); font-size: 12px; }
.facts dd { margin: 2px 0 0; font-weight: 600; }

/* ---------- сообщения ---------- */
.alert { padding: 12px 14px; border-radius: 10px; border: 1px solid; }
.alert ul { margin: 6px 0 0; padding-left: 18px; }
.alert-ok { background: var(--good-soft); border-color: var(--alert-ok-border); color: var(--alert-ok-text); }
.alert-warn { background: var(--warn-soft); border-color: var(--alert-warn-border); color: var(--alert-warn-text); margin-top: 14px; }
.alert-error { background: var(--bad-soft); border-color: var(--alert-error-border); color: var(--alert-error-text); }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hint { color: var(--muted); font-size: 12.5px; margin: 12px 0 0; }
.empty { color: var(--muted); margin: 4px 0; }
.empty-state { text-align: center; padding: 36px 16px; }
.empty-state p { margin: 0 0 8px; }
.empty-state .btn { margin-top: 10px; }

/* ---------- вход ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--popover-shadow);
  padding: 28px; display: flex; flex-direction: column; gap: 16px;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.login-brand strong { display: block; font-size: 16px; }
.login-brand span:not(.brand-mark) { color: var(--muted); font-size: 13px; }

/* ---------- адаптив ---------- */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; padding: 10px 16px; gap: 12px; overflow-x: auto; }
  .brand-text small, .sidebar-foot { display: none; }
  .nav { flex-direction: row; }
  .nav a { padding: 8px 10px; white-space: nowrap; }
  .topbar { padding: 14px 16px; }
  .user-meta { display: none; }
  .user-chip { padding: 3px; }
  .content { padding: 16px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary { grid-template-columns: 1fr; }
  .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid, .form-grid-4 { grid-template-columns: 1fr 1fr; }
  .checks { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 520px) {
  .form-grid, .form-grid-4, .checks { grid-template-columns: 1fr; }
  .nav a svg { display: none; }
}
.login-theme { position: fixed; top: 16px; right: 16px; }

/* ---------- обновления ---------- */
.nav-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); margin-left: auto; box-shadow: 0 0 0 3px var(--warn-soft); }
.update-card { display: flex; flex-direction: column; gap: 16px; }
.update-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.update-version { font-size: 30px; font-weight: 800; letter-spacing: -.02em; line-height: 1.2; }
.update-card .alert { margin-top: 0; }
.update-progress {
  display: flex; gap: 14px; align-items: center; padding: 14px 16px;
  border: 1px solid var(--accent); background: var(--accent-soft); border-radius: 12px;
}
.update-progress[hidden] { display: none; }
.spinner {
  width: 22px; height: 22px; flex: none; border-radius: 50%;
  border: 3px solid color-mix(in srgb, var(--accent) 25%, transparent); border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.update-available { border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; background: var(--surface-2); }
.update-available-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 6px; flex-wrap: wrap; }
.update-available h2 { font-size: 17px; }
.release { padding: 12px 0; border-top: 1px solid var(--border); }
.release:first-of-type { border-top: 0; }
.update-available .release:first-of-type { border-top: 1px solid var(--border); }
.release-title { font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.release ul { margin: 8px 0 0; padding-left: 20px; }
.release li { margin: 4px 0; }
.release code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 0 4px; }
.update-log summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.update-log pre {
  margin: 10px 0 0; padding: 12px; max-height: 320px; overflow: auto; white-space: pre-wrap;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  font-family: var(--mono); font-size: 12px; line-height: 1.5;
}
.cmd { display: block; margin: 8px 0; padding: 8px 10px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); word-break: break-all; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- настройки с подменю ---------- */
.settings-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 22px; align-items: start; }
.settings-nav { padding: 8px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 16px; }
.settings-nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px;
  color: var(--nav-text); font-weight: 500;
}
.settings-nav a svg { width: 17px; height: 17px; fill: currentColor; opacity: .75; flex: none; }
.settings-nav a:hover { background: var(--surface-2); color: var(--text); }
.settings-nav a.active { background: var(--accent); color: #fff; }
.settings-nav a.active svg { opacity: 1; }
.settings-nav a.active .nav-dot { background: #fff; box-shadow: none; }
.settings-body { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.settings-title { font-size: 18px; margin: 4px 0 0; }
.settings-title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.settings-title-row p { margin: 4px 0 0; }
.section-label { text-transform: uppercase; letter-spacing: .06em; font-size: 13px; color: var(--muted); font-weight: 800; }
.section-label::before { content: ""; display: inline-block; width: 3px; height: 13px; background: var(--accent); border-radius: 2px; margin-right: 9px; vertical-align: -1px; }

/* ---------- система ---------- */
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.metric { text-align: center; padding: 22px 18px; }
.metric-label { display: flex; align-items: center; justify-content: center; gap: 7px; color: var(--muted); font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.metric-label svg { width: 17px; height: 17px; fill: var(--accent); }
.metric-value { font-size: 32px; font-weight: 800; margin: 12px 0 14px; letter-spacing: -.02em; }
.metric-value-sm { font-size: 24px; margin: 18px 0 16px; }
.metric-sub { color: var(--muted); font-size: 12.5px; margin-top: 10px; line-height: 1.6; }
.meter { height: 7px; border-radius: 999px; background: var(--neutral-soft); overflow: hidden; }
.meter-fill { display: block; height: 100%; border-radius: 999px; min-width: 6px; }
.meter-blue { background: #6366f1; }
.meter-ok { background: var(--good); }
.meter-warn { background: var(--warn); }
.meter-bad { background: var(--bad); }

/* ---------- бэкапы ---------- */
.backup-actions { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin: 14px 0; }
.backup-create { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.backup-create .field select { width: 260px; }
.backup-import { display: flex; align-items: center; gap: 8px; }
.file-btn { cursor: pointer; }
.btn-icon { width: 16px; height: 16px; fill: currentColor; }
.btn-danger { background: var(--bad); color: #fff; }
.btn-danger:hover { filter: brightness(.92); color: #fff; }
.backup-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.backup-item {
  display: flex; align-items: center; gap: 14px; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
}
.backup-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.backup-icon svg { width: 18px; height: 18px; fill: currentColor; }
.backup-meta { min-width: 0; flex: 1; }
.backup-name { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 600; }
.backup-name .mono { font-size: 13px; overflow-wrap: anywhere; }
.backup-buttons { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.backup-buttons form { margin: 0; }
.tag { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--neutral-soft); color: var(--muted); white-space: nowrap; }
.tag-good { background: var(--good-soft); color: var(--good); }
.tag-bad { background: var(--bad-soft); color: var(--bad); }
.tag-warn { background: var(--warn-soft, rgba(230,150,0,.12)); color: var(--warn); }
.icon-btn { width: 32px; height: 32px; border-radius: 8px; border: 0; background: transparent; color: var(--bad); cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: var(--bad-soft); }
.icon-btn svg { width: 17px; height: 17px; fill: currentColor; }

@media (max-width: 1100px) { .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 860px) {
  .settings-layout { grid-template-columns: 1fr; }
  .settings-nav { position: static; flex-direction: row; overflow-x: auto; }
  .settings-nav a { white-space: nowrap; }
  .backup-item { flex-wrap: wrap; }
  .backup-buttons { width: 100%; justify-content: flex-start; }
}
@media (max-width: 520px) { .metrics { grid-template-columns: 1fr; } }

/* ---------- журнал ---------- */
.journal { padding: 0; overflow: visible; }
.journal-tabs {
  display: flex; gap: 4px; padding: 14px 16px 0; border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: thin;
}
.jtab {
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
  padding: 9px 12px 11px; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600;
}
.jtab span { font-size: 11.5px; padding: 1px 7px; border-radius: 999px; background: var(--neutral-soft); color: var(--muted); }
.jtab:hover { color: var(--text); }
.jtab.active { color: var(--accent-strong); border-bottom-color: var(--accent); }
.jtab.active span { background: var(--accent-soft); color: var(--accent-strong); }

.journal-filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.search-box { position: relative; flex: 1 1 180px; max-width: 320px; }
.search-box svg { position: absolute; left: 11px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); fill: var(--muted); }
.search-box input { padding-left: 34px; }
.date-field { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.date-field input { width: 140px; }

.clear-menu { position: relative; }
.clear-menu summary { list-style: none; }
.clear-menu summary::-webkit-details-marker { display: none; }
.clear-pop {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 15; width: 280px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--popover-shadow); padding: 14px; display: flex; flex-direction: column; gap: 6px;
}
.clear-pop p { margin: 2px 0 6px; }
.clear-option {
  text-align: left; padding: 9px 12px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
}
.clear-option:hover { background: var(--bad-soft); border-color: var(--danger-border); color: var(--bad); }
.clear-option.danger { color: var(--bad); }

.filter-chip {
  display: flex; align-items: center; gap: 8px; margin: 12px 16px 0; padding: 8px 12px;
  background: var(--accent-soft); color: var(--accent-strong); border-radius: 10px; font-size: 13px;
}
.filter-chip > a:first-of-type { font-size: 18px; line-height: 1; padding: 0 4px; color: var(--accent-strong); }
.filter-chip .link { margin-left: auto; }

.journal-list { list-style: none; margin: 0; padding: 8px 16px 4px; }
.journal-day {
  position: sticky; top: 0; z-index: 1; padding: 12px 4px 6px; background: var(--surface);
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
}
.journal-item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: start;
  padding: 12px 14px; margin-bottom: 8px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
}
.journal-item:hover { border-color: var(--border-strong); }
.journal-icon { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; }
.journal-icon svg { width: 17px; height: 17px; fill: currentColor; }
.sev-info .journal-icon { background: var(--accent-soft); color: var(--accent); }
.sev-success .journal-icon { background: var(--good-soft); color: var(--good); }
.sev-warn .journal-icon { background: var(--warn-soft); color: var(--warn); }
.sev-error .journal-icon { background: var(--bad-soft); color: var(--bad); }
.sev-error { border-color: var(--danger-border); }
.journal-body { min-width: 0; }
.journal-title { font-weight: 600; overflow-wrap: anywhere; }
.journal-details { font-weight: 400; color: var(--muted); margin-left: 6px; }
.journal-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 5px; font-size: 12px; }
.tag-link { background: var(--accent-soft); color: var(--accent-strong); }
.tag-link:hover { color: var(--accent); text-decoration: underline; }
.journal-time { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; white-space: nowrap; padding-top: 2px; }
.journal-empty { padding: 28px 16px; text-align: center; }

.journal-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
  padding: 12px 16px 16px; border-top: 1px solid var(--border);
}
.per-page { display: flex; align-items: center; gap: 8px; }
.per-page select { width: auto; height: 32px; padding: 0 8px; }
.pager { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.pg {
  min-width: 34px; height: 34px; padding: 0 8px; border-radius: 9px; display: inline-grid; place-items: center;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 600; font-size: 13px;
}
a.pg:hover { border-color: var(--accent); color: var(--accent); }
.pg.current { background: var(--accent); border-color: var(--accent); color: #fff; }
.pg.disabled { opacity: .4; }
.pg.gap { border: 0; background: transparent; min-width: 18px; color: var(--muted); }
.form-row { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
.form-row .field { flex: 1 1 280px; max-width: 420px; }

@media (max-width: 860px) {
  .journal-item { grid-template-columns: auto 1fr; }
  .journal-time { grid-column: 2; padding: 0; }
  .search-box { max-width: none; }
  .date-field { flex: 1 1 140px; }
  .date-field input { width: 100%; }
}

/* ---------- часы сервера в шапке ---------- */
.server-clock {
  display: flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
  font-size: 13px; color: var(--muted); white-space: nowrap; cursor: default;
}
.server-clock svg { width: 16px; height: 16px; fill: currentColor; flex: none; }
.clock-time { font-size: 15px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.clock-zone { font-weight: 600; }
.clock-date::before { content: "·"; margin-right: 6px; }
.server-clock.drift { border-color: var(--warn); background: var(--warn-soft); color: var(--warn); }
@media (max-width: 860px) {
  .server-clock { height: 34px; padding: 0 10px; }
  .clock-date { display: none; }
}
@media (max-width: 520px) {
  .user-chip { display: none; }
  .topbar-user { gap: 8px; }
  .topbar h1 { font-size: 19px; }
}
@media (max-width: 360px) {
  .server-clock svg { display: none; }
}

/* ---------- срок лицензии: метка, карандаш, окно ---------- */
.field > label:first-child { font-weight: 600; font-size: 13px; }
.check-inline { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; margin-top: 2px; }
.check-inline input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.badge-perpetual { background: var(--accent-soft); color: var(--accent); }
.expiry-cell { display: inline-flex; align-items: center; gap: 4px; }
.tool-btn {
  width: 32px; height: 32px; border-radius: 8px; border: 0; background: transparent; color: var(--muted);
  cursor: pointer; display: inline-grid; place-items: center; flex: none;
}
.tool-btn:hover, .tool-btn:focus-visible { background: var(--accent-soft); color: var(--accent); }
.tool-btn svg { width: 17px; height: 17px; fill: currentColor; }
.tool-btn-sm { width: 26px; height: 26px; border-radius: 7px; }
.tool-btn-sm svg { width: 14px; height: 14px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.modal {
  border: 1px solid var(--border); border-radius: 16px; padding: 0; width: min(400px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: var(--popover-shadow);
}
.modal::backdrop { background: rgba(10, 20, 30, .45); }
.modal-form { display: flex; flex-direction: column; gap: 14px; padding: 18px 20px 20px; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; order: 0; }
.modal-head h3 { margin: 0 0 2px; font-size: 17px; }
.modal-head p { margin: 0; }
.modal-date { order: 1; }
.quick-row { display: flex; gap: 8px; flex-wrap: wrap; order: 2; }
.modal-note { order: 3; margin: -4px 0 0; }
.modal-note:empty { display: none; }
.modal-actions { display: flex; flex-direction: row-reverse; justify-content: flex-start; gap: 8px; order: 4;
  padding-top: 14px; border-top: 1px solid var(--border); }
.chip-btn {
  padding: 7px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.chip-btn:hover { border-color: var(--accent); color: var(--accent); }
.chip-perpetual { color: var(--accent); }

/* ---------- копирование ключа: зелёная галочка ---------- */
.key-copy {
  display: inline-flex; align-items: center; gap: 8px; padding: 5px 8px; margin: -5px -8px;
  border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--text);
  font: inherit; font-size: 12.5px; cursor: copy;
}
.key-copy:hover { border-color: var(--border); background: var(--bg); }
.copy-icon { position: relative; width: 16px; height: 16px; display: grid; place-items: center; }
.copy-icon svg { width: 15px; height: 15px; fill: var(--muted); opacity: 0; transition: opacity .15s; }
.key-copy:hover .copy-icon svg, .key-copy:focus-visible .copy-icon svg { opacity: 1; }
.copied { position: relative; }
.copy-check {
  position: absolute; inset: 0; margin: auto; width: 20px; height: 20px; pointer-events: none;
  fill: none; stroke: var(--good); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 24; stroke-dashoffset: 24; animation: copy-check .35s ease-out forwards, copy-fade .3s ease-in 1.1s forwards;
}
.btn.copied { color: transparent !important; }
.btn.copied .copy-check { width: 22px; height: 22px; }
.key-copy.copied .copy-icon svg:not(.copy-check) { opacity: 0; }
.key-copy .copy-check { width: 18px; height: 18px; }
@keyframes copy-check { to { stroke-dashoffset: 0; } }
@keyframes copy-fade { to { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .copy-check { animation: copy-fade .3s ease-in 1.1s forwards; stroke-dashoffset: 0; } }
.col-actions { width: 40px; }
.table td .key-copy { font-size: 12px; }
.table-licenses th, .table-licenses td { padding-left: 8px; padding-right: 8px; }
.table-licenses th:first-child, .table-licenses td:first-child { padding-left: 10px; }
.table td .key-copy { font-size: 11.5px; gap: 4px; padding: 5px 6px; margin: -5px -6px; }
.table td .key-copy .copy-icon { width: 14px; height: 14px; }
.table td .key-copy .copy-icon svg { width: 13px; height: 13px; }
.table td .key-copy .mono { font-size: 11.5px; }

/* ---------- релизы платформы ---------- */
.release-steps { margin: 0 0 14px; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.release-item { align-items: flex-start; }
.release-notes { margin-top: 6px; }
.release-notes summary { cursor: pointer; color: var(--accent-strong); font-size: 13px; font-weight: 600; }
.release-notes ul { margin: 6px 0 0; padding-left: 20px; }
.release-notes li { margin: 3px 0; }
.release-notes code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 0 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }

/* ---------- вкладка «Система»: службы, точки состояния ---------- */
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot-good { background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.dot-bad { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.dot-muted { background: var(--border); }
.status-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.status-tile { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; }
.status-tile strong { display: block; font-size: 13.5px; }
.status-tile small { color: var(--muted); font-size: 12px; }
.facts-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 860px) { .facts-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.text-good { color: var(--good); font-weight: 600; }
.text-bad { color: var(--bad); font-weight: 600; }
.text-warn { color: var(--warn); font-weight: 600; }
.alert-info { background: var(--accent-soft); color: var(--text); border-color: transparent; }
[data-live-system].is-loading { opacity: .85; transition: opacity .2s; }

/* ---------- формы настроек: кнопка «Сохранить» под пояснением ---------- */
.form-stack { display: flex; flex-direction: column; align-items: flex-start; gap: 14px; max-width: 560px; }
.form-stack .field { width: 100%; }
.field-title { font-weight: 600; font-size: 13px; }
.segmented { display: inline-flex; padding: 4px; gap: 4px; border-radius: 12px; background: var(--neutral-soft); align-self: flex-start; }
.segmented label { cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 8px 16px; border-radius: 9px; font-weight: 600; font-size: 13.5px; color: var(--muted); }
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- кнопки действий значками ---------- */
.act-icon { width: 32px; height: 32px; padding: 0; display: inline-grid; place-items: center; }
.act-icon svg { width: 17px; height: 17px; fill: currentColor; }

/* ---------- телефон: меню не растягивается, таблицы — карточками ---------- */
@media (max-width: 860px) {
  .layout { grid-template-rows: auto 1fr; align-content: start; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
}
@media (max-width: 760px) {
  .table-cards thead { display: none; }
  .table-cards, .table-cards tbody { display: block; width: 100%; }
  .table-wrap:has(> .table-cards) { overflow: visible; }
  .table-cards tr {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px 14px; align-items: start;
    padding: 14px; margin-bottom: 12px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface);
  }
  .table-cards tr:last-child { margin-bottom: 0; }
  .table-cards td { display: block; padding: 0 !important; border: 0 !important; min-width: 0; white-space: normal; text-align: left; }
  .table-cards td[data-label]::before {
    content: attr(data-label); display: block; margin-bottom: 3px;
    font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted);
  }
  .table-cards td.c-title { grid-column: 1; grid-row: 1; font-size: 15px; }
  .table-cards td.c-badge { grid-column: 2; grid-row: 1; justify-self: end; }
  .table-cards td.c-full, .table-cards td.c-wide { grid-column: 1 / -1; }
  .table-cards td.c-title.c-full { grid-column: 1 / -1; }
  .table-cards td.c-actions {
    grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap;
    padding-top: 12px !important; border-top: 1px solid var(--border) !important;
  }
  .table-cards td.c-actions form { display: contents; }
  .table-cards td:empty { display: none; }
  .table-cards .check-time { display: inline; margin-left: 4px; }
  /* События: время над названием, без рамок-отступов */
  .table-events tr { grid-template-columns: 1fr; gap: 4px; padding: 12px 14px; }
  .table-events td.c-badge-left { font-size: 12px; }
  .table-events td.c-title { grid-row: auto; }
  .table-events td.right { text-align: left; }
  .table-licenses td .key-copy { margin: 0; padding: 7px 10px; border-color: var(--border); background: var(--bg); width: 100%; justify-content: space-between; }
  .table-licenses td .key-copy .mono { font-size: 13px; }
  .table-licenses td .key-copy .copy-icon svg { opacity: 1; }
}
.check-cell { display: inline-flex; align-items: center; gap: 4px; }
.check-time { display: block; }
.recheck-btn.spinning svg { animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- всплывающее сообщение ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 100; transform: translate(-50%, 20px); opacity: 0;
  width: max-content; max-width: min(520px, calc(100vw - 32px)); padding: 12px 16px; border-radius: 12px;
  background: var(--text); color: var(--surface); box-shadow: var(--popover-shadow);
  font-size: 14px; line-height: 1.45; transition: opacity .2s, transform .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-good { background: var(--good); color: #fff; }
.toast-bad { background: var(--bad); color: #fff; }
.toast-warn { background: var(--warn); color: #fff; }
@media (max-width: 760px) { .toast { bottom: calc(16px + env(safe-area-inset-bottom)); } }

/* ---------- страница «Нет связи» (PWA) ---------- */
.offline-card { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.offline-card img { border-radius: 16px; }
.offline-card h1 { font-size: 20px; margin: 4px 0 0; }
.table-licenses th, .table-licenses td { padding-left: 6px; padding-right: 6px; }
.table-licenses .tool-btn-sm { width: 24px; }
[data-live-system] { display: flex; flex-direction: column; gap: 20px; }
[data-live-system] > .grid-2 > .card { margin: 0; }
@media (max-width: 520px) {
  .topbar { gap: 10px; }
  .topbar h1 { min-width: 0; flex: 1 1 auto; overflow-wrap: anywhere; line-height: 1.2; }
  .topbar h1 .crumb, .topbar h1 .crumb-sep { display: none; }
  .topbar-user { flex: none; }
}

/* ---------- релизы с GitHub ---------- */
.gh-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.gh-result { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 14px 16px; border: 1px solid var(--border); border-radius: 12px; margin-bottom: 12px; }
.gh-result.gh-new { border-color: var(--accent); background: var(--accent-soft); }
.gh-result-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1 1 320px; }
.gh-result-main .tag { margin-left: 6px; }
.tag-accent { background: var(--accent); color: #fff; }
.gh-settings { margin: 6px 0 10px; }
.gh-settings summary { cursor: pointer; }
.gh-settings[open] summary { margin-bottom: 12px; }
.gh-settings form + form { margin-top: 12px; }
.gh-connect { margin: 10px 0 4px; }
form[data-busy-text].busy button { opacity: .7; pointer-events: none; }

/* ---------- телефон: нижнее меню и окно «Ещё» (как на платформе) ---------- */
.topbar-brand, .bottom-nav, .sheet { display: none; }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto; }
  .sidebar { display: none; }
  .topbar { position: sticky; top: 0; z-index: 20; padding: 10px 14px; gap: 10px; }
  .topbar-brand { display: block; flex: none; }
  .topbar-brand .brand-mark { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; }
  .topbar h1 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 19px; }
  .topbar .user-chip, .topbar-logout { display: none; }
  .content { padding: 14px 14px calc(84px + env(safe-area-inset-bottom)); }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(10px);
    border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom-nav a, .bottom-nav button {
    display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; border: 0; background: transparent;
    color: var(--muted); font: inherit; font-size: 11px; font-weight: 600; cursor: pointer; text-decoration: none;
  }
  .bottom-nav .tab-icon { position: relative; display: grid; place-items: center; width: 52px; height: 30px; border-radius: 999px; }
  .bottom-nav svg { width: 22px; height: 22px; fill: currentColor; }
  .bottom-nav .active { color: var(--accent-strong); }
  .bottom-nav .active .tab-icon { background: var(--accent-soft); }
  .bottom-nav .nav-dot { position: absolute; top: 3px; right: 12px; margin: 0; }
  dialog.sheet[open] {
    display: block; margin: auto 0 0; width: 100%; max-width: 100%; border: 0; padding: 0;
    border-radius: 18px 18px 0 0; background: var(--surface); color: var(--text);
  }
  dialog.sheet::backdrop { background: rgba(10, 16, 24, .45); }
  .sheet-body { padding: 14px 14px calc(18px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 2px; }
  .sheet-user { display: flex; align-items: center; gap: 10px; padding: 4px 4px 12px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
  .sheet-user .avatar { font-weight: 700; }
  .sheet-user .user-meta { display: flex; flex: 1; min-width: 0; }
  .sheet-user .user-meta small { overflow: hidden; text-overflow: ellipsis; }
  .sheet-close { width: 36px; height: 36px; border: 0; border-radius: 50%; background: var(--surface-2); color: var(--text); font-size: 22px; cursor: pointer; }
  .sheet-body > a, .sheet-logout {
    display: flex; align-items: center; gap: 12px; padding: 13px 10px; border-radius: 12px; border: 0; width: 100%;
    background: transparent; color: var(--text); font: inherit; font-size: 15px; font-weight: 600; text-align: left; cursor: pointer; text-decoration: none;
  }
  .sheet-body > a.active { background: var(--accent-soft); color: var(--accent-strong); }
  .sheet-body svg { width: 22px; height: 22px; fill: currentColor; opacity: .75; }
  .sheet-logout { color: var(--bad); }
  .sheet-version { text-align: center; margin: 8px 0 0; }
  .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
}

/* ---------- телефон: ничего не выходит за край экрана (особенно Safari на iPhone) ---------- */
.form-actions { flex-wrap: wrap; }
input[type="date"] { min-width: 0; max-width: 100%; }
@media (max-width: 860px) {
  /* Safari увеличивает страницу при касании поля со шрифтом меньше 16px — после этого её можно двигать вбок */
  input:not([type="checkbox"]):not([type="radio"]), select, textarea { font-size: 16px; }
  /* Safari не даёт полю даты сжаться по ширине экрана без этого */
  input[type="date"] { -webkit-appearance: none; appearance: none; display: block; width: 100%; text-align: left; }
  input[type="date"]::-webkit-date-and-time-value { text-align: left; }
  /* Подстраховка: страница никогда не ездит вбок */
  html, body { overflow-x: clip; max-width: 100%; }
}
.login-remember { margin: 2px 0 4px; color: var(--muted); }

/* ---------- компактные списки: «Раньше» и «Показать ещё» ---------- */
.fold-card > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.fold-card > summary::-webkit-details-marker { display: none; }
.fold-card > summary .section-label { margin: 0; }
.fold-card > summary .fold-hint::after { content: " ▾"; }
.fold-card[open] > summary { margin-bottom: 14px; }
.fold-card[open] > summary .fold-hint { display: none; }
.old-list { margin-top: 12px; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.old-list-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px; background: var(--surface-2); }
.old-rows { list-style: none; margin: 0; padding: 0; }
.old-row { display: flex; align-items: flex-start; gap: 10px; padding: 8px 12px 8px 16px; border-top: 1px solid var(--border); }
.old-row[hidden] { display: none; }
.old-row-main { flex: 1; min-width: 0; }
.old-row-main > summary { list-style: none; cursor: pointer; display: grid; grid-template-columns: 76px 96px 1fr; gap: 10px; align-items: center; min-height: 34px; }
.old-row-main > summary::-webkit-details-marker { display: none; }
.old-row-main > summary:hover .old-ver { color: var(--accent); }
.old-ver { font-weight: 700; }
.old-ver::before { content: "▸ "; color: var(--muted); }
.old-row-main[open] .old-ver::before { content: "▾ "; }
.old-info { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }
.old-row-body { padding: 6px 0 4px 20px; font-size: 13.5px; }
.old-row-body ul { margin: 0 0 6px; padding-left: 18px; }
.old-row-acts { display: flex; gap: 6px; flex: none; }
.old-row-acts form { display: contents; }
.more-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); }
@media (max-width: 760px) {
  .old-row-main > summary { grid-template-columns: auto 1fr; }
  .old-info { grid-column: 1 / -1; }
  .old-row { flex-wrap: wrap; }
  .old-row-acts { margin-left: auto; }
}
.backup-item[hidden] { display: none; }
.more-row-plain { border-top: 0; padding: 12px 0 0; }
.card-foot { margin: 12px 0 0; }

/* ---------- бэкапы: копия в облаке S3 ---------- */
.cloud-status { display: flex; align-items: center; gap: 8px; margin: 4px 0 12px; font-size: 14px; flex-wrap: wrap; }
.cloud-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.cloud-list { margin-bottom: 12px; }
.cloud-row { align-items: center; }
.cloud-row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; padding: 4px 0; }
.cloud-row-main .mono { overflow-wrap: anywhere; font-size: 13px; }
.cloud-form { display: flex; flex-direction: column; gap: 14px; margin-top: 12px; }
.cloud-form .btn-primary { align-self: flex-start; }
.cloud-advanced summary { cursor: pointer; }
.cloud-advanced[open] summary { margin-bottom: 10px; }
.cloud-settings { margin-top: 6px; padding-top: 12px; border-top: 1px solid var(--border); }
.cloud-disconnect { margin-top: 14px; }

/* Продукты (коробки): переключатель и значки */
.product-switch { display: inline-flex; flex-wrap: wrap; padding: 4px; gap: 4px; border-radius: 12px; background: var(--neutral-soft); margin: 0 0 16px; }
.product-switch a { display: inline-flex; align-items: center; gap: 7px; padding: 8px 16px; border-radius: 9px; font-weight: 600; font-size: 13.5px; color: var(--muted); }
.product-switch a:hover { color: var(--text); }
.product-switch a.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.product-switch a span { font-size: 11.5px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.tag-p-magicwebinar { background: var(--accent-soft); color: var(--accent-strong); }
.tag-p-magictelegram { background: var(--tg-soft); color: var(--tg); }
.product-summary { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: -4px 0 16px; font-size: 13px; color: var(--muted); }
.product-summary a { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
.product-summary a:hover { color: var(--text); }
.product-summary b { color: var(--text); }
.product-pick { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin: 0 0 16px; }
.product-pick a { display: block; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 14px 16px; color: var(--text); }
.product-pick a:hover { border-color: var(--border-strong); }
.product-pick a.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
.product-pick b { display: block; font-size: 15px; margin-bottom: 2px; }
.product-pick small { color: var(--muted); }

/* Magic Telegram */
.plain-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.target-list { display: grid; gap: 8px; }
.check.target { padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }
.check.target:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.check.target small { display: block; }
.check.target.disabled { opacity: .55; cursor: default; }
.send-when { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 14px; align-items: end; }
.dt { position: relative; display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; font-weight: 600; }
.dt-btn { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--input-bg); color: var(--text); font: inherit; cursor: pointer; text-align: left; }
.dt-btn svg { width: 18px; height: 18px; fill: var(--muted); flex: none; }
.dt-pop { position: absolute; z-index: 30; top: 70px; left: 0; width: 300px; max-width: calc(100vw - 40px); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--popover-shadow, 0 10px 30px rgba(16,24,40,.15)); padding: 12px; }
.dt-pop[hidden] { display: none; }
.dt-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.dt-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.dt-grid .wd { font-size: 11px; color: var(--muted); padding: 4px 0; font-weight: 600; }
.dt-grid .wd.we { color: var(--bad); }
.dt-grid button { border: 0; background: transparent; color: var(--text); font: inherit; font-size: 13px; height: 34px; border-radius: 8px; cursor: pointer; }
.dt-grid button:hover:not(:disabled) { background: var(--surface-2); }
.dt-grid button.out { color: var(--muted); }
.dt-grid button.past { color: var(--muted); opacity: .4; cursor: default; }
.dt-grid button.today { outline: 1px solid var(--accent); outline-offset: -1px; }
.dt-grid button.sel { background: var(--accent); color: #fff; }
.dt-time { display: flex; align-items: center; gap: 6px; margin-top: 10px; }
.dt-time select { width: 70px; }
.dt-time .btn { margin-left: auto; }
.row-actions { display: flex; gap: 8px; }
@media (max-width: 860px) { .send-when { grid-template-columns: minmax(0, 1fr); } }
.code-block { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0 0 12px; }
.target input[type=text] { margin-top: 8px; width: 100%; }
.cal-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.cal-head h2 { margin: 0; min-width: 150px; text-align: center; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-wd { font-size: 12px; font-weight: 600; color: var(--muted); text-align: center; padding: 4px 0; }
.cal-wd.we { color: var(--bad); }
.cal-day { min-height: 92px; border: 1px solid var(--border); border-radius: 10px; padding: 6px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal-day.empty { border-style: dashed; opacity: .4; }
.cal-day.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.cal-n { font-size: 12px; font-weight: 600; color: var(--muted); }
.cal-post { display: block; font-size: 11.5px; line-height: 1.3; padding: 3px 6px; border-radius: 6px; color: var(--text); background: var(--neutral-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-post b { font-weight: 700; }
.cal-post.st-scheduled, .cal-dot.st-scheduled { background: var(--accent-soft); }
.cal-post.st-sent, .cal-dot.st-sent { background: var(--good-soft); }
.cal-post.st-failed, .cal-post.st-partial, .cal-dot.st-failed { background: var(--bad-soft); }
.cal-dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: -1px; margin-left: 8px; }
.cal-legend { margin: 10px 0 0; }
@media (max-width: 860px) { .cal-day { min-height: 64px; padding: 4px; } .cal-post b { display: none; } .cal-post { font-size: 10.5px; padding: 2px 4px; } }

/* Приглашения и розыгрыши */
.stats-inline { grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 4px 0 16px; }
.stats-inline .stat { box-shadow: none; border: 1px solid var(--border); }
.inline-form { display: inline-block; margin: 0 0 0 4px; }
.form-grid .field-wide { grid-column: 1 / -1; }
.form-grid .check-inline, .form-grid .form-actions { grid-column: 1 / -1; }
.req-answer { margin-top: 4px; padding: 6px 8px; border-radius: 8px; background: var(--surface-2, rgba(127,127,127,.08)); overflow-wrap: anywhere; }
.join-set { padding: 14px 0; border-bottom: 1px solid var(--border); }
.join-set:last-of-type { border-bottom: 0; }
.join-head { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; margin-bottom: 10px; }
.join-set .form-actions { margin-top: 8px; }
@media (max-width: 640px) { .stats-inline { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; } }
.gw-pv-btn { margin-top: 4px; padding: 9px 10px; border-radius: 10px; text-align: center; font-size: 13px; font-weight: 600;
  background: var(--surface-2, rgba(127,127,127,.12)); color: var(--accent); }
.stat .small-value { font-size: 16px; line-height: 1.3; }
.join-set [hidden] { display: none !important; }
.gw-kinds { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.gw-kind { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1px solid var(--border); border-radius: 12px; cursor: pointer; }
.gw-kind:has(input:checked) { border-color: var(--accent); background: var(--accent-soft, rgba(0,136,204,.06)); }
.gw-kind.disabled { cursor: default; opacity: .75; }
.gw-kind span { display: flex; flex-direction: column; gap: 2px; }
.gw-kind input { margin-top: 3px; }
.gw-pv-leave { color: var(--muted, #888); font-weight: 500; }
.row-picked td { background: var(--good-soft, rgba(34,160,90,.07)); }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.tag-sm { font-size: 11px; padding: 1px 6px; }
[data-gw-form] [hidden] { display: none !important; }
@media (max-width: 640px) { .gw-kinds { grid-template-columns: 1fr; } }
.check-inline:has(> small) { flex-wrap: wrap; row-gap: 2px; }
.check-inline > small { flex-basis: 100%; padding-left: 24px; line-height: 1.4; }
[data-gw-form] .check-inline { margin: 6px 0; }
