/* ════════════════════════════════════════════════════════════════
   App shell — sidebar (.sn) and top bar (.tb)
   Same visual language as the dashboard: white surfaces, hairline
   borders, soft indigo selection, quiet muted labels.
   Loaded after design-system.css; every rule is scoped under
   .app-shell so it wins over the legacy shell styles.
   ════════════════════════════════════════════════════════════════ */

.app-shell {
  --sh-surface: #ffffff;
  --sh-sunken: #f5f6fa;
  --sh-border: #e7e9f0;
  --sh-hairline: #eff1f6;
  --sh-text: #0f172a;
  --sh-text-2: #475569;
  --sh-muted: #8a94a6;
  --sh-primary: var(--ds-primary, #0b0f8a);
  --sh-primary-soft: #eef0ff;
  --sh-warn: #b45309;
  --sh-warn-soft: #fff1dc;
  --sh-bad: #dc2626;
  --sh-radius: 10px;
}

.app-shell .lucide { flex: none; }

/* ════════ Sidebar ════════ */
.app-shell .sn {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 12px 12px;
  background: var(--sh-surface);
  border-right: 1px solid var(--sh-border);
}

.app-shell .sn-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 56px;
  padding: 0 4px 0 6px;
}
.app-shell .sn-logo { display: flex; align-items: center; min-width: 0; }
/* logo.png has ~17% transparent padding on each side — pull it back to align with the nav */
.app-shell .sn-logo img { display: block; width: auto; height: 58px; max-width: none; margin-left: -14px; object-fit: contain; }
.app-shell .sn-collapse {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--sh-muted);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.app-shell .sn-collapse:hover { background: var(--sh-sunken); color: var(--sh-text); }
.app-shell .sn-collapse .lucide { width: 18px; height: 18px; transition: transform .2s; }

