/* =========================================================
   FAW Inspector PWA — style.css
   Мобильная тёмная тема для промышленного цеха
   ========================================================= */

/* ── Изоляция экранов и модалок ── */
.hidden {
    display: none !important;
}
.screen {
    display: none !important;
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    box-sizing: border-box;
}
.screen.active {
    display: block !important;
}
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    background: rgba(0,0,0,0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal.hidden {
    display: none !important;
}
.modal img {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    border-radius: var(--radius-sm);
}
.modal-close-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255,255,255,0.2);
    border: none;
    color: #fff;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* ── Переменные ── */
:root {
  --bg-primary:    #0f172a;
  --bg-secondary:  #1e293b;
  --bg-card:       #243044;
  --bg-input:      #162032;
  --border:        #334155;
  --border-focus:  #3b82f6;

  --text-primary:  #f1f5f9;
  --text-secondary:#94a3b8;
  --text-muted:    #64748b;

  --accent:        #3b82f6;
  --accent-hover:  #2563eb;
  --success:       #22c55e;
  --warning:       #f59e0b;
  --danger:        #ef4444;
  --pending:       #f59e0b;

  --radius:        12px;
  --radius-sm:     8px;
  --shadow:        0 4px 24px rgba(0,0,0,0.4);

  /* Safe Area для iPhone notch/home bar */
  --safe-top:      env(safe-area-inset-top, 0px);
  --safe-bottom:   env(safe-area-inset-bottom, 0px);
  --safe-left:     env(safe-area-inset-left, 0px);
  --safe-right:    env(safe-area-inset-right, 0px);
}

/* ── Сброс и база ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100%;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* ── Экраны (SPA навигация) ── */
.screen {
  padding-bottom: calc(72px + var(--safe-bottom));
}

/* ── Шапка ── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 60px;
}
.app-header h1 {
  font-size: 18px;
  font-weight: 700;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-header .back-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
}

/* ── Нижняя навигация ── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: var(--safe-bottom);
}
.bottom-nav.hidden { display: none; }
.nav-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 10px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  cursor: pointer;
  transition: color 0.2s;
  min-height: 60px;
}
.nav-btn.active { color: var(--accent); }
.nav-btn svg { width: 24px; height: 24px; }

/* ── Статус сети ── */
.sync-banner {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
}
.sync-banner.offline {
  display: flex;
  background: rgba(245,158,11,0.15);
  color: var(--warning);
  border-bottom: 1px solid rgba(245,158,11,0.3);
}
.sync-banner.syncing {
  display: flex;
  background: rgba(59,130,246,0.12);
  color: var(--accent);
  border-bottom: 1px solid rgba(59,130,246,0.2);
}
.sync-banner .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: currentColor;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.3} }
.sync-banner.syncing .dot { animation: pulse 1.2s infinite; }

/* ── Кнопки (крупные — для работы в перчатках) ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 12px 20px;
  border-radius: var(--radius);
  border: none;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s, opacity 0.18s;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  width: 100%;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { background: var(--accent-hover); }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-ghost   { background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border); }
.btn:disabled { opacity: 0.45; pointer-events: none; }
.btn-sm { min-height: 40px; padding: 8px 14px; font-size: 14px; }

/* FAB (Floating Action Button) */
.fab {
  position: fixed;
  bottom: calc(80px + var(--safe-bottom));
  right: 20px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(59,130,246,0.5);
  cursor: pointer;
  z-index: 150;
  transition: transform 0.2s;
}
.fab:active { transform: scale(0.93); }

/* ── Поля ввода ── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}
.form-input, .form-select {
  width: 100%;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 16px;
  padding: 14px 16px;
  outline: none;
  transition: border-color 0.2s;
  min-height: 52px;
  appearance: none;
  -webkit-appearance: none;
}
.form-input:focus, .form-select:focus { border-color: var(--border-focus); }
.form-select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 42px; }

/* ── Экран авторизации ── */
#screen-auth {
  justify-content: center;
  align-items: center;
  padding: 24px 20px;
  min-height: 100dvh;
}
.auth-logo {
  text-align: center;
  margin-bottom: 36px;
}
.auth-logo .logo-icon {
  width: 80px; height: 80px;
  background: var(--accent);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  margin: 0 auto 16px;
}
.auth-logo h2 { font-size: 26px; font-weight: 800; }
.auth-logo p { color: var(--text-secondary); font-size: 14px; margin-top: 4px; }
.auth-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 24px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}
.auth-error {
  display: none;
  background: rgba(239,68,68,0.15);
  color: var(--danger);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
  margin-bottom: 16px;
}
.auth-error.visible { display: block; }

