/* ===== SHARED HEADER/SIDEBAR CSS — HL & MODULAR dùng chung ===== */
/* Copy file này sang cả 2 project sau mỗi lần sửa.         */
/* KHÔNG thêm rule mới vào file khác cho sidebar/header.   */

/* ---------- SIDEBAR ---------- */
#sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: var(--z-sidebar);
  width: var(--sidebar-width);
  display: none;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--surface-soft);
  border-right: 1px solid var(--line);
  box-shadow: 2px 0 8px rgba(0,0,0,0.06);
}
body.logged-in #sidebar {
  display: block;
}

.sidebar-inner {
  width: 100% !important;
  padding: 0 12px 16px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 72px;
  margin: 0 -12px 12px;
  padding: 12px;
  background: #e8fff3;
  border-bottom: 1px solid var(--line);
}

.sidebar-logo {
  width: 44px; height: 44px;
  object-fit: contain;
  flex: 0 0 44px;
}

.sidebar-brand-text {
  min-width: 0;
  line-height: 1.2;
}

.sidebar-brand-top { display: none; }

.sidebar-brand-main {
  color: var(--brand);
  font-size: 17px;
  font-weight: 900;
  line-height: 1.15;
  text-transform: uppercase;
  white-space: nowrap;
}

.menu-title, .menu-group {
  margin: 4px 8px 10px;
  color: var(--brand);
  font-size: 14px;
  font-weight: 900;
}

.menu-item {
  display: block;
  margin-bottom: 4px;
  padding: 10px 14px;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
  transition: var(--transition);
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: normal;
  text-decoration: none;
}
.menu-item:hover {
  background: var(--brand-soft);
  color: var(--brand);
}
.menu-item.active {
  background: var(--brand);
  color: #ffffff;
  box-shadow: var(--shadow-brand);
}

.sidebar-update-info,
.viewing-agent-info,
.desktop-update-date {
  margin: 8px 0;
  padding: 8px 12px;
  border: 1px solid var(--brand-border);
  border-left: 4px solid var(--brand);
  border-radius: var(--radius);
  background: #f0fdf4;
  color: var(--brand);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
}

.viewing-agent-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  text-align: left;
  background: #e6f4f1;
}

.sidebar-user-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

#sidebarViewingName {
  display: block;
  color: var(--brand);
  font-size: 16px;
  font-weight: 900;
  line-height: 1.3;
}

.viewing-agent-info .sidebar-user-label {
  display: block;
}

.sidebar-logout-btn {
  width: 144px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 8px 0 14px;
  padding: 6px 14px;
  border: 1px solid var(--brand-border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--brand);
  font-weight: 800;
  gap: 8px;
  transition: var(--transition);
  cursor: pointer;
}
.sidebar-logout-btn::before { content: none; }
.sidebar-logout-btn:hover {
  background: var(--brand);
  color: #ffffff;
  border-color: var(--brand);
}

.view-other-agent-btn {
  width: 100%;
  margin: 8px 0;
  background: var(--warning);
}
.view-other-agent-btn:hover {
  background: #d97706;
}

/* ---------- MAIN HEADER (logged-in) ---------- */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: var(--z-header);
  min-height: calc(var(--header-h) + var(--safe-area-top));
  padding-top: var(--safe-area-top);
  background: #e8fff3;
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
}

body.logged-out .app-header {
  display: none;
}

/* Desktop: hide header, use sidebar instead */
@media (min-width: 1024px) {
  body.logged-in .app-header {
    display: none;
    left: var(--sidebar-width);
  }
}
body.logged-in .app-header {
  height: calc(var(--header-h) + var(--safe-area-top));
  min-height: calc(var(--header-h) + var(--safe-area-top));
  max-height: calc(var(--header-h) + var(--safe-area-top));
  background: #e8fff3;
  overflow: hidden;
}

.header-grid {
  min-height: var(--header-h);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 8px 20px;
}

body.logged-in .header-grid {
  height: var(--header-h);
  min-height: var(--header-h);
  padding: 0 24px;
}

/* ---------- BRAND ROW ---------- */
.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.logo-d {
  width: 48px; height: 48px;
  max-width: 48px;
  object-fit: contain;
  flex: 0 0 auto;
}

body.logged-in .logo-d {
  display: none;
}

/* Title (logged-in state only — login titles use shared login.css) */
body.logged-in .title-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

body.logged-in .title-top,
body.logged-in .title-main {
  color: var(--brand);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0;
}

body.logged-in .title-top {
  display: none;
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
}

body.logged-in .title-main {
  font-size: 26px;
  color: var(--brand);
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}

/* ---------- CONTENT WRAP ---------- */
#contentWrap {
  position: relative;
  z-index: var(--z-content);
  margin-left: 0;
}

/* ---------- MOBILE HEADER ---------- */
@media (max-width: 1023px), (hover: none) and (pointer: coarse) {
  .app-header {
    box-shadow: none;
  }
  .header-grid {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding: 8px 10px;
  }
  .brand-row {
    justify-content: flex-start;
    gap: 8px;
  }
  .logo-d {
    width: 40px; height: 40px;
    max-width: 40px;
  }
  body.logged-in .logo-d {
    display: block;
  }
  body.logged-in .title-wrap {
    align-items: flex-start;
  }
  body.logged-in .title-top {
    display: none;
  }
  body.logged-in .title-main {
    font-size: 16px;
    font-weight: 900;
    line-height: 1.15;
    white-space: normal;
    overflow: visible;
    text-align: left;
    color: var(--brand);
  }
  .header-mobile-logout-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 32px;
    padding: 4px 0;
    background: transparent;
    color: var(--brand);
    border: 0;
    border-radius: 0;
    font-size: 12px;
    font-weight: 900;
    line-height: 1;
    cursor: pointer;
    flex: 0 0 auto;
    justify-self: end;
    z-index: 2;
    font-family: inherit;
  }
  body.logged-out .header-mobile-logout-btn {
    display: none !important;
  }
}
