@import url('https://fonts.googleapis.com/css2?family=Inter:opsz,wght@14..32,400;14..32,500;14..32,600;14..32,700&display=swap');

:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --warning: #f59e0b;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  --shadow-hover: 0 8px 32px rgba(0, 0, 0, 0.10);
  --transition: 0.25s ease;
  --input-bg: #fff;
  --badge-bg: #f1f5f9;
  --calendar-bg: #f8fafc;
  --calendar-header-bg: #e2e8f0;
  --issued-bg: #fffbeb;
  --issued-line: #fde68a;
}

body.dark-theme {
  --bg: #0f172a;
  --panel: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --line: #334155;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --danger: #ef4444;
  --danger-hover: #f87171;
  --success: #4ade80;
  --warning: #fbbf24;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-hover: 0 8px 32px rgba(0, 0, 0, 0.4);
  --input-bg: #1e293b;
  --badge-bg: #334155;
  --calendar-bg: #1e293b;
  --calendar-header-bg: #334155;
  --issued-bg: #302410;
  --issued-line: #78350f;
}

/* ---------- Общее ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  transition: background var(--transition), color var(--transition);
}

.shell { width: min(1100px, calc(100% - 32px)); margin: 0 auto; padding: 24px 0 40px; }
.hidden { display: none !important; }
.spacer { flex: 1; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: background var(--transition), border-color var(--transition);
}

/* ---------- Авторизация ---------- */
.auth-view { min-height: 100vh; display: grid; place-items: center; }
.auth-panel { width: min(400px, 100%); padding: 32px 28px; display: grid; gap: 14px; }
.auth-panel h1 { font-weight: 600; font-size: 28px; letter-spacing: -0.02em; }
.auth-panel p { color: var(--muted); margin-top: -8px; }

