* { box-sizing: border-box; transition: background-color 0.25s ease, border-color 0.25s ease; }
html, body { margin: 0; }
body {
  font-family: var(--font-sans);
  background: var(--bg); color: var(--fg); min-height: 100vh; font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--acc); text-decoration: none; font-weight: 500; transition: color 0.2s; }
a:hover { color: var(--acc-hover); }
.ic { flex: none; vertical-align: -3px; }

/* ── Клиентский топбар ── */
header.topbar-client {
  background: var(--card); border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  padding: 0 24px; display: flex; align-items: center; gap: 16px; height: var(--header-height);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 800; font-size: 16px; }
.brand .logo {
  width: 36px; height: 36px; border-radius: 8px; flex: none; color: var(--on-accent);
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow);
}
.brand small { display: block; font-size: 11px; color: var(--mut); font-weight: 500; margin-top: 1px; }
.sp { flex: 1; }
.icon-btn {
  background: var(--card); border: 1px solid var(--line); color: var(--fg);
  border-radius: 8px; padding: 9px; cursor: pointer; display: inline-flex;
  align-items: center; justify-content: center; transition: transform 0.15s ease, border-color 0.2s;
}
.icon-btn:hover { border-color: var(--acc); transform: translateY(-1px); }
:root[data-theme="light"] .ic-sun { display: none; }
:root[data-theme="dark"] .ic-moon { display: none; }

@keyframes pageIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
body.client main {
  max-width: 820px; margin: 32px auto; padding: 0 20px 60px;
  animation: pageIn 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* ── Админский сайдбар ── */
.shell { display: flex; min-height: 100vh; }
aside {
  width: var(--sidebar-width); flex: none; background: var(--sb-bg); color: var(--sb-fg);
  display: flex; flex-direction: column; padding: 18px 12px;
  position: sticky; top: 0; height: 100vh; box-shadow: var(--shadow); z-index: 30;
}
aside .brand { padding: 6px 12px 24px; color: var(--text-primary); }
aside .brand b { font-size: 16px; font-weight: 800; }
aside .brand small { color: var(--sb-fg); }
nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 8px;
  color: var(--sb-fg); font-weight: 600; text-decoration: none; cursor: pointer;
  transition: all 0.2s ease; user-select: none;
}
.nav-item:hover { background: var(--sb-hover); color: var(--sb-active); text-decoration: none; }
.nav-item.active {
  background: var(--accent-subtle); color: var(--accent);
  box-shadow: none;
}
.sb-foot { display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--surface-2); padding-top: 10px; margin-top: auto; }
.sb-foot button, .sb-foot .nav-item {
  background: none; border: 0; font: inherit; font-weight: 600; width: 100%; text-align: left;
}
.sb-foot .nav-item.logout { color: var(--danger); margin-top: 6px; }
.sb-foot .nav-item.logout:hover { background: var(--danger-subtle); color: var(--danger); }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px; height: var(--header-height); padding: 8px 32px; position: sticky; top: 0;
  background: var(--surface-1); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  z-index: 10; border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 20px; font-weight: 800; margin: 0; flex: 1; letter-spacing: -0.4px; }
.burger { display: none; background: var(--card); border: 1px solid var(--line); color: var(--fg);
  border-radius: 8px; padding: 9px; cursor: pointer; transition: all 0.2s; }
.burger:hover { border-color: var(--acc); }
.shell main {
  padding: 16px 32px 60px; max-width: 1140px; width: 100%;
  animation: pageIn 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* ── Общие блоки ── */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 24px;
  margin-bottom: 24px; box-shadow: var(--shadow);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.card h2 { font-size: 16px; font-weight: 700; margin: 0 0 16px; display: flex; align-items: center; gap: 10px; letter-spacing: -0.2px; }
.card h2 .ic { color: var(--acc); }
.mut { color: var(--mut); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px; box-shadow: var(--shadow); }
.stat .n { font-size: 24px; font-weight: 800; letter-spacing: -0.5px; margin-top: 4px; }
.stat .l { font-size: 12px; color: var(--mut); font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; display: flex; gap: 8px; align-items: center; }

.table-wrap { overflow-x: auto; width: 100%; max-width: 100%; min-width: 0; border-radius: 12px; border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { text-align: left; padding: 6px 10px; line-height: 1.3; vertical-align: middle; border-bottom: 1px solid var(--line); }
tr:last-child td { border-bottom: 0; }
th { color: var(--mut); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; background: var(--card2); }
tbody tr { transition: background-color 0.15s; }
tbody tr:hover { background: var(--card2); }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 99px; font-size: 12px; font-weight: 600; border: 1px solid var(--surface-2); }
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.blue { background: var(--blue-soft); color: var(--blue); }
.pill.warn { background: var(--danger-subtle); color: var(--danger); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.acc { background: var(--acc-soft); color: var(--acc); }
.avatar { width: 24px; height: 24px; border-radius: 50%; flex: none; color: var(--on-accent); font-size: 12px; font-weight: 700;
  background: var(--accent); display: inline-flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow); }
.who { display: flex; align-items: center; gap: 12px; }
code { font-family: var(--font-mono); background: var(--card2);
  padding: 4px 8px; border-radius: 8px; border: 1px solid var(--line); font-size: 13px; color: var(--fg); word-break: break-all; }

input, select {
  background: var(--card2); border: 1px solid var(--line); color: var(--fg); padding: 10px 14px;
  border-radius: 8px; font-size: 14px; width: 100%; outline: none; transition: border-color 0.2s, box-shadow 0.2s;
}
select {
  appearance: auto; cursor: pointer;
}
input:focus, select:focus { border-color: var(--acc); box-shadow: var(--shadow); }
label.chk { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--fg); cursor: pointer; margin: 4px 0; }
label.chk input { width: auto; }

