/* ==========================================================================
   Layout CSS — Sidebar, Topbar, App Shell
   ========================================================================== */

.app-body { margin: 0; padding: 0; }

.app-wrapper {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

/* ===== Sidebar ===== */
.app-sidebar {
  width: var(--sidebar-width);
  background-color: var(--sidebar-bg);
  border-right: 1px solid var(--border-color);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 1040;
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-base);
  overflow: hidden;
}

.sidebar-header {
  min-height: var(--topbar-height);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 1.05rem;
  min-width: 0;
}

.sidebar-brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--brand-primary), #6366f1);
  color: white;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
  flex-shrink: 0;
}

.sidebar-brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.sidebar-brand-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.sidebar-brand-text {
  flex: 1;
  min-width: 0;
  /* Allow wrapping for long firm names — keeps name visible within sidebar */
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.25rem;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.75rem;
}

.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }

.sidebar-section { margin-bottom: 1.25rem; }

.sidebar-section-title {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--sidebar-section);
  padding: 0 0.75rem;
  margin-bottom: 0.5rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-md);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all var(--transition-fast);
  margin-bottom: 0.15rem;
}

.sidebar-link i { font-size: 1.05rem; width: 22px; text-align: center; }

.sidebar-link:hover:not(.disabled) {
  background-color: var(--sidebar-hover);
  color: var(--text-primary);
}

.sidebar-link.active {
  background-color: var(--sidebar-active);
  color: var(--sidebar-text-active);
  font-weight: 600;
}

.sidebar-link.disabled {
  opacity: 0.5;
  pointer-events: none;
}

.sidebar-link .badge {
  margin-left: auto;
  font-size: 0.625rem;
  padding: 0.2em 0.5em;
}

.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.4rem;
  border-radius: var(--radius-md);
}

.sidebar-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-primary), #6366f1);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-user-avatar img { width: 100%; height: 100%; object-fit: cover; }

.sidebar-user-info { flex: 1; min-width: 0; }

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

.sidebar-user-role {
  font-size: 0.6875rem;
  color: var(--text-muted);
  text-transform: capitalize;
}

.sidebar-user-logout {
  color: var(--text-muted);
  padding: 0.4rem;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.sidebar-user-logout:hover { background-color: var(--bg-hover); color: var(--danger); }

.sidebar-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1035;
}

.sidebar-backdrop.show { display: block; }

/* ===== Main content ===== */
.app-main {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}

/* ===== Topbar ===== */
.app-topbar {
  height: var(--topbar-height);
  background-color: var(--topbar-bg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 1020;
  flex-shrink: 0;
  width: 100%;
}

.topbar-left { display: flex; align-items: center; gap: 0.75rem; flex: 1; min-width: 0; }

.topbar-toggle {
  background: none;
  border: none;
  color: var(--topbar-text);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0.25rem;
  display: none;
}

.topbar-search {
  display: flex;
  align-items: center;
  background-color: var(--bg-hover);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0 0.85rem;
  max-width: 500px;
  flex: 1;
  position: relative;
  transition: all var(--transition-base);
}

.topbar-search:focus-within {
  border-color: var(--brand-primary);
  background-color: var(--bg-surface);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.topbar-search i { color: var(--text-muted); font-size: 0.95rem; }

.topbar-search input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  padding: 0.6rem 0.6rem;
  font-size: 0.875rem;
  color: var(--text-primary);
}

.topbar-search input::placeholder { color: var(--text-muted); }

.search-shortcut {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 0.15rem 0.45rem;
  font-size: 0.7rem;
  border-radius: 4px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.topbar-right { display: flex; align-items: center; gap: 0.4rem; }

.topbar-action-btn {
  width: 38px;
  height: 38px;
  background: none;
  border: none;
  color: var(--topbar-text);
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: all var(--transition-fast);
  font-size: 1rem;
}

.topbar-action-btn:hover { background-color: var(--bg-hover); color: var(--text-primary); }

.theme-icon-dark { display: none; }
[data-theme="dark"] .theme-icon-light { display: none; }
[data-theme="dark"] .theme-icon-dark { display: inline; }

.notification-badge {
  position: absolute;
  top: 5px;
  right: 5px;
  min-width: 16px;
  height: 16px;
  background: var(--danger);
  color: white;
  font-size: 0.625rem;
  font-weight: 700;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

.notification-badge:empty,
.notification-badge[data-count="0"] { display: none; }

.notification-dropdown {
  width: 360px;
  max-width: calc(100vw - 2rem);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 0;
  overflow: hidden;
}

.notification-header {
  padding: 0.85rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
}

.notification-header h6 { margin: 0; font-weight: 600; font-size: 0.95rem; }

.notification-header .mark-all-read {
  font-size: 0.75rem;
  text-decoration: none;
}

.notification-list { max-height: 400px; overflow-y: auto; }

.notification-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-muted);
}

.notification-empty i { font-size: 2rem; margin-bottom: 0.5rem; }

.notification-footer {
  padding: 0.75rem 1rem;
  text-align: center;
  border-top: 1px solid var(--border-color);
}

/* User menu */
.topbar-user-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: none;
  border: none;
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--topbar-text);
  transition: all var(--transition-fast);
}

