/* ==========================================================================
   V360 Grid Layout — Responsive multi-column grid system
   Requirements: 7.1, 7.2, 7.5, 7.6, 10.1, 10.2, 10.3
   ========================================================================== */

/* --- Base Grid Container --- */
.v360-tab-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 16px;
  max-width: 100%;
  overflow-x: hidden;
  box-sizing: border-box;
}

/* --- Section spanning classes --- */

/* Full-width section spans both columns */
.v360-section-full {
  grid-column: 1 / -1;
}

/* Half-width section occupies one column */
.v360-section-half {
  grid-column: span 1;
}

/* Pair group: keeps two items side by side within a single-column layout */
.v360-pair-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  grid-column: 1 / -1;
  align-items: start;
}

/* --- Equal-height paired sections via grid row alignment --- */
.v360-tab-grid > .v360-section-half {
  align-self: start;
  min-height: 0;
}

.v360-pair-group > * {
  align-self: start;
  min-height: 0;
}

/* --- Collapsible section styling --- */
.v360-section {
  box-sizing: border-box;
  overflow: hidden;
}

.v360-collapsible .v360-section-header {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}

.v360-collapsible .v360-section-title {
  flex: 1;
  margin: 0;
}

.v360-collapse-icon {
  display: inline-block;
  transition: transform 300ms ease;
  font-size: 0.75em;
}

.v360-collapsible[data-collapsed="false"] .v360-collapse-icon {
  transform: rotate(90deg);
}

.v360-collapsible[data-collapsed="true"] .v360-collapse-icon {
  transform: rotate(0deg);
}

.v360-section-body {
  transition: max-height 300ms ease;
  overflow: hidden;
}

.v360-collapsible[data-collapsed="true"] .v360-section-body {
  max-height: 0 !important;
}

/* --- Block separators (24px minimum between grouped blocks) --- */
.v360-block-separator {
  grid-column: 1 / -1;
  height: 0;
  margin: 4px 0;
  border: none;
  border-top: 1px solid #e0e0e0;
}

.v360-tab-grid > .v360-block-separator + * {
  margin-top: 8px;
}

/* --- Tablet: 768px–1024px --- */
@media (max-width: 1024px) {
  .v360-tab-grid {
    grid-template-columns: 1fr;
  }

  .v360-section-half {
    grid-column: 1 / -1;
  }

  /* Keep paired sections side by side on tablet (Req 10.1) */
  .v360-pair-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }
}

/* --- Mobile: <768px --- */
@media (max-width: 768px) {
  .v360-tab-grid {
    grid-template-columns: 1fr;
    padding: 12px;
    gap: 12px;
  }

  .v360-section-half {
    grid-column: 1 / -1;
  }

  .v360-pair-group {
    grid-template-columns: 1fr;
  }

  /* Full-width inputs on mobile (Req 4.3) */
  .v360-input {
    width: 100% !important;
    min-width: unset !important;
  }
}

/* --- Overflow prevention for all viewports above 320px (Req 10.3) --- */
@media (min-width: 320px) {
  .v360-tab-grid,
  .v360-tab-grid * {
    max-width: 100%;
    box-sizing: border-box;
  }

  .v360-tab-grid img,
  .v360-tab-grid video,
  .v360-tab-grid iframe {
    max-width: 100%;
    height: auto;
  }

  .v360-tab-grid table {
    max-width: 100%;
    overflow-x: auto;
    display: block;
  }
}

/* --- Pending Sync Indicator (Offline Queue) --- */
/* Requirements: 29.2, 29.3 — Visual indicator for sections awaiting sync */
.v360-pending-sync {
  position: relative;
  border-left: 3px solid #f59e0b;
}

.v360-pending-sync::after {
  content: '⏳ Pending sync';
  position: absolute;
  top: 4px;
  right: 8px;
  font-size: 11px;
  color: #b45309;
  background: #fef3c7;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 500;
  z-index: 1;
}

/* --- Wide-Screen Compact Section Styles (Requirements 2.2, 2.3, 11.1, 11.2) --- */
@media (min-width: 1200px) {
  .v360-section,
  .v360-section-readonly {
    padding: 8px 10px !important;
    margin-bottom: 6px !important;
  }

  .v360-field-row {
    padding: 2px 0 !important;
  }

  /* 3-column layout for Overview tab sections on wide screens */
  .v360-tab-grid--overview {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 8px;
  }

  .v360-tab-grid--overview .v360-section-half {
    grid-column: span 1;
  }
}

/* --- Section Saving State --- */
.v360-section-saving {
  opacity: 0.7;
  pointer-events: none;
}


/* --- Multi-column field layout for dense sections (Req 2.5, 3.1, 3.3) --- */
.v360-fields-multicol {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
}

@media (max-width: 1199px) {
  .v360-fields-multicol {
    grid-template-columns: 1fr;
  }
}

/* --- Wide Screen: ≥1200px — 3-column compact grid (Req 2.1, 2.3, 3.1, 3.4) --- */
@media (min-width: 1200px) {
  .v360-tab-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 8px;
  }
}

/* --- Extra-Wide Screen: ≥1600px — 4-column layout --- */
@media (min-width: 1600px) {
  .v360-tab-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 10px;
  }
}
