/* ============================================================
   SPOT - Core Styles & Thumb-Zone Ergonomics
   Mobile-First Portrait (Bottom Dock), Adaptive Landscape
   ============================================================ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --nav-height: 64px;
  --topbar-height: 56px;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-pill: 9999px;
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

#app-root {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  background-color: var(--bg-primary);
  position: relative;
}

/* ============================================================
   TOP BAR (Branding, Theme, Lang, Status)
   ============================================================ */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-height);
  padding: 0 16px;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  z-index: 50;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.brand-logo {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  color: var(--text-inverse);
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.5px;
}

[data-theme="astro"] .brand-logo {
  background: var(--accent-primary);
  color: #000000;
}

.brand-info {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.5px;
  line-height: 1.1;
  color: var(--text-primary);
}

.brand-subtitle {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.top-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.lang-segmented-control {
  display: inline-flex;
  align-items: center;
  background-color: var(--bg-pill);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  padding: 2px;
}

.lang-pill-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 700;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: all var(--transition-fast);
  line-height: 1;
}

.lang-pill-btn:hover {
  color: var(--text-primary);
}

.lang-pill-btn.active {
  background-color: var(--accent-primary);
  color: var(--text-inverse);
}

[data-theme="astro"] .lang-pill-btn.active {
  background-color: var(--accent-primary);
  color: #000000;
}

.pill-ir {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 700;
  border-radius: var(--radius-pill);
  background-color: var(--bg-pill);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.pill-ir:hover {
  border-color: #ff3333;
  color: #ff3333;
}

.pill-ir.active {
  background-color: #220000;
  border-color: #ff0000;
  color: #ff3333;
  box-shadow: 0 0 8px rgba(255, 0, 0, 0.4);
}

.ir-indicator-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: #ff4d4d;
  display: inline-block;
  transition: transform var(--transition-fast);
}

.pill-ir.active .ir-indicator-dot {
  background-color: #ff0000;
  box-shadow: 0 0 6px #ff0000;
  animation: pulse-red-dot 1.5s infinite;
}

@keyframes pulse-red-dot {
  0% { transform: scale(0.9); opacity: 0.8; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.8; }
}

.control-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-pill);
  background-color: var(--bg-pill);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.control-pill:hover,
.control-pill:active {
  background-color: var(--border-subtle);
  color: var(--text-primary);
}

.theme-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-pill);
  background-color: var(--bg-pill);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.theme-toggle-btn:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
}

#fullscreen-toggle-btn svg {
  pointer-events: none;
}

#fullscreen-toggle-btn.is-fullscreen .fs-icon-enter {
  display: none !important;
}

#fullscreen-toggle-btn.is-fullscreen .fs-icon-exit {
  display: block !important;
}

#fullscreen-toggle-btn.is-fullscreen {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.network-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--status-online);
  transition: background-color var(--transition-normal);
}

.network-status-dot.offline {
  background-color: var(--status-offline);
}

/* ============================================================
   MAIN CONTENT SCROLL AREA
   ============================================================ */
.main-viewport {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 20px);
  -webkit-overflow-scrolling: touch;
}

.tab-view {
  display: none;
  animation: fadeIn 0.2s ease-in-out;
  max-width: 900px;
  margin: 0 auto;
}

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

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

/* ============================================================
   BOTTOM NAVIGATION BAR (Thumb Zone Optimized)
   ============================================================ */
.bottom-dock {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background-color: var(--bg-nav);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

.nav-tab-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  height: 100%;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
  padding: 4px 2px;
  position: relative;
}

.nav-tab-btn svg {
  width: 22px;
  height: 22px;
  margin-bottom: 3px;
  transition: transform var(--transition-fast), color var(--transition-fast);
}

.nav-tab-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: -0.2px;
  transition: color var(--transition-fast);
}

.nav-tab-btn.active {
  color: var(--accent-primary);
}

.nav-tab-btn.active svg {
  transform: translateY(-2px);
}

.nav-tab-btn.active::after {
  content: "";
  position: absolute;
  top: 0;
  width: 32px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background-color: var(--accent-primary);
}

/* ============================================================
   MODALS & DRAWERS
   ============================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
}

.modal-backdrop.open {
  display: flex;
  animation: backdropIn 0.2s ease-out;
}

.modal-sheet {
  background-color: var(--bg-secondary);
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border: 1px solid var(--border-strong);
  border-bottom: none;
  padding: 20px;
  padding-bottom: calc(20px + var(--safe-bottom));
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes backdropIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}

/* ============================================================
   LANDSCAPE & TABLET / DESKTOP ADAPTATION
   ============================================================ */
@media (min-width: 768px) and (orientation: landscape), (min-width: 1024px) {
  #app-root {
    flex-direction: row;
  }

  .top-bar {
    display: none; /* Merged into desktop sidebar/top */
  }

  .bottom-dock {
    position: static;
    flex-direction: column;
    justify-content: flex-start;
    gap: 8px;
    width: 240px;
    height: 100%;
    padding: 20px 12px;
    border-top: none;
    border-right: 1px solid var(--border-subtle);
    background-color: var(--bg-secondary);
  }

  .nav-tab-btn {
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    gap: 12px;
    width: 100%;
    height: 44px;
    padding: 0 16px;
    border-radius: var(--radius-md);
    flex: initial;
  }

  .nav-tab-btn svg {
    margin-bottom: 0;
  }

  .nav-tab-btn.active::after {
    display: none;
  }

  .nav-tab-btn.active {
    background-color: var(--bg-nav-active);
  }

  .main-viewport {
    flex: 1;
    padding: 24px 32px;
    padding-bottom: 32px;
  }

  .modal-backdrop {
    align-items: center;
  }

  .modal-sheet {
    border-radius: var(--radius-lg);
    border-bottom: 1px solid var(--border-strong);
  }
}

/* Very narrow portrait phones (<= 390px) */
@media (max-width: 390px) {
  .top-controls {
    gap: 4px;
  }
  .pill-ir {
    padding: 4px 6px;
    font-size: 10px;
    gap: 4px;
  }
  .lang-pill-btn {
    padding: 3px 5px;
    font-size: 10px;
  }
  .theme-toggle-btn {
    width: 30px;
    height: 30px;
  }
  .theme-toggle-btn svg {
    width: 15px;
    height: 15px;
  }
}