/* ── Список заявок ── */
.filter-row {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  position: sticky;
  top: 60px;
  z-index: 90;
}
.filter-row::-webkit-scrollbar { display: none; }
.filter-chip {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 600;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.18s;
  white-space: nowrap;
}
.filter-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.tickets-list { padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; }
.ticket-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  transition: border-color 0.18s;
  -webkit-user-select: none;
  user-select: none;
}
.ticket-card:active { border-color: var(--accent); }
.ticket-status-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}
.ticket-status-dot.draft    { background: var(--text-muted); }
.ticket-status-dot.pending  { background: var(--pending); }
.ticket-status-dot.synced   { background: var(--success); }
.ticket-status-dot.submitted{ background: var(--accent); }
.ticket-info { flex: 1; min-width: 0; }
.ticket-engine {
  font-size: 17px;
  font-weight: 700;
  font-family: 'SF Mono', 'Fira Code', monospace;
  letter-spacing: 0.04em;
}
.ticket-meta { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.ticket-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 99px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.ticket-badge.synced   { background: rgba(34,197,94,0.15); color: var(--success); border-color: rgba(34,197,94,0.3); }
.ticket-badge.pending  { background: rgba(245,158,11,0.15); color: var(--warning); border-color: rgba(245,158,11,0.3); }
.ticket-badge.submitted{ background: rgba(59,130,246,0.15); color: var(--accent); border-color: rgba(59,130,246,0.3); }

.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
}
.empty-state svg { width: 64px; height: 64px; opacity: 0.4; margin-bottom: 16px; }
.empty-state p { font-size: 16px; }

/* ── Форма создания заявки ── */
.form-screen-body { padding: 20px 16px; flex: 1; overflow-y: auto; }
.ticket-id-chip {
  display: inline-block;
  font-family: monospace;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-secondary);
  padding: 3px 8px;
  border-radius: 4px;
  margin-bottom: 20px;
}
.form-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 20px 0 12px;
}
.status-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
  color: var(--text-secondary);
}
.status-row .status-label { font-weight: 600; color: var(--text-primary); }

/* ── Сетка фотографий ── */
.photo-section { margin-bottom: 24px; }
.photo-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.photo-section-title { font-size: 15px; font-weight: 700; }
.photo-counter {
  font-size: 13px;
  color: var(--text-muted);
  background: var(--bg-secondary);
  padding: 3px 10px;
  border-radius: 99px;
  border: 1px solid var(--border);
}
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.photo-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
}
.photo-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.photo-thumb-status {
  position: absolute;
  top: 4px; right: 4px;
  width: 18px; height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
}
.photo-thumb-status.pending { background: var(--pending); }
.photo-thumb-status.synced  { background: var(--success); }
.photo-add-btn {
  aspect-ratio: 1;
  background: var(--bg-card);
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 28px;
  color: var(--text-muted);
  transition: border-color 0.18s, color 0.18s;
}
.photo-add-btn:active { border-color: var(--accent); color: var(--accent); }

/* ── Прогресс загрузки ── */
.upload-progress {
  margin-top: 8px;
  background: var(--border);
  border-radius: 99px;
  height: 4px;
  overflow: hidden;
}
.upload-progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.3s;
}

