/* 03-layout.css — Layout system, drawer, containers */

/* App Shell */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* Drawer */
.drawer {
  position: fixed;
  top: 0; left: 0;
  width: var(--drawer-w);
  height: 100vh;
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transform: translateX(0);
  transition: transform var(--dur-base) var(--ease);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.drawer--closed {
  transform: translateX(-100%);
}
.drawer__overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-base);
}
.drawer__overlay--visible {
  opacity: 1;
  pointer-events: auto;
}

/* Drawer User Card */
.drawer__user {
  padding: var(--s-4);
  border-bottom: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  gap: var(--s-3);
}
.drawer__avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--c-primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: var(--text-md);
  flex-shrink: 0;
}
.drawer__user-info { min-width: 0; }
.drawer__user-name {
  font-weight: 600; font-size: var(--text-sm);
  color: var(--c-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.drawer__user-tier {
  font-size: var(--text-xs);
  color: var(--c-text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Drawer Nav */
.drawer__section-label {
  padding: var(--s-3) var(--s-4) var(--s-2);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--c-text-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.drawer__item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  margin: 0 var(--s-2);
  border-radius: var(--radius);
  color: var(--c-text-2);
  font-size: var(--text-sm);
  transition: all var(--dur-fast);
  position: relative;
  min-height: 44px;
}
.drawer__item:hover {
  background: var(--c-surface-2);
  color: var(--c-text);
}
.drawer__item--active {
  background: var(--c-surface-2);
  color: var(--c-primary);
  font-weight: 500;
}
.drawer__item--active::before {
  content: '';
  position: absolute;
  left: calc(-1 * var(--s-2)); top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 20px;
  background: var(--c-primary);
  border-radius: 0 2px 2px 0;
}
.drawer__icon {
  width: 20px; height: 20px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.drawer__icon svg {
  width: 18px; height: 18px;
}

/* AppBar */
.appbar {
  position: fixed;
  top: 0; left: var(--drawer-w); right: 0;
  height: var(--appbar-h);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  padding: 0 var(--s-4);
  gap: var(--s-3);
  z-index: 50;
  transition: left var(--dur-base);
}
.appbar__menu-btn {
  display: none;
  padding: var(--s-2);
  border-radius: var(--radius);
  color: var(--c-text-2);
  min-width: 44px; min-height: 44px;
  align-items: center; justify-content: center;
}
.appbar__menu-btn:hover { background: var(--c-surface-2); }
.appbar__title {
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--c-text);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.appbar__actions {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}
.appbar__btn {
  padding: var(--s-2);
  border-radius: var(--radius);
  color: var(--c-text-2);
  position: relative;
  min-width: 44px; min-height: 44px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.appbar__btn:hover { background: var(--c-surface-2); color: var(--c-text); }

/* Main Content */
.main {
  margin-left: var(--drawer-w);
  margin-top: var(--appbar-h);
  min-height: calc(100vh - var(--appbar-h));
  padding: var(--s-5);
  transition: margin-left var(--dur-base);
  width: calc(100% - var(--drawer-w));
}

/* Container */
.container {
  max-width: var(--max-w);
  margin: 0 auto;
  width: 100%;
}

/* Landing mode (#'/') — full-screen tanpa drawer & appbar */
body.landing-mode .drawer,
body.landing-mode .appbar,
body.landing-mode .drawer__overlay {
  display: none;
}
body.landing-mode .main {
  margin-left: 0;
  margin-top: 0;
  min-height: 100vh;
  width: 100%;
  padding: 0;
}
body.landing-mode .container {
  max-width: none;
}

/* Grid */
.grid {
  display: grid;
  gap: var(--s-4);
}
.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid--4 { grid-template-columns: repeat(4, 1fr); }
.grid--auto { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

/* Flex */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: var(--s-1); }
.gap-2 { gap: var(--s-2); }
.gap-3 { gap: var(--s-3); }
.gap-4 { gap: var(--s-4); }

/* ======================== */
/* MOBILE BREAKPOINT: 768px */
/* ======================== */
@media (max-width: 768px) {
  .drawer {
    transform: translateX(-100%);
    width: 280px;
    box-shadow: 4px 0 24px rgba(0,0,0,0.15);
  }
  .drawer--open {
    transform: translateX(0);
  }
  .appbar {
    left: 0;
    padding: 0 var(--s-3);
    height: 52px;
  }
  .appbar__menu-btn {
    display: flex;
    margin-left: calc(-1 * var(--s-2));
  }
  .appbar__title {
    font-size: var(--text-base);
  }
  .main {
    margin-left: 0;
    padding: var(--s-3);
    width: 100%;
  }
  .container {
    padding: 0;
  }

  /* Grids: all single column on mobile */
  .grid--2,
  .grid--3,
  .grid--4,
  .grid--auto {
    grid-template-columns: 1fr;
    gap: var(--s-3);
  }

  /* Typography scale down slightly */
  h1 { font-size: var(--text-lg); }
  h2 { font-size: var(--text-md); }

  /* Cards: less padding */
  .card {
    padding: var(--s-4);
    border-radius: var(--radius);
  }
  .stat-card {
    padding: var(--s-3);
  }

  /* Tables: smaller padding */
  .table th,
  .table td {
    padding: var(--s-2) var(--s-3);
  }

  /* Search: full width */
  .search {
    max-width: 100% !important;
  }

  /* Buttons: larger touch targets */
  .btn {
    min-height: 44px;
    padding: var(--s-3) var(--s-4);
  }
  .btn--sm {
    min-height: 36px;
    padding: var(--s-2) var(--s-3);
  }

  /* Toolbar: stack vertically */
  .toolbar-mobile-stack {
    flex-direction: column !important;
    align-items: stretch !important;
  }
  .toolbar-mobile-stack .field,
  .toolbar-mobile-stack .search {
    width: 100% !important;
  }
}

/* ======================== */
/* SMALL MOBILE: 480px      */
/* ======================== */
@media (max-width: 480px) {
  .main {
    padding: var(--s-2);
  }
  .card {
    padding: var(--s-3);
  }
  .card__head {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--s-2);
  }
  .card__foot {
    flex-direction: column;
    gap: var(--s-2);
  }
  .card__foot .btn {
    width: 100%;
  }

  /* Stat cards: 2 columns */
  .grid--4 {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Table: even smaller */
  .table th,
  .table td {
    padding: var(--s-2);
    font-size: var(--text-xs);
  }

  /* AppBar: tighter */
  .appbar {
    padding: 0 var(--s-2);
  }
  .appbar__title {
    font-size: var(--text-sm);
  }
}
