/**
 * Saha Events — Layout System
 * App shell structure, grid, spacing, and reusable layout components.
 * Mobile-first, production-grade layout architecture.
 */

/* ═══════════════════════════════════════════════════════════════
   LAYOUT TOKENS
═══════════════════════════════════════════════════════════════ */
:root {
  --layout-content-max:            480px;
  --layout-content-max-tablet:     720px;
  --layout-content-max-desktop:    960px;
  --layout-section-gap:            10px;
  --layout-block-gap:              8px;
  --layout-inline-gap:             12px;
  --layout-page-padding-x:         16px;
  --layout-page-padding-y:         16px;
  --layout-page-padding-x-tablet:  20px;
  --layout-page-padding-y-tablet:  20px;
  --layout-page-padding-x-desktop: 24px;
  --layout-page-padding-y-desktop: 24px;
}

@media (min-width: 600px) {
  :root {
    --layout-page-padding-x: var(--layout-page-padding-x-tablet);
    --layout-page-padding-y: var(--layout-page-padding-y-tablet);
    --layout-section-gap:    12px;
  }
}

@media (min-width: 1024px) {
  :root {
    --layout-page-padding-x: var(--layout-page-padding-x-desktop);
    --layout-page-padding-y: var(--layout-page-padding-y-desktop);
    --layout-section-gap:    16px;
  }
}

/* ═══════════════════════════════════════════════════════════════
   APP SHELL
═══════════════════════════════════════════════════════════════ */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  width: 100%;
  overflow-x: hidden;
}

.app-shell .app-body {
  display: flex;
  flex: 1;
  min-height: 0;
  min-width: 0;
}

.app-shell .main-area,
.app-shell #main-content {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.app-shell #screen-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ═══════════════════════════════════════════════════════════════
   SCREEN / PAGE WRAPPER
═══════════════════════════════════════════════════════════════ */
.screen.layout-page {
  padding: var(--layout-page-padding-y) var(--layout-page-padding-x);
  padding-bottom: calc(var(--layout-page-padding-y) + env(safe-area-inset-bottom, 0px) + 28px);
  display: flex;
  flex-direction: column;
  gap: 0;
}

@media (min-width: 768px) {
  .screen.layout-page > .page-layout,
  .screen.layout-page > .crm-page {
    max-width: var(--layout-content-max);
    margin-left: 0;
    margin-right: auto;
  }
}

@media (min-width: 1024px) {
  .screen.layout-page > .page-layout,
  .screen.layout-page > .crm-page {
    max-width: var(--layout-content-max-tablet);
  }
}

/* ═══════════════════════════════════════════════════════════════
   PAGE LAYOUT STRUCTURE
═══════════════════════════════════════════════════════════════ */
.page-layout {
  display: flex;
  flex-direction: column;
  gap: var(--layout-section-gap);
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.page-layout__header {
  display: flex;
  flex-direction: column;
  gap: var(--layout-block-gap);
  margin-bottom: 0;
}

.page-layout__title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--layout-inline-gap);
}

.page-layout__title-wrap {
  min-width: 0;
  flex: 1 1 auto;
}

.page-layout__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--layout-inline-gap);
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════════
   SECTIONS
═══════════════════════════════════════════════════════════════ */
.layout-section {
  display: flex;
  flex-direction: column;
  gap: var(--layout-block-gap);
}

.layout-section__body {
  min-width: 0;
}

/* ═══════════════════════════════════════════════════════════════
   KPI / STATS BLOCKS
═══════════════════════════════════════════════════════════════ */
.layout-kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  width: 100%;
}

@media (min-width: 600px) {
  .layout-kpi-grid { gap: 16px; }
}

@media (min-width: 1024px) {
  .layout-kpi-grid { grid-template-columns: repeat(4, 1fr); }
}

.layout-kpi-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px;
  border-radius: var(--radius-card, 12px);
  background: var(--bg-card, #fff);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm, 0 1px 4px rgba(0,0,0,0.06));
  min-height: 64px;
  transition: transform 0.12s ease, box-shadow 0.2s ease;
}

.layout-kpi-block:active { transform: scale(0.98); }

.layout-kpi-block__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.layout-kpi-block__label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary, #3f4552);
}

.layout-kpi-block__value {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--text-primary, #111318);
  font-variant-numeric: tabular-nums;
}

/* ═══════════════════════════════════════════════════════════════
   SPACING UTILITIES
═══════════════════════════════════════════════════════════════ */
.layout-stack-1 > * + * { margin-top: 4px; }
.layout-stack-2 > * + * { margin-top: 8px; }
.layout-stack-3 > * + * { margin-top: 12px; }
.layout-stack-4 > * + * { margin-top: 16px; }
.layout-stack-5 > * + * { margin-top: 20px; }
.layout-stack-6 > * + * { margin-top: 24px; }

/* ═══════════════════════════════════════════════════════════════
   DASHBOARD
═══════════════════════════════════════════════════════════════ */
.layout-dashboard-hero {
  border-radius: var(--radius-card, 12px);
  overflow: hidden;
  margin-bottom: 0;
}
