/* ========================================
   CSS для сервиса школьных справок
   ======================================== */

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #f59e0b;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.5;
  min-height: 100vh;
}

/* ========== Утилиты ========== */
.hidden { display: none !important; }
.text-muted { color: var(--gray-500); }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-5 { margin-bottom: 1.25rem; }
.mt-4 { margin-top: 1rem; }
.mt-5 { margin-top: 1.25rem; }

/* ========== Шапка ========== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--gray-200);
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.topbar-logo {
  width: 40px;
  height: 40px;
  background: var(--gray-900);
  color: white;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  font-size: 1.25rem;
}

.topbar-title {
  font-weight: 600;
  font-size: 1rem;
}

.topbar-subtitle {
  font-size: 0.75rem;
  color: var(--gray-500);
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ========== Кнопки ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}

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

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

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

.btn-outline {
  background: white;
  border: 1px solid var(--gray-300);
  color: var(--gray-700);
}

.btn-outline:hover:not(:disabled) {
  background: var(--gray-50);
  border-color: var(--gray-400);
}

.btn-ghost {
  background: transparent;
  color: var(--gray-600);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--gray-100);
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover:not(:disabled) {
  background: #15803d;
}

/* ========== Карточки ========== */
.card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.card-title {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-body {
  padding: 1.25rem;
}

/* ========== Формы ========== */
.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.375rem;
  color: var(--gray-700);
}

.form-input,
.form-select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  background: white;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-input::placeholder {
  color: var(--gray-400);
}

.form-input-sm {
  padding: 0.375rem 0.5rem;
  font-size: 0.8125rem;
}

/* ========== Бейджи ========== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 9999px;
  background: var(--gray-100);
  color: var(--gray-600);
}

.badge-primary {
  background: rgba(37, 99, 235, 0.1);
  color: var(--primary);
}

.badge-success {
  background: rgba(22, 163, 74, 0.1);
  color: var(--success);
}

/* ========== Контейнер ========== */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}

/* ========== Страница входа ========== */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: linear-gradient(135deg, var(--gray-50) 0%, var(--gray-100) 100%);
}

.login-card {
  width: 100%;
  max-width: 400px;
}

.login-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.login-logo {
  width: 48px;
  height: 48px;
  background: var(--gray-900);
  color: white;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  font-size: 1.5rem;
}

.login-title {
  font-size: 1.25rem;
  font-weight: 600;
}

.login-hint {
  font-size: 0.75rem;
  color: var(--gray-500);
}

.login-error {
  padding: 0.75rem;
  background: rgba(220, 38, 38, 0.1);
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

/* ========== Заголовок страницы ========== */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.page-subtitle {
  font-size: 0.875rem;
  color: var(--gray-500);
  margin-top: 0.25rem;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* ========== Разделитель ========== */
.divider {
  height: 1px;
  background: var(--gray-200);
  margin: 1.25rem 0;
}

/* ========== Список учеников ========== */
.student-list {
  divide-y: 1px solid var(--gray-100);
}

.student-item {
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--gray-100);
}

.student-item:last-child {
  border-bottom: none;
}

.student-name {
  font-weight: 500;
}

.student-info {
  font-size: 0.75rem;
  color: var(--gray-500);
}

/* ========== Таблица оценок ========== */
.marks-table-wrapper {
  overflow-x: auto;
  margin: -1.25rem;
  margin-top: 1rem;
}

.marks-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.marks-table th,
.marks-table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--gray-100);
}

.marks-table th {
  background: var(--gray-50);
  font-weight: 500;
  color: var(--gray-600);
  position: sticky;
  top: 0;
}

.marks-table th:first-child,
.marks-table td:first-child {
  position: sticky;
  left: 0;
  background: white;
  z-index: 1;
  min-width: 280px;
}

.marks-table th:first-child {
  background: var(--gray-50);
  z-index: 2;
}

.marks-table tbody tr:hover {
  background: var(--gray-50);
}

