/* Layout & Responsiveness */

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

html, body {
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Background atmospheric ambient gradient */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100vw;
  max-width: 960px;
  height: 480px;
  background: radial-gradient(
    ellipse at 50% 0%,
    rgba(0, 242, 254, 0.08) 0%,
    rgba(16, 185, 129, 0.04) 35%,
    rgba(6, 9, 17, 0) 70%
  );
  pointer-events: none;
  z-index: 0;
}

/* ==========================================================================
   1. MOBILE-FIRST DEFAULT (< 640px)
   - Single column
   - Large touch targets
   - Current mobile hierarchy
   ========================================================================== */

.app-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 14px calc(env(safe-area-inset-bottom, 0px) + 20px);
}

.app-main {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

/* Mobile Hero Card: natural vertical flow */
.hero-body-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Mobile Action Launchers: 2 columns for INCY/Happ, and full width Copy SUB below */
.app-launchers-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

#btn-copy-sub {
  grid-column: 1 / -1;
}

/* Mobile Cabinet Grid: single column */
.cabinet-columns-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Mobile Side Widgets: 1. Bonus Days, 2. Service Status, 3. Support */
.side-widgets-column {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Mobile touch targets and normal vertical expansion */
@media (max-width: 639px) {
  .btn {
    min-height: 48px;
    padding: 13px 16px;
    font-size: 14px;
  }

  .widget-card {
    min-height: 70px;
    padding: 12px;
  }

  .device-item {
    min-height: 52px;
    padding: 10px 12px;
  }

  /* Mobile: keep normal vertical expansion without internal scroll */
  .devices-section {
    height: auto;
    overflow: visible;
  }

  .devices-section .device-list,
  .devices-section.is-expanded .device-list {
    max-height: none;
    overflow-y: visible;
    flex: none;
    padding-bottom: 0;
  }

  .devices-section.is-expanded .device-list::after {
    display: none;
  }

  .devices-section .devices-card-footer,
  .devices-section .btn-show-more-devices {
    margin-top: 4px;
    padding-top: 0;
  }
}

/* ==========================================================================
   2. TABLET ADAPTIVE (640px – 900px)
   - Adaptive spacing
   - Partial 2-column layout where useful
   ========================================================================== */

@media (min-width: 640px) and (max-width: 900px) {
  body {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 24px 16px;
    background-color: #04060c;
  }

  .app-container {
    max-width: 680px;
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: 0 16px 45px rgba(0, 0, 0, 0.65), 0 0 35px rgba(0, 242, 254, 0.03);
    min-height: auto;
    padding: 20px 22px 28px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
  }

  .app-main {
    gap: 14px;
  }

  /* Partial 2-column for hero body */
  .hero-body-row {
    display: grid;
    grid-template-columns: 1.15fr 1fr;
    gap: 14px;
    align-items: center;
  }

  /* All 3 action buttons in one row */
  .app-launchers-row {
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
  }

  #btn-copy-sub {
    grid-column: auto;
  }

  /* Split devices & widgets */
  .cabinet-columns-grid {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 12px;
    align-items: stretch;
  }

  /* Fixed height Devices section on tablet: true 3-part flex layout */
  .devices-section {
    height: 250px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 16px 18px;
    gap: 0;
  }

  /* 1. Fixed Header */
  .devices-section .section-header-row,
  .devices-section .member-guidance-box {
    flex-shrink: 0;
    margin-bottom: 10px;
  }

  /* 2. Middle Scrollable Device List */
  .devices-section .device-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
  }

  .devices-section .device-item {
    height: 50px;
    min-height: 50px;
    max-height: 50px;
    box-sizing: border-box;
    flex-shrink: 0;
  }

  /* In expanded state, scroll additional devices inside the middle list area */
  .devices-section.is-expanded .device-list {
    overflow-y: auto;
    padding-right: 4px;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 242, 254, 0.3) transparent;
  }

  .devices-section.is-expanded .device-list::-webkit-scrollbar {
    width: 4px;
  }

  .devices-section.is-expanded .device-list::-webkit-scrollbar-track {
    background: transparent;
  }

  .devices-section.is-expanded .device-list::-webkit-scrollbar-thumb {
    background: rgba(0, 242, 254, 0.3);
    border-radius: var(--radius-full);
  }

  /* 3. Fixed Footer Button: occupies its own layout space, never over the list */
  .devices-section .devices-card-footer {
    flex-shrink: 0;
    margin-top: 14px;
    display: flex;
    flex-direction: column;
  }

  .devices-section .btn-show-more-devices {
    margin-top: 0;
    flex-shrink: 0;
  }

  /* Keep right column cards aligned and unchanged at matching fixed height */
  .side-widgets-column {
    display: flex;
    flex-direction: column;
    gap: 10px;
    height: 250px;
    box-sizing: border-box;
    justify-content: space-between;
  }
}

