* {
  box-sizing: border-box;
}

:root {
  --bg: #f1f3f7;
  --surface: #ffffff;
  --text: #1a1d26;
  --muted: #6b7280;
  --border: #e2e5ec;
  --accent: #4f6ef7;
  --accent-dark: #3b55d9;
  --danger: #e5484d;
  --success: #30a46c;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

/* ===================== Логин ===================== */

.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-card h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: -0.02em;
}

.login-card p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 14px;
}

.login-card input {
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
}

.login-card input:focus {
  border-color: var(--accent);
}

.error-text {
  color: var(--danger);
  font-size: 13px;
}

/* ===================== Кнопки ===================== */

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  background: var(--accent);
  color: #fff;
}

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

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

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

.btn-secondary:hover {
  background: #f6f7f9;
}

.btn-danger-ghost {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 6px 10px;
  font-size: 13px;
}

.btn-danger-ghost:hover {
  color: var(--danger);
  background: transparent;
}

/* ===================== Шапка ===================== */

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.01em;
}

.brand span {
  color: var(--muted);
  font-size: 13px;
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* ===================== Зона загрузки ===================== */

.dropzone {
  margin: 24px auto 0;
  max-width: 1100px;
  width: calc(100% - 48px);
  border: 2px dashed #c9cfdd;
  border-radius: var(--radius);
  background: var(--surface);
  padding: 34px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  background: #f6f8ff;
}

.dropzone .dz-icon {
  font-size: 30px;
  line-height: 1;
  margin-bottom: 10px;
}

.dropzone .dz-title {
  font-weight: 600;
  font-size: 15px;
}

.dropzone .dz-hint {
  color: var(--muted);
  font-size: 13px;
  margin-top: 6px;
}

.dropzone .dz-hint code {
  background: #eef1f6;
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 12px;
}

/* ===================== Карточки ===================== */

.cards-grid {
  max-width: 1100px;
  margin: 24px auto 120px;
  width: calc(100% - 48px);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 18px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.card-top {
  display: flex;
  gap: 14px;
  padding: 14px 14px 0;
  align-items: flex-start;
}

.card-photo {
  width: 96px;
  height: 96px;
  border-radius: 8px;
  object-fit: cover;
  background: #eef1f6;
  flex-shrink: 0;
}

.card-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card-filename {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  align-self: flex-start;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
}

.badge-ok {
  background: #e7f5ee;
  color: var(--success);
}

.badge-manual {
  background: #fdf1e2;
  color: #b45309;
}

.badge-loading {
  background: #eef1f6;
  color: var(--muted);
}

.card-fields {
  padding: 12px 14px 4px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

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

.field.wide {
  grid-column: 1 / -1;
}

.field label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.field input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 14px;
  outline: none;
  width: 100%;
  transition: border-color 0.15s;
}

.field input:focus {
  border-color: var(--accent);
}

.field input.invalid {
  border-color: var(--danger);
}

.card-actions {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px 14px;
}

.card-actions .btn {
  padding: 8px 16px;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
  vertical-align: -2px;
  margin-right: 6px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ===================== Нижняя панель ===================== */

.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.bottom-bar .stat {
  color: var(--muted);
  font-size: 14px;
}

.bottom-bar .stat b {
  color: var(--text);
}

/* ===================== Модалка PDF ===================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 18, 28, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
}

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

.modal-header h3 {
  margin: 0;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal-body {
  overflow: auto;
  background: #eceef3;
  display: flex;
  justify-content: center;
  padding: 18px;
  flex: 1;
}

.modal-body canvas {
  max-width: 100%;
  height: auto !important;
  border-radius: 4px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
}

.icon-btn {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}

.icon-btn:hover {
  background: #f1f3f7;
  color: var(--text);
}

/* ===================== Тосты ===================== */

.toast-container {
  position: fixed;
  top: 70px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: #22252f;
  color: #fff;
  font-size: 13px;
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease-out;
  max-width: 340px;
}

.toast.error {
  background: var(--danger);
}

@keyframes toast-in {
  from {
    transform: translateY(-8px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@media (max-width: 600px) {
  .cards-grid {
    grid-template-columns: 1fr;
  }

  .brand span {
    display: none;
  }
}
