/* Shared Admin / Order shell. Density changes spacing, never business readability. */
.app-shell {
  --shell-sidebar: 208px;
  --shell-padding: 16px;
  --shell-gap: 12px;
  --control-height: 38px;
  --text-xs: 13px;
  --text-sm: 14px;
  --text-base: 16px;
  grid-template-columns: var(--shell-sidebar) minmax(0, 1fr);
  font-size: var(--text-base);
  line-height: 1.45;
  letter-spacing: 0;
}

.app-shell[data-density-effective="compact"] {
  --shell-padding: 12px;
  --shell-gap: 8px;
  --control-height: 36px;
  --text-base: 15px;
}

.app-shell[data-density-effective="pos"] {
  --shell-padding: 12px;
  --shell-gap: 10px;
  --control-height: 44px;
  --text-base: 16px;
}

.app-shell .shell {
  width: 100%;
  max-width: none;
  min-width: 0;
  padding: var(--shell-padding);
}

.app-shell .sidebar {
  padding: 16px 10px;
  min-width: 0;
  height: 100dvh;
  scrollbar-width: thin;
}

.app-shell .brand { gap: 8px; margin: 0 2px 18px; align-items: center; }
.app-shell .brand > span:last-child { min-width: 0; }
.app-shell .brand strong { display: block; font-size: 15px; line-height: 1.25; }
.app-shell .brand small { font-size: 13px; line-height: 1.3; }
.app-shell .brand-mark { flex: 0 0 32px; width: 32px; height: 32px; border-radius: 6px; }
.shell-icon { flex: 0 0 20px; width: 20px; height: 20px; vertical-align: middle; }
.app-shell .nav-tree { gap: 3px; }
.app-shell .nav-root,
.app-shell .nav-group > summary { min-height: 40px; padding: 8px; font-size: 15px; line-height: 1.3; gap: 8px; }
.app-shell .nav-group { display: block; }
.app-shell .nav-group > summary { display: flex; color: var(--ink); font-weight: 600; }
.app-shell .nav-group > summary::after { content: "+"; margin-left: auto; color: var(--muted); font-size: 17px; font-weight: 400; }
.app-shell .nav-group[open] > summary::after { content: "\2212"; }
.app-shell .nav-group > a { display: block; max-width: none; margin: 2px 0 2px 20px; padding: 8px; overflow: visible; font-size: 14px; line-height: 1.35; -webkit-line-clamp: unset; }
.app-shell .nav-subgroup { margin-left: 20px; padding-left: 0; }
.app-shell .nav-subgroup > summary { font-size: 14px; }
.app-shell .nav-subgroup > a { margin-left: 8px; border-left: 1px solid var(--line); border-radius: 0 4px 4px 0; }
.app-shell .nav-tree a.active { color: #0b5e52; background: #e4f2ed; font-weight: 700; }
.app-shell .nav-tree a[aria-current="page"] { box-shadow: inset 3px 0 0 var(--green); }
.app-shell .nav-tree button.nav-root { min-height: var(--control-height); padding: 8px; font-size: 15px; }
.shell-preferences { display: grid; gap: 6px; margin: 16px 2px 0; padding-top: 14px; border-top: 1px solid var(--line); }
.app-shell .shell-preferences label { font-size: 13px; }
.shell-preferences select { width: 100%; min-width: 0; }
.shell-workspace-link { display: inline-block; padding: 12px 4px; color: var(--muted); font-size: 14px; }
.app-shell .nav-close { display: none; }

.app-shell .topbar { flex-wrap: wrap; gap: 10px 16px; margin-bottom: 16px; align-items: center; }
.app-shell .topbar > div:first-child { min-width: 0; flex: 1 1 260px; }
.app-shell h1 { font-size: 26px; line-height: 1.2; overflow-wrap: anywhere; }
.app-shell h2 { line-height: 1.3; }
.app-shell .eyebrow { font-size: 13px; }
.app-shell .status-row { align-items: center; max-width: 100%; gap: 6px; }
.app-shell .badge { max-width: 100%; overflow-wrap: anywhere; padding: 5px 8px; border-radius: 5px; font-size: 13px; }
.app-shell .shell > .panel:not(.table-panel) { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; padding: 14px 0; }
.app-shell .panel-head { flex-wrap: wrap; }
.app-shell .shell > *,
.app-shell .grid-two > *,
.app-shell .metrics > *,
.app-shell .toolbar > *,
.app-shell .filters > * { min-width: 0; }
.app-shell :is(button, input, select, textarea, .button-link) { font-size: 15px; line-height: 1.35; }
.app-shell :is(button, input, select, .button-link) { min-height: var(--control-height); }
.app-shell :is(button, .button-link) { max-width: 100%; padding: 8px 12px; }
.app-shell button { width: auto; }
.app-shell :is(input, select, textarea) { max-width: 100%; }
.app-shell textarea { font-family: inherit; }
.app-shell input:is([type="checkbox"], [type="radio"]) { min-height: 20px; width: 20px; height: 20px; }
.app-shell :is(label, small) { font-size: 13px; }
.app-shell .shell table :is(th, td) { font-size: 15px; line-height: 1.4; }
.app-shell .shell table :is(small, .status-label, .factor-badge, .stock-status, .reason-cell [data-why], .link-button) { font-size: 13px; }
.app-shell .shell :is(.supplier-status, .status-label, .factor-badge, .health-pill, .owner-severity, .daily-action-priority strong, .daily-action-body dt, .daily-action-body > small, .supplier-action-card dt, .stock-risk-row small, .excess-action-card dt) { font-size: 13px; }
.app-shell .shell :is(.owner-kpi > strong) { font-size: 26px; }
.app-shell .shell .density-ultra :is(th, td, input, button) { font-size: 15px; line-height: 1.4; }
.app-shell .shell .density-ultra :is(.status-label, .factor-badge) { font-size: 13px; }
.app-shell .supplier-search { grid-template-columns: minmax(0, 1fr) 40px; }
.app-shell .supplier-search-label { min-width: 0; }
.app-shell .supplier-list { grid-template-columns: repeat(auto-fit, minmax(min(290px, 100%), 1fr)); }
.app-shell .sync-actions-grid { grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); }
.app-shell .owner-section { padding-block: 16px; }
.app-shell .owner-kpi { min-height: 116px; padding: 12px; }
.app-shell .owner-kpi > span { min-height: 0; font-size: 14px; }
.app-shell .owner-snapshot-grid { gap: var(--shell-gap); }
.app-shell .owner-two-column { gap: 20px; }
.app-shell .owner-freshness-grid { gap: 6px; }
.app-shell .owner-freshness { padding: 8px; }
.app-shell .owner-section-head { flex-wrap: wrap; }
.app-shell .order-sidebar .nav-root { width: 100%; }
.order-freshness-disclosure { min-width: 0; margin-bottom: 12px; }
.order-freshness-disclosure > summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; padding: 10px 0; border-block: 1px solid var(--line); cursor: pointer; list-style: none; }
.order-freshness-disclosure > summary::-webkit-details-marker { display: none; }
.freshness-brief { display: grid; min-width: 0; gap: 3px; }
.freshness-brief > strong { font-size: 14px; }
.freshness-brief > span { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.freshness-brief-warning { color: #8b5305; }
.freshness-disclosure-indicator { flex: 0 0 24px; font-size: 22px; text-align: center; }
.order-freshness-disclosure[open] .freshness-disclosure-indicator { transform: rotate(45deg); }
.app-shell[data-navigation="sidebar"] .order-freshness-disclosure > summary { display: none; }
.app-shell[data-navigation="drawer"] .order-freshness-content { padding-top: 12px; }
.app-shell[data-navigation="drawer"] .order-freshness-content .section-heading { display: none; }
.app-shell :focus-visible { outline: 3px solid #2879a7; outline-offset: 3px; }
.app-shell #main-content:focus { outline: none; }
.skip-link { position: fixed; left: 12px; top: -80px; z-index: 100; padding: 10px 14px; background: #fff; color: var(--ink); border: 2px solid var(--green); border-radius: 4px; }
.skip-link:focus { top: 12px; }

.app-shell :is(.bottom-nav, .order-mobile-nav) { display: none; }
.app-shell :is(.bottom-nav, .order-mobile-nav) :is(a, button) { min-width: 0; min-height: 60px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 6px 2px; border: 0; border-radius: 0; background: transparent; color: var(--muted); font-size: 13px; line-height: 1.25; font-weight: 600; text-align: center; text-decoration: none; }
.app-shell :is(.bottom-nav, .order-mobile-nav) a.active { color: var(--green); background: #e4f2ed; }
.app-shell .menu-toggle { min-width: 44px; min-height: 44px; width: 44px; height: 44px; padding: 0; align-items: center; justify-content: center; }

.app-shell[data-navigation="drawer"] { grid-template-columns: minmax(0, 1fr); padding-bottom: calc(66px + env(safe-area-inset-bottom)); }
.app-shell[data-navigation="drawer"] .sidebar { position: fixed; z-index: 70; inset: 0 auto 0 0; width: min(320px, calc(100vw - 24px)); height: 100dvh; padding: 16px; transform: translateX(-105%); visibility: hidden; transition: transform .18s ease, visibility .18s; }
.app-shell[data-navigation="drawer"].nav-open .sidebar { transform: translateX(0); visibility: visible; }
.app-shell[data-navigation="drawer"] .menu-toggle { display: inline-flex; z-index: 40; top: 12px; left: 12px; }
.app-shell[data-navigation="drawer"] .topbar { padding-left: 54px; min-height: 44px; }
.app-shell[data-navigation="drawer"] .sidebar .brand { margin-right: 40px; }
.app-shell[data-navigation="drawer"] .nav-close { display: inline-flex; position: absolute; right: 10px; top: 10px; width: 40px; min-height: 40px; padding: 0; align-items: center; justify-content: center; }
.app-shell[data-navigation="drawer"] :is(.bottom-nav, .order-mobile-nav) { display: grid; position: fixed; z-index: 30; inset: auto 0 0; grid-template-columns: repeat(5, minmax(0, 1fr)); padding: 0 0 env(safe-area-inset-bottom); border-top: 1px solid var(--line); background: #fff; box-shadow: none; }
.app-shell[data-navigation="drawer"].nav-open { overflow: hidden; }
.app-shell[data-navigation="drawer"].nav-open .nav-backdrop { display: block; z-index: 65; }
.app-shell[data-density-effective="pos"] :is(button, input, select, .button-link, .nav-group > summary, .nav-group > a, .nav-root) { min-height: 44px; }
.app-shell[data-density-effective="pos"] .nav-close { width: 44px; min-height: 44px; }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .app-shell:not([data-navigation]) .sidebar { display: none; }
  .app-shell .weekday-cards { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .app-shell .calendar-grid { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
  .app-shell .purchase-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .app-shell .dashboard-kpi, .app-shell .dashboard-kpi.secondary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 768px) {
  .app-shell { --shell-padding: 12px; --control-height: 44px; }
  .app-shell h1 { font-size: 23px; }
  .app-shell .topbar { gap: 8px; }
  .app-shell .status-row { justify-content: flex-start; }
  .app-shell .topbar > div:first-child { flex-basis: 100%; }
  .app-shell .metrics, .app-shell .dashboard-kpi, .app-shell .dashboard-kpi.secondary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .app-shell .metrics article { padding: 10px; }
  .app-shell .metrics strong { font-size: 22px; overflow-wrap: anywhere; }
  .app-shell .toolbar, .app-shell .filters { gap: 8px; }
  .app-shell .owner-section-head .button-link { width: auto; }
  .app-shell .owner-command-actions button { width: auto; }
  .app-shell .owner-day-details { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .app-shell .owner-kpi { min-height: 106px; padding: 10px; }
  .app-shell .owner-kpi > strong { font-size: 23px; }
  .app-shell .owner-freshness-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .app-shell .owner-freshness strong { overflow-wrap: anywhere; }
  .app-shell .purchase-filters { grid-template-columns: minmax(0, 1fr); }
  .app-shell .password-row { grid-template-columns: minmax(0, 1fr) auto; }
  .app-shell .order-export-actions { display: flex; flex-wrap: wrap; }
  .app-shell .owner-action .button-link { width: auto; justify-self: start; }
  .app-shell .quantity-stepper { grid-template-columns: 44px minmax(60px, 1fr) 44px; }
  .app-shell .stock-table td::before, .app-shell .supplier-directory-table td::before,
  .app-shell .order-workspace .supplier-order-table tr[data-product-id] > td::before,
  .app-shell .order-history-table td::before, .app-shell .order-final-table td::before { font-size: 13px; }
}

@media (max-width: 380px) {
  .app-shell { --shell-padding: 10px; }
  .app-shell h1 { font-size: 22px; }
  .app-shell .topbar-logout button { min-height: 40px; }
  .app-shell .owner-kpi > strong { font-size: 22px; }
  .app-shell .owner-kpi > span { font-size: 13px; }
  .app-shell .owner-freshness-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (pointer: coarse), (hover: none) {
  .app-shell :is(button, input, select, .button-link, .nav-group > summary, .nav-group > a) { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .app-shell .sidebar { transition: none; }
}

@media print {
  .app-shell { display: block; padding: 0; }
  .app-shell :is(.sidebar, .menu-toggle, .bottom-nav, .order-mobile-nav, .skip-link, .nav-backdrop) { display: none !important; }
  .app-shell .shell { padding: 0; }
}
