/* ================================
   Mobile-only styles (<=768px)
   Safe: affects ONLY mobile via media query in base.html
   Includes: burger+drawer, centered logo, nicer tables, auth polish, cabinet avatar fix
   ================================ */

@media (max-width: 768px){

  :root{ --mobile-pad: 12px; }

  /* ---------- TOPBAR / LOGO / BURGER ---------- */
  .topbar{
    padding: 8px var(--mobile-pad) !important;
    min-height: 56px;
  }

  /* Row wrapper (added in base.html) */
  .topbar .mobile-topbar-row{
    position: relative !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important; /* logo centered */
    min-height: 56px;
  }

  /* Burger pinned left */
  .topbar .mobile-menu-btn{
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 1px solid rgba(229,231,235,1);
    background: #fff;
    font-size: 20px;
    line-height: 1;
    position: absolute !important;
    left: 12px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    margin: 0 !important;
    z-index: 2;
  }

  /* Hide desktop nav row on mobile to avoid wrap/duplicates */
  .topbar .nav{
    display: none !important;
  }

  /* Center logo image/link inside topbar row */
  .topbar .mobile-topbar-row a,
  .topbar .mobile-topbar-row .brand,
  .topbar .mobile-topbar-row .logo{
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .topbar .mobile-topbar-row img{
    display: block;
    height: 34px;
    width: auto;
    max-width: 160px;
    margin: 0 auto;
  }

  /* ---------- DRAWER ---------- */
  .mobile-drawer{
    position: fixed;
    inset: 0;
    z-index: 9000;
    display: none;
  }
  .mobile-drawer.is-open{ display: block; }

  .mobile-drawer__backdrop{
    position: absolute;
    inset: 0;
    background: rgba(17,24,39,0.35);
  }

  .mobile-drawer__panel{
    position: absolute;
    top: 0; left: 0; bottom: 0;
    width: min(86vw, 360px);
    background: #fff;
    border-right: 1px solid rgba(229,231,235,1);
    display: flex;
    flex-direction: column;
  }

  .mobile-drawer__head{
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 14px;
    border-bottom: 1px solid rgba(229,231,235,1);
  }

  .mobile-drawer__title{ font-weight: 700; }

  .mobile-drawer__close{
    width: 36px; height: 36px;
    border-radius: 10px;
    border: 1px solid rgba(229,231,235,1);
    background: #fff;
    font-size: 18px;
  }

  .mobile-drawer__nav{
    padding: 10px;
    overflow-y: auto;
  }

  .mobile-drawer__nav a{
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 12px;
    border-radius: 12px;
    text-decoration: none;
    color: inherit;
    border: 1px solid rgba(229,231,235,1);
    margin-bottom: 10px;
    background: #fff;
    font-size: 16px;
  }

  /* ---------- LAYOUT ---------- */
  .container{
    padding-left: var(--mobile-pad) !important;
    padding-right: var(--mobile-pad) !important;
  }

  /* ---------- TABLES (nicer) ---------- */
  /* Wrap-like behavior even if templates don't have .table-responsive */
  table.table, table.list-table{
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    font-size: 13px;
    background: #fff;
    border-radius: 14px;
    border: 1px solid rgba(229,231,235,1);
  }

  table.table thead th, table.table thead td,
  table.list-table thead th, table.list-table thead td{
    background: #f8fafc;
    position: sticky;
    top: 0;
    z-index: 2;
  }

  table.table th, table.table td,
  table.list-table th, table.list-table td{
    padding: 10px 12px !important;
  }

  /* Fix left clipping on first column */
  table.table th:first-child, table.table td:first-child,
  table.list-table th:first-child, table.list-table td:first-child{
    padding-left: 14px !important;
  }

  /* ---------- AUTH (login) polish ---------- */
  body.auth-page{
    background: #f7f8fb;
  }

  .auth-wrapper{
    min-height: 100vh;
    padding: 24px 14px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .auth-card{
    width: 100%;
    max-width: 420px;
    padding: 20px 16px;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 12px 30px rgba(17,24,39,0.08);
  }

  .auth-logo{
    display: flex;
    justify-content: center;
    margin-bottom: 8px;
  }

  .auth-logo img{
    width: 54px;
    height: auto;
  }

  .auth-title{
    font-size: 22px;
    line-height: 1.2;
    margin: 10px 0 18px;
    text-align: center;
  }

  .auth-field{ margin-bottom: 14px; }

  .auth-field label{
    font-size: 14px;
    margin-bottom: 6px;
    display: block;
  }

  /* Prevent iOS zoom-on-focus: >= 16px */
  .auth-field input,
  .auth-field select,
  .auth-field textarea{
    width: 100%;
    font-size: 16px !important;
    padding: 12px 12px !important;
    border-radius: 12px;
    border: 1px solid rgba(229,231,235,1);
    background: #fff;
    box-sizing: border-box;
  }

  .auth-btn{
    width: 100%;
    margin-top: 6px;
    padding: 12px 14px !important;
    font-size: 16px !important;
    border-radius: 12px;
  }

  /* ---------- CABINET avatar (prevent squish) ---------- */
  /* Generic: any avatar circle inside cabinet header must not shrink */
  .cabinet-profile-header .cabinet-avatar,
  .cabinet-profile-header .avatar,
  .cabinet-profile-header .profile-avatar{
    width: 64px !important;
    height: 64px !important;
    min-width: 64px !important;
    min-height: 64px !important;
    border-radius: 50% !important;
    overflow: hidden !important;
    flex: 0 0 64px !important;   /* do not shrink */
  }

  .cabinet-profile-header .cabinet-avatar img,
  .cabinet-profile-header .avatar img,
  .cabinet-profile-header .profile-avatar img{
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    display: block;
  }

  /* Let text shrink instead of avatar */
  .cabinet-profile-header .cabinet-profile-info,
  .cabinet-profile-header .profile-info{
    min-width: 0;
  }

  /* ---------- CABINET (APP-LIKE PROFILE) ---------- */
  .cabinet-page{
    padding: 12px var(--mobile-pad) 18px !important;
  }

  /* Header becomes vertical like an app profile */
  .cabinet-profile-header{
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    text-align: center !important;
    gap: 12px !important;
  }

  /* Bigger avatar for profile feel */
  .cabinet-profile-header .cabinet-avatar{
    width: 96px !important;
    height: 96px !important;
    min-width: 96px !important;
    min-height: 96px !important;
    flex: 0 0 96px !important;
    border-radius: 50% !important;
  }

  /* Hide redundant "Кабинет" title on mobile */
  .cabinet-profile-info .cabinet-title{
    display: none !important;
  }

  .cabinet-profile-info{
    width: 100% !important;
  }

  /* Meta lines – compact, centered */
  .cabinet-user-meta{
    display: grid;
    gap: 6px;
    font-size: 14px;
    line-height: 1.35;
  }
  .cabinet-user-meta div{
    display: flex;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
  }
  .cabinet-user-meta strong{
    color: rgba(107,114,128,1);
    font-weight: 700;
  }

  /* Role badge centered under meta */
  .cabinet-role{
    width: 100%;
    display: flex;
    justify-content: center;
    margin-top: -4px;
  }
  .cabinet-role .role-badge{
    border-radius: 9999px;
    padding: 6px 12px;
    font-size: 12px;
    line-height: 1;
    white-space: nowrap;
  }

  /* Actions stack (app buttons) */
  .cabinet-actions{
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 14px;
  }
  .cabinet-actions .btn{
    width: 100%;
    padding: 12px 14px;
    border-radius: 12px;
    font-weight: 800;
  }

  /* Stats: 1 column on small phones, 2 on wider */
  .cabinet-stats{
    display: grid !important;
    grid-template-columns: 1fr;
    gap: 10px;
  }
  @media (min-width: 390px) and (max-width: 768px){
    .cabinet-stats{
      grid-template-columns: 1fr 1fr;
    }
    .cabinet-stats .stat-card:nth-child(3){
      grid-column: 1 / -1;
    }
  }
  .cabinet-stats .stat-card{
    border-radius: 14px;
    padding: 14px 12px;
  }

}
