/* ChefAssist responsive compatibility layer.
   Loaded after the recovered inline CSS. Desktop stays unchanged; compact
   layout fixes overflow, viewport ownership and touch targets. */

.chat-main,
.chat-header,
.tab-switcher,
.instr-panel {
  min-width: 0;
}

.tab-switcher {
  max-width: 100%;
  flex-shrink: 1;
  justify-content: flex-start;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

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

.tab-switcher-btn {
  flex: 0 0 auto;
  scroll-snap-align: start;
  white-space: nowrap;
}

.instr-panel {
  width: 100%;
  min-height: 0;
}

/* Closed off-canvas panels must not cast a full-height shadow into the app. */
.refs-panel:not(.open),
.haccp-panel:not(.open) {
  box-shadow: none !important;
}

@supports not (height: 100dvh) {
  #screen-chat,
  .chat-main,
  .sidebar {
    height: 100vh;
  }
}

/* Бургер показывается только там, где sidebar скрыт (см. ≤900px ниже);
   на 901–1100px меню и так видно слева. */
@media (max-width: 1100px) {
  .mob-menu-btn {
    display: none;
  }
}

@media (max-width: 900px), (max-height: 500px) and (max-width: 1100px) {
  #screen-chat,
  .chat-main {
    height: 100dvh;
    min-height: 0;
  }

  .chat-main {
    width: 100%;
    flex: 1 1 auto;
    overflow: hidden;
  }

  .chat-header {
    min-width: 0;
    gap: 8px;
    padding-top: max(11px, env(safe-area-inset-top));
    padding-left: max(12px, env(safe-area-inset-left));
    /* Reserve a real lane for the right overflow affordance. */
    padding-right: max(42px, env(safe-area-inset-right));
  }

  .tab-switcher,
  .tab-bar {
    flex: 1 1 auto;
    min-width: 0;
    max-width: 100%;
    justify-content: flex-start;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

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

  .tab-switcher-btn,
  .tab {
    flex: 0 0 auto;
    min-height: 44px;
    scroll-snap-align: start;
    white-space: nowrap;
  }

  .model-badge {
    display: none !important;
  }

  #chat-empty,
  .chat-empty {
    flex: 1 1 auto;
    min-height: 0;
    justify-content: flex-start;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    padding: 20px 12px 20px;
  }

  .chat-messages,
  .kb-panel,
  .ttklib-panel,
  .instr-panel {
    min-height: 0;
  }

  .chat-input-area {
    position: relative;
    z-index: 2;
    flex: 0 0 auto;
    background: var(--w, #fff);
    padding-bottom: max(14px, env(safe-area-inset-bottom));
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }

  .mob-menu-btn,
  .icon-btn,
  .mic-btn,
  .send-btn {
    min-width: 44px;
    min-height: 44px;
  }

  .mob-menu-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 200;
    width: min(320px, 86vw);
    height: 100dvh;
    min-height: 0;
    transform: translateX(-100%);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: auto;
    box-shadow: 4px 0 24px rgba(0, 0, 0, .12);
  }

  .sidebar.mob-open {
    transform: translateX(0);
  }

  .sidebar-logo {
    padding-top: max(16px, env(safe-area-inset-top));
  }

  .sidebar-section {
    min-height: 0;
    flex: 0 0 auto;
    overflow: visible;
  }

  .sidebar-nav {
    margin-top: auto;
  }

  .mob-overlay {
    position: fixed;
    inset: 0;
    z-index: 185;
    display: none;
    background: rgba(0, 0, 0, .45);
  }

  .mob-overlay.active {
    display: block;
  }

  .suggestions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .sug {
    min-width: 0;
    min-height: 96px;
    padding: 10px;
  }

  .sug-icon {
    width: 32px;
    height: 32px;
    margin-bottom: 7px !important;
  }

  .sug-title {
    font-size: 12px;
    line-height: 1.25;
  }

  .sug-desc {
    display: -webkit-box;
    overflow: hidden;
    font-size: 11px;
    line-height: 1.35;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }
}

@media (max-width: 359px) {
  .suggestions {
    grid-template-columns: 1fr;
    padding-bottom: 18px;
  }

  .sug {
    min-height: 76px;
  }

  .chat-empty-icon {
    width: 42px;
    height: 42px;
    margin-bottom: 6px;
  }

  .chat-empty-title {
    font-size: 20px;
  }

  .chat-empty-sub {
    margin-bottom: 14px;
  }

  .input-hint {
    display: none;
  }
}

@media (max-width: 900px), (max-height: 500px) and (max-width: 1100px) {
  .chat-header {
    position: relative;
  }

  .chat-header.tabs-overflow-right::after {
    position: absolute;
    top: 50%;
    z-index: 5;
    display: flex;
    width: 30px;
    height: 44px;
    align-items: center;
    justify-content: center;
    color: var(--g900);
    font-size: 22px;
    font-weight: 700;
    line-height: 1;
    pointer-events: none;
    transform: translateY(-50%);
  }

  .chat-header.tabs-overflow-right::after {
    right: max(8px, env(safe-area-inset-right));
    content: '›';
    background: linear-gradient(90deg, rgba(255,255,255,0), var(--w) 52%);
  }


  .mob-menu-btn:focus-visible,
  .tab-switcher-btn:focus-visible,
  .icon-btn:focus-visible,
  .mic-btn:focus-visible,
  .send-btn:focus-visible,
  #chat-empty .sug:focus-visible {
    outline: 3px solid var(--g700);
    outline-offset: 2px;
  }

  .chat-input-wrap textarea::placeholder {
    color: #4b5563;
    opacity: 1;
  }

  .chat-empty-sub,
  .sug-desc,
  .input-hint {
    color: #4b5563;
  }

  .chat-input-area .icon-btn,
  .chat-input-area .mic-btn {
    color: #4b5563;
  }

  .chat-input-area .icon-btn svg,
  .chat-input-area .mic-btn svg {
    stroke: currentColor;
  }

  .instr-head {
    align-items: stretch;
  }

  .instr-panel .instr-search {
    width: 100%;
  }

  #chat-empty {
    scroll-padding-bottom: 20px;
  }
}

@media (max-height: 500px) and (max-width: 1100px) {
  .chat-empty,
  #chat-empty {
    padding-top: 8px;
    padding-bottom: 10px;
  }

  .chat-empty-icon {
    width: 34px;
    height: 34px;
    margin-bottom: 4px;
  }

  .chat-empty-icon svg {
    width: 18px;
    height: 18px;
  }

  .chat-empty-title {
    margin-bottom: 2px;
    font-size: 18px;
  }

  .chat-empty-sub {
    margin-bottom: 8px;
    font-size: 12px;
  }

  .suggestions {
    gap: 6px;
    padding-bottom: 10px;
  }

  .sug {
    min-height: 72px;
    padding: 8px;
  }

  .sug-icon {
    width: 28px;
    height: 28px;
    margin-bottom: 4px !important;
  }

  .input-hint {
    display: none;
  }
}

/* Bottom navigation: hidden by default (desktop), fixed bar in compact layout. */
.bottom-nav {
  display: none;
}

/* Dedicated compact menu. Kept below the enterprise references panel. */
#more-drawer,
#more-overlay {
  display: none;
}

@media (max-width: 900px), (max-height: 500px) and (max-width: 1100px) {
  #more-drawer {
    display: flex;
    z-index: 1701;
    width: min(360px, 100vw);
    background: var(--gray50, #f9fafb);
  }

  #more-overlay {
    z-index: 1700;
  }

  #more-overlay.open {
    display: block;
  }

  #more-drawer .more-menu {
    padding: 12px;
  }

  #more-drawer .more-menu-item {
    display: flex;
    width: 100%;
    min-height: 52px;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--gray200, #e5e7eb);
    border-radius: 10px;
    background: var(--w, #fff);
    color: var(--gray900, #111827);
    font: inherit;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
  }

  #more-drawer .more-menu-item:focus-visible {
    outline: 3px solid var(--g700, #40916c);
    outline-offset: 2px;
  }
  .bottom-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 180;
    height: calc(56px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--w, #fff);
    border-top: 1px solid var(--gray200, #e5e7eb);
    box-shadow: 0 -2px 12px rgba(0, 0, 0, .06);
  }

  .bottom-nav .bottom-item {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: none;
    background: none;
    color: var(--gray500, #6b7280);
    font-size: 11px;
    font-weight: 500;
    line-height: 1.2;
    padding: 4px 2px;
    cursor: pointer;
    font-family: inherit;
  }

  .bottom-nav .bottom-item svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
  }

  .bottom-nav .bottom-item.active {
    color: var(--g900, #1b4332);
    font-weight: 600;
  }

  .bottom-nav .bottom-item:focus-visible {
    outline: 3px solid var(--g700, #40916c);
    outline-offset: -2px;
  }

  /* The bottom bar replaces the duplicated top tab strip in compact layout. */
  .chat-header .tab-switcher {
    display: none;
  }

  /* Keep the whole main column above the fixed bar (100vh fallback first). */
  #screen-chat,
  .chat-main {
    height: 100vh;
    height: calc(100dvh - 56px - env(safe-area-inset-bottom));
  }

  .chat-input-area {
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }

  #chat-empty,
  .chat-empty {
    padding-bottom: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar,
  #more-drawer,
  .tab-switcher,
  .tab-bar {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
