/*
  File: public/CSS/layout.css
  Path: backend/public/CSS/layout.css

  Global layout – OTS
*/

/* =========================================================
   APP LAYOUT
   ========================================================= */

.app-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
  background-color: var(--bg-main);
}

.main-content {
  flex: 1;
  padding: 32px;
  overflow-y: auto;
}

/* =========================================================
   SIDEBAR
   ========================================================= */

.sidebar {
  width: 290px; /* slightly wider to avoid wrapping */
  height: 100%;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;

  background-color: var(--bg-card);
  border-right: 1px solid var(--border-color);
}

/* Header */
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px;
}

.sidebar-header img {
  width: 28px;
  height: 28px;
}

.sidebar-title {
  font-weight: 600;
}

.sidebar-badge {
  margin-left: auto;
}

/* =========================================================
   NAV
   ========================================================= */

.sidebar-nav {
  flex: 1;
  padding: 10px;
  overflow-y: auto;
}

.nav-section {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 16px 10px 6px;
}

/* =========================================================
   NAV ITEMS
   ========================================================= */

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  color: var(--text-main);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.nav-item:hover {
  background-color: var(--bg-card-alt);
}

.nav-item.active,
.nav-item.open {
  background-color: #eaf3ff;
  color: var(--primary);
}

:root[data-theme="dark"] .nav-item.active,
:root[data-theme="dark"] .nav-item.open {
  background-color: var(--bg-card-alt);
  color: var(--primary);
}

/* Icon */
.icon {
  width: 18px;
  text-align: center;
  color: #8a94a6;
}

.nav-item.active .icon,
.nav-item.open .icon {
  color: var(--primary);
}

/* Arrow */
.arrow {
  margin-left: auto;
  color: #8a94a6;
  transition: transform 0.25s ease;
}

.nav-parent.open .arrow {
  transform: rotate(180deg);
}

/* =========================================================
   SUBMENU
   ========================================================= */

.nav-submenu {
  position: relative;
  margin-left: 22px;
  padding-left: 16px;
  border-left: 2px solid rgba(70, 128, 255, 0.25);

  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.nav-submenu.open {
  max-height: 300px;
  margin: 6px 0;
}

.nav-subitem {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 14px;
  color: #4b5563;
  text-decoration: none;
  transition: color 0.15s ease;
}

.nav-subitem:hover {
  color: var(--primary);
}

.nav-subitem::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--primary);
  opacity: 0.35;
}

.nav-subitem.active {
  color: var(--primary);
  font-weight: 500;
}

/* =========================================================
   FOOTER (USER + POPUP MENU)
   ========================================================= */

.sidebar-footer {
  position: relative;
  padding: 14px;
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;

  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Clickable user row */
.sidebar-user {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;

  padding: 12px;
  border-radius: 14px;

  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;

  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.sidebar-user:hover {
  background: var(--bg-card-alt);
  border-color: var(--border-color);
}

.sidebar-user:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}

.sidebar-footer .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-card-alt);
  border: 1px solid var(--border-color);

  display: flex;
  align-items: center;
  justify-content: center;

  color: var(--text-muted);
  flex: 0 0 auto;
}

.sidebar-user-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.sidebar-user-name {
  font-weight: 700;
  font-size: 14px;
  line-height: 1.1;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Little handle icon on the right */
.sidebar-user-handle {
  margin-left: auto;
  width: 22px;
  text-align: center;
  color: #8a94a6;
}

.sidebar-user:hover .sidebar-user-handle {
  color: var(--primary);
}

/* =========================================================
   USER MENU — TILE GRID (STAFF: 2x2 / USER: 2+1 wide)
   ========================================================= */

.sidebar-user-menu {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: calc(14px + 62px); /* footer padding + user row height */
  z-index: 50;

  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  box-shadow: var(--shadow-card);

  padding: 0;       /* tiles touch separators */
  overflow: hidden; /* keep rounded corners clean */

  display: grid;
}

.sidebar-user-menu.hidden {
  display: none;
}

/* STAFF: 2x2 */
.sidebar-user-menu.is-staff {
  grid-template-columns: 1fr 1fr;
}

/* USER: 2 columns, last item spans full width */
.sidebar-user-menu.is-user {
  grid-template-columns: 1fr 1fr;
}

/* Tile */
.sidebar-user-menu-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;

  padding: 18px 14px;

  background: transparent;
  border: 0;
  border-radius: 0;

  color: var(--text-main);
  font-size: 13px;
  font-weight: 600;
  text-align: center;

  transition: background-color 0.15s ease, color 0.15s ease;
}

.sidebar-user-menu-item i {
  color: var(--text-muted);
  font-size: 18px;
}

/* Hover */
.sidebar-user-menu-item:hover {
  background: var(--bg-card-alt);
  color: var(--primary);
}

.sidebar-user-menu-item:hover i {
  color: var(--primary);
}

/* =========================
   SEPARATORS — STAFF (2x2)
   items: 1 2
          3 4
   ========================= */

.sidebar-user-menu.is-staff .sidebar-user-menu-item:nth-child(1),
.sidebar-user-menu.is-staff .sidebar-user-menu-item:nth-child(2) {
  border-bottom: 1px solid var(--border-color);
}

.sidebar-user-menu.is-staff .sidebar-user-menu-item:nth-child(1),
.sidebar-user-menu.is-staff .sidebar-user-menu-item:nth-child(3) {
  border-right: 1px solid var(--border-color);
}

/* =========================
   SEPARATORS + LAYOUT — USER (2 + wide)
   items: 1 2
          3 (spans 2 cols)
   ========================= */

/* make last tile full width */
.sidebar-user-menu.is-user .sidebar-user-menu-item:last-child {
  grid-column: 1 / -1;
}

/* horizontal separator between row1 and row2 */
.sidebar-user-menu.is-user .sidebar-user-menu-item:nth-child(1),
.sidebar-user-menu.is-user .sidebar-user-menu-item:nth-child(2) {
  border-bottom: 1px solid var(--border-color);
}

/* vertical separator between first two tiles */
.sidebar-user-menu.is-user .sidebar-user-menu-item:nth-child(1) {
  border-right: 1px solid var(--border-color);
}

/* Logout/login should stay same style (no red special) */
.sidebar-user-menu-item.danger:hover {
  color: var(--primary);
}

.sidebar-user-menu-item.danger:hover i {
  color: var(--primary);
}
