/* ============================================
   ИЛ-2 ШТУРМОВИК — МОБИЛЬНАЯ АДАПТАЦИЯ
   Подключить в <head> ПОСЛЕ style.css:
   <link rel="stylesheet" href="css/mobile.css">
   ============================================ */

/* ======================== GLOBAL OVERFLOW FIX ======================== */
@media (max-width: 768px) {
  html {
    overflow-x: hidden;
  }

  body {
    overflow-x: hidden;
    width: 100%;
    position: relative;
  }

  /* Все блоки не должны выходить за экран */
  .site-header,
  .main-nav,
  .section,
  .pilot-layout,
  .pilot-card-block,
  .flight-hours-block,
  .pilot-insignia-block,
  .controls-settings-block {
    max-width: 100vw;
    box-sizing: border-box;
    overflow-x: hidden;
  }

  /* Фиксим padding у хедера и секций */
  .header-inner {
    padding: 10px 14px 8px;
    box-sizing: border-box;
  }

  .main-nav {
    padding: 0 4px;
  }

  .section {
    padding: 16px 12px 60px;
    box-sizing: border-box;
  }

  /* nowrap-элементы могут вызывать горизонтальный скролл */
  .controls-file-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100vw - 130px);
  }

  .controls-download-btn,
  .controls-remove-btn {
    white-space: normal;
    word-break: break-word;
  }

  /* Тултип insignia — не влияет на ширину страницы */
  .insignia-tooltip {
    position: fixed !important;
    bottom: auto !important;
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -50%) !important;
    width: calc(100vw - 48px) !important;
    max-width: 340px !important;
    white-space: normal !important;
    word-break: break-word !important;
    font-size: 12px !important;
    padding: 10px 14px !important;
    z-index: 9999 !important;
    line-height: 1.5 !important;
    border-radius: 2px;
  }

  .insignia-item:hover .insignia-tooltip {
    opacity: 0 !important; /* на мобиле hover не нужен, только touch */
  }

  .insignia-item.touch-active .insignia-tooltip {
    opacity: 1 !important;
    transform: translate(-50%, -50%) !important;
  }
}