/* ==========================================================================
   3. DESKTOP OPTIMIZED (> 900px)
   - Centered cabinet width: 800–860px (840px)
   - Compact vertical spacing to fit in standard desktop viewport
   - INCY, Happ, Copy SUB in one row
   - Devices on the left, Bonus Days + Support on the right
   - Full width subscription summary
   ========================================================================== */

@media (min-width: 901px) {
  body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 16px;
    background-color: #04060c;
  }

  .app-container {
    width: 840px;
    max-width: 840px;
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7), 0 0 45px rgba(0, 242, 254, 0.04);
    min-height: auto;
    padding: 16px 24px 20px;
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
  }

  /* Compact vertical spacing */
  .app-main {
    gap: 10px;
  }

  /* Hero card full width with compact dual-unit layout */
  .sub-hero-card {
    padding: 14px 18px;
    gap: 10px;
  }

  .hero-body-row {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 16px;
    align-items: center;
  }

  /* Actions Cluster: Renew + [INCY, Happ, Copy SUB in one row] */
  .actions-cluster {
    gap: 8px;
  }

  .btn {
    padding: 10px 14px;
    font-size: 13px;
  }

  .app-launchers-row {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  #btn-copy-sub {
    grid-column: auto;
  }

  /* Lower section: Devices on the left, Bonus Days + Support on the right */
  .cabinet-columns-grid {
    display: grid;
    grid-template-columns: 1.35fr 1fr;
    gap: 12px;
    align-items: stretch;
  }

  /* Fixed height Devices section on desktop: true 3-part flex layout */
  .devices-section {
    padding: 16px 16px;
    gap: 0;
    height: 220px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  /* 1. Fixed Header */
  .devices-section .section-header-row,
  .devices-section .member-guidance-box {
    flex-shrink: 0;
    margin-bottom: 10px;
  }

  /* 2. Middle Scrollable Device List */
  .device-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
  }

  .device-item {
    height: 50px;
    min-height: 50px;
    max-height: 50px;
    padding: 7px 10px;
    box-sizing: border-box;
    flex-shrink: 0;
  }

  /* In expanded state, scroll additional devices inside the middle list area */
  .devices-section.is-expanded .device-list {
    overflow-y: auto;
    padding-right: 4px;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 242, 254, 0.3) transparent;
  }

  .devices-section.is-expanded .device-list::-webkit-scrollbar {
    width: 4px;
  }

  .devices-section.is-expanded .device-list::-webkit-scrollbar-track {
    background: transparent;
  }

  .devices-section.is-expanded .device-list::-webkit-scrollbar-thumb {
    background: rgba(0, 242, 254, 0.3);
    border-radius: var(--radius-full);
  }

  /* 3. Fixed Footer Button: occupies its own layout space, never over the list */
  .devices-section .devices-card-footer {
    flex-shrink: 0;
    margin-top: 14px;
    display: flex;
    flex-direction: column;
  }

  .devices-section .btn-show-more-devices {
    margin-top: 0;
    flex-shrink: 0;
  }

  /* Keep right column cards aligned and unchanged at matching fixed height */
  .side-widgets-column {
    display: flex;
    flex-direction: column;
    gap: 8px;
    height: 220px;
    box-sizing: border-box;
    justify-content: space-between;
  }

  .widget-card {
    padding: 10px 14px;
    gap: 3px;
  }
}

/* ==========================================================================
   4. MODALS & BOTTOM SHEETS
   ========================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 13, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--trans-smooth);
}

@media (min-width: 640px) {
  .modal-overlay {
    align-items: center;
  }
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-sheet {
  background: var(--bg-modal);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-elevated);
  transform: translateY(100%);
  transition: transform var(--trans-smooth);
  padding: 16px 20px 32px;
}

@media (min-width: 640px) {
  .modal-sheet {
    border-radius: var(--radius-lg);
    transform: scale(0.95) translateY(10px);
  }
}

.modal-overlay.active .modal-sheet {
  transform: translateY(0);
}

@media (min-width: 640px) {
  .modal-overlay.active .modal-sheet {
    transform: scale(1) translateY(0);
  }
}

/* Sheet Handle */
.sheet-handle {
  width: 40px;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-full);
  margin: 0 auto 16px;
}

@media (min-width: 640px) {
  .sheet-handle {
    display: none;
  }
}
