/**
 * 3.98" BWRY E-Paper Open Smart Badge & Ita-Bag
 * Layout & Responsive Multi-Device Styles (Material Design 3)
 * Copyright (c) 2026 ZGQ Inc. All Rights Reserved.
 */

/* ========================================================
 * 1. Global Header
 * ======================================================== */
header {
  background: var(--md-sys-color-surface-container);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.brand {
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: -0.2px;
}

.brand-badge {
  font-size: 11px;
  font-weight: 700;
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  padding: 2px 8px;
  border-radius: 6px;
  letter-spacing: 0.5px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ========================================================
 * 2. Top Connectivity & Status Bar Cards
 * ======================================================== */
/* Primary Connection Card (WebBLE) */
.conn-banner,
.ble-banner {
  background: var(--md-sys-color-surface-container-high);
  margin: 12px 16px 8px 16px;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-1);
  border: 1px solid var(--md-sys-color-outline-variant);
  flex-wrap: wrap;
  gap: 10px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.conn-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conn-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
}

.conn-status-dot,
.ble-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  background-color: #888888;
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.25);
  flex-shrink: 0;
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.conn-status-dot.connected,
.ble-status-dot.connected {
  background-color: #4caf50;
  box-shadow: 0 0 8px #4caf50;
}

.conn-status-dot.connecting,
.ble-status-dot.connecting {
  background-color: #ff9800;
  animation: pulse-dot 1.2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

.conn-subtext {
  font-size: 11px;
  color: var(--md-sys-color-outline);
  padding-left: 18px;
}

.conn-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Secondary Connection Bar (LAN / Wi-Fi Air Provisioning) */
.network-sub-bar {
  margin: 0 16px 8px 16px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  background: var(--md-sys-color-surface-container);
  font-size: 12px;
  color: var(--md-sys-color-outline);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--md-sys-color-outline-variant);
  box-shadow: var(--shadow-1);
  flex-wrap: wrap;
  gap: 8px;
}

.network-sub-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lan-ip-badge {
  font-weight: 700;
  color: var(--md-sys-color-primary);
  font-family: monospace;
  font-size: 12px;
}

.lan-console-link {
  color: var(--md-sys-color-primary);
  text-decoration: none;
  font-weight: 600;
  margin-left: 4px;
  border-bottom: 1px dashed var(--md-sys-color-primary);
  padding-bottom: 1px;
}

.lan-console-link:hover {
  opacity: 0.8;
}

.network-sub-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* 4-Way Display Orientation Bar */
.orientation-bar {
  margin: 0 16px 12px 16px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  background: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-1);
  flex-wrap: wrap;
  gap: 8px;
}

.orientation-left {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
}

.orientation-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  font-family: monospace;
}

.orientation-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* Transmission Progress Bar */
.progress-bar-wrap {
  margin: 0 16px 8px 16px;
  height: 6px;
  background: var(--md-sys-color-surface-container-highest);
  border-radius: 3px;
  overflow: hidden;
  display: none;
}

.progress-bar {
  width: 0%;
  height: 100%;
  background: var(--md-sys-color-primary);
  transition: width 0.15s ease;
}

.transfer-msg {
  margin: -4px 16px 8px 16px;
  font-size: 11px;
  font-weight: 600;
  color: var(--md-sys-color-primary);
  min-height: 16px;
}

/* ========================================================
 * 3. Responsive Sliding Tab Bar Navigation with Scroll Hint
 * ======================================================== */
.tab-scroll-wrapper {
  position: relative;
  margin: 4px 16px 14px 16px;
}

.tab-scroll-container {
  position: relative;
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  scroll-behavior: smooth;
  padding: 4px 2px;
}

.tab-scroll-container::-webkit-scrollbar {
  display: none;
}