/* ======================== BASE MOBILE ======================== */
@media (max-width: 768px) {

  /* --- HEADER --- */
  .site-header {
    position: sticky;
    top: 0;
    z-index: 500;
  }

  .header-inner {
    padding: 10px 14px 8px;
    gap: 10px;
    flex-wrap: nowrap;
  }

  .header-emblem {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
  }

  .header-titles {
    flex: 1;
    min-width: 0;
  }

  .header-sub {
    font-size: 9px;
    letter-spacing: 3px;
  }

  .header-main {
    font-size: 18px;
    letter-spacing: 4px;
  }

  .header-sub2 {
    font-size: 9px;
    letter-spacing: 2px;
    margin-top: 3px;
  }

  .header-date {
    display: none;
  }

  .header-divider {
    display: none;
  }

  .header-right {
    gap: 0;
  }

  /* --- STOPWATCH --- */
  .stopwatch-wrap {
    gap: 3px;
  }

  .stopwatch-label {
    font-size: 8px;
    letter-spacing: 2px;
  }

  .stopwatch-display {
    font-size: 18px;
    letter-spacing: 2px;
    min-width: 80px;
  }

  .sw-btn {
    width: 26px;
    height: 26px;
    font-size: 12px;
  }

  /* --- NAV --- */
  .main-nav {
    padding: 0 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 0;
    flex-wrap: nowrap;
  }

  .main-nav::-webkit-scrollbar {
    display: none;
  }

  .nav-btn {
    font-size: 11px;
    letter-spacing: 1.5px;
    padding: 10px 10px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* --- SECTIONS --- */
  .section {
    padding: 16px 12px 60px;
  }

  .section-header h2 {
    font-size: 16px;
    letter-spacing: 3px;
  }

  .section-header-row {
    gap: 8px;
  }

  /* --- SEARCH BAR --- */
  .search-wrap {
    padding: 6px 8px;
    gap: 5px;
    width: 100%;
  }

  .search-wrap input {
    width: 100%;
    font-size: 14px;
  }

  .filter-btn {
    font-size: 10px;
    padding: 3px 7px;
    letter-spacing: 1px;
  }

  /* --- PLANES GRID --- */
  .planes-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  /* --- PLANE CARD --- */
  .plane-card-name {
    font-size: 20px;
    letter-spacing: 3px;
  }

  .plane-card-desc {
    font-size: 13px;
  }

  /* --- ADD PLANE FORM --- */
  .plane-form {
    padding: 16px 12px;
  }

  .plane-form::before {
    display: none;
  }

  .form-columns {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .specs-grid {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .col-title {
    font-size: 15px;
    letter-spacing: 2px;
  }

  .form-group input,
  .form-group textarea,
  .form-group select {
    font-size: 16px; /* prevents iOS zoom */
  }

  .form-actions {
    flex-direction: column;
    gap: 8px;
  }

  .btn-primary,
  .btn-secondary {
    width: 100%;
    text-align: center;
    font-size: 14px;
    padding: 12px 16px;
  }

  /* --- ENGINE PARAM BLOCKS --- */
  .engine-param-block {
    padding: 10px;
  }

  .param-header {
    font-size: 12px;
    letter-spacing: 1px;
  }

  /* --- PILOT SECTION --- */
  /* На мобиле все блоки в одну колонку, сбрасываем grid-row/grid-column */
  .pilot-layout {
    grid-template-columns: 1fr !important;
    gap: 16px;
  }

  .pilot-card-block {
    grid-column: 1 !important;
    grid-row: auto !important;
    padding: 14px;
  }

  .flight-hours-block {
    grid-column: 1 !important;
    grid-row: auto !important;
    padding: 14px;
  }

  .pilot-insignia-block {
    grid-column: 1 !important;
    grid-row: auto !important;
    padding: 14px;
  }

  .controls-settings-block {
    grid-column: 1 !important;
    grid-row: auto !important;
    padding: 14px;
  }

  .pilot-photo-wrap {
    flex-direction: row;
    align-items: flex-start;
    gap: 14px;
  }

  .pilot-photo-frame {
    width: 100px;
    height: 128px;
    flex-shrink: 0;
  }

  .pilot-info-form {
    flex: 1;
    min-width: 0;
  }

  .insignia-grid {
    gap: 15px;
  }

  .insignia-item {
    width: 64px;
    height: 64px;
  }

  /* Тултип на мобиле — фиксированная ширина, текст переносится */
  .insignia-tooltip {
    position: fixed !important;
    bottom: auto !important;
    left: 50% !important;
    top: auto !important;
    transform: translateX(-50%) !important;
    width: calc(100vw - 32px) !important;
    max-width: 360px !important;
    white-space: normal !important;
    word-break: break-word !important;
    font-size: 12px !important;
    padding: 8px 12px !important;
    z-index: 9999 !important;
    pointer-events: none;
  }

  /* Показываем тултип по центру экрана при touch-active */
  .insignia-item.touch-active .insignia-tooltip {
    opacity: 1 !important;
    transform: translateX(-50%) !important;
    top: 50vh !important;
  }

  /* --- CONTROLS SETTINGS BLOCK --- */
  .controls-drop-inner {
    padding: 16px 12px;
  }

  .controls-upload-icon {
    font-size: 24px;
  }

  .controls-upload-text {
    font-size: 13px;
  }

  .controls-upload-sub {
    font-size: 11px;
    letter-spacing: 1px;
  }

  .controls-file-info {
    flex-wrap: wrap;
    padding: 10px 12px;
    gap: 10px;
  }

  .controls-file-actions {
    width: 100%;
    flex-direction: row;
    gap: 8px;
  }

  .controls-download-btn,
  .controls-remove-btn {
    flex: 1;
    text-align: center;
  }

  /* --- FLIGHT HOURS --- */
  .hours-big {
    font-size: 38px;
  }

  .form-row {
    flex-direction: column;
    gap: 8px;
  }

  .form-row input,
  .form-row select {
    font-size: 16px; /* prevents iOS zoom */
    max-width: 100%;
  }

  .btn-add-hours {
    width: 100%;
    padding: 10px;
  }

  .hours-plane-row {
    flex-wrap: wrap;
    gap: 6px;
  }

  .hours-plane-bar-wrap {
    flex: 1 1 100%;
    order: 3;
  }

  /* --- SORTIES SECTION --- */
  .sortie-form-wrap {
    padding: 14px 12px;
  }

  .sortie-form-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .sortie-stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .stat-num {
    font-size: 28px;
  }

  .stat-label {
    font-size: 10px;
    letter-spacing: 2px;
  }

  .sortie-entry {
    grid-template-columns: 80px 1fr auto;
  }

  .sortie-date-day {
    font-size: 24px;
  }

  .sortie-date-month,
  .sortie-date-year,
  .sortie-date-time {
    font-size: 11px;
  }

  .sortie-date-col {
    padding: 10px 6px;
  }

  .sortie-body {
    padding: 10px 10px;
  }

  .sortie-plane-name {
    font-size: 15px;
    letter-spacing: 1px;
  }

  .sortie-mission {
    font-size: 13px;
  }

  .sortie-notes-text {
    font-size: 13px;
  }

  .sortie-duration-badge {
    font-size: 11px;
    padding: 2px 7px;
  }

  .sortie-actions {
    padding: 6px 6px 6px 0;
    gap: 3px;
  }

  .sortie-edit-btn,
  .sortie-del-btn {
    padding: 4px 6px;
    font-size: 14px;
  }

  /* --- MODAL --- */
  .modal {
    padding: 10px 8px;
    align-items: flex-start;
  }

  .modal-inner {
    width: 100%;
    max-width: 100%;
  }

  .modal-plane-header {
    grid-template-columns: 1fr;
  }

  .modal-plane-img {
    width: 100%;
    max-height: 200px;
    object-fit: cover;
    border-right: none;
    border-bottom: 2px solid var(--paper-deep);
  }

  .modal-plane-img-placeholder {
    width: 100%;
    height: 130px;
    border-right: none;
    border-bottom: 2px solid var(--paper-deep);
  }

  .modal-plane-title-block {
    padding: 14px 16px;
  }

  .modal-plane-name {
    font-size: 28px;
    letter-spacing: 4px;
  }

  .modal-plane-desc {
    font-size: 14px;
  }

  .spec-tag {
    font-size: 12px;
    padding: 3px 7px;
  }

  .modal-engine-section {
    padding: 14px 16px;
  }

  .modal-engine-title {
    font-size: 16px;
    letter-spacing: 3px;
  }

  .engine-table {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .modal-extra-notes {
    padding: 12px 16px 16px;
  }

  .modal-toolbar {
    padding: 8px 10px;
    gap: 5px;
  }

  .modal-print-btn,
  .modal-pdf-btn {
    font-size: 11px;
    padding: 5px 10px;
    letter-spacing: 1px;
  }

  /* --- TOAST --- */
  .toast {
    bottom: 16px;
    right: 12px;
    left: 12px;
    font-size: 13px;
    letter-spacing: 2px;
    padding: 10px 14px;
    text-align: center;
  }
}

/* ======================== SMALL PHONES (< 420px) ======================== */
@media (max-width: 420px) {

  .header-main {
    font-size: 15px;
    letter-spacing: 2px;
  }

  .header-sub,
  .header-sub2 {
    display: none;
  }

  .stopwatch-display {
    font-size: 15px;
    min-width: 68px;
  }

  .nav-btn {
    font-size: 10px;
    letter-spacing: 1px;
    padding: 9px 8px;
  }

  .section-header h2 {
    font-size: 14px;
    letter-spacing: 2px;
  }

  .sortie-form-grid {
    grid-template-columns: 1fr;
  }

  .sortie-entry {
    grid-template-columns: 70px 1fr auto;
  }

  .sortie-date-day {
    font-size: 20px;
  }

  .plane-card-name {
    font-size: 18px;
  }

  .hours-big {
    font-size: 30px;
  }

  .stat-num {
    font-size: 24px;
  }

  .modal-plane-name {
    font-size: 22px;
    letter-spacing: 2px;
  }

  .pilot-photo-wrap {
    flex-direction: column;
    align-items: center;
  }

  .pilot-photo-frame {
    width: 120px;
    height: 152px;
  }
}

/* ======================== TABLET (769px – 1024px) ======================== */
@media (min-width: 769px) and (max-width: 1024px) {

  .header-inner {
    padding: 14px 20px 10px;
  }

  .header-main {
    font-size: 26px;
    letter-spacing: 5px;
  }

  .section {
    padding: 24px 20px 60px;
  }

  .planes-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 18px;
  }

  .form-columns {
    gap: 24px;
  }

  /* На планшете тоже сбрасываем фиксированные grid-row */
  .pilot-layout {
    grid-template-columns: 240px 1fr;
    gap: 16px;
  }

  .pilot-card-block {
    grid-column: 1;
    grid-row: 1;
  }

  .flight-hours-block {
    grid-column: 2;
    grid-row: 1;
  }

  .pilot-insignia-block {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .controls-settings-block {
    grid-column: 1 / -1;
    grid-row: 3;
  }

  .sortie-form-grid {
    grid-template-columns: 1fr 1fr;
  }

  .engine-table {
    grid-template-columns: repeat(2, 1fr);
  }

  .modal-plane-header {
    grid-template-columns: 240px 1fr;
  }

  .modal-plane-img-placeholder {
    width: 240px;
    height: 200px;
  }

  .modal-plane-name {
    font-size: 36px;
  }

  .sortie-stats {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ======================== TOUCH IMPROVEMENTS ======================== */
@media (hover: none) and (pointer: coarse) {

  /* Larger tap targets */
  .nav-btn {
    padding: 13px 12px;
  }

  .btn-card-view,
  .btn-card-edit,
  .btn-card-delete {
    padding: 10px;
  }

  .sortie-edit-btn,
  .sortie-del-btn {
    padding: 8px 10px;
    font-size: 16px;
  }

  .sw-btn {
    width: 32px;
    height: 32px;
  }

  .filter-btn {
    padding: 6px 10px;
  }

  /* Remove hover transforms on touch */
  .plane-card:hover {
    transform: none;
    box-shadow: 3px 3px 0 var(--paper-deep), 5px 5px 16px rgba(0,0,0,0.45);
  }

  /* Active press feedback instead */
  .plane-card:active {
    transform: scale(0.98);
  }

  .btn-primary:active {
    background: var(--red-stamp);
    border-color: var(--red-stamp);
  }
}

/* ======================== SCROLLBAR MOBILE FIX ======================== */
@media (max-width: 768px) {
  /* Убираем кастомный скроллбар на мобиле — он резервирует 8px справа и сдвигает контент */
  ::-webkit-scrollbar {
    width: 0;
    display: none;
  }

  body {
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
  }
}