/**
 * Кабинет /app: выдвижной сайдбар, main на всю ширину на телефоне и планшете.
 */
.app-shell {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  position: relative;
}

.app-sidebar {
  width: 18rem;
  max-width: min(18rem, 92vw);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 45;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);
}

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

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}

.app-shell.sidebar-open .sidebar-backdrop.is-active {
  display: block;
}

.app-main-wrap {
  flex: 1;
  min-width: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-topbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid rgba(100, 150, 255, 0.15);
  background: rgba(10, 20, 35, 0.85);
  backdrop-filter: blur(8px);
}

.app-topbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 0.5rem;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(30, 41, 59, 0.8);
  color: #e2e8f0;
  cursor: pointer;
  min-height: 44px;
}

.app-topbar-btn:hover {
  background: rgba(51, 65, 85, 0.9);
  border-color: rgba(96, 165, 250, 0.5);
}

.app-topbar-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  margin-left: auto;
  font-size: 0.8rem;
}

.app-topbar-nav a {
  color: #94a3b8;
  text-decoration: none;
  padding: 0.35rem 0;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.app-topbar-nav a:hover {
  color: #67e8f9;
  text-decoration: underline;
}

.sidebar-close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.5rem;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(30, 41, 59, 0.6);
  color: #cbd5e1;
  cursor: pointer;
}

.sidebar-close-btn:hover {
  background: rgba(51, 65, 85, 0.9);
}

#mainContent {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#tenderView {
  min-width: 0;
  overflow-x: auto;
}

/* AI (RAG): не использовать #ragPanel { display:flex } — иначе .hidden не работает */
.rag-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 48;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}

.rag-backdrop.is-active {
  display: block;
}

.rag-panel {
  display: none;
  pointer-events: none;
  position: fixed;
  z-index: 50;
  flex-direction: column;
  background: rgba(15, 23, 42, 0.97);
  border: 1px solid rgba(59, 130, 246, 0.35);
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.45);
  bottom: 1rem;
  right: 1rem;
  width: min(420px, calc(100vw - 2rem));
  max-height: min(55vh, 520px);
  border-radius: 1rem;
  overflow: hidden;
}

.rag-panel.is-open {
  display: flex;
  pointer-events: auto;
}

.rag-panel-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(15, 23, 42, 0.95);
}

.rag-close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 44px;
  min-width: 44px;
  padding: 0 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #e2e8f0;
  background: rgba(51, 65, 85, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.4);
  border-radius: 0.5rem;
  cursor: pointer;
  touch-action: manipulation;
}

.rag-close-btn:hover {
  background: rgba(71, 85, 105, 1);
}

#ragMessages {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  padding: 0.75rem;
  font-size: 0.9rem;
  gap: 0.5rem;
  display: flex;
  flex-direction: column;
}

.rag-panel-footer {
  flex-shrink: 0;
  padding: 0.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  gap: 0.5rem;
}

.rag-fab {
  position: fixed;
  bottom: max(1rem, env(safe-area-inset-bottom));
  right: max(1rem, env(safe-area-inset-right));
  z-index: 35;
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 9999px;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
  font-size: 1.35rem;
  box-shadow: 0 4px 20px rgba(59, 130, 246, 0.45);
}

.rag-fab.is-hidden {
  display: none !important;
}

/* Телефон / планшет: нижний лист */
@media (max-width: 1023px) {
  .rag-panel {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    max-height: min(88vh, 640px);
    border-radius: 1rem 1rem 0 0;
    transform: translateY(100%);
    transition: transform 0.28s ease;
  }

  .rag-panel.is-open {
    transform: translateY(0);
  }

  .rag-fab {
    bottom: max(1.25rem, env(safe-area-inset-bottom));
    right: max(1rem, env(safe-area-inset-right));
  }
}

body.rag-sheet-open {
  overflow: hidden;
}

/* Планшет и ПК: сайдбар по умолчанию открыт, без затемнения */
@media (min-width: 1024px) {
  .app-sidebar {
    position: relative;
    transform: translateX(0);
    box-shadow: none;
  }

  .app-shell:not(.sidebar-open) .app-sidebar {
    position: fixed;
    transform: translateX(-100%);
  }

  .app-shell.sidebar-open .sidebar-backdrop.is-active {
    display: none !important;
  }

  .sidebar-close-btn {
    display: inline-flex;
  }
}

/* Только мобила: крестик в сайдбаре */
@media (max-width: 1023px) {
  .sidebar-close-btn {
    display: inline-flex;
  }
}
