/* ============================================================
   AccountingOS — Portal Mobile Enhancement
   Зарежда се СЛЕД inline стиловете в portal.php
   Файл: /css/portal_mobile.css
   ============================================================ */

/* ── BREAKPOINT STRATEGY ──
   ≤1024px — tablet landscape (right panel → bottom)
   ≤768px  — tablet portrait (sidebar off-canvas, single column)
   ≤480px  — phone (compact everything)
   ≤360px  — small phone (minimal padding)
   ──────────────────────────────────────────── */

/* ================================================================
   1. RIGHT PANEL — допълнителни мобилни подобрения
   ================================================================ */
@media (max-width: 768px) {
  .right-panel {
    padding: 14px !important;
  }

  .right-panel .rp-section {
    grid-template-columns: 1fr !important;
  }
}

@media (max-width: 480px) {
  .right-panel {
    padding: 10px !important;
    margin-top: 16px !important;
  }
}

/* ================================================================
   2. SIDEBAR — подобрения за touch
   ================================================================ */
@media (max-width: 768px) {
  /* Backdrop при отворен sidebar */
  .sidebar::after {
    content: '';
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: -1;
    pointer-events: none; /* Позволява click-through за close handler */
  }

  .sidebar.open::after {
    display: block;
  }

  /* По-големи touch targets — мин. 44px */
  .nav-item {
    padding: 12px 16px 12px 20px !important;
    min-height: 44px;
    font-size:calc(15px * var(--fs, 1)) !important;
  }

  .nav-item .ic {
    font-size:calc(20px * var(--fs, 1));
  }

  /* Firm selector по-голям */
  .sb-firm select {
    padding: 10px 12px !important;
    font-size:calc(13.5px * var(--fs, 1)) !important;
    min-height: 44px;
  }

  /* Logout бутон по-голям */
  .sb-firm a[href*="logout"] {
    padding: 10px 0 !important;
    font-size:calc(13.5px * var(--fs, 1)) !important;
    min-height: 44px;
    display: flex !important;
    align-items: center;
    justify-content: flex-end;
  }

  /* Topbar — повече място за hamburger */
  .topbar {
    padding-left: 46px;
  }

  /* Hamburger бутон — по-голям за пръсти */
  .sb-toggle {
    width: 44px !important;
    height: 44px !important;
    font-size:calc(20px * var(--fs, 1)) !important;
    top: 10px !important;
    left: 10px !important;
  }
}

/* ================================================================
   3. STAT CARDS — мобилна оптимизация
   ================================================================ */
@media (max-width: 768px) {
  .stat-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }

  .stat-grid > div {
    padding: 12px !important;
  }

  .stat-grid > div span:first-child {
    font-size:calc(20px * var(--fs, 1)) !important;
  }
}

