/* Drawers & Overlay */
.bottom-drawer,
.submenu-drawer {
  position: fixed;
  bottom: -100vh;
  left: 0;
  width: 100%;
  max-height: 90vh;
  background-color: var(--white);
  border-top-left-radius: 15px;
  border-top-right-radius: 15px;
  box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.1);
  transition: bottom var(--transition-speed) ease;
  z-index: 1100;
  overflow-y: auto;
  pointer-events: none;
  visibility: hidden;
}

.bottom-drawer.active,
.submenu-drawer.active {
  bottom: 0;
  pointer-events: auto;
  visibility: visible;
}

.submenu-drawer {
    z-index: 1150;
    display: none;
}
.submenu-drawer.active {
    display: block;
}

.drawer-handle {
  width: 40px;
  height: 5px;
  background-color: var(--border-color);
  border-radius: 3px;
  margin: 6px auto;
}

.overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 999;
  display: none;
}

.overlay.active {
  display: block;
}

/* Settings-specific styles */
.settings-title {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 600;
  margin: 15px 0;
}

.menu-section {
  padding-bottom: 20px;
}

.menu-user-info {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-color);
}

.menu-user-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-color);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-user-email {
  font-size: 0.8rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 20px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
}

button.menu-item {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
}

a.menu-item {
  text-decoration: none;
}

.menu-item:hover {
  background-color: var(--light-bg);
}

.menu-item-left {
  display: flex;
  align-items: center;
  gap: 15px;
}

.menu-item-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  color: var(--text-color);
  font-size: 1.1rem;
}

.menu-item-icon i {
  color: var(--primary-color);
}

.menu-item-text {
  font-size: 1rem;
  color: var(--text-color);
}

.menu-item-right {
  color: var(--text-secondary);
}

.menu-section .menu-item:last-child {
  border-bottom: none;
}

/* Submenu (Account Drawer) */
.submenu-header {
  display: flex;
  align-items: center;
  padding: 15px 20px;
  border-bottom: 1px solid var(--border-color);
}

.account-modal-header {
  justify-content: space-between;
}

.account-close-button {
  align-items: center;
  background: none;
  border: none;
  border-radius: 50%;
  color: var(--primary-color);
  cursor: pointer;
  display: flex;
  font-size: 1.2rem;
  height: 44px;
  justify-content: center;
  margin: -10px -10px -10px 0;
  padding: 0;
  width: 44px;
}

.account-close-button:hover {
  background-color: var(--primary-light);
}

.account-close-button:focus-visible {
  outline: 3px solid rgba(81, 154, 179, 0.35);
  outline-offset: 1px;
}

.back-button {
  background: none;
  border: none;
  cursor: pointer;
  margin-right: 15px;
  font-size: 1.1rem;
}

.back-button i {
  color: var(--primary-color);
}

.submenu-title {
  font-size: 1.1rem;
  font-weight: 600;
}

.submenu-content {
  padding: 20px;
}

