/*
 * Application shell — sidebar, topbar, page header, responsive layout.
 * Sprint 1 (UI redesign): "Only redesign the application shell and
 * reusable UI system." Every business page's own content is untouched;
 * it just renders inside `.app-content-body` below.
 */

/* ---------------------------------------------------------------------
   Shell skeleton
--------------------------------------------------------------------- */

.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background-color: var(--color-background);
}

.app-main {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  height: 100vh;
}

.app-content {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
}

.app-content-body {
  padding: var(--space-6) var(--space-8);
  max-width: 1400px;
  margin: 0 auto;
}

@media (max-width: 767.98px) {
  .app-content-body {
    padding: var(--space-4);
  }
}

/* ---------------------------------------------------------------------
   Sidebar
--------------------------------------------------------------------- */

.app-sidebar {
  width: var(--shell-sidebar-width);
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  background-color: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow: hidden;
  transition: width var(--transition-slow), transform var(--transition-slow);
  z-index: var(--z-sidebar);
}

[data-sidebar-collapsed="true"] .app-sidebar {
  width: var(--shell-sidebar-width-collapsed);
}

.app-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  height: var(--shell-topbar-height);
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.app-sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text-primary);
  font-weight: 700;
  font-size: 0.9375rem;
  min-width: 0;
  overflow: hidden;
}
.app-sidebar-brand:hover {
  text-decoration: none;
  color: var(--color-text-primary);
}

.app-sidebar-logo {
  flex: 0 0 auto;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-hover));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8125rem;
}

.app-sidebar-brand-text {
  white-space: nowrap;
}

.app-sidebar-toggle {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.app-sidebar-toggle:hover {
  background-color: var(--color-hover);
  color: var(--color-text-primary);
}

.app-sidebar-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-3) var(--space-3);
}

.app-sidebar-section + .app-sidebar-section {
  margin-top: var(--space-5);
}

.app-sidebar-section-title {
  font-size: var(--font-size-caption);
  letter-spacing: var(--letter-spacing-caption);
  text-transform: uppercase;
  font-weight: 600;
  color: var(--color-muted);
  padding: 0 var(--space-3);
  margin-bottom: var(--space-2);
  white-space: nowrap;
}

.app-sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0.5rem var(--space-3);
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  font-size: var(--font-size-small);
  font-weight: 500;
  white-space: nowrap;
  transition: background-color var(--transition-fast), color var(--transition-fast);
  position: relative;
}

.app-sidebar-link:hover {
  background-color: var(--color-hover);
  color: var(--color-text-primary);
  text-decoration: none;
}

.app-sidebar-link .icon {
  flex: 0 0 auto;
  color: inherit;
}

.app-sidebar-link.active {
  background-color: var(--color-primary-subtle);
  color: var(--color-primary);
  font-weight: 600;
}

.app-sidebar-link + .app-sidebar-link {
  margin-top: 0.125rem;
}

[data-sidebar-collapsed="true"] .app-sidebar-brand-text,
[data-sidebar-collapsed="true"] .app-sidebar-section-title,
[data-sidebar-collapsed="true"] .app-sidebar-link-label,
[data-sidebar-collapsed="true"] .app-sidebar-user-details,
[data-sidebar-collapsed="true"] .app-sidebar-footer-actions {
  opacity: 0;
  pointer-events: none;
}

[data-sidebar-collapsed="true"] .app-sidebar-link {
  justify-content: center;
}

.app-sidebar-footer {
  border-top: 1px solid var(--color-border);
  padding: var(--space-3);
  flex-shrink: 0;
}

.app-sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2);
  border-radius: var(--radius-md);
  min-width: 0;
}

/* Phase E: the user block doubles as the "Hesabım" link — reset the
   default anchor styling (color/underline) so it still reads as plain
   text, add a hover/active affordance so it's discoverable as clickable. */
.app-sidebar-user-link {
  color: inherit;
  text-decoration: none;
  transition: background-color 0.15s ease;
}

.app-sidebar-user-link:hover,
.app-sidebar-user-link.active {
  background-color: var(--color-secondary-subtle);
}

.app-avatar {
  flex: 0 0 auto;
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-full);
  background-color: var(--color-primary-subtle);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
}

.app-sidebar-user-details {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}

.app-sidebar-user-name {
  font-size: var(--font-size-small);
  font-weight: 600;
  color: var(--color-text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-sidebar-user-role {
  font-size: var(--font-size-caption);
  color: var(--color-text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-sidebar-footer-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-top: var(--space-2);
}

.app-sidebar-footer-actions .btn {
  flex: 1 1 auto;
}

/* Backdrop shown behind the sidebar on mobile/tablet when it's opened */
.app-sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background-color: var(--color-overlay);
  z-index: calc(var(--z-sidebar) - 1);
}

@media (max-width: 991.98px) {
  .app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-xl);
    width: var(--shell-sidebar-width);
    /* Off-canvas and closed: remove from the tab order / accessibility
       tree too, not just visually — otherwise a keyboard user tabs
       through invisible off-screen sidebar links before reaching the
       topbar/main content. Hidden only after the slide-out transition
       finishes so the animation itself is unaffected. */
    visibility: hidden;
    transition: transform var(--transition-slow), visibility 0s linear var(--transition-slow);
  }

  [data-sidebar-mobile-open="true"] .app-sidebar {
    transform: translateX(0);
    visibility: visible;
    transition: transform var(--transition-slow), visibility 0s linear;
  }

  [data-sidebar-mobile-open="true"] .app-sidebar-backdrop {
    display: block;
  }

  /* The collapsed (icon-only) state is desktop-only — on mobile the
     sidebar is either fully open (overlay) or fully hidden. */
  [data-sidebar-collapsed="true"] .app-sidebar-brand-text,
  [data-sidebar-collapsed="true"] .app-sidebar-section-title,
  [data-sidebar-collapsed="true"] .app-sidebar-link-label,
  [data-sidebar-collapsed="true"] .app-sidebar-user-details,
  [data-sidebar-collapsed="true"] .app-sidebar-footer-actions {
    opacity: 1;
    pointer-events: auto;
  }
}