.marks-table tbody tr:hover td:first-child {
  background: var(--gray-50);
}

.mark-input {
  width: 70px;
  padding: 0.375rem 0.5rem;
  text-align: center;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
}

.mark-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

/* ========== Табы ========== */
.tabs {
  display: inline-flex;
  background: var(--gray-100);
  border-radius: var(--radius);
  padding: 0.25rem;
}

.tab-btn {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  background: transparent;
  color: var(--gray-600);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab-btn:hover {
  color: var(--gray-800);
}

.tab-btn.active {
  background: white;
  color: var(--gray-900);
  box-shadow: var(--shadow);
}

/* ========== Журнал справок ========== */
.report-item {
  padding: 1rem 1.25rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--gray-100);
}

.report-item:last-child {
  border-bottom: none;
}

.report-fio {
  font-weight: 500;
}

.report-meta {
  font-size: 0.75rem;
  color: var(--gray-500);
  margin-top: 0.25rem;
}

/* ========== Фильтры ========== */
.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  align-items: end;
}

.filters-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ========== Статистика ========== */
.stats {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ========== Лоадер ========== */
.loader {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ========== Пустое состояние ========== */
.empty-state {
  padding: 2rem;
  text-align: center;
  color: var(--gray-500);
}

/* ========== Payload preview ========== */
.payload-preview {
  background: var(--gray-50);
  border-radius: var(--radius-sm);
  padding: 1rem;
  font-family: "SF Mono", Monaco, "Courier New", monospace;
  font-size: 0.75rem;
  overflow-x: auto;
  max-height: 240px;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ========== Адаптивность ========== */
@media (max-width: 768px) {
  .page-header {
    flex-direction: column;
    align-items: stretch;
  }
  
  .page-actions {
    justify-content: flex-start;
  }
  
  .topbar-nav .btn span {
    display: none;
  }
  
  .filters {
    grid-template-columns: 1fr;
  }
}

/* ========== Уведомления ========== */
.toast {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  background: var(--gray-900);
  color: white;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-size: 0.875rem;
  z-index: 1000;
  animation: slideIn 0.3s ease;
}

.toast-success {
  background: var(--success);
}

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

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(1rem);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ========== Модальное окно ========== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: grid;
  place-items: center;
  z-index: 1000;
  padding: 1rem;
  animation: fadeIn 0.2s ease;
}

.modal {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 420px;
  animation: scaleIn 0.2s ease;
}

.modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 1.125rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--gray-400);
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.modal-close:hover {
  color: var(--gray-600);
}

.modal-body {
  padding: 1.25rem;
}

.modal-body p {
  margin-bottom: 0.5rem;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}

.modal-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--gray-100);
  display: flex;
  justify-content: flex-end;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ========== Маленькие кнопки ========== */
.btn-sm {
  padding: 0.375rem 0.625rem;
  font-size: 0.75rem;
}

/* ========== Журнал - улучшенный вид ========== */
.report-info {
  flex: 1;
  min-width: 0;
}

.report-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

@media (max-width: 640px) {
  .report-item {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .report-actions {
    margin-top: 0.75rem;
    width: 100%;
  }
  
  .report-actions .btn {
    flex: 1;
  }
}

/* ========== Админ-панель ========== */
.admin-filters {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 1rem;
  align-items: end;
}

.filter-group {
  display: flex;
  flex-direction: column;
}

.filter-actions {
  display: flex;
  flex-direction: column;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

.stat-card {
  background: white;
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 0.875rem;
  color: var(--gray-500);
  margin-top: 0.25rem;
}

.export-buttons {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.admin-journal {
  max-height: 500px;
  overflow-y: auto;
}

@media (max-width: 768px) {
  .admin-filters {
    grid-template-columns: 1fr;
  }
  
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .export-buttons {
    flex-direction: column;
  }
  
  .export-buttons .btn {
    width: 100%;
  }
}
