/* ===== MOBILE RESPONSIVE — JARVIS HUD ===== */

/* ===== HAMBURGER MENU ===== */
.hamburger-btn {
  display: none;
  background: none;
  border: 1px solid rgba(0, 240, 255, 0.2);
  border-radius: 3px;
  padding: 8px;
  cursor: pointer;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.hamburger-btn span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--cyan);
  border-radius: 1px;
  transition: all 0.3s ease;
}
.hamburger-btn.active span:nth-child(1) { transform: rotate(45deg) translate(4px, 4px); }
.hamburger-btn.active span:nth-child(2) { opacity: 0; }
.hamburger-btn.active span:nth-child(3) { transform: rotate(-45deg) translate(4px, -4px); }

/* Right panel toggle for mobile */
.mobile-right-toggle {
  display: none;
  background: none;
  border: 1px solid rgba(0, 240, 255, 0.2);
  border-radius: 3px;
  padding: 8px;
  cursor: pointer;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  color: var(--cyan);
  font-size: 16px;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

/* Sidebar overlay backdrop */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 99;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.sidebar-overlay.visible {
  opacity: 1;
}

/* ===== TABLET (768px - 1024px) ===== */
@media (max-width: 1024px) {
  #sidebar {
    width: 56px;
    transition: width 0.3s ease;
  }
  #sidebar .channel-name,
  #sidebar .sidebar-footer,
  #sidebar .panel-title,
  #sidebar .panel-indicator,
  #sidebar .channel-unread {
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
  }
  #sidebar .channel-item {
    justify-content: center;
    padding: 12px 8px;
  }
  #sidebar .channel-icon {
    margin-right: 0;
    font-size: 16px;
  }
  #sidebar .panel-header {
    justify-content: center;
    padding: 12px 8px;
  }

  /* Expand sidebar on hover (tablet with pointer) */
  @media (hover: hover) {
    #sidebar:hover {
      width: 220px;
      z-index: 50;
      position: relative;
    }
    #sidebar:hover .channel-name,
    #sidebar:hover .sidebar-footer,
    #sidebar:hover .panel-title,
    #sidebar:hover .panel-indicator,
    #sidebar:hover .channel-unread {
      opacity: 1;
      pointer-events: auto;
    }
    #sidebar:hover .channel-item {
      justify-content: flex-start;
      padding: 10px 12px;
    }
    #sidebar:hover .channel-icon {
      margin-right: 8px;
    }
    #sidebar:hover .panel-header {
      justify-content: space-between;
      padding: 12px 16px;
    }
  }

  /* Right panel narrower */
  #right-panel {
    width: 200px;
  }
  #right-panel.collapsed {
    width: 40px;
  }
}