/* ---------- Шапка ---------- */
.topbar {
  display: flex; justify-content: space-between; gap: 16px;
  align-items: center; flex-wrap: wrap;
  margin-bottom: 24px; padding-bottom: 12px;
  border-bottom: 2px solid var(--line);
}
.topbar h1 { font-size: 24px; font-weight: 600; }
.sync-status { color: var(--muted); font-size: 14px; }
.topbar-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------- Кнопки ---------- */
button {
  min-height: 40px; border: 0; border-radius: 8px; padding: 8px 16px;
  font-family: inherit; font-weight: 500; font-size: 14px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--badge-bg); color: var(--text);
  transition: background var(--transition), transform 0.1s, box-shadow var(--transition);
}
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.5; pointer-events: none; }
.primary { background: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25); }
.primary:hover { background: var(--primary-hover); }
.secondary:hover { background: var(--line); }
.danger { background: var(--danger); color: #fff; }
.danger:hover { background: var(--danger-hover); }

/* ---------- Поля ввода ---------- */
input, select {
  min-height: 42px; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 12px; font-family: inherit; font-size: 14px;
  background: var(--input-bg); color: var(--text); width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
label { display: grid; gap: 6px; font-weight: 500; font-size: 14px; }
.form-grid { display: grid; gap: 14px; }

/* ---------- Список ---------- */
.list { display: grid; gap: 10px; }
.row {
  display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center;
  padding: 16px 20px; border: 1px solid var(--line); background: var(--panel);
  border-radius: var(--radius);
  transition: border-color var(--transition), box-shadow var(--transition), transform 0.15s;
}
.row:hover { border-color: var(--primary); box-shadow: var(--shadow-hover); }
.row-selectable { grid-template-columns: auto 1fr; }
.row-link {
  display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center;
  text-decoration: none; color: inherit;
}
.row-title { font-weight: 600; font-size: 16px; overflow-wrap: anywhere; }
.row-subtitle { color: var(--muted); font-size: 14px; margin-top: 4px; overflow-wrap: anywhere; }
.instrument-checkbox { width: 18px; height: 18px; cursor: pointer; accent-color: var(--primary); }

/* ---------- Бейджи ---------- */
.badges { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; align-items: center; }
.badges-left { justify-content: flex-start; margin-top: 8px; }
.badge {
  display: inline-flex; align-items: center; min-height: 28px; padding: 4px 12px;
  border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--badge-bg); color: var(--text); white-space: nowrap;
}
.muted { background: #f1f5f9; color: #475569; }
.ok    { background: #dcfce7; color: #166534; }
.warn  { background: #fef3c7; color: #92400e; }
.bad   { background: #fee2e2; color: #991b1b; }
.badge.red    { background: #fee2e2; color: #b91c1c; }
.badge.green  { background: #dcfce7; color: #166534; }
.badge.blue   { background: #dbeafe; color: #1e40af; }
.badge.purple { background: #ede9fe; color: #6b21a8; }

body.dark-theme .muted { background: #334155; color: #94a3b8; }
body.dark-theme .ok    { background: #065f46; color: #86efac; }
body.dark-theme .warn  { background: #78350f; color: #fcd34d; }
body.dark-theme .bad   { background: #7f1d1d; color: #fca5a5; }

/* ---------- Карточка ---------- */
.card { padding: 24px; }
.card h1 { font-weight: 600; font-size: 26px; letter-spacing: -0.02em; }
.card-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; margin-top: 20px; }
.field { border-top: 1px solid var(--line); padding-top: 12px; }
.field-label {
  color: var(--muted); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.field-value { margin-top: 6px; font-size: 15px; overflow-wrap: anywhere; }
.field-value a { color: var(--primary); }

.photo-box { text-align: center; margin-bottom: 16px; color: var(--muted); font-size: 14px; }
.photo-box img {
  max-width: 100%; max-height: 300px; object-fit: contain;
  border-radius: var(--radius); border: 1px solid var(--line);
}

.issued {
  margin-top: 20px; padding: 16px; border-radius: var(--radius);
  background: var(--issued-bg); border: 1px solid var(--issued-line);
}
.issued .field:first-child { border-top: 0; padding-top: 0; }
.issued.booked  { background: #fef2f2; border-color: #fecaca; }
.issued.retired { background: var(--badge-bg); border-color: var(--line); }
body.dark-theme .issued.booked { background: #3b1a1a; border-color: #7f1d1d; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; align-items: center; }

/* ---------- Панель фильтров ---------- */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: center;
  padding: 16px 20px; margin-bottom: 20px;
}
.search { flex: 2 1 220px; min-width: 160px; }
.filter-group {
  display: flex; align-items: center; gap: 8px; background: var(--input-bg);
  padding: 4px 12px 4px 16px; border-radius: 40px; border: 1px solid var(--line);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.filter-group:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15); }
.filter-label { font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.filter-group select {
  border: none; background: transparent; padding: 6px 24px 6px 0;
  font-weight: 500; font-size: 14px; color: var(--text);
  outline: none; min-height: auto; width: auto; cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 4px center;
}

/* ---------- Модальные окна ---------- */
dialog {
  border: 0; border-radius: var(--radius); padding: 0;
  width: min(580px, calc(100% - 24px)); margin: auto;
  max-height: 90vh; overflow-y: auto;
  background: var(--panel); color: var(--text);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.2);
  animation: modalIn 0.25s ease;
}
dialog::backdrop { background: rgba(15, 23, 42, 0.5); backdrop-filter: blur(3px); }
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(16px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-body { padding: 24px; }
.modal-head {
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
  margin-bottom: 16px; border-bottom: 1px solid var(--line); padding-bottom: 12px;
}
.modal-head h1 { font-weight: 600; font-size: 22px; }
.modal-actions {
  display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end;
  margin-top: 20px; border-top: 1px solid var(--line); padding-top: 16px;
}

/* ---------- Уведомления ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #0f172a; color: #fff; border-radius: 999px;
  padding: 12px 24px; z-index: 100; font-weight: 500;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  max-width: calc(100% - 32px); text-align: center;
  animation: toastIn 0.3s ease;
}
.toast-error { background: #b42318; }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ---------- Календарь ---------- */
.calendar-header {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;
}
.calendar-title { font-weight: 600; font-size: 18px; text-transform: capitalize; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.day {
  min-height: 44px; border-radius: 8px; display: grid; place-items: center;
  background: var(--calendar-bg); color: var(--text); font-weight: 500;
  transition: transform 0.1s;
}
.day.header { font-weight: 700; background: var(--calendar-header-bg); }
.day[data-day] { cursor: pointer; }
.day[data-day]:hover { transform: scale(1.05); }
.day.red    { background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5; }
.day.green  { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.day.blue   { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }
.day.orange { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.day.purple { background: #ede9fe; color: #6b21a8; border: 1px solid #c4b5fd; }
.day.today  { outline: 3px solid var(--primary); font-weight: 700; }
.calendar-legend {
  display: flex; gap: 12px; flex-wrap: wrap; justify-content: center;
  margin-top: 16px; font-size: 13px; color: var(--muted);
}
.day-section { margin-top: 12px; display: grid; gap: 8px; }

/* ---------- QR ---------- */
.qr-box { display: grid; place-items: center; padding: 8px; }
.qr-box img, .qr-box canvas { background: #fff; padding: 8px; border-radius: 8px; }
.qr-caption { text-align: center; color: var(--muted); margin-top: 8px; }

/* ---------- Мобильные экраны ---------- */
@media (max-width: 720px) {
  .shell { padding: 12px 8px; }
  .topbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .topbar-actions > * { flex: 1 1 auto; }
  .toolbar { flex-direction: column; align-items: stretch; gap: 10px; padding: 12px; }
  .toolbar .search { font-size: 16px; min-height: 44px; }
  .filter-group { width: 100%; justify-content: space-between; }
  .toolbar button { min-height: 44px; font-size: 15px; }
  .row, .row-link { grid-template-columns: 1fr; gap: 8px; }
  .row-selectable { grid-template-columns: auto 1fr; }
  .row { padding: 12px 14px; }
  .badges { justify-content: flex-start; }
  .card { padding: 16px; }
  .card h1 { font-size: 20px; }
  .card-grid { grid-template-columns: 1fr; gap: 10px; }
  .actions { flex-direction: column; align-items: stretch; }
  .actions button { width: 100%; }
  .spacer { display: none; }
  dialog { width: calc(100% - 16px); max-height: 95vh; }
  .modal-body { padding: 16px; }
  .modal-actions { flex-direction: column; }
  .modal-actions button { width: 100%; }
  .form-grid input, .form-grid select { min-height: 44px; font-size: 16px; }
  .calendar-grid { gap: 4px; }
  .day { min-height: 36px; font-size: 13px; }
  .calendar-legend { font-size: 11px; gap: 8px; }
}
