/* MyAsset — Application shell
 *
 *   .app-shell
 *     ├── .app-sidebar            sticky, full viewport height (rendered by js/shell.js)
 *     └── .app-main
 *           ├── .app-topbar       sticky, spans the content column
 *           └── .page-content     page body, natural document scroll
 *
 * The browser viewport is the application canvas: no centred max-width
 * wrapper, no outer card, no decorative layers. Design tokens come from
 * tokens.css (load that first).
 */

:root {
  --sidebar-width: 248px;
  --topbar-height: 64px;
  --page-pad-x: 32px;
  --page-pad-y: 28px;
}

/* ───────────── Shell grid ───────────── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  width: 100%;
  min-height: 100vh;
  background: var(--bg-canvas);
}

.app-main {
  display: flex;
  flex-direction: column;
  min-width: 0;               /* lets wide children (tables) scroll inside their own box */
  min-height: 100vh;
}

.page-content {
  flex: 1 0 auto;
  width: 100%;
  padding: var(--page-pad-y) var(--page-pad-x) 48px;
}

/* ───────────── Sidebar ───────────── */
.app-sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--panel-bg);
  border-right: 1px solid var(--border-subtle);
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 40;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  height: var(--topbar-height);
  padding: 0 18px;
  border-bottom: 1px solid var(--border-subtle);
  font-family: 'Outfit', sans-serif;
  font-weight: 800;
  font-size: 18px;
  color: var(--text-primary);
  cursor: pointer;
}

.app-brand-icon {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--emerald-deep), #00796B);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFFFFF;
  font-size: 16px;
}

.app-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px 12px 24px;
}

.app-nav-title {
  font-family: 'Outfit', sans-serif;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  padding: 0 10px 6px;
}

.app-nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  margin-bottom: 1px;
  border-radius: 10px;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 13px;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.app-nav-link-content {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.app-nav-link svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-nav-link:hover {
  background: rgba(0, 91, 79, 0.07);
  color: var(--text-primary);
}

.app-nav-link.active {
  background: var(--emerald-deep);
  color: #FFFFFF;
}

.app-nav-link:focus-visible,
.app-brand:focus-visible {
  outline: 2px solid var(--brand-secondary);
  outline-offset: -2px;
}

/* ───────────── Topbar ───────────── */
.app-topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 16px;
  height: var(--topbar-height);
  padding: 0 var(--page-pad-x);
  background: rgba(255, 253, 248, 0.97);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-subtle);
}

.app-icon-btn.app-menu-btn {
  display: none;           /* shown on mobile only */
}

.app-icon-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border-subtle);
  background: #FFFFFF;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.app-icon-btn:hover {
  background: #F4F1EA;
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.app-icon-btn:focus-visible {
  outline: 2px solid var(--brand-secondary);
  outline-offset: 2px;
}

.app-icon-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-search {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 360px;
  max-width: 480px;
  min-width: 0;
  height: 38px;
  padding: 0 14px;
  background: #F1EEE4;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  color: var(--text-secondary);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.app-search:focus-within {
  background: #FFFFFF;
  border-color: var(--brand-secondary);
  box-shadow: 0 0 0 3px rgba(0, 120, 100, 0.14);
}

.app-search svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-search input {
  flex: 1;
  min-width: 0;
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  color: var(--text-primary);
}

.app-search input::placeholder {
  color: var(--text-tertiary);
}

.app-topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
  flex-shrink: 0;
}

.app-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 4px;
  min-width: 0;
}

.app-user[hidden] {
  display: none;
}

.app-avatar {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--emerald-deep);
  color: #FFFFFF;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-user-name {
  font-weight: 600;
  font-size: 13px;
  max-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-cta-icon {
  font-size: 1.05em;
  line-height: 1;
}

/* ───────────── User Dropdown ───────────── */
.app-user {
  position: relative;
  cursor: pointer;
  user-select: none;
}

.app-user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 220px;
  background: #FFFFFF;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.08);
  padding: 6px 0;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
}

.app-user-dropdown.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 6px;
}

.dropdown-header-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dropdown-header-email {
  font-size: 11px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.dropdown-item:hover {
  background: #F4F1EA;
  color: var(--text-primary);
}

.dropdown-item.text-danger {
  color: #D32F2F;
}

.dropdown-item.text-danger:hover {
  background: rgba(211, 47, 47, 0.08);
}

/* ───────────── Mobile drawer scrim ───────────── */
.app-scrim {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(23, 32, 31, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.app-scrim.is-visible {
  opacity: 1;
  pointer-events: auto;
}

body.nav-open {
  overflow: hidden;
}

/* ───────────── Tablet: collapsed icon rail ───────────── */
@media (min-width: 768px) and (max-width: 1099.98px) {
  :root {
    --sidebar-width: 72px;
    --page-pad-x: 24px;
  }

  .app-brand {
    justify-content: center;
    padding: 0;
  }

  .app-brand-text,
  .app-nav-label,
  .app-nav-title,
  .app-user-name {
    display: none;
  }

  .app-nav {
    gap: 14px;
    padding: 14px 10px 20px;
  }

  .app-nav-group + .app-nav-group {
    border-top: 1px solid var(--border-subtle);
    padding-top: 14px;
  }

  .app-nav-link {
    position: relative;
    justify-content: center;
    padding: 10px;
  }

  .app-nav-link .nav-badge {
    position: absolute;
    top: 0;
    right: 2px;
    margin: 0;
    padding: 1px 5px;
    font-size: 9px;
  }
}

/* ───────────── Mobile: off-canvas drawer ───────────── */
@media (max-width: 767.98px) {
  :root {
    --page-pad-x: 16px;
    --page-pad-y: 20px;
  }

  .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .app-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(288px, 86vw);
    height: 100%;
    z-index: 1000;
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.25s ease, visibility 0s linear 0.25s;
  }

  .app-sidebar.is-open {
    transform: none;
    visibility: visible;
    box-shadow: var(--shadow-overlay);
    transition: transform 0.25s ease, visibility 0s;
  }

  .app-topbar {
    gap: 10px;
  }

  .app-icon-btn.app-menu-btn {
    display: inline-grid;
  }

  .app-search {
    flex: 1 1 auto;
    max-width: none;
  }

  .app-search .pill-badge,
  .app-user-name {
    display: none;
  }

  .app-topbar-actions {
    gap: 10px;
  }

  .app-cta {
    width: 38px;
    height: 38px;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
    font-size: 18px;
  }

  .app-cta-label {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-sidebar,
  .app-scrim {
    transition: none;
  }
}