.topbar-user-btn:hover { background-color: var(--bg-hover); }

.topbar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-primary), #6366f1);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.875rem;
  overflow: hidden;
}

.topbar-user-avatar img { width: 100%; height: 100%; object-fit: cover; }

.topbar-user-name { font-size: 0.875rem; font-weight: 500; }

.user-menu { width: 280px; padding: 0.5rem; }

.user-menu-header {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.75rem;
  margin: -0.5rem -0.5rem 0;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 0.5rem;
}

.user-menu-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-primary), #6366f1);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1rem;
  overflow: hidden;
}

.user-menu-avatar img { width: 100%; height: 100%; object-fit: cover; }

.user-menu-name { font-weight: 600; font-size: 0.875rem; }
.user-menu-email { font-size: 0.75rem; color: var(--text-muted); }

/* ===== Content area ===== */
.app-content {
  flex: 1;
  padding: 1.5rem;
  width: 100%;
  box-sizing: border-box;
}

.page-header {
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.page-title { font-size: 1.5rem; font-weight: 700; margin: 0; color: var(--text-primary); }
.page-subtitle { font-size: 0.875rem; margin: 0.2rem 0 0; }

/* ===== Footer ===== */
.app-footer {
  padding: 0.7rem 1.5rem;
  border-top: 1px solid var(--border-color);
  background: linear-gradient(180deg, var(--bg-surface) 0%, var(--bg-hover) 100%);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  gap: 1rem;
  position: relative;
  z-index: 10;
}

.app-footer::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--brand-primary), transparent);
  opacity: 0.4;
}

.footer-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.footer-brand-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--brand-primary), #6366f1);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  box-shadow: 0 3px 8px rgba(79, 70, 229, 0.25);
  flex-shrink: 0;
}

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

.footer-brand-name {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
}

.footer-brand-version {
  font-size: 0.6875rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.footer-center {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex: 1;
  justify-content: center;
}

.footer-clock {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  font-weight: 500;
  background: var(--bg-surface);
  padding: 0.3rem 0.7rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  white-space: nowrap;
}

.footer-clock i { color: var(--brand-primary); font-size: 0.85rem; }

.footer-divider {
  width: 1px;
  height: 18px;
  background: var(--border-color);
}

.footer-status {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.6875rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.footer-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
  animation: footerPulse 2s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes footerPulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15); }
  50% { box-shadow: 0 0 0 5px rgba(16, 185, 129, 0.08); }
}

