:root {
  --bg: #0f172a;
  --card: #1e293b;
  --card-border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #22c55e;
  --error: #ef4444;
  --warning: #f59e0b;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.page {
  max-width: 560px;
  margin: 0 auto;
  padding: 24px 16px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.admin-page {
  max-width: 1100px;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.logo {
  font-size: 1.4rem;
  font-weight: 700;
}

.back-link {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.9rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 32px 24px;
}

h1 {
  font-size: 1.6rem;
  text-align: center;
  margin-bottom: 8px;
}

h2 {
  margin-bottom: 16px;
}

.subtitle {
  text-align: center;
  color: var(--muted);
  margin-bottom: 24px;
}

form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.code-input {
  padding: 14px 16px;
  font-size: 1.1rem;
  border-radius: 10px;
  border: 1px solid var(--card-border);
  background: #0f172a;
  color: var(--text);
  text-align: center;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.code-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

.btn {
  padding: 12px 20px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  transition: all 0.15s ease;
  background: var(--card-border);
  color: var(--text);
}

.btn:hover {
  opacity: 0.9;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-copy {
  background: var(--success);
  color: #fff;
  white-space: nowrap;
}

.btn-danger {
  background: var(--error);
  color: #fff;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.8rem;
}

/* Loader */
.loader {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
  color: var(--muted);
}

.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--card-border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.hidden {
  display: none !important;
}

/* Результат */
.result {
  margin-top: 20px;
  text-align: center;
}

.result.success {
  animation: pop 0.4s ease;
}

@keyframes pop {
  0% { transform: scale(0.9); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.success-badge {
  color: var(--success);
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 16px;
}

.key-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: #0f172a;
  border: 1px dashed var(--primary);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.key-value {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 1px;
  word-break: break-all;
  color: #fff;
}

.error-text {
  color: var(--error);
  font-weight: 600;
}

.activation-instruction {
  text-align: left;
  color: var(--muted);
  background: #0f172a;
  border-radius: 10px;
  padding: 16px;
  margin-top: 8px;
}

/* Инструкции */
.instructions {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--card-border);
}

.instructions h3 {
  margin-bottom: 12px;
  font-size: 1rem;
}

.instructions ol {
  padding-left: 20px;
  color: var(--muted);
}

.instructions li {
  margin-bottom: 6px;
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: auto;
  padding-top: 24px;
}

.footer-links {
  margin-top: 8px;
}

.footer-link {
  color: var(--primary);
  text-decoration: none;
}

.footer-link:hover {
  text-decoration: underline;
}

/* ---------- Админ-панель ---------- */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.tab {
  padding: 10px 16px;
  border: 1px solid var(--card-border);
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.15s ease;
}

.tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.panel {
  display: none;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 24px;
}

.panel.active {
  display: block;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

/* Выравнивание полей «Название продукта» и «Инструкция» в форме продукта */
#panel-products .form-grid label {
  align-items: stretch;
  justify-content: flex-end;
}

#panel-products .form-grid input,
#panel-products .form-grid textarea {
  width: 100%;
}

/* Поля «Название» и «Инструкция» — выровнены по нижней границе.
   «Название» фиксированной высоты, «Инструкция» — растягиваемая,
   но не выходит за пределы окна «Создать продукт». */
#prod-name {
  height: 42px;
  min-height: 42px;
}

#prod-instruction {
  min-height: 42px;
  max-height: 200px;
  resize: both;
}

input, select, textarea {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--card-border);
  background: #0f172a;
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.import-box {
  margin: 20px 0;
  padding: 16px;
  border: 1px dashed var(--card-border);
  border-radius: 12px;
}

.full-width {
  grid-column: 1 / -1;
}

.section-title {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--card-border);
}

.muted {
  color: var(--muted);
}

.promo-result {
  margin-top: 20px;
  padding: 16px;
  background: #0f172a;
  border: 1px solid var(--success);
  border-radius: 12px;
}

.promo-result h3 {
  margin-bottom: 8px;
  color: var(--success);
}

.promo-result textarea {
  width: 100%;
  font-family: monospace;
  font-size: 1rem;
  letter-spacing: 1px;
  margin: 12px 0;
}

.promo-result .btn {
  margin-right: 8px;
  margin-top: 4px;
}

/* Модальное окно */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--card-border);
}

.modal-header h2 {
  margin: 0;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.8rem;
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 24px;
}

.modal-body .btn {
  margin-top: 12px;
}

.import-box h3 {
  margin-bottom: 12px;
  font-size: 1rem;
}

.import-box textarea {
  width: 100%;
  margin-bottom: 12px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
  font-size: 0.9rem;
}

.table th, .table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--card-border);
}

.table th {
  color: var(--muted);
  font-weight: 600;
}

.table .ua {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge.free, .badge.active {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

.badge.issued, .badge.used {
  background: rgba(59, 130, 246, 0.15);
  color: var(--primary);
}

.badge.reserved {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
}

.report-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.report-card {
  background: #0f172a;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 16px;
}

.report-card h3 {
  margin-bottom: 12px;
  font-size: 1rem;
}

.report-card p {
  color: var(--muted);
  margin-bottom: 4px;
}

.report-card strong {
  color: var(--text);
}

/* Адаптивность */
@media (max-width: 600px) {
  .card {
    padding: 24px 16px;
  }

  .key-value {
    font-size: 1.2rem;
  }

  .key-box {
    flex-direction: column;
  }

  .table {
    font-size: 0.8rem;
  }

  .table th, .table td {
    padding: 8px 6px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }
}

/* Экран логина */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
}

.login-card {
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.login-card form {
  margin-top: 16px;
}

.login-card .error-text {
  margin-top: 12px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Политика конфиденциальности */
.privacy-content h2 {
  margin-top: 24px;
  margin-bottom: 8px;
  font-size: 1.1rem;
}

.privacy-content p {
  color: var(--muted);
  margin-bottom: 12px;
}

.privacy-content ul {
  padding-left: 20px;
  margin-bottom: 12px;
}

.privacy-content li {
  color: var(--muted);
  margin-bottom: 6px;
}

.privacy-content strong {
  color: var(--text);
}