button, .btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center; background: var(--acc);
  color: var(--on-accent); border: 0; padding: 10px 18px; border-radius: 8px; cursor: pointer; font-size: 14px;
  font-weight: 600; font-family: inherit; line-height: 1.25; box-shadow: var(--shadow); transition: all 0.2s ease;
  position: static;
}
button svg, .btn svg { flex: none; width: 16px; height: 16px; }
button:hover, .btn:hover { background: var(--acc-hover); color: var(--on-accent); transform: translateY(-1px); box-shadow: var(--shadow); }
button:active, .btn:active { transform: translateY(0); }
a.btn:hover { text-decoration: none; }
button.ghost, .btn.ghost { background: var(--card); border: 1px solid var(--line); color: var(--fg); box-shadow: var(--shadow); }
button.ghost:hover, .btn.ghost:hover { background: var(--card2); border-color: var(--acc); color: var(--fg); transform: translateY(-1px); box-shadow: var(--shadow); }
button.danger, .btn.danger { background: var(--danger-subtle); border: 1px solid transparent; color: var(--danger); box-shadow: var(--shadow); }
button.danger:hover, .btn.danger:hover { background: var(--danger); color: var(--on-accent); transform: translateY(-1px); box-shadow: var(--shadow); }
.sm { padding: 6px 12px !important; font-size: 13px !important; }
.row { display: flex; gap: 14px; flex-wrap: wrap; align-items: end; }
.auth-card form { display: flex; flex-direction: column; gap: 0; }
.auth-card .field { margin-bottom: 12px; }
.auth-card .field:last-of-type { margin-bottom: 16px; }
.auth-card button, .auth-card .btn { width: 100%; margin: 0; position: static; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; flex: 1 1 180px; }
.auth-card .field, .modal-box .field { width: 100%; flex: none; }
.field label { font-size: 12px; color: var(--mut); font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; }
.grow { flex: 1; }

.alert { border-radius: 12px; padding: 14px 18px; margin-bottom: 20px; display: flex; gap: 10px; align-items: center; font-weight: 600; border: 1px solid var(--line); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.warn { background: var(--danger-subtle); color: var(--danger); }

/* Конфиги (kv-list) */
.cfg { border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 16px; background: var(--card2); }
.cfg-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.kv-list { display: flex; flex-direction: column; gap: 4px; }
.kv { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.kv:last-child { border-bottom: 0; }
.kv-name { flex: none; width: 260px; font-size: 13px; color: var(--mut); font-weight: 500; }
.kv code { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.kv-copy { padding: 6px 10px !important; flex: none; }
@media (max-width:680px) { .kv { flex-wrap: wrap; gap: 6px; } .kv-name { width: 100%; } }

/* Кнопки-магазины */
.store { display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px; border-radius: 8px; font-size: 13.5px; font-weight: 600; color: var(--text-primary); box-shadow: var(--shadow); }
.store.ios { background: var(--surface-2); } .store.android { background: var(--surface-2); }

/* Авторизация */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 390px; }
.auth-logo { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 26px; }
.auth-logo .logo { width: 56px; height: 56px; border-radius: 16px; display: flex; align-items: center; justify-content: center; color: var(--on-accent); }
.auth-logo .logo.acc { background: var(--accent); box-shadow: var(--shadow); }
.auth-logo .logo.green { background: var(--accent); box-shadow: var(--shadow); }

.overlay { display: none; }
@media (max-width: 860px) {
  aside { position: fixed; left: 0; top: 0; bottom: 0; z-index: 50; height: 100vh;
    transform: translateX(-105%); transition: transform .22s ease; }
  body.sb-open aside { transform: none; }
  .overlay { position: fixed; inset: 0; background: var(--overlay); z-index: 40; }
  body.sb-open .overlay { display: block; }
  .burger { display: inline-flex; }
  .topbar { padding: 12px 18px; }
  .shell main { padding: 16px 18px 40px; }
  .row { flex-direction: column; align-items: stretch; }
  .field { min-width: 0; }
}
@media (max-width: 640px) {
  header.topbar-client { padding: 8px 16px; height: auto; min-height: var(--header-height); flex-wrap: wrap; gap: 8px; }
  .brand small { display: none; }
  body.client main { margin: 20px auto; padding: 0 12px 40px; }
}

/* ---------- modal ---------- */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0; z-index: 100;
  background: var(--overlay);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  align-items: center; justify-content: center;
  padding: 24px;
}
.modal-backdrop.open { display: flex; animation: backdropIn 0.18s ease both; }
@keyframes backdropIn { from { opacity: 0; } to { opacity: 1; } }
.modal-box {
  width: 100%; max-width: 460px;
  max-height: calc(100vh - 48px); overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px;
  box-shadow: var(--shadow);
  animation: modalIn 0.28s cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(8px) scale(0.97); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 6px; }
.modal-head .m-ic {
  width: 40px; height: 40px; flex: none; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--on-accent);
  box-shadow: var(--shadow);
}
.modal-head h2 { font-size: 17px; font-weight: 700; margin: 2px 0 0; display: flex; align-items: center; gap: 8px; letter-spacing: -0.2px; }
.modal-head h2 .ic { color: var(--acc); }
.modal-x { margin-left: auto; background: none; border: 0; box-shadow: var(--shadow); color: var(--mut); padding: 6px; cursor: pointer; border-radius: 8px; line-height: 1; }
.modal-x:hover { background: var(--card2); color: var(--fg); transform: none; box-shadow: var(--shadow); }
.modal-sub { color: var(--mut); font-size: 13.5px; margin: 0 0 18px; line-height: 1.5; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

select {
  appearance: auto; cursor: pointer;
}