/* ===== MOBILE (< 768px) ===== */
@media (max-width: 767px) {
  /* Show mobile controls */
  .hamburger-btn,
  .mobile-right-toggle {
    display: flex;
  }

  /* Reduce HUD padding */
  #hud-container {
    padding: 4px;
    gap: 4px;
  }

  /* === TOP BAR === */
  #top-bar {
    padding: 6px 10px;
    min-height: 48px;
    gap: 6px;
  }
  .top-left {
    flex-shrink: 0;
  }
  .jarvis-logo {
    font-size: 13px;
  }
  .logo-text {
    letter-spacing: 2px;
  }
  .logo-subtitle {
    display: none;
  }

  /* Time/date condensed on one line */
  .top-center {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    justify-content: center;
    min-width: 0;
  }
  .hud-time {
    font-size: 14px;
    letter-spacing: 1px;
  }
  .hud-date {
    font-size: 9px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Badges as small dots */
  .top-right .status-badges {
    gap: 4px;
  }
  .badge {
    font-size: 0;
    padding: 0;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    min-width: 10px;
    overflow: hidden;
  }
  .badge::before {
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 6px;
    height: 6px;
  }
  .badge-online { background: rgba(0, 255, 136, 0.15); border-color: var(--green); }
  .badge-warn { background: rgba(255, 170, 0, 0.15); border-color: var(--yellow); }
  .badge-offline { background: rgba(255, 51, 102, 0.15); border-color: var(--red); }

  /* === MAIN CONTENT === */
  #main-content {
    flex-direction: column;
  }

  /* === SIDEBAR as slide-out drawer === */
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    max-width: 85vw;
    height: 100vh;
    z-index: 100;
    border-radius: 0;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
  }
  #sidebar.drawer-open {
    transform: translateX(0);
  }
  /* Restore hidden elements in drawer mode */
  #sidebar .channel-name,
  #sidebar .sidebar-footer,
  #sidebar .panel-title,
  #sidebar .panel-indicator,
  #sidebar .channel-unread {
    opacity: 1;
    pointer-events: auto;
  }
  #sidebar .channel-item {
    justify-content: flex-start;
    padding: 12px 14px;
    min-height: 44px;
  }
  #sidebar .channel-icon {
    margin-right: 10px;
    font-size: 14px;
  }
  #sidebar .panel-header {
    justify-content: space-between;
    padding: 12px 16px;
  }

  /* === CHAT PANEL full width === */
  #chat-panel {
    flex: 1;
    min-height: 0;
  }
  .panel-header {
    padding: 8px 12px;
  }
  .panel-subtitle {
    display: none;
  }
  #chat-messages {
    padding: 10px;
  }
  .message {
    padding: 6px;
    margin-bottom: 12px;
  }
  .message-body {
    font-size: 14px;
  }
  .message-body.jarvis-msg {
    padding-left: 8px;
  }

  /* Input area full width, larger touch targets */
  #chat-input-container {
    padding: 8px;
  }
  .input-wrapper {
    padding: 10px 12px;
  }
  #chat-input {
    font-size: 16px; /* prevents iOS zoom */
  }
  #send-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 10px;
  }

  /* === RIGHT PANEL === */
  #right-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 300px;
    max-width: 90vw;
    height: 100vh;
    z-index: 100;
    border-radius: 0;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
  }
  #right-panel.mobile-open {
    transform: translateX(0);
  }
  /* Override desktop collapsed state on mobile */
  #right-panel.collapsed {
    width: 300px;
    max-width: 90vw;
    transform: translateX(100%);
  }
  #right-panel.collapsed.mobile-open {
    transform: translateX(0);
  }
  #right-panel.collapsed #right-panel-content {
    opacity: 1;
    pointer-events: auto;
  }
  #right-panel.collapsed .panel-title {
    display: inline;
  }
  /* Hide desktop toggle on mobile */
  .panel-toggle {
    display: none;
  }

  /* Action buttons larger for touch */
  .action-btn {
    min-height: 44px;
    font-size: 10px;
    padding: 10px 6px;
  }

  /* Scroll to bottom button */
  .scroll-to-bottom {
    width: 44px;
    height: 44px;
    font-size: 16px;
  }

  /* Clear chat button */
  .clear-chat-btn {
    min-height: 36px;
    padding: 6px 10px;
  }

  /* === LOGIN SCREEN === */
  .login-container {
    padding: 32px 24px;
    width: 95%;
  }
  .login-logo {
    font-size: 22px;
  }
  .login-title {
    letter-spacing: 4px;
  }
  .login-subtitle {
    font-size: 9px;
    letter-spacing: 3px;
  }
  .login-code-input {
    width: 100%;
    max-width: 240px;
    font-size: 24px;
    padding: 14px;
    letter-spacing: 10px;
  }
  .login-btn {
    padding: 16px 24px;
    min-height: 48px;
  }

  /* === PERFORMANCE === */
  /* Reduce backdrop-filter intensity */
  .panel,
  #top-bar,
  .login-container {
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }
  .scroll-to-bottom {
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }

  /* Simplify scanlines on mobile */
  #scanlines {
    animation: none;
    opacity: 0.5;
  }

  /* Code blocks scroll */
  .message-body pre {
    max-width: calc(100vw - 48px);
  }

  /* Boot screen mobile */
  .boot-container {
    width: 95%;
  }
  .boot-log {
    font-size: 11px;
  }

  /* Car mode button - bigger & visible on mobile */
  .car-mode-btn {
    font-size: 11px;
    opacity: 0.9;
    padding: 6px 12px;
    min-height: 36px;
  }
}

/* ===== VERY SMALL SCREENS (< 400px) ===== */
@media (max-width: 400px) {
  .jarvis-logo {
    font-size: 11px;
  }
  .logo-bracket {
    display: none;
  }
  .hud-date {
    display: none;
  }
  .top-center {
    justify-content: center;
  }
  .login-code-input {
    font-size: 20px;
    letter-spacing: 8px;
  }
}

/* Fix for mobile browser URL bar eating bottom space */
@supports (height: 100dvh) {
  @media (max-width: 768px) {
    body, html {
      height: 100dvh;
    }
    #hud-container {
      height: 100dvh;
    }
  }
}

@media (max-width: 768px) {
  body, html {
    height: -webkit-fill-available;
  }
  #hud-container {
    height: 100vh;
    height: -webkit-fill-available;
    max-height: -webkit-fill-available;
  }
  #chat-input-container {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
}
