/* R&C Patrol — App shell (mobile/tablet first). Load after app.css overrides. */

:root {
  --shell-header: 3.5rem;
  --shell-tabbar: 4.25rem;
  --shell-sidebar: 15.5rem;
  --shell-sidebar-collapsed: 4.5rem;
  --shell-gold: #C9962E;
  --shell-gold-light: #E2B84F;
  --shell-black: #0B0B0D;
  --shell-ink: #141416;
  --shell-bg: #ECEAE4;
  --shell-card: #FFFFFF;
  --shell-muted: #4B4B53;
  --shell-radius: 1rem;
  --shell-safe-top: env(safe-area-inset-top, 0px);
  --shell-safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--shell-bg) !important;
  color: var(--shell-ink);
  font-family: "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif;
}

body.app-body {
  overflow-x: hidden;
}

/* Reset broken shell rules from earlier CSS */
.app-shell {
  display: block !important;
  min-height: 100dvh;
  max-width: none !important;
  margin: 0 !important;
  position: relative;
  background: var(--shell-bg);
}

.app-main {
  display: block !important;
  width: 100% !important;
  min-height: 100dvh;
  margin: 0 !important;
  padding: 0 !important;
  background: var(--shell-bg);
}

/* Top app bar */
.app-header,
.topbar {
  position: sticky !important;
  top: 0;
  z-index: 100;
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  justify-content: flex-start;
  gap: 0.65rem;
  width: 100% !important;
  height: calc(var(--shell-header) + var(--shell-safe-top)) !important;
  min-height: calc(var(--shell-header) + var(--shell-safe-top)) !important;
  max-height: calc(var(--shell-header) + var(--shell-safe-top)) !important;
  padding: var(--shell-safe-top) 0.75rem 0 !important;
  margin: 0 !important;
  background: var(--shell-black) !important;
  border-bottom: 1px solid rgba(201, 150, 46, 0.45) !important;
  box-sizing: border-box;
}

.app-header-brand {
  display: flex !important;
  align-items: center;
  gap: 0.6rem;
  flex: 1 1 auto;
  min-width: 0;
}

.app-header-logo,
.app-header img.app-header-logo {
  width: 1.75rem !important;
  height: 1.75rem !important;
  max-width: 1.75rem !important;
  object-fit: contain;
  flex-shrink: 0;
}

.app-header-titles {
  min-width: 0;
}

.app-header-title,
.topbar-title {
  margin: 0 !important;
  font-size: 1.05rem !important;
  font-weight: 700;
  color: #F3D77A !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.15;
}

.app-header-sub {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 248, 236, 0.78);
}

.app-header-actions {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex: 0 0 auto;
}

.app-header-alert,
.app-header-search,
.app-header-profile > summary {
  flex: 0 0 auto;
  width: 2.6rem;
  height: 2.6rem;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid rgba(201, 150, 46, 0.35);
  color: var(--shell-gold-light);
  text-decoration: none !important;
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  list-style: none;
  font-weight: 800;
  position: relative;
}

.app-header-alert-count {
  position: absolute;
  top: -0.15rem;
  right: -0.15rem;
  min-width: 1.2rem;
  height: 1.2rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: #c9962e;
  color: #1a1205;
  font-size: 0.7rem;
  font-weight: 900;
  line-height: 1.2rem;
  text-align: center;
}

.app-header-signout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.6rem;
  padding: 0 0.9rem;
  border-radius: 999px;
  border: 1px solid rgba(201, 150, 46, 0.55);
  background: rgba(201, 150, 46, 0.14);
  color: #F3D77A !important;
  font-weight: 750;
  font-size: 0.9rem;
  text-decoration: none !important;
  white-space: nowrap;
}

.app-header-signout:hover,
.app-header-signout:focus-visible {
  background: rgba(201, 150, 46, 0.28);
  outline: 2px solid rgba(243, 215, 122, 0.55);
  outline-offset: 2px;
}

