/* Shared sidebar layout for every authenticated MADIS page. */
.sidebar {
  width: 16rem;
  background: #ffffff;
  border-right: 1px solid #e5e7eb;
  box-shadow: 4px 0 18px rgba(15, 23, 42, 0.04);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.sidebar > .flex {
  min-height: 0;
  overflow: hidden;
}

.sidebar .sidebar-brand {
  flex: 0 0 auto;
  padding: 1.125rem 1.25rem;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
}

.sidebar .sidebar-brand h1 {
  letter-spacing: -0.025em;
}

.sidebar .sidebar-brand p {
  max-width: 12.5rem;
  line-height: 1.4;
}

.sidebar .sidebar-nav {
  min-height: 0;
  padding: 0.75rem;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}

.sidebar .sidebar-nav::-webkit-scrollbar {
  width: 5px;
}

.sidebar .sidebar-nav::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar .sidebar-nav::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 9999px;
}

.sidebar .sidebar-nav > ul > li + li {
  margin-top: 0.2rem;
}

.sidebar .sidebar-link,
.sidebar .sidebar-submenu-toggle {
  width: 100%;
  min-height: 2.625rem;
  padding: 0.625rem 0.75rem;
  border: 0 !important;
  border-radius: 0.625rem;
  font-size: 0.84375rem;
  line-height: 1.2;
  text-align: left;
}

.sidebar .sidebar-link {
  position: relative;
}

.sidebar .sidebar-link > svg,
.sidebar .sidebar-submenu-toggle > svg:first-child {
  width: 1.125rem;
  height: 1.125rem;
  flex: 0 0 1.125rem;
}

.sidebar .sidebar-link > span:not([id^="badge-"]),
.sidebar .sidebar-submenu-toggle > span {
  min-width: 0;
  flex: 1 1 auto;
}

.sidebar .sidebar-link:hover,
.sidebar .sidebar-submenu-toggle:hover {
  background: #eff6ff;
  color: #1d4ed8;
}

.sidebar .sidebar-link:focus-visible,
.sidebar .sidebar-submenu-toggle:focus-visible,
.sidebar .sidebar-logout:focus-visible,
.sidebar-mobile-toggle:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

.sidebar .sidebar-link.active {
  background: #dbeafe;
  color: #1d4ed8;
  font-weight: 600;
  box-shadow: inset 3px 0 0 #2563eb;
}

.sidebar .sidebar-submenu-toggle {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: #374151;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.sidebar .sidebar-submenu-toggle.is-active {
  color: #1d4ed8;
  font-weight: 600;
}

.sidebar .sidebar-submenu {
  margin: 0.3rem 0 0.25rem 1.3rem;
  padding-left: 0.6rem !important;
  border-left: 1px solid #dbeafe;
}

.sidebar .sidebar-submenu > li + li {
  margin-top: 0.125rem;
}

.sidebar .sidebar-submenu .sidebar-link {
  min-height: 2.25rem;
  padding: 0.5rem 0.65rem;
  font-size: 0.78rem;
}

.sidebar .sidebar-submenu .sidebar-link.active {
  box-shadow: none;
}

.sidebar #badge-mcu-expiry {
  flex: 0 0 auto;
  min-width: 1.5rem;
  padding: 0.15rem 0.4rem;
  text-align: center;
}

.sidebar .sidebar-user {
  flex: 0 0 auto;
  padding: 0.875rem 1rem;
  background: #ffffff;
}

.sidebar .sidebar-user [id="user-name"],
.sidebar .sidebar-user [id="user-role"] {
  max-width: 8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar .sidebar-logout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  flex: 0 0 2.25rem;
  border-radius: 0.5rem;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.sidebar .sidebar-logout:hover {
  color: #dc2626;
  background: #fef2f2;
}

.sidebar-backdrop,
.sidebar-mobile-toggle {
  display: none;
}

@media (max-width: 767px) {
  html,
  body {
    max-width: 100%;
    overflow-x: hidden;
  }

  body > .ml-64 {
    margin-left: 0;
    width: 100%;
    min-width: 0;
  }

  body > .ml-64 > header {
    padding: 0.75rem 1rem 0.75rem 4.25rem;
  }

  body > .ml-64 > header .flex,
  body > .ml-64 main .flex.justify-between,
  body > .ml-64 main .flex.items-center.justify-between {
    min-width: 0;
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  body > .ml-64 > header h1,
  body > .ml-64 main h1,
  body > .ml-64 main h2 {
    line-height: 1.2;
  }

  body > .ml-64 main,
  body > .ml-64 > .p-8 {
    padding: 1rem;
  }

  body > .ml-64 .card {
    padding: 1rem;
    border-radius: 0.875rem;
  }

  body > .ml-64 .grid.grid-cols-2,
  body > .ml-64 .grid.grid-cols-3,
  body > .ml-64 .grid.md\:grid-cols-2,
  body > .ml-64 .grid.md\:grid-cols-3,
  body > .ml-64 .grid.md\:grid-cols-4,
  body > .ml-64 .grid.lg\:grid-cols-2,
  body > .ml-64 .grid.lg\:grid-cols-3,
  body > .ml-64 .grid.lg\:grid-cols-4,
  body > .ml-64 .grid.lg\:grid-cols-5 {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  body > .ml-64 .col-span-2,
  body > .ml-64 .col-span-3,
  body > .ml-64 .md\:col-span-2,
  body > .ml-64 .lg\:col-span-2,
  body > .ml-64 .lg\:col-span-3 {
    grid-column: auto !important;
  }

  body > .ml-64 .table-container {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  body > .ml-64 .table {
    width: max-content;
    min-width: 100%;
  }

  body > .ml-64 .table th {
    padding: 0.625rem 0.75rem;
    font-size: 0.6875rem;
  }

  body > .ml-64 .table td {
    padding: 0.75rem;
  }

  .modal-overlay {
    align-items: flex-start;
    padding: 0.75rem;
    overflow-y: auto;
  }

  .modal {
    max-width: 100%;
    max-height: calc(100vh - 1.5rem);
    border-radius: 1rem;
  }

  .modal-header,
  .modal-footer {
    padding: 1rem;
  }

  .modal-footer {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .modal-footer .btn,
  .modal-footer button {
    width: 100%;
    justify-content: center;
  }

  .toast {
    right: 1rem;
    left: 1rem;
    min-width: 0;
    max-width: none;
  }

  .sidebar {
    transform: translateX(-100%);
    box-shadow: none;
  }

  .sidebar.sidebar-open {
    transform: translateX(0);
    box-shadow: 12px 0 30px rgba(15, 23, 42, 0.18);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 25;
    display: block;
    visibility: hidden;
    background: rgba(15, 23, 42, 0.42);
    opacity: 0;
    transition: opacity 0.2s ease, visibility 0.2s ease;
  }

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

  .sidebar-mobile-toggle {
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 24;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    color: #1d4ed8;
    background: #ffffff;
    border: 1px solid #dbeafe;
    border-radius: 0.75rem;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12);
  }

  .sidebar-mobile-toggle svg {
    width: 1.25rem;
    height: 1.25rem;
  }

  body.sidebar-mobile-open {
    overflow: hidden;
  }
}