/* Property switcher */
.app-shell .sn-property {
  position: relative;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) 16px;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 8px 10px;
  border: 1px solid var(--sh-border);
  border-radius: 12px;
  background: var(--sh-surface);
  transition: border-color .15s, background .15s;
}
.app-shell .sn-property:hover { border-color: #cfd4e0; background: #fbfbfd; }
.app-shell .sn-property:focus-within { border-color: var(--sh-primary); box-shadow: 0 0 0 3px var(--sh-primary-soft); }
.app-shell .sn-property-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--sh-primary-soft);
  color: var(--sh-primary);
}
.app-shell .sn-property-icon .lucide { width: 16px; height: 16px; }
.app-shell .sn-property-body { display: grid; gap: 1px; min-width: 0; margin: 0; cursor: pointer; }
.app-shell .sn-property-body > span {
  color: var(--sh-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.app-shell .sn-property-body strong,
.app-shell .sn-property-body select {
  overflow: hidden;
  color: var(--sh-text);
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.app-shell .sn-property-body select {
  width: 100%;
  min-height: 0;
  height: auto;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  font-family: inherit;
  appearance: none;
  cursor: pointer;
  outline: none;
}
.app-shell .sn-property-chevron { width: 14px; height: 14px; color: var(--sh-muted); pointer-events: none; }

/* Navigation */
.app-shell .sn-nav {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
  margin: 0 -4px;
  padding: 0 4px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #dfe2ea transparent;
}
.app-shell .sn-heading {
  margin: 14px 0 6px;
  padding: 0 10px;
  color: var(--sh-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.app-shell .sn-heading:first-child { margin-top: 4px; }
.app-shell .sn-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 38px;
  padding: 0 10px;
  border-radius: var(--sh-radius);
  color: var(--sh-text-2);
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
  transition: background .12s, color .12s;
}
.app-shell .sn-link .lucide { width: 18px; height: 18px; color: var(--sh-muted); transition: color .12s; }
.app-shell .sn-link > span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-shell .sn-link:hover { background: var(--sh-sunken); color: var(--sh-text); }
.app-shell .sn-link:hover .lucide { color: var(--sh-text-2); }
.app-shell .sn-link:focus-visible { outline: 2px solid var(--sh-primary); outline-offset: -2px; }
.app-shell .sn-link.active,
.app-shell .sn-link.active:hover { background: var(--sh-primary); color: #fff; font-weight: 700; }
.app-shell .sn-link.active .lucide,
.app-shell .sn-link.active:hover .lucide { color: #fff; }
.app-shell .sn-link.active .sn-badge:not(.warn) { background: #fff; color: var(--sh-primary); }
.app-shell .sn-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--sh-primary);
  color: #fff;
  font-size: 11px;
  font-style: normal;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
}
.app-shell .sn-badge.warn { background: var(--sh-warn-soft); color: var(--sh-warn); }

/* Footer: signed-in user */
.app-shell .sn-footer { padding-top: 10px; border-top: 1px solid var(--sh-hairline); }
.app-shell .sn-user { display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: 12px; }
.app-shell .sn-avatar,
.app-shell .tb-avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2a3bd1, var(--sh-primary));
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}
.app-shell .sn-user-body { display: grid; min-width: 0; }
.app-shell .sn-user-body strong { overflow: hidden; color: var(--sh-text); font-size: 13px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.app-shell .sn-user-body small { color: var(--sh-muted); font-size: 11px; font-weight: 600; }

/* Collapsed rail (toggle on desktop, automatic on tablet) */
.app-shell.sidebar-collapsed .sn { padding-inline: 10px; }
.app-shell.sidebar-collapsed .sn-brand { flex-direction: column; justify-content: center; padding: 0; }
.app-shell.sidebar-collapsed .sn-logo { display: none; }
.app-shell.sidebar-collapsed .sn-collapse .lucide { transform: scaleX(-1); }
.app-shell.sidebar-collapsed .sn-property { grid-template-columns: 1fr; justify-items: center; padding: 8px 0; }
.app-shell.sidebar-collapsed .sn-property-body,
.app-shell.sidebar-collapsed .sn-property-chevron,
.app-shell.sidebar-collapsed .sn-heading,
.app-shell.sidebar-collapsed .sn-link > span,
.app-shell.sidebar-collapsed .sn-user-body { display: none; }
.app-shell.sidebar-collapsed .sn-nav { margin-top: 6px; }
.app-shell.sidebar-collapsed .sn-link { justify-content: center; padding: 0; min-height: 42px; }
.app-shell.sidebar-collapsed .sn-badge {
  position: absolute;
  top: 5px;
  right: 7px;
  min-width: 8px;
  height: 8px;
  padding: 0;
  font-size: 0;
  border: 2px solid var(--sh-surface);
  box-sizing: content-box;
}
.app-shell.sidebar-collapsed .sn-badge.warn { background: var(--sh-warn); }
.app-shell.sidebar-collapsed .sn-user { justify-content: center; padding: 6px 0; }

/* ════════ Top bar ════════ */
.app-shell .tb {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 64px;
  padding: 10px var(--ds-page-pad, 24px);
  overflow: visible;
  background: rgba(255, 255, 255, .86);
  border-bottom: 1px solid var(--sh-border);
  box-shadow: none;
  backdrop-filter: saturate(180%) blur(12px);
}

.app-shell .tb-context { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 0 1 auto; }
.app-shell .tb-context-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--sh-sunken);
  color: var(--sh-text-2);
}
.app-shell .tb-context-icon .lucide { width: 16px; height: 16px; }
.app-shell .tb-context-body { display: grid; min-width: 0; line-height: 1.25; }
.app-shell .tb-context-body small { color: var(--sh-muted); font-size: 11px; font-weight: 600; }
.app-shell .tb-context-body strong { overflow: hidden; color: var(--sh-text); font-size: 14px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }

.app-shell .tb-search {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1 1 360px;
  max-width: 560px;
  height: 40px;
  margin: 0 auto;
  padding: 0 10px 0 38px;
  border: 1px solid var(--sh-border);
  border-radius: 10px;
  background: var(--sh-sunken);
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.app-shell .tb-search:hover { border-color: #d6dae4; }
.app-shell .tb-search:focus-within { border-color: var(--sh-primary); background: var(--sh-surface); box-shadow: 0 0 0 3px var(--sh-primary-soft); }
.app-shell .tb-search > .lucide { position: absolute; left: 12px; width: 16px; height: 16px; color: var(--sh-muted); }
.app-shell .tb-search input {
  flex: 1;
  min-width: 0;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  color: var(--sh-text);
  font-family: inherit;
  font-size: 13.5px;
  outline: none;
}
.app-shell .tb-search input::placeholder { color: var(--sh-muted); }
.app-shell .tb-search input::-webkit-search-cancel-button { cursor: pointer; }
.app-shell .tb-search kbd {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border: 1px solid var(--sh-border);
  border-radius: 6px;
  background: var(--sh-surface);
  color: var(--sh-muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
}
.app-shell .tb-search:focus-within kbd { display: none; }

.app-shell .tb-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; flex: none; }
.app-shell .tb-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--sh-border);
  border-radius: 10px;
  background: var(--sh-surface);
  color: var(--sh-text);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.app-shell .tb-btn .lucide { width: 16px; height: 16px; }
.app-shell .tb-btn:hover { background: var(--sh-sunken); border-color: #d6dae4; }
.app-shell .tb-btn.primary { border-color: var(--sh-primary); background: var(--sh-primary); color: #fff; }
.app-shell .tb-btn.primary:hover { filter: brightness(1.15); }
.app-shell .tb-count {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--sh-warn-soft);
  color: var(--sh-warn);
  font-size: 11px;
  font-style: normal;
  line-height: 20px;
  text-align: center;
}
.app-shell .tb-divider { width: 1px; height: 24px; margin: 0 4px; background: var(--sh-border); }
.app-shell .tb-icon {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--sh-text-2);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.app-shell .tb-icon:hover { background: var(--sh-sunken); color: var(--sh-text); }
.app-shell .tb-icon .lucide { width: 18px; height: 18px; }
.app-shell .tb-icon.mobile-menu { display: none; }
.app-shell .tb-dot {
  position: absolute;
  top: 8px;
  right: 9px;
  width: 8px;
  height: 8px;
  border: 2px solid var(--sh-surface);
  border-radius: 50%;
  background: var(--sh-bad);
}

/* Account menu */
.app-shell .tb-user { position: relative; }
.app-shell .tb-user > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 44px;
  padding: 4px 8px 4px 4px;
  border-radius: 12px;
  cursor: pointer;
  list-style: none;
  transition: background .15s;
}
.app-shell .tb-user > summary::-webkit-details-marker { display: none; }
.app-shell .tb-user > summary:hover,
.app-shell .tb-user[open] > summary { background: var(--sh-sunken); }
.app-shell .tb-user > summary:focus-visible { outline: 2px solid var(--sh-primary); }
.app-shell .tb-user > summary > .lucide { width: 16px; height: 16px; color: var(--sh-muted); transition: transform .15s; }
.app-shell .tb-user[open] > summary > .lucide { transform: rotate(180deg); }
.app-shell .tb-user-body { display: grid; line-height: 1.2; }
.app-shell .tb-user-body strong { color: var(--sh-text); font-size: 13px; font-weight: 700; white-space: nowrap; }
.app-shell .tb-user-body small { color: var(--sh-muted); font-size: 11px; font-weight: 600; white-space: nowrap; }
.app-shell .tb-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 40;
  display: grid;
  min-width: 220px;
  padding: 6px;
  border: 1px solid var(--sh-border);
  border-radius: 12px;
  background: var(--sh-surface);
  box-shadow: 0 16px 40px rgba(15, 23, 42, .14);
}
.app-shell .tb-menu-head { display: grid; padding: 8px 10px 10px; margin-bottom: 4px; border-bottom: 1px solid var(--sh-hairline); }
.app-shell .tb-menu-head strong { font-size: 13px; }
.app-shell .tb-menu-head small { overflow: hidden; color: var(--sh-muted); font-size: 12px; text-overflow: ellipsis; }
.app-shell .tb-menu form { margin: 0; }
.app-shell .tb-menu a,
.app-shell .tb-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--sh-text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.app-shell .tb-menu a:hover,
.app-shell .tb-menu button:hover { background: var(--sh-sunken); }
.app-shell .tb-menu .lucide { width: 16px; height: 16px; color: var(--sh-muted); }
.app-shell .tb-menu button { color: var(--sh-bad); }
.app-shell .tb-menu button .lucide { color: var(--sh-bad); }

/* ════════ Responsive ════════ */
@media (max-width: 1280px) {
  .app-shell .tb-context-body small { display: none; }
  .app-shell .tb-user-body { display: none; }
}

/* Tablet: the legacy CSS shrinks the sidebar to a rail — mirror the rail look. */
@media (min-width: 768px) and (max-width: 1024px) {
  .app-shell .sn { padding-inline: 10px; }
  .app-shell .sn-brand { justify-content: center; padding: 0; }
  .app-shell .sn-logo { display: none; }
  .app-shell .sn-collapse { display: none; }
  .app-shell .sn-property { grid-template-columns: 1fr; justify-items: center; padding: 8px 0; }
  .app-shell .sn-property-body,
  .app-shell .sn-property-chevron,
  .app-shell .sn-heading,
  .app-shell .sn-link > span,
  .app-shell .sn-user-body { display: none; }
  .app-shell .sn-link { justify-content: center; padding: 0; min-height: 42px; }
  .app-shell .sn-badge { position: absolute; top: 5px; right: 7px; min-width: 8px; height: 8px; padding: 0; font-size: 0; border: 2px solid var(--sh-surface); box-sizing: content-box; }
  .app-shell .sn-badge.warn { background: var(--sh-warn); }
  .app-shell .sn-user { justify-content: center; }
  .app-shell .tb-context { display: none; }
  .app-shell .tb-icon.mobile-menu { display: none; }
  .app-shell .tb-btn span { display: none; }
  .app-shell .tb-btn { padding: 0 10px; }
}

/* Phone: off-canvas drawer with full labels; slim top bar. */
@media (max-width: 767px) {
  .app-shell .sn-collapse { display: none; }
  .app-shell .tb { gap: 8px; min-height: 56px; padding: 8px 12px; }
  .app-shell .tb-icon.mobile-menu { display: inline-grid; }
  .app-shell .tb-context,
  .app-shell .tb-divider,
  .app-shell .tb-search kbd,
  .app-shell .tb-btn span { display: none; }
  .app-shell .tb-search { flex: 1 1 auto; height: 38px; margin: 0; }
  .app-shell .tb-btn { width: 36px; padding: 0; justify-content: center; }
  .app-shell .tb-btn .tb-count { position: absolute; top: -6px; right: -6px; }
  .app-shell .tb-actions { gap: 4px; }
  .app-shell .tb-user > summary { padding: 2px; }
  .app-shell .tb-user > summary > .lucide { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .app-shell .sn *, .app-shell .tb * { transition: none !important; }
}
