/* =====================================================================
   MAILNEX MAIN LAYOUT & GLOBAL STYLES (LIGHT THEME)
   Desktop-First Responsive Structure
   ===================================================================== */

@import url('variables.css');

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-family-base);
  font-size: var(--font-size-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

a {
  color: var(--navy-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--yellow-hover);
}

/* App Master Shell */
.app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar Styling (Navy #14213D Surface) */
.app-sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  background-color: var(--navy-primary);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width var(--transition-normal);
  z-index: 100;
}

.sidebar-header {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  padding: 0 var(--space-lg);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 20px;
  font-weight: 700;
  color: #FFFFFF;
  letter-spacing: -0.02em;
}

.brand-icon {
  width: 28px;
  height: 28px;
  background: var(--yellow-accent);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #000000;
  font-weight: 800;
  font-size: 15px;
}

.sidebar-brand-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #FFFFFF;
  border-radius: var(--radius-md);
  padding: 4px 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  width: 100%;
  max-width: 196px;
  height: 48px;
  box-sizing: border-box;
}

.sidebar-brand-badge:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.28);
}

.brand-logo-img {
  max-height: 40px;
  max-width: 180px;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
}

.brand-icon-compact {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  background: #FFFFFF;
  border-radius: var(--radius-md);
  padding: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  transition: transform var(--transition-fast);
}

.brand-icon-compact:hover {
  transform: scale(1.04);
}

.brand-icon-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.sidebar-nav {
  flex: 1;
  padding: var(--space-md) var(--space-sm);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: 10px 14px;
  color: #E5E5E5;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 14px;
  transition: all var(--transition-fast);
  cursor: pointer;
  text-decoration: none;
}

.nav-item:hover {
  background-color: rgba(255, 255, 255, 0.08);
  color: #FFFFFF;
}

.nav-item.active {
  background-color: var(--yellow-accent);
  color: #000000;
  font-weight: 600;
  border-left: none;
  box-shadow: 0 2px 6px rgba(252, 163, 49, 0.25);
}

.nav-item .nav-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.9;
}

.nav-item.active .nav-icon {
  color: #000000;
  opacity: 1;
}

.nav-divider {
  height: 1px;
  background-color: rgba(255, 255, 255, 0.1);
  margin: var(--space-sm) var(--space-sm);
}

/* Main Workspace Area */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background-color: var(--bg-primary);
}

/* Topbar Styling (White #FFFFFF Surface) */
.app-topbar {
  height: var(--topbar-height);
  background-color: #FFFFFF;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-xl);
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.topbar-search {
  position: relative;
  width: 320px;
}

.topbar-search input {
  width: 100%;
  padding: 8px 14px 8px 36px;
  background-color: #FFFFFF;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition-fast);
}

.topbar-search input:focus {
  border-color: var(--yellow-accent);
  box-shadow: var(--focus-ring);
}

.topbar-search .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.smtp-status-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background-color: #FFFFFF;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.status-indicator-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--status-valid-text);
}

.user-profile-badge {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 4px 8px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.user-profile-badge:hover {
  background-color: var(--bg-hover);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--navy-primary);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  border: 1px solid var(--navy-primary);
}

/* Main Content Workspace */
.workspace-content {
  flex: 1;
  padding: var(--space-xl);
  overflow-y: auto;
  background-color: var(--bg-primary);
}

/* Page Header Structure */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-xl);
}

.page-title {
  font-size: var(--font-size-h1);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.page-subtitle {
  font-size: var(--font-size-body);
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Responsive Media Queries */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 72px;
  }

  .brand-title, .nav-text, .topbar-search {
    display: none;
  }

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

  .brand-icon-compact {
    display: inline-flex;
  }

  .sidebar-header {
    justify-content: center;
    padding: 0;
  }

  .nav-item {
    justify-content: center;
    padding: 12px 0;
  }
}

@media (max-width: 768px) {
  .app-container {
    flex-direction: column;
  }

  .app-sidebar {
    width: 100vw;
    height: 60px;
    flex-direction: row;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
  }

  .sidebar-brand-badge {
    display: inline-flex;
    padding: 4px 10px;
  }

  .brand-icon-compact {
    display: none;
  }

  .sidebar-nav {
    flex-direction: row;
    overflow-x: auto;
    padding: 4px;
  }

  .app-main {
    height: calc(100vh - 60px);
  }
}

/* MailNex responsive safety overrides: prevent flex/grid children escaping the workspace. */
.app-container {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.app-main {
  min-width: 0;
  min-height: 0;
}

.workspace-content {
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  overflow-x: hidden;
  overflow-wrap: break-word;
}

.workspace-content > *,
.workspace-content .card,
.workspace-content .card-header,
.workspace-content .page-header,
.workspace-content .table-responsive {
  min-width: 0;
  max-width: 100%;
}

.page-header {
  flex-wrap: wrap;
  gap: var(--space-md);
  align-items: flex-start;
}

.page-header > div {
  min-width: 0;
  max-width: 100%;
}

.page-title,
.page-subtitle,
.card-title,
.card-subtitle {
  overflow-wrap: anywhere;
}

@media (max-width: 1024px) {
  .workspace-content {
    padding: 24px;
  }
}

@media (max-width: 768px) {
  .workspace-content {
    padding: 16px;
  }

  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .page-header > div:last-child {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
  }

  .card-header {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 10px;
  }
}

@media (max-width: 420px) {
  .workspace-content {
    padding: 12px;
  }

  .page-title {
    font-size: 25px;
  }
}