/* ---------------------------------------------------------------------
   Topbar
--------------------------------------------------------------------- */

.app-topbar {
  height: var(--shell-topbar-height);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-6);
  border-bottom: 1px solid var(--color-border);
  background-color: var(--color-surface);
  z-index: var(--z-topbar);
}

@media (max-width: 767.98px) {
  .app-topbar {
    padding: 0 var(--space-4);
  }
}

.app-topbar-menu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  border-radius: var(--radius-sm);
  flex: 0 0 auto;
}
.app-topbar-menu-btn:hover {
  background-color: var(--color-hover);
}

@media (min-width: 992px) {
  .app-topbar-menu-btn {
    display: none;
  }
}

.app-topbar-search {
  flex: 1 1 auto;
  max-width: 22rem;
}

.app-topbar-search .form-control {
  background-color: var(--color-background);
  border-color: var(--color-border);
}

.app-topbar-search-hint {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: var(--font-size-caption);
  color: var(--color-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.0625rem 0.375rem;
  pointer-events: none;
}

@media (max-width: 575.98px) {
  .app-topbar-search {
    display: none;
  }
}

.app-topbar-context {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--font-size-small);
  color: var(--color-text-secondary);
  min-width: 0;
}

.app-topbar-context .dropdown-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  font-size: var(--font-size-small);
  font-weight: 500;
  padding: 0.375rem 0.5rem;
  border-radius: var(--radius-sm);
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.app-topbar-context .dropdown-toggle:hover {
  background-color: var(--color-hover);
  color: var(--color-text-primary);
}
.app-topbar-context .dropdown-toggle::after {
  display: none;
}

@media (max-width: 767.98px) {
  .app-topbar-context {
    display: none;
  }
}

.app-topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-left: auto;
  flex: 0 0 auto;
}

.app-topbar-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  border-radius: var(--radius-md);
  position: relative;
}
.app-topbar-icon-btn:hover {
  background-color: var(--color-hover);
  color: var(--color-text-primary);
}

.app-topbar-icon-btn .badge-dot {
  position: absolute;
  top: 0.375rem;
  right: 0.375rem;
  width: 0.4rem;
  height: 0.4rem;
  border-radius: var(--radius-full);
  background-color: var(--color-danger);
  border: 1.5px solid var(--color-surface);
}

/* Web Monitoring Phase 3 (§7): the notification-center dropdown reuses the
   dashboard's existing `.activity-item`/`.activity-*` classes for each row
   — only the popover box itself (width/scroll/header) is new here. */
.app-notification-dropdown {
  width: 22rem;
  max-width: calc(100vw - 2rem);
  padding: 0;
}
.app-notification-dropdown-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  font-weight: 600;
}
.app-notification-dropdown-body {
  max-height: 24rem;
  overflow-y: auto;
  padding: var(--space-2) var(--space-3);
}
.activity-item.is-unread {
  background-color: var(--color-hover);
  border-radius: var(--radius-md);
}

.app-topbar-profile-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  border: none;
  background: transparent;
  padding: 0.25rem;
  border-radius: var(--radius-md);
}
.app-topbar-profile-btn:hover {
  background-color: var(--color-hover);
}
.app-topbar-profile-btn::after {
  display: none;
}

/* Theme toggle: the icon shown reflects the CURRENT theme (sun = light,
   moon = dark); clicking it switches. */
.theme-toggle {
  display: inline-flex;
  align-items: center;
}
.theme-toggle-icon-dark {
  display: none;
}
[data-bs-theme="dark"] .theme-toggle-icon-light {
  display: none;
}
[data-bs-theme="dark"] .theme-toggle-icon-dark {
  display: inline-flex;
}

/* ---------------------------------------------------------------------
   Page header (consistent per-page: title, subtitle, breadcrumb, actions)
--------------------------------------------------------------------- */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-6);
}

.page-header-heading {
  min-width: 0;
}

.page-header-breadcrumb {
  margin-bottom: var(--space-2);
}

.page-header-title {
  font-size: var(--font-size-h1);
  line-height: var(--line-height-h1);
  font-weight: var(--font-weight-h1);
  letter-spacing: var(--letter-spacing-h1);
  color: var(--color-text-primary);
  margin: 0;
}

.page-header-subtitle {
  font-size: var(--font-size-body);
  color: var(--color-text-secondary);
  margin-top: var(--space-1);
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

@media (max-width: 575.98px) {
  .page-header {
    flex-direction: column;
    align-items: stretch;
  }
  .page-header-actions {
    justify-content: flex-end;
  }
}

/* ---------------------------------------------------------------------
   Reduced motion
--------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    transition-delay: 0ms !important;
  }
}