/* ── Spinner ── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 22px; height: 22px;
  border: 2.5px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

/* ── Toast уведомления ── */
.toast-container {
  position: fixed;
  top: calc(20px + var(--safe-top));
  left: 16px; right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 14px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: slideDown 0.25s ease;
  opacity: 1;
  transition: opacity 0.3s;
}
@keyframes slideDown { from { opacity:0; transform:translateY(-16px); } }
.toast-success { background: #166534; border: 1px solid #22c55e; color: #f0fdf4; }
.toast-error   { background: #7f1d1d; border: 1px solid #ef4444; color: #fef2f2; }
.toast-info    { background: #1e3a5f; border: 1px solid #3b82f6; color: #eff6ff; }

/* ── Скелетон ── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--border) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ── Утилиты ── */
.hidden { display: none !important; }
.flex-row { display: flex; align-items: center; gap: 8px; }
.flex-1 { flex: 1; }
.mt-4 { margin-top: 16px; }
.mt-2 { margin-top: 8px; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); font-size: 13px; }

/* ── FAW Категории и Секции ── */
.faw-category-sections {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.faw-category-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.faw-category-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.faw-category-title-wrap {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex: 1;
}
.faw-title-bar {
  width: 4px;
  height: 18px;
  background: var(--accent);
  border-radius: 2px;
  flex-shrink: 0;
  margin-top: 2px;
}
.faw-category-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.35;
}
.faw-category-hint {
  font-size: 11.5px;
  color: var(--text-secondary);
  font-style: italic;
  margin-top: 3px;
  line-height: 1.35;
}
.faw-category-subinfo {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.sample-link {
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}
.sample-link:hover {
  filter: brightness(1.2);
}
.faw-category-badge {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 99px;
  white-space: nowrap;
  background: var(--bg-secondary);
  color: var(--accent);
  border: 1px solid rgba(59,130,246,0.3);
}
.faw-category-badge.complete {
  background: rgba(34,197,94,0.15);
  color: var(--success);
  border-color: rgba(34,197,94,0.3);
}

.photos-ticket-subinfo {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  margin-top: 2px;
}
.photos-ticket-subinfo .bullet { color: var(--text-muted); font-size: 10px; }

/* ── Триггер выбора сервиса ── */
.form-select-trigger {
  width: 100%;
  min-height: 52px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 16px;
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  box-sizing: border-box;
}
.form-select-trigger:active {
  border-color: var(--accent);
  background: var(--bg-secondary);
}

/* ── FAW Bottom Sheet Modal ── */
.modal-bottom-sheet {
  justify-content: flex-end;
  padding: 0;
  background: rgba(0,0,0,0.7);
}
.bottom-sheet-content {
  width: 100%;
  max-width: 500px;
  background: var(--bg-secondary);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  border: 1px solid var(--border);
  border-bottom: none;
  padding: 20px 16px calc(20px + var(--safe-bottom));
  box-sizing: border-box;
  animation: slideUpSheet 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes slideUpSheet {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.bottom-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.bottom-sheet-header h3 {
  font-size: 17px;
  font-weight: 700;
  margin: 0;
  color: var(--text-primary);
}
.modal-close-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  padding: 8px;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.service-types-radio-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
  max-height: 50vh;
  overflow-y: auto;
}
.service-radio-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  min-height: 52px;
}
.service-radio-item.selected {
  border-color: var(--accent);
  background: rgba(59,130,246,0.12);
  color: #60a5fa;
}
.service-radio-item input[type="radio"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}
.btn-danger {
  background: #dc2626;
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
}
.divider { height: 1px; background: var(--border); margin: 16px 0; }

/* ── Модальное окно подтверждения удаления заявки ── */
.confirm-dialog-content {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-sizing: border-box;
  animation: scaleIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}
.confirm-dialog-header {
  display: flex;
  align-items: center;
  gap: 12px;
}
.confirm-icon-wrap {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(239, 68, 68, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ── Кнопка удаления на карточке заявки ── */
.ticket-delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 8px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.18s, background 0.18s;
  min-width: 36px;
  min-height: 36px;
}
.ticket-delete-btn:hover, .ticket-delete-btn:active {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.12);
}

/* ── Заголовок заявки в списке ── */
.ticket-title-line {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
  line-height: 1.3;
}

/* ── Кнопка выбора из галереи ── */
.photo-add-btn.gallery-btn {
  border-style: solid;
  border-color: var(--border);
  background: var(--bg-secondary);
}
.photo-add-btn.gallery-btn:hover, .photo-add-btn.gallery-btn:active {
  border-color: var(--accent);
  color: var(--accent);
}
.photo-btn-sublabel {
  font-size: 10px;
  font-weight: 600;
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Адаптив для планшетов ── */
@media (min-width: 600px) {
  #screen-auth { padding: 40px; }
  .tickets-list { max-width: 640px; margin: 0 auto; }
  .form-screen-body { max-width: 600px; margin: 0 auto; }
  .photo-grid { grid-template-columns: repeat(4, 1fr); }
}