.footer-shortcuts {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.footer-shortcut-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.35rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.footer-shortcut-btn i { color: var(--brand-primary); font-size: 0.85rem; }

.footer-shortcut-btn kbd {
  background: var(--bg-hover);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-weight: 600;
  line-height: 1;
}

.footer-shortcut-btn:hover {
  background: var(--brand-primary-light);
  border-color: var(--brand-primary);
  color: var(--brand-primary);
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(79, 70, 229, 0.15);
}

.footer-shortcut-btn:hover kbd {
  background: var(--brand-primary);
  color: white;
  border-color: var(--brand-primary);
}

.footer-shortcut-btn:hover i { color: var(--brand-primary); }

.footer-shortcut-btn-sm { padding: 0.35rem 0.5rem; }

.footer-shortcut-btn-sm span { display: none; }

/* ===== Responsive ===== */
@media (max-width: 992px) {
  .app-sidebar { transform: translateX(-100%); }
  .app-sidebar.show { transform: translateX(0); }
  .app-main { margin-left: 0; }
  .topbar-toggle { display: block; }
  .topbar-search { max-width: 100%; }
  .app-topbar { padding: 0 1rem; }
}

@media (max-width: 768px) {
  .app-content { padding: 1rem; }
  .page-title { font-size: 1.25rem; }
  .topbar-user-name { display: none !important; }
  .search-shortcut { display: none; }
  .topbar-search input { padding: 0.5rem; font-size: 0.85rem; }
  .footer-center { display: none; }
  .footer-shortcut-btn span { display: none; }
  /* Hide less-used action buttons on mobile — keep notifications + user */
  #commandPaletteTrigger,
  #quickNotesTrigger { display: none; }
  /* Make page header stack vertically */
  .page-header {
    flex-direction: column;
    align-items: stretch !important;
    gap: 0.75rem;
  }
  .page-header > div:first-child { width: 100%; }
  .page-header .btn { width: 100%; }
  /* Compact topbar on mobile */
  .app-topbar { padding: 0 0.75rem; height: 56px; }
  .topbar-action-btn { width: 34px; height: 34px; font-size: 0.95rem; }
  .topbar-user-btn { padding: 0.25rem; }
  .topbar-user-avatar { width: 30px; height: 30px; font-size: 0.8rem; }
  /* Filter bar stacks vertically */
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
    padding: 0.75rem;
  }
  .filter-bar .form-group { width: 100% !important; }
  .filter-bar .form-control, .filter-bar .form-select { width: 100%; }
  .filter-bar .form-group:last-child {
    display: flex;
    gap: 0.5rem;
  }
  .filter-bar .form-group:last-child .btn { flex: 1; }
}

@media (max-width: 576px) {
  .app-content { padding: 0.75rem; }
  .topbar-action-btn { width: 32px; height: 32px; }
  .app-footer { padding: 0.5rem 0.75rem; gap: 0.5rem; }
  .footer-brand-text { display: none; }
  /* Stat cards: smaller text on very small screens */
  .stat-card { padding: 0.75rem !important; }
  .stat-card-value { font-size: 1.25rem !important; }
  .stat-card-label { font-size: 0.7rem !important; }
  .stat-card-icon { width: 36px !important; height: 36px !important; font-size: 1rem !important; }
  /* Make search bar more compact */
  .topbar-search { max-width: 200px; }
  .topbar-search input { font-size: 0.8rem; padding: 0.4rem; }
  /* Tables: smaller font */
  .table { font-size: 0.8rem; }
  .table th, .table td { padding: 0.4rem 0.5rem; }
  /* Cards: less padding */
  .card-body { padding: 0.75rem; }
  .card-header { padding: 0.6rem 0.75rem; font-size: 0.85rem; }
  /* Forms: stack all columns */
  .row > [class*="col-md-"], .row > [class*="col-lg-"] {
    margin-bottom: 0.5rem;
  }
  /* Modal adjustments */
  .modal-dialog { margin: 0.5rem; }
  /* Notification dropdown smaller */
  .notification-dropdown { width: calc(100vw - 1.5rem); }
  .user-menu { width: calc(100vw - 1.5rem); max-width: 280px; }
}