.app-header-profile { position: relative; }
.app-header-profile > summary::-webkit-details-marker { display: none; }
.app-header-profile .rc-menu-panel {
  right: 0;
  min-width: 13rem;
  z-index: var(--rc-z-dropdown, 40);
}

.btn-icon.sidebar-toggle,
.app-header .sidebar-toggle {
  flex: 0 0 auto;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 999px;
  border: 1px solid rgba(201, 150, 46, 0.35);
  background: rgba(255, 255, 255, 0.04);
  color: #F3D77A;
}

/* Content — width finalized in rc-page.css; shell keeps vertical padding */
.app-content,
.content {
  display: block !important;
  width: 100% !important;
  max-width: 1440px !important;
  margin: 0 auto !important;
  padding: 1rem 0 calc(1.25rem + var(--shell-safe-bottom)) !important;
  background: transparent !important;
  box-sizing: border-box;
}

body.has-bottom-nav .app-content,
body.has-bottom-nav .content {
  padding-bottom: calc(var(--shell-tabbar) + var(--shell-safe-bottom) + 1rem) !important;
}

/* Drawer */
.sidebar {
  position: fixed !important;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(20rem, 86vw) !important;
  height: 100dvh !important;
  z-index: 300;
  display: flex !important;
  flex-direction: column !important;
  background: var(--shell-black) !important;
  color: #F7F5EF;
  transform: translateX(-105%) !important;
  transition: transform 220ms ease;
  border-right: 1px solid #3A3A40;
  padding-top: var(--shell-safe-top);
  overflow: hidden;
}

.sidebar.is-open {
  transform: translateX(0) !important;
}

.sidebar-overlay {
  position: fixed !important;
  inset: 0;
  z-index: 250;
  background: rgba(11, 11, 13, 0.55);
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms ease, visibility 200ms ease;
}

.sidebar-overlay.is-visible {
  opacity: 1;
  visibility: visible;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 0.9rem;
  border-bottom: 1px solid #2a2a30;
  flex: 0 0 auto;
}

.sidebar-brand img {
  width: 2.25rem !important;
  height: 2.25rem !important;
  max-width: 2.25rem !important;
  object-fit: contain;
  flex-shrink: 0;
}

.sidebar-brand-copy { min-width: 0; flex: 1; }

.sidebar-brand-text {
  font-family: Manrope, "Source Sans 3", system-ui, sans-serif;
  font-weight: 800;
  color: #F3D77A;
  font-size: 1.05rem;
  line-height: 1.15;
}

.sidebar-brand-sub {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 248, 236, 0.82);
  margin-top: 0.1rem;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.95rem 0.95rem;
  border-bottom: 1px solid #2a2a30;
  flex: 0 0 auto;
  background: linear-gradient(180deg, rgba(23, 23, 26, 0.55) 0%, transparent 100%);
}

.sidebar-user-avatar {
  width: 2.55rem;
  height: 2.55rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 30% 30%, #222226 0%, #141416 75%);
  border: 1px solid rgba(201, 150, 46, 0.55);
  box-shadow: 0 0 0 3px rgba(201, 150, 46, 0.08);
  color: #F3D77A;
  font-weight: 800;
  flex-shrink: 0;
}

