/* ===========================================================
   CSS Variables & Reset (Light Theme)
   =========================================================== */
:root {
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-input: #ffffff;
  --bg-modal: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --border-color: #e2e8f0;
  --border-focus: #10b981;
  
  --color-accent: #10b981;
  --color-accent-dark: #059669;
  --color-accent-trans: rgba(16, 185, 129, 0.15);
  
  --color-danger: #ef4444;
  --color-danger-hover: #dc2626;

  --status-shelter: #10b981;
  --status-shelter-bg: rgba(16, 185, 129, 0.15);
  --status-adopted: #0ea5e9;
  --status-adopted-bg: rgba(14, 165, 233, 0.15);
  --status-deceased: #64748b;
  --status-deceased-bg: rgba(100, 116, 139, 0.15);

  --font-main: 'Inter', system-ui, sans-serif;
  
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  
  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.6);
  --shadow-modal: 0 -10px 40px rgba(0,0,0,0.8);
}

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

body {
  background-color: var(--bg-main);
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none; /* Предотвращает pull-to-refresh на мобильных */
}

/* Глобальный фикс: display:flex переопределяет стандартный атрибут hidden.
   Это было причиной того, что все окна наслаивались друг на друга. */
[hidden] {
  display: none !important;
}

/* Блокировка скролла для body, когда открыта модалка */
body.modal-open {
  overflow: hidden;
}

button {
  font-family: var(--font-main);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

input, select, textarea {
  font-family: var(--font-main);
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 16px; /* 16px предотвращает автозум в iOS Safari */
  outline: none;
  transition: border-color 0.2s;
  width: 100%;
}

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

input::placeholder {
  color: var(--text-secondary);
}

/* ===========================================================
   Кнопки
   =========================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  border: none;
  transition: all 0.2s;
  text-align: center;
}

.btn-primary {
  background-color: var(--color-accent);
  color: #fff;
}
.btn-primary:hover, .btn-primary:active {
  background-color: var(--color-accent-dark);
}

.btn-ghost {
  background-color: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}
.btn-ghost:hover, .btn-ghost:active {
  background-color: var(--bg-card-hover);
}

.btn-danger {
  background-color: var(--color-danger);
  color: #fff;
}
.btn-danger:hover, .btn-danger:active {
  background-color: var(--color-danger-hover);
}

.btn-icon {
  background: var(--bg-card-hover);
  color: var(--text-secondary);
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover {
  color: var(--text-primary);
}

/* ===========================================================
   Экран входа
   =========================================================== */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top right, var(--bg-card) 0%, var(--bg-main) 100%);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  border: 1px solid var(--border-color);
}

.login-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.login-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}

.login-subtitle {
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-button {
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  transition: opacity 0.2s;
}
.login-button:active {
  opacity: 0.8;
}

.login-error {
  color: var(--color-danger);
  margin-top: 16px;
  font-size: 14px;
}

/* ===========================================================
   Основной лейаут
   =========================================================== */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

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

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-logo {
  font-size: 24px;
}

.header-title {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.5px;
}

.header-tabs {
  display: none; /* На мобильных скрыто */
}

.header-add-button {
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-xl);
  padding: 8px 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}
.header-add-text { display: none; }

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

.header-logout-button {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 8px 14px;
  font-weight: 600;
  cursor: pointer;
}

.app-main {
  flex: 1;
  padding: 16px 16px 80px 16px; /* 80px для bottom nav */
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.section-heading {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 20px;
}

.empty-msg {
  text-align: center;
  color: var(--text-secondary);
  padding: 60px 20px;
}

/* ===========================================================
   Нижняя навигация (Mobile)
   =========================================================== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-around;
  padding: 8px 0;
  padding-bottom: calc(8px + env(safe-area-inset-bottom)); /* Для iPhone X+ */
}

.bottom-nav-item {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 500;
  width: 25%;
}

.bottom-nav-item svg {
  width: 24px;
  height: 24px;
  opacity: 0.8;
  transition: all 0.2s;
}

.bottom-nav-item.active {
  color: var(--color-accent);
}
.bottom-nav-item.active svg {
  opacity: 1;
}

