:root {
  --bg: #0b0e14;
  --surface: #131823;
  --surface-2: #1a2130;
  --border: #252f42;
  --text: #eef2f8;
  --muted: #8b98b1;
  --primary: #4f8cff;
  --primary-hover: #3b7bff;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --radius: 16px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  min-height: 100dvh;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.mt-8 {
  margin-top: 8px;
}

/* Экран входа */
.login-view {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-card h1 {
  margin: 0;
  font-size: 24px;
}

.login-card p {
  margin: 0;
  font-size: 14px;
}

.brand-badge {
  display: inline-flex;
  align-self: flex-start;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(79, 140, 255, 0.16);
  color: var(--primary);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.08em;
}

/* Верхняя панель */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(11, 14, 20, 0.88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.topbar-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-title strong {
  display: block;
  font-size: 17px;
  line-height: 1.2;
}

.topbar-title small {
  display: block;
  font-size: 12px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 10px rgba(34, 197, 94, 0.6);
  flex-shrink: 0;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

/* Основная область */
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
}

.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-input {
  flex: 1 1 200px;
  min-width: 0;
}

/* Поля ввода и кнопки */
input[type="text"],
input[type="password"],
input[type="search"],
input[type="number"],
textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, textarea:focus {
  border-color: var(--primary);
}

input[readonly] {
  opacity: 0.78;
}

textarea {
  resize: vertical;
  min-height: 76px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field > span {
  font-size: 13px;
  font-weight: 600;
  color: #c2cce0;
}

.hint {
  font-size: 12px;
  color: var(--muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, opacity 0.15s, transform 0.08s;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.35);
  color: #ff8080;
}

.btn-full {
  width: 100%;
}

.btn-grow {
  flex: 1;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Список карточек пользователей */
.users-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.user-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-card.is-disabled {
  opacity: 0.72;
}

.user-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.user-name {
  font-size: 17px;
  font-weight: 700;
  word-break: break-word;
}

.user-desc {
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
}

.status-pill {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status-ACTIVE {
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
}

.status-DISABLED {
  background: rgba(239, 68, 68, 0.16);
  color: #f87171;
}

.status-LIMITED, .status-EXPIRED {
  background: rgba(245, 158, 11, 0.16);
  color: #fbbf24;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badges.center {
  justify-content: center;
}

.badge {
  font-size: 12px;
  padding: 4px 9px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: #cdd6e8;
}

.badge-accent {
  background: rgba(79, 140, 255, 0.14);
  border-color: rgba(79, 140, 255, 0.32);
  color: #96bcff;
}

.badge-warn {
  background: rgba(245, 158, 11, 0.14);
  border-color: rgba(245, 158, 11, 0.3);
  color: #fcd34d;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
  flex-wrap: wrap;
}

.progress-track {
  height: 5px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
}

.card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  margin-top: 2px;
}

.card-actions .btn {
  min-height: 40px;
  padding: 8px 10px;
  font-size: 14px;
}

.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--muted);
}

/* Модальные окна и нижняя шторка */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

@media (min-width: 640px) {
  .modal {
    align-items: center;
    padding: 20px;
  }
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
}

.modal-sheet {
  position: relative;
  width: 100%;
  max-width: 540px;
  max-height: 92dvh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px 22px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (min-width: 640px) {
  .modal-sheet {
    border-radius: 22px;
  }
}

.modal-sheet-compact {
  max-width: 420px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-head h2 {
  margin: 0;
  font-size: 18px;
}

.modal-body {
  padding: 16px 18px calc(22px + env(safe-area-inset-bottom));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 2px 0;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.seg-btn {
  min-height: 42px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.seg-btn.active {
  background: rgba(79, 140, 255, 0.16);
  border-color: var(--primary);
  color: var(--text);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  min-height: 38px;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.chip.active {
  background: rgba(79, 140, 255, 0.18);
  border-color: var(--primary);
  color: var(--text);
}

.mode-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mode-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
}

.mode-card:has(input:checked) {
  border-color: var(--primary);
  background: rgba(79, 140, 255, 0.1);
}

.mode-card input {
  margin-top: 3px;
  accent-color: var(--primary);
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.mode-card strong {
  display: block;
  font-size: 14px;
}

.mode-card small {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.selected-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
}

.services-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.service-tile {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
}

.service-tile:has(input:checked) {
  border-color: var(--primary);
  background: rgba(79, 140, 255, 0.14);
}

.service-tile input {
  margin-top: 2px;
  accent-color: var(--primary);
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

.service-tile strong {
  display: block;
  font-size: 13px;
  line-height: 1.25;
}

.service-tile small {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1.25;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  cursor: pointer;
}

.switch-row strong {
  display: block;
  font-size: 14px;
}

.switch-row small {
  display: block;
  font-size: 12px;
}

.switch-row input {
  width: 22px;
  height: 22px;
  accent-color: var(--primary);
  flex-shrink: 0;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.error-box {
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 13px;
}

/* Выдача доступа и код быстрого отклика */
.share-body {
  align-items: center;
}

.qr-box {
  background: #ffffff;
  padding: 14px;
  border-radius: 16px;
  width: 228px;
  height: 228px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-box svg {
  width: 100%;
  height: 100%;
  display: block;
}

.link-box {
  width: 100%;
  display: flex;
  gap: 8px;
}

.link-box input {
  font-size: 13px;
  padding: 10px 12px;
}

.small-center {
  text-align: center;
  font-size: 12px;
  margin: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #1f293d;
  border: 1px solid var(--primary);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  z-index: 80;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