@media (max-width: 480px) {
  .stat-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ================================================================
   4. ДОКУМЕНТИ — по-добро мобилно представяне
   ================================================================ */
@media (max-width: 768px) {
  .doc-row {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 8px !important;
    padding: 12px 0 !important;
  }

  .doc-info {
    width: 100%;
  }

  .doc-actions {
    width: 100%;
    display: flex !important;
    gap: 8px !important;
  }

  .doc-actions .btn,
  .doc-actions a {
    flex: 1;
    text-align: center;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Doc tabs — 21.09.2026, Хазарос: табовете се пренасят на нов ред. Дотук бяха
     на един ред с хоризонтално превъртане без плъзгач и последният („Налични
     документи") се режеше, без да личи, че има още. */
  .doc-tabs {
    flex-wrap: wrap !important;
    row-gap: 2px;
  }

  .doc-tab {
    white-space: nowrap;
    flex-shrink: 0;
    padding: 10px 14px !important;
    font-size:calc(13.5px * var(--fs, 1)) !important;
  }
}

/* ================================================================
   5. ФОРМИ — touch-friendly inputs
   ================================================================ */
@media (max-width: 768px) {
  /* Всички input-и и select-и — мин. 44px височина */
  .form-ctl,
  .form-ctrl,
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="tel"],
  input[type="date"],
  select,
  textarea {
    min-height: 44px !important;
    font-size:calc(16px * var(--fs, 1)) !important; /* Спира iOS auto-zoom */
    padding: 10px 12px !important;
  }

  /* File inputs */
  input[type="file"] {
    width: 100% !important;
    min-height: 44px;
    font-size:calc(15px * var(--fs, 1)) !important;
  }

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

  .form-row label {
    font-size:calc(12.5px * var(--fs, 1));
    margin-bottom: 4px;
  }

  /* Upload area — full width */
  .upload-area,
  [class*="upload"] {
    width: 100% !important;
  }
}

/* ================================================================
   6. БУТОНИ — touch-friendly sizing
   ================================================================ */
@media (max-width: 768px) {
  .btn {
    min-height: 44px !important;
    padding: 10px 16px !important;
    font-size:calc(15px * var(--fs, 1)) !important;
  }

  .btn.sm {
    min-height: 36px !important;
    padding: 8px 12px !important;
    font-size:calc(12.5px * var(--fs, 1)) !important;
  }

  /* Пълна ширина за primary бутони във форми */
  form .btn-am,
  form .btn-bl,
  form [type="submit"] {
    width: 100%;
    justify-content: center;
  }
}

/* ================================================================
   7. ТАБЛИЦИ — responsive cards за малки екрани
   ================================================================ */
@media (max-width: 768px) {
  table {
    display: block !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* За таблици в settings с 2-3 колони — по-компактно */
  table td,
  table th {
    padding: 8px 10px !important;
    font-size:calc(12.5px * var(--fs, 1)) !important;
  }

  table td:first-child {
    white-space: nowrap;
  }
}

/* ================================================================
   8. КАРТИ — мобилна оптимизация
   ================================================================ */
@media (max-width: 768px) {
  .card {
    padding: 14px !important;
    border-radius: 4px !important;
    margin-bottom: 14px !important;
  }

  .card-title {
    font-size:calc(13.5px * var(--fs, 1)) !important;
    margin-bottom: 12px !important;
  }
}

@media (max-width: 480px) {
  .card {
    padding: 12px !important;
    margin-bottom: 10px !important;
    border-radius: 3px !important;
  }
}

/* ================================================================
   9. СЪОБЩЕНИЯ (chat) — мобилна оптимизация
   ================================================================ */
@media (max-width: 768px) {
  .msg {
    max-width: 88% !important;
    font-size:calc(15px * var(--fs, 1)) !important;
    padding: 10px 14px !important;
  }

  /* Chat input area — фиксиран долу */
  .msg-form,
  form[style*="sticky"] {
    padding: 10px !important;
  }

  .msg-form textarea,
  .msg-area textarea {
    min-height: 44px !important;
    font-size:calc(16px * var(--fs, 1)) !important;
  }
}

@media (max-width: 480px) {
  .msg {
    max-width: 94% !important;
  }
}

/* ================================================================
   10. МОДАЛИ — full-screen на малки екрани
   ================================================================ */
@media (max-width: 768px) {
  [id$="-modal"],
  [style*="position:fixed"][style*="inset:0"],
  [style*="position: fixed"] {
    padding: 10px !important;
  }

  [id$="-modal"] > div,
  [style*="max-width:480px"] {
    max-width: 100% !important;
    width: 100% !important;
    max-height: 90vh !important;
    border-radius: 4px !important;
    padding: 20px !important;
  }
}

/* ================================================================
   11. ORGANIZER CARDS — мобилен layout
   ================================================================ */
@media (max-width: 768px) {
  .org-card {
    padding: 12px !important;
  }

  .org-card h4 {
    font-size:calc(15px * var(--fs, 1)) !important;
  }
}

/* ================================================================
   12. TAB BAR — хоризонтален скрол
   ================================================================ */
@media (max-width: 768px) {
  .tab-bar {
    display: flex;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 4px !important;
    padding-bottom: 2px;
  }

  .tab-bar::-webkit-scrollbar {
    display: none;
  }

  .tab {
    white-space: nowrap !important;
    flex-shrink: 0;
    padding: 8px 14px !important;
    font-size:calc(13.5px * var(--fs, 1)) !important;
    min-height: 40px;
  }
}

/* ================================================================
   13. LOGIN / OTP SCREEN — мобилни подобрения
   ================================================================ */
@media (max-width: 480px) {
  .login-wrap {
    padding: 16px;
    align-items: flex-start;
    padding-top: 15vh;
  }

  .login-box {
    padding: 24px 18px !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  .otp-input {
    font-size:calc(16px * var(--fs, 1)) !important;
    min-height: 48px !important;
    padding: 12px !important;
  }

  .otp-code-input {
    font-size:calc(24px * var(--fs, 1)) !important;
    letter-spacing: 6px !important;
    text-align: center;
  }

  .otp-btn {
    min-height: 48px !important;
    font-size:calc(15px * var(--fs, 1)) !important;
    width: 100%;
  }

  .otp-remember {
    padding: 8px 0;
    font-size:calc(13.5px * var(--fs, 1));
  }
}

/* ================================================================
   14. MAIN CONTENT — мобилни корекции
   ================================================================ */
@media (max-width: 768px) {
  .main {
    max-width: 100% !important;
    padding: 56px 14px 20px !important;
  }
}

@media (max-width: 480px) {
  .main {
    padding: 52px 10px 16px !important;
  }
}

@media (max-width: 360px) {
  .main {
    padding: 50px 8px 12px !important;
  }

  .card {
    padding: 10px !important;
  }

  .btn {
    padding: 8px 12px !important;
    font-size:calc(13.5px * var(--fs, 1)) !important;
  }
}

/* ================================================================
   15. TYPOGRAPHY — четливост на малък екран
   ================================================================ */
@media (max-width: 768px) {
  .topbar h1 {
    font-size:calc(16px * var(--fs, 1)) !important;
    line-height: 1.3;
  }
}

@media (max-width: 480px) {
  .topbar h1 {
    font-size:calc(15px * var(--fs, 1)) !important;
  }

  /* По-голям текст за четливост */
  body {
    font-size:calc(15px * var(--fs, 1));
  }

  .err-box,
  .ok-box {
    font-size:calc(13.5px * var(--fs, 1)) !important;
    padding: 10px 12px !important;
  }
}

/* ================================================================
   16. BADGES — по-видими на мобилен
   ================================================================ */
@media (max-width: 768px) {
  .badge {
    min-width: 20px;
    height: 20px;
    font-size:calc(11.5px * var(--fs, 1));
  }
}

/* ================================================================
   17. REGISTRATION SECTION — responsive forms
   ================================================================ */
@media (max-width: 768px) {
  /* Dynamic rows in registration (employee/partner lists) */
  /* 06.11.2026: без отметките и радио бутоните — flex:1 ги разпъваше и
     надписът им отиваше в другия край на реда (Настройки ▸ Известия) */
  [style*="display:flex"][style*="gap"] > input:not([type="checkbox"]):not([type="radio"]),
  [style*="display:flex"][style*="gap"] > select {
    flex: 1;
    min-width: 0 !important;
  }

  /* Submit buttons in registration */
  button[name="submit_reg_request"] {
    font-size:calc(15px * var(--fs, 1)) !important;
    padding: 12px !important;
  }
}

/* ================================================================
   18. SAFE AREAS — iPhone notch и подобни
   ================================================================ */
@supports (padding: env(safe-area-inset-top)) {
  .login-wrap {
    padding-top: max(15vh, env(safe-area-inset-top));
  }

  @media (max-width: 768px) {
    .sb-toggle {
      top: max(10px, env(safe-area-inset-top)) !important;
      left: max(10px, env(safe-area-inset-left)) !important;
    }

    .main {
      padding-bottom: max(16px, env(safe-area-inset-bottom)) !important;
    }

    .sidebar {
      padding-top: env(safe-area-inset-top);
    }
  }
}

/* ================================================================
   19. SMOOTH TRANSITIONS — по-приятно усещане
   ================================================================ */
@media (max-width: 768px) {
  .sidebar {
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
  }

  .card,
  .btn,
  .nav-item {
    transition: all 0.15s ease;
  }
}

/* ================================================================
   20. PRINT — скрий ненужните елементи при печат
   ================================================================ */
@media print {
  .sidebar,
  .sb-toggle,
  .topbar form,
  .nav-item,
  .btn {
    display: none !important;
  }

  .main {
    margin-left: 0 !important;
    padding: 0 !important;
    max-width: 100% !important;
  }

  .right-panel {
    display: block !important;
    position: static !important;
    width: 100% !important;
    border: 1px solid #ccc;
    page-break-before: always;
  }
}