/* ===========================================================
   Фильтры и Табы статуса
   =========================================================== */
.filter-bar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
  background: var(--bg-card);
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.filter-input {
  background: var(--bg-main);
}

.filter-date-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.filter-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.filter-reset {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border: none;
  padding: 12px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  margin-top: 4px;
}

.status-tabs {
  display: flex;
  background: var(--bg-card);
  padding: 4px;
  border-radius: var(--radius-md);
  margin-bottom: 24px;
  overflow-x: auto;
  border: 1px solid var(--border-color);
}
.status-tabs::-webkit-scrollbar { display: none; }

.status-tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  white-space: nowrap;
  transition: all 0.2s;
}
.status-tab.active {
  background: var(--bg-main);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* ===========================================================
   Сетка карточек собак
   =========================================================== */
.dog-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.dog-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  position: relative;
}

.dog-card:active {
  background: var(--bg-card-hover);
}

.dog-card-photo-wrap {
  aspect-ratio: 1 / 1;
  background: var(--bg-card-hover);
  position: relative;
}

.dog-card-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.dog-card-photo-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
}

.dog-card-status {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--bg-card);
}

.status-InShelter { background: var(--status-shelter); }
.status-Adopted { background: var(--status-adopted); }
.status-Deceased { background: var(--status-deceased); }

.dog-card-info {
  padding: 10px;
}

.dog-card-name {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dog-card-meta {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ===========================================================
   Вольеры
   =========================================================== */
.enclosure-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.enclosure-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  cursor: pointer;
}

.enclosure-card-photos {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 12px;
}

.enclosure-card-photos img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.enclosure-card-placeholder {
  background: var(--bg-card-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.enclosure-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.enclosure-num {
  font-size: 16px;
  font-weight: 700;
}

.enclosure-count {
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-main);
  padding: 2px 8px;
  border-radius: 12px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 500;
  margin-bottom: 20px;
  padding: 8px 0;
}

/* ===========================================================
   Статистика
   =========================================================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
  text-align: center;
}

.stat-num {
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 4px;
  line-height: 1.2;
}

.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ===========================================================
   Модальные окна
   =========================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  flex-direction: column;
  justify-content: flex-end; /* Для slide-up на мобилках */
}

.modal-overlay-top {
  justify-content: center;
  align-items: center;
  padding: 24px;
  z-index: 110; /* Confirm поверх DogModal */
}

/* Основной лист модалки (Slide up on mobile) */
.modal-sheet {
  background: var(--bg-modal);
  width: 100%;
  height: 90vh; /* Почти на весь экран */
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-modal);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

.modal-overlay:not([hidden]) .modal-sheet {
  transform: translateY(0);
}

.modal-sheet-header {
  display: flex;
  justify-content: flex-end;
  padding: 16px 20px 8px;
  position: relative;
}

/* Декоративная ручка для slide-up */
.modal-sheet-header::before {
  content: '';
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 4px;
  background: var(--border-color);
  border-radius: 4px;
}

.modal-close {
  background: var(--bg-card-hover);
  border: none;
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 20px 40px;
}

/* ===========================================================
   Внутренности модалки собаки
   =========================================================== */
.dog-modal-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 24px;
  text-align: center;
}

.dog-modal-photo {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-card-hover);
  margin-bottom: 16px;
  border: 3px solid var(--bg-main);
  box-shadow: 0 0 0 1px var(--border-color);
}

.dog-modal-photo-empty {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: var(--bg-card-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  margin-bottom: 16px;
  border: 3px solid var(--bg-main);
  box-shadow: 0 0 0 1px var(--border-color);
}

.dog-modal-name {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 4px;
}

.dog-modal-meta {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 12px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 600;
}
.status-badge::before { content: ''; width: 8px; height: 8px; border-radius: 50%; }

.badge-InShelter { background: var(--status-shelter-bg); color: var(--status-shelter); }
.badge-InShelter::before { background: var(--status-shelter); }

.badge-Adopted { background: var(--status-adopted-bg); color: var(--status-adopted); }
.badge-Adopted::before { background: var(--status-adopted); }

.badge-Deceased { background: var(--status-deceased-bg); color: var(--status-deceased); }
.badge-Deceased::before { background: var(--status-deceased); }

/* Подтабы в модалке */
.modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 24px;
  overflow-x: auto;
}
.modal-tabs::-webkit-scrollbar { display: none; }

.modal-tab {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 12px 16px;
  font-weight: 500;
  font-size: 14px;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.modal-tab.active {
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
}

/* Формы внутри модалки */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.marks-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.mark-tag {
  background: var(--bg-card-hover);
  border: 1px solid var(--border-color);
  border-radius: 100px;
  padding: 4px 12px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.mark-tag button {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 12px;
  padding: 0;
}

.danger-zone {
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Записи (Лечение/Вакцинация) */
.record-item {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 12px;
  position: relative;
}

.record-date {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.record-title {
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 8px;
}

.record-text {
  font-size: 14px;
  color: var(--text-secondary);
  white-space: pre-wrap;
}

.record-del {
  position: absolute;
  top: 12px;
  right: 12px;
}

/* Медиа сетка */
.media-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.media-item {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-input);
}

.media-item img, .media-item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-cat {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,0.7);
  color: #fff;
  font-size: 11px;
  padding: 4px;
  text-align: center;
}

.media-del {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 12px;
}

/* ===========================================================
   Модалка подтверждения
   =========================================================== */
.confirm-card {
  background: var(--bg-modal);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 320px;
  box-shadow: var(--shadow-lg);
}

.confirm-text {
  font-size: 16px;
  margin-bottom: 24px;
  text-align: center;
}

.confirm-actions {
  display: flex;
  gap: 12px;
}
.confirm-actions button {
  flex: 1;
}

/* ===========================================================
   Просмотр медиа (Viewer)
   =========================================================== */
.media-viewer-close {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 120;
  background: rgba(0,0,0,0.5);
  color: #fff;
}
.media-viewer-content {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.media-viewer-content img, .media-viewer-content video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}

.media-type-tag {
  position: absolute;
  top: 4px;
  left: 4px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
}
.media-item {
  cursor: pointer;
}

/* ===========================================================
   Тосты
   =========================================================== */
.toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 90%;
  max-width: 400px;
  pointer-events: none;
}

.toast {
  background: var(--color-accent);
  color: #fff;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 14px;
  box-shadow: var(--shadow-md);
  text-align: center;
  animation: toast-down 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

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

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

/* ===========================================================
   Адаптив (Desktop & Tablet)
   =========================================================== */
@media (min-width: 768px) {
  /* Скрываем нижнюю навигацию, показываем табы в хедере */
  .bottom-nav { display: none; }
  .app-main { padding-bottom: 40px; }
  
  .header-tabs {
    display: flex;
    gap: 4px;
  }
  
  .header-tab {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    transition: all 0.2s;
  }
  .header-tab.active {
    background: var(--bg-card);
    color: var(--text-primary);
  }
  
  .header-add-button {
    padding: 8px 16px;
  }
  .header-add-text { display: inline; }
  
  .filter-bar {
    flex-direction: row;
    align-items: flex-end;
  }
  .filter-input { flex: 1; min-width: 0; }
  .filter-short { flex: 0 0 120px; }
  .filter-reset { margin-top: 0; }
  
  .dog-grid, .enclosure-grid, .stats-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 20px;
  }
  
  .media-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }

  /* Модалка собаки как классическое центрированное окно на десктопе */
  .modal-overlay {
    justify-content: center;
    align-items: center;
    padding: 40px;
  }
  
  .modal-sheet {
    max-width: 600px;
    height: auto;
    max-height: 85vh;
    border-radius: var(--radius-lg);
    transform: scale(0.95);
    opacity: 0;
    transition: all 0.2s;
  }
  
  .modal-overlay:not([hidden]) .modal-sheet {
    transform: scale(1);
    opacity: 1;
  }
  
  .modal-sheet-header::before { display: none; }
  
  .dog-modal-head {
    flex-direction: row;
    text-align: left;
    gap: 24px;
  }
  
  .dog-modal-photo, .dog-modal-photo-empty {
    margin-bottom: 0;
  }
}