.sidebar-user-meta { min-width: 0; }
.sidebar-user-name {
  font-weight: 780;
  font-size: 0.96rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-role {
  color: rgba(243, 215, 122, 0.9);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 750;
}
.sidebar-user-profile {
  display: inline-block;
  margin-top: 0.25rem;
  color: rgba(247, 245, 239, 0.68);
  font-size: 0.78rem;
  font-weight: 650;
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
.sidebar-user-profile:hover,
.sidebar-user-profile:focus-visible {
  color: #F3D77A;
  border-bottom-color: rgba(243, 215, 122, 0.55);
  text-decoration: none;
}

.sidebar-tools {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid #2a2a30;
  flex: 0 0 auto;
}

.sidebar-search {
  flex: 1;
  min-width: 0;
  margin: 0;
}

.sidebar-search input {
  width: 100%;
  min-height: 2.5rem !important;
  height: 2.5rem;
  border-radius: 0.7rem !important;
  border: 1px solid #3A3A40;
  background: #141416;
  color: #F7F5EF;
  padding: 0 0.75rem;
  font-size: 0.9rem !important;
}

.sidebar-search input:focus {
  outline: 2px solid rgba(201, 150, 46, 0.55);
  outline-offset: 1px;
  border-color: rgba(201, 150, 46, 0.65);
}

.sidebar-collapse-btn {
  flex: 0 0 auto;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.75rem;
  border: 1px solid #3A3A40;
  background: linear-gradient(180deg, #1A1A1E 0%, #141416 100%);
  color: #F3D77A;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.sidebar-collapse-btn:hover,
.sidebar-collapse-btn:focus-visible {
  border-color: rgba(201, 150, 46, 0.7);
  background: #1C1C20;
  outline: 2px solid rgba(201, 150, 46, 0.35);
  outline-offset: 1px;
  box-shadow: 0 0 0 3px rgba(201, 150, 46, 0.08);
}

.sidebar-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.45rem 0.35rem 0.65rem;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(201, 150, 46, 0.35) transparent;
}

.sidebar-footer {
  flex: 0 0 auto;
  border-top: 1px solid #2a2a30;
  padding: 0.4rem 0 calc(0.75rem + var(--shell-safe-bottom));
  background: #0E0E11;
}

.nav-section {
  padding: 0.15rem 0 0.45rem;
}

.nav-section + .nav-section {
  margin-top: 0.45rem;
  border-top: 1px solid rgba(58, 58, 64, 0.55);
  padding-top: 0.35rem;
}

.nav-section-label {
  padding: 0.7rem 0.85rem 0.35rem;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(243, 215, 122, 0.7);
  pointer-events: none;
  user-select: none;
}

.nav-section-links {
  display: grid;
  gap: 0.22rem;
  padding: 0 0.3rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-height: 2.95rem;
  padding: 0.62rem 0.85rem;
  color: rgba(255, 248, 236, 0.92);
  text-decoration: none;
  font-weight: 650;
  font-size: 0.94rem;
  border-left: 0;
  border-radius: 0.8rem;
  transition: background 150ms ease, color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.nav-link-icon {
  width: 1.4rem;
  flex: 0 0 auto;
  text-align: center;
  color: rgba(255, 248, 236, 0.72);
  font-size: 1.02rem;
  line-height: 1;
  transition: color 150ms ease;
}

.nav-link-text {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.045);
  color: #F7F5EF;
  text-decoration: none;
}

.nav-link:hover .nav-link-icon {
  color: rgba(243, 215, 122, 0.92);
}

.nav-link:focus-visible {
  outline: 2px solid rgba(201, 150, 46, 0.65);
  outline-offset: 1px;
}

.nav-link.is-active {
  background: linear-gradient(90deg, rgba(201, 150, 46, 0.16) 0%, rgba(23, 23, 26, 0.95) 100%);
  color: #F3D77A;
  text-decoration: none;
  box-shadow: inset 3px 0 0 #C9962E;
}

.nav-link.is-active .nav-link-icon,
.nav-link.is-active .nav-link-text {
  color: #F3D77A;
  font-weight: 750;
}

.nav-link-badge {
  margin-left: auto;
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #B42318;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 800;
  line-height: 1;
}

.nav-link.nav-alert .nav-link-text {
  color: #F3D77A;
}

/* Consolidated module tab strips */
.rc-modtabs {
  margin: 0 0 1rem;
  padding: 0.45rem;
  background: linear-gradient(180deg, #FFFFFF 0%, #FCFBF8 100%);
  border: 1px solid rgba(11, 11, 13, 0.08);
  border-radius: 0.95rem;
  box-shadow: 0 6px 16px rgba(11, 11, 13, 0.04);
}

.rc-modtabs-track {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.35rem;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 0.1rem;
}

.rc-modtabs-track::-webkit-scrollbar {
  height: 3px;
}

.rc-modtab {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 2.35rem;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  text-decoration: none;
  color: #5C5C66;
  font-size: 0.84rem;
  font-weight: 700;
  border: 1px solid transparent;
  white-space: nowrap;
  max-width: none;
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease;
}

.rc-modtab > span {
  white-space: nowrap;
  overflow: visible;
  text-overflow: clip;
}

.rc-modtab:hover {
  background: #F5F2EA;
  color: #0B0B0D;
}

.rc-modtab.is-active {
  background: #0B0B0D;
  color: #F3D77A;
  box-shadow: 0 4px 12px rgba(11, 11, 13, 0.14);
}

.rc-modtab-badge {
  min-width: 1.2rem;
  height: 1.2rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #B42318;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 800;
}

.rc-modtab.is-active .rc-modtab-badge {
  background: #F3D77A;
  color: #0B0B0D;
}

.nav-link.nav-danger {
  color: #F0B4AE;
}
.nav-link.nav-danger .nav-link-icon { color: #E08A82; }

.nav-signout {
  margin-top: 0.35rem;
  border-top: 1px solid rgba(58, 58, 64, 0.8);
  color: #F3D77A;
  font-weight: 750;
}
.nav-signout .nav-link-icon { color: #F3D77A; }
.nav-signout:hover {
  background: rgba(201, 150, 46, 0.12);
  color: #F3D77A;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Bottom tabs */
.mobile-bottom-nav {
  position: fixed !important;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
  display: flex !important;
  align-items: stretch;
  height: calc(var(--shell-tabbar) + var(--shell-safe-bottom));
  padding: 0.2rem 0.15rem var(--shell-safe-bottom);
  background: rgba(11, 11, 13, 0.98) !important;
  border-top: 1px solid rgba(201, 150, 46, 0.4);
  box-sizing: border-box;
}

.mobile-bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  color: rgba(255, 248, 236, 0.82);
  text-decoration: none;
  font-size: 0.8125rem;
  font-weight: 700;
  border-radius: 0.7rem;
  min-height: 44px;
}

.mobile-bottom-nav a.is-active,
.mobile-bottom-nav a:hover {
  color: #E2B84F;
  background: rgba(201, 150, 46, 0.12);
  text-decoration: none;
}

.mobile-bottom-nav a.is-active .mobile-bottom-nav-icon {
  color: #F3D77A;
}

.mobile-bottom-nav-icon {
  font-size: 1.25rem;
  line-height: 1;
}

/* Home screen app tiles */
.app-home-hero {
  background: linear-gradient(160deg, #0B0B0D, #1a1a1f);
  color: #F7F5EF;
  border: 1px solid rgba(201, 150, 46, 0.35);
  border-radius: 1.15rem;
  padding: 1.15rem 1.2rem;
  margin-bottom: 1rem;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.12);
}

.app-home-hero h1 {
  margin: 0 0 0.25rem;
  font-size: 1.45rem;
  color: #F3D77A;
}

.app-home-hero p {
  margin: 0;
  color: rgba(247, 245, 239, 0.7);
  font-size: 0.92rem;
}

.app-tile-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.app-tile {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 6.5rem;
  padding: 1rem;
  border-radius: 1rem;
  background: var(--shell-card);
  border: 1px solid rgba(11, 11, 13, 0.06);
  box-shadow: 0 6px 16px rgba(11, 11, 13, 0.06);
  text-decoration: none !important;
  color: inherit;
}

.app-tile:hover {
  border-color: rgba(201, 150, 46, 0.55);
  transform: translateY(-1px);
}

.app-tile-icon {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 0.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(11, 11, 13, 0.92);
  color: #E2B84F;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.app-tile-label {
  font-weight: 700;
  font-size: 1rem;
  color: var(--shell-ink);
}

.app-tile-meta {
  margin-top: 0.2rem;
  font-size: 0.78rem;
  color: var(--shell-muted);
  font-weight: 600;
}

.app-stat-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.app-stat {
  background: var(--shell-card);
  border-radius: 1rem;
  padding: 1rem;
  border: 1px solid rgba(11, 11, 13, 0.06);
}

.app-stat .value {
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--shell-gold);
  line-height: 1;
}

.app-stat .label {
  margin-top: 0.35rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--shell-muted);
}

/* Cards / controls polish */
.card {
  border-radius: 1rem !important;
  box-shadow: 0 6px 16px rgba(11, 11, 13, 0.06) !important;
}

.btn {
  min-height: 3rem !important;
  border-radius: 0.85rem !important;
}

input, select, textarea {
  min-height: 3rem;
  border-radius: 0.85rem !important;
  font-size: 16px !important; /* prevent iOS zoom */
}

@media (min-width: 900px) {
  .app-tile-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .app-stat-row {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* Desktop: persistent left nav for staff; bottom tabs remain for phones/tablets */
@media (min-width: 1100px) {
  body.app-body:not(.role-client) .sidebar {
    position: fixed !important;
    transform: none !important;
    width: var(--shell-sidebar) !important;
  }

  body.app-body:not(.role-client) .sidebar-overlay {
    display: none !important;
  }

  body.app-body:not(.role-client) .app-main {
    margin-left: var(--shell-sidebar);
    width: calc(100% - var(--shell-sidebar));
    transition: margin-left 180ms ease, width 180ms ease;
  }

  body.app-body:not(.role-client) .app-header .sidebar-toggle,
  body.app-body:not(.role-client) .sidebar-close {
    display: none !important;
  }

  body.app-body:not(.role-client) .mobile-bottom-nav,
  body.app-body:not(.role-client) .m-bottom-nav {
    display: none !important;
  }

  body.app-body:not(.role-client).has-bottom-nav .app-content,
  body.app-body:not(.role-client).has-bottom-nav .content {
    padding-bottom: 1.25rem !important;
  }

  /* Collapsed icon rail */
  body.app-body:not(.role-client).sidebar-collapsed .sidebar {
    width: var(--shell-sidebar-collapsed) !important;
  }

  body.app-body:not(.role-client).sidebar-collapsed .app-main {
    margin-left: var(--shell-sidebar-collapsed);
    width: calc(100% - var(--shell-sidebar-collapsed));
  }

  body.app-body:not(.role-client).sidebar-collapsed .sidebar-brand-copy,
  body.app-body:not(.role-client).sidebar-collapsed .sidebar-user-meta,
  body.app-body:not(.role-client).sidebar-collapsed .sidebar-search,
  body.app-body:not(.role-client).sidebar-collapsed .nav-section-label,
  body.app-body:not(.role-client).sidebar-collapsed .nav-link-text {
    display: none !important;
  }

  body.app-body:not(.role-client).sidebar-collapsed .sidebar-brand,
  body.app-body:not(.role-client).sidebar-collapsed .sidebar-user,
  body.app-body:not(.role-client).sidebar-collapsed .sidebar-tools {
    justify-content: center;
    padding-left: 0.45rem;
    padding-right: 0.45rem;
  }

  body.app-body:not(.role-client).sidebar-collapsed .nav-link {
    justify-content: center;
    padding-left: 0.4rem;
    padding-right: 0.4rem;
    gap: 0;
  }

  body.app-body:not(.role-client).sidebar-collapsed .nav-link-icon {
    width: auto;
    font-size: 1.15rem;
  }
}

@media (max-width: 1099.98px) {
  body.app-body .sidebar-collapse-btn {
    display: none !important;
  }
}