/* Profile Section Styles */
.profile-section { margin-bottom: 1rem; }
.profile-header { border: 1px solid var(--border-color); border-radius: var(--border-radius); padding: 1.5rem; }
.profile-info { display: flex; align-items: center; gap: 1rem; padding-bottom: 1rem; }
.profile-avatar { width: 50px; height: 50px; border-radius: 50%; background-color: var(--primary-color); color: #ffffff; display: flex; align-items: center; justify-content: center; font-size: 1.25rem; font-weight: 600; flex-shrink: 0; }
.profile-name { font-size: 1.1rem; font-weight: 600; }
.profile-email { font-size: 0.9rem; color: var(--text-secondary); }
.profile-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; padding-top: 1rem; border-top: 1px solid var(--border-color); }
.stat-item { text-align: center; background: var(--bg-secondary, #f4f5f7); border-radius: 8px; padding: 0.75rem 0.5rem; }
.stat-item.stat-full-width { grid-column: 1 / -1; display: flex; align-items: center; justify-content: center; gap: 0.5rem; background: var(--primary-light, #ebf5f7); }
.stat-item.stat-full-width .stat-label { margin-bottom: 0; color: var(--primary-color, #519ab3); font-size: 0.9rem; }
.stat-item.stat-full-width .stat-value { color: var(--primary-color, #519ab3); }
.stat-label { font-size: 0.75rem; color: var(--text-secondary); margin-bottom: 0.35rem; }
.stat-value { font-size: 1rem; font-weight: 600; }

/* --- Auth & Google Styles (Polished) --- */

.auth-options {
    padding: 0.75rem 1.5rem;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow-y: auto;
    gap: 4px;
}

.auth-header-title {
    text-align: center;
    margin-bottom: 0.25rem;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-color);
}

.auth-subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.45;
    margin: -0.1rem auto 0.75rem;
    max-width: 320px;
    text-align: center;
}

.auth-mode-icon {
    align-items: center;
    background: var(--primary-light, #ebf5f7);
    border-radius: 999px;
    color: var(--primary-color, #519ab3);
    display: flex;
    height: 44px;
    justify-content: center;
    margin: 0 auto 0.75rem;
    width: 44px;
}

.auth-mode-icon i {
    color: inherit;
    font-size: 1rem;
}

.social-auth,
.auth-divider {
    transition: max-height 0.4s ease, opacity 0.3s ease, margin 0.4s ease;
    overflow: hidden;
}

.social-auth { max-height: 60px; }

.social-auth.collapsed,
.auth-divider.collapsed {
    max-height: 0;
    opacity: 0;
    margin: 0;
}

/* Google Button - Identity Compliant */
.google-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 44px;
    background-color: #ffffff;
    border: 1px solid #dadce0;
    border-radius: 4px;
    color: #3c4043;
    font-family: "Roboto", -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.2s, box-shadow 0.2s, border-color 0.2s;
    position: relative;
}

.google-btn:hover {
    background-color: #f7fafe;
    box-shadow: 0 1px 2px 0 rgba(60,64,67,0.30), 0 1px 3px 1px rgba(60,64,67,0.15);
    border-color: #d2e3fc;
}

.google-btn:active {
    background-color: #f1f3f4;
}

.google-btn svg {
    margin-right: 12px;
    height: 18px;
    width: 18px;
}

.auth-divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 0.25rem 0;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    text-transform: uppercase;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--border-color);
}

.auth-divider span {
    padding: 0 12px;
}

/* Compact Form Styles */
.auth-form .form-group {
    margin-bottom: 0.25rem;
}

.auth-form .form-input {
    padding: 10px 12px;
}

.form-submit {
    margin-top: 0.25rem;
    width: 100%;
}

.auth-secondary-action {
    font-size: 0.85rem;
    margin: 0.6rem 0 0;
    text-align: center;
}

.auth-secondary-action a {
    color: var(--primary-color);
    font-weight: 500;
    text-decoration: none;
}

.auth-secondary-action a:hover {
    text-decoration: underline;
}

#authDrawer[data-auth-mode="2fa"] .auth-options,
#authDrawer[data-auth-mode="2fa-recovery"] .auth-options {
    padding-top: 1.75rem;
}

#authDrawer[data-auth-mode="2fa"] .auth-header-title,
#authDrawer[data-auth-mode="2fa-recovery"] .auth-header-title {
    font-size: 1.35rem;
    margin-bottom: 0.35rem;
}

#authDrawer[data-auth-mode="2fa"] .auth-form .form-group,
#authDrawer[data-auth-mode="2fa-recovery"] .auth-form .form-group {
    margin-bottom: 0.5rem;
}

#authDrawer[data-auth-mode="2fa"] .form-label,
#authDrawer[data-auth-mode="2fa-recovery"] .form-label {
    color: var(--text-color);
    font-size: 0.85rem;
    font-weight: 600;
}

#authDrawer[data-auth-mode="2fa"] .form-input,
#authDrawer[data-auth-mode="2fa-recovery"] .form-input {
    border-radius: 8px;
    font-size: 1.1rem;
    height: 48px;
    padding: 0 0.9rem;
}

#authDrawer[data-auth-mode="2fa"] #totpCode {
    height: 1px;
    opacity: 0;
    pointer-events: none;
    position: absolute;
    width: 1px;
}

.otp-input-grid {
    display: grid;
    gap: 0.55rem;
    grid-template-columns: repeat(6, 1fr);
    margin-top: 0.35rem;
}

.otp-box {
    aspect-ratio: 1;
    border: 1.5px solid var(--border-color);
    border-radius: 7px;
    color: var(--text-color);
    font-family: "DM Mono", "SFMono-Regular", Consolas, monospace;
    font-size: 1.25rem;
    font-weight: 600;
    min-width: 0;
    outline: none;
    text-align: center;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.otp-box:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(81, 154, 179, 0.16);
}