/* Gradient Fade Masks on Left & Right */
.tab-scroll-wrapper::before,
.tab-scroll-wrapper::after {
  content: '';
  position: absolute;
  top: 4px;
  bottom: 4px;
  width: 28px;
  pointer-events: none;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.tab-scroll-wrapper::before {
  left: 0;
  background: linear-gradient(to right, var(--md-sys-color-surface), transparent);
}

.tab-scroll-wrapper::after {
  right: 0;
  background: linear-gradient(to left, var(--md-sys-color-surface), transparent);
}

.tab-scroll-wrapper.has-scroll-left::before {
  opacity: 1;
}

.tab-scroll-wrapper.has-scroll-right::after {
  opacity: 1;
}

/* Tab Bar Base (Desktop / Tablet top bar) */
.tab-nav {
  display: inline-flex;
  gap: 8px;
  padding: 4px;
  background: var(--md-sys-color-surface-container);
  border-radius: var(--radius-lg);
  border: 1px solid var(--md-sys-color-outline-variant);
  white-space: nowrap;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
}

.tab-btn:hover {
  background: var(--md-sys-color-surface-container-high);
}

.tab-btn:active {
  transform: scale(0.97);
}

.tab-btn.active {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  box-shadow: var(--shadow-1);
}

/* Mobile Slide Hint Tooltip */
.tab-scroll-hint {
  display: none;
  align-items: center;
  justify-content: space-between;
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  font-size: 11px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 20px;
  margin-bottom: 6px;
  animation: fadeIn 0.3s ease;
  box-shadow: var(--shadow-2);
}

.tab-scroll-hint span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tab-scroll-hint .hint-close {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 15px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

/* ========================================================
 * 4. Main Container & Tab Panes
 * ======================================================== */
main {
  flex: 1;
  padding: 0 16px 24px 16px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.tab-pane,
.tab-view {
  display: none;
  animation: fadeIn 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.tab-pane.active,
.tab-view.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ========================================================
 * 5. Footer
 * ======================================================== */
.app-footer {
  margin-top: auto;
  border-top: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container);
  padding: 18px 20px;
  text-align: center;
  font-size: 13px;
  color: var(--md-sys-color-outline);
}

.footer-links {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.footer-links a {
  color: var(--md-sys-color-primary);
  text-decoration: none;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: opacity 0.2s;
}

.footer-links a:hover {
  text-decoration: underline;
  opacity: 0.85;
}

.footer-sep {
  color: var(--md-sys-color-outline-variant);
}

.footer-copy {
  font-size: 12px;
  color: var(--md-sys-color-outline);
}

/* ========================================================
 * 6. Responsive Mobile Navigation (Bottom Fixed Sliding Bar)
 * ======================================================== */
@media (max-width: 640px) {
  header {
    padding: 10px 14px;
  }
  .brand {
    font-size: 14px;
  }

  .conn-banner,
  .ble-banner {
    margin: 8px 10px 6px 10px;
    padding: 10px 12px;
    gap: 8px;
  }
  .conn-right {
    width: 100%;
    justify-content: flex-start;
  }

  .network-sub-bar {
    margin: 0 10px 6px 10px;
    padding: 8px 12px;
    gap: 6px;
  }

  .orientation-bar {
    margin: 0 10px 10px 10px;
    padding: 8px 12px;
    gap: 6px;
  }

  /* Fixed Bottom Sliding Navigation Bar */
  .tab-scroll-wrapper {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    margin: 0;
    background: var(--md-sys-color-surface-container);
    border-top: 1px solid var(--md-sys-color-outline-variant);
    border-bottom: none;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.28);
    padding-bottom: env(safe-area-inset-bottom, 8px);
    padding-top: 6px;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
  }

  .tab-scroll-container {
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding: 2px 10px;
  }

  /* Gradient edge masks */
  .tab-scroll-wrapper::before,
  .tab-scroll-wrapper::after {
    top: 0;
    bottom: env(safe-area-inset-bottom, 8px);
    width: 28px;
    pointer-events: none;
    z-index: 10;
  }

  .tab-scroll-wrapper::before {
    left: 0;
    background: linear-gradient(to right, var(--md-sys-color-surface-container), transparent);
  }

  .tab-scroll-wrapper::after {
    right: 0;
    background: linear-gradient(to left, var(--md-sys-color-surface-container), transparent);
  }

  .tab-nav {
    display: inline-flex;
    background: transparent;
    border: none;
    padding: 0 2px;
    gap: 6px;
    white-space: nowrap;
  }

  /* Touch-friendly tab buttons */
  .tab-btn {
    min-height: 42px;
    padding: 8px 14px;
    font-size: 13px;
    border-radius: var(--radius-xl);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .tab-btn.active {
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    box-shadow: var(--shadow-2);
  }

  /* Floating swipe hint banner above bottom nav bar */
  .tab-scroll-hint {
    display: flex;
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 1001;
    white-space: nowrap;
    border: 1px solid var(--md-sys-color-outline-variant);
    box-shadow: var(--shadow-3);
    margin-bottom: 0;
    pointer-events: auto;
  }

  /* Safe padding on body and main to avoid occlusion */
  body {
    padding-bottom: calc(78px + env(safe-area-inset-bottom, 8px));
  }

  main {
    padding: 0 10px calc(78px + env(safe-area-inset-bottom, 8px)) 10px;
  }

  .app-footer {
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 8px));
  }
}

/* Tablets (641px - 1024px) */
@media (min-width: 641px) and (max-width: 1024px) {
  .grid-2col {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  .tab-scroll-wrapper {
    margin: 6px 14px 12px 14px;
  }
}

/* Desktop (>= 1025px) */
@media (min-width: 1025px) {
  .tab-scroll-wrapper::before,
  .tab-scroll-wrapper::after {
    display: none;
  }
  .tab-nav {
    display: flex;
    justify-content: flex-start;
  }
}