.otp-box:not(:placeholder-shown) {
    background: var(--primary-light, #ebf5f7);
}

#authDrawer[data-auth-mode="2fa"] .form-submit,
#authDrawer[data-auth-mode="2fa-recovery"] .form-submit {
    height: 46px;
    margin-top: 0.7rem;
}

.form-footer {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    text-align: center;
    color: var(--text-secondary);
}

.form-footer p {
    margin: 0.4rem 0;
}

.form-footer .legal-links-inline {
    font-size: 0.75rem;
}

.form-footer .legal-links-inline a {
    color: var(--text-secondary);
    text-decoration: none;
}

/* Desktop Overrides for "One Screen" fit */
@media (min-width: 768px) {
  .drawer-handle { display: none !important; }
  
  .bottom-drawer,
  .submenu-drawer {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    width: 420px !important; /* Slightly wider for better auth layout */
    height: auto !important;
    max-height: 90vh !important; /* Allow it to fit on screen */
    border-radius: 12px !important;
    bottom: auto !important;
    opacity: 0;
    display: none;
    box-shadow: 0 24px 38px 3px rgba(0,0,0,0.14), 0 9px 46px 8px rgba(0,0,0,0.12);
  }
  
  .bottom-drawer.active,
  .submenu-drawer.active {
    opacity: 1 !important;
    display: block !important;
    bottom: auto !important;
  }

  .auth-options {
    padding: 1.25rem 2rem;
    gap: 8px;
  }

  .auth-options h2 {
    font-size: 1.25rem;
    margin-bottom: 4px;
  }

  .auth-form {
    gap: 10px;
  }

  .form-group {
    gap: 4px;
  }

  .auth-divider {
    margin: 0;
  }

  .form-footer {
    margin-top: 0;
  }

  .form-submit {
    margin-top: 2px;
  }

  /* User dropdown: the logged-in settings menu anchors under the header
     avatar instead of centering as a modal. The auth view (logged out)
     never gets .dropdown-mode and keeps the centered layout. */
  .bottom-drawer.dropdown-mode {
    top: calc(var(--header-height) + 8px) !important;
    right: 16px !important;
    left: auto !important;
    transform: none !important;
    width: 300px !important;
    max-height: calc(100vh - var(--header-height) - 24px) !important;
    border-radius: 12px !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
  }

  .bottom-drawer.dropdown-mode .settings-title {
    display: none !important;
  }

  .bottom-drawer.dropdown-mode .menu-section {
    padding: 8px 0;
  }

  .bottom-drawer.dropdown-mode .menu-item {
    padding: 12px 20px;
    border-bottom: none;
  }

  .bottom-drawer.dropdown-mode .menu-user-info {
    margin-bottom: 4px;
  }

  .overlay.dropdown-mode {
    background-color: transparent;
  }
}

/* Admin desktop: the settings drawer presents as a compact dropdown anchored
   to the header avatar instead of a full-screen bottom sheet. */
@media (min-width: 993px) {
  body.admin-page .bottom-drawer,
  body.admin-page .submenu-drawer {
    top: calc(var(--header-height) + 6px);
    right: 14px;
    bottom: auto;
    left: auto;
    width: 320px;
    max-height: min(30rem, calc(100vh - var(--header-height) - 24px));
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 14px 36px rgba(28, 36, 46, 0.16);
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity 150ms ease-out, transform 150ms ease-out, visibility 150ms;
  }

  body.admin-page .bottom-drawer.active,
  body.admin-page .submenu-drawer.active {
    bottom: auto;
    opacity: 1;
    transform: translateY(0);
  }

  body.admin-page .bottom-drawer .drawer-handle,
  body.admin-page .submenu-drawer .drawer-handle,
  body.admin-page #authDrawer > .settings-title {
    display: none;
  }

  body.admin-page .bottom-drawer .menu-section {
    padding-top: 8px;
  }

  body.admin-page .overlay.active {
    background-color: transparent;
  }
}

/* The account view is a modal at every breakpoint, including places where the
   regular settings menu is presented as a backdrop-free dropdown. */
body .overlay.active.account-modal-backdrop {
  background-color: rgba(28, 36, 46, 0.56);
}
