/*
 * SecurityView Shell Layout
 * Sidebar + TitleBar + PageContent
 * ─────────────────────────────────────────────────────────────
 * Requires: tokens.css, reset.css
 * ─────────────────────────────────────────────────────────────
 */

/* ── Base ───────────────────────────────────────────────── */
body {
  font-family: var(--font-family);
  background: var(--bg-app);
  color: var(--text-primary);
}

/* ── App Shell ──────────────────────────────────────────── */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────── */
.sidebar {
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-sidebar);
  box-shadow: var(--shadow-sidebar);
  overflow: hidden;
  transition: width var(--transition-base), min-width var(--transition-base);
  position: relative;
  z-index: var(--z-sidebar);
  flex-shrink: 0;
}

.app-shell.sidebar-collapsed .sidebar {
  width: var(--sidebar-collapsed-width);
  min-width: var(--sidebar-collapsed-width);
}

/* Collapsed header: stack logo + toggle vertically, both centered */
.app-shell.sidebar-collapsed .sidebar-header {
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: var(--space-2) 0;
  height: auto;
  min-height: var(--title-bar-height);
  gap: var(--space-1);
  overflow: visible;
}

.app-shell.sidebar-collapsed .sidebar-logo {
  flex: none;
  justify-content: center;
}

.app-shell.sidebar-collapsed .sidebar-logo img {
  width: 32px;
  height: 32px;
}

/* ── Sidebar Header ─────────────────────────────────────── */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-4);
  height: var(--title-bar-height);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow: hidden;
  gap: var(--space-2);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  overflow: hidden;
  flex: 1;
  min-width: 0;
  text-decoration: none;
}

.sidebar-logo img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex-shrink: 0;
  transition: filter var(--transition-base);
}

[data-theme="dark"] .sidebar-logo img {
  filter: brightness(0) invert(1);
}

.sidebar-logo-text {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  opacity: 1;
  max-width: 160px;
  transition: opacity var(--transition-base), max-width var(--transition-base);
}

.app-shell.sidebar-collapsed .sidebar-logo-text {
  opacity: 0;
  max-width: 0;
}

.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  flex-shrink: 0;
  /* Reset browser button defaults */
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.sidebar-toggle:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ── Sidebar Nav ────────────────────────────────────────── */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-3) 0;
  scrollbar-width: none;
}

.sidebar-nav::-webkit-scrollbar {
  display: none;
}

.nav-section {
  margin-bottom: var(--space-2);
}

.nav-section-label {
  display: block;
  padding: var(--space-2) var(--space-4) var(--space-1);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  opacity: 1;
  transition: opacity var(--transition-base);
}

.app-shell.sidebar-collapsed .nav-section-label {
  opacity: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  margin: 1px var(--space-2);
  border-radius: var(--radius-md);
  color: var(--nav-text);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
  text-decoration: none;
  position: relative;
}

.nav-item:hover {
  background: var(--nav-hover-bg);
}

.nav-item.active {
  background: var(--nav-active-bg);
  color: var(--nav-active-text);
}

.nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: inherit;
}

.nav-label {
  overflow: hidden;
  opacity: 1;
  max-width: 160px;
  transition: opacity var(--transition-base), max-width var(--transition-base);
}

.app-shell.sidebar-collapsed .nav-label {
  opacity: 0;
  max-width: 0;
}

/* Collapsed: center icons */
.app-shell.sidebar-collapsed .nav-item {
  justify-content: center;
  padding: var(--space-2);
}

/* Badge on nav items (e.g. unread count) */
.nav-item-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 var(--space-1);
  border-radius: var(--radius-full);
  background: var(--color-error);
  color: #fff;
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  margin-left: auto;
  flex-shrink: 0;
  opacity: 1;
  transition: opacity var(--transition-base);
}

.app-shell.sidebar-collapsed .nav-item-badge {
  opacity: 0;
}

/* ── Sidebar Footer ─────────────────────────────────────── */
.sidebar-footer {
  padding: var(--space-3) var(--space-2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}

.sidebar-profile {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2);
  border-radius: var(--radius-md);
  cursor: pointer;
  overflow: hidden;
  transition: background var(--transition-fast);
}

.sidebar-profile:hover {
  background: var(--bg-hover);
}

.app-shell.sidebar-collapsed .sidebar-profile {
  justify-content: center;
}

.sidebar-profile-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  opacity: 1;
  max-width: 140px;
  transition: opacity var(--transition-base), max-width var(--transition-base);
}

.app-shell.sidebar-collapsed .sidebar-profile-info {
  opacity: 0;
  max-width: 0;
}

.profile-name {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-role {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: capitalize;
}

.sidebar-profile-chevron {
  color: var(--text-tertiary);
  flex-shrink: 0;
  opacity: 1;
  transition: opacity var(--transition-base);
}

.app-shell.sidebar-collapsed .sidebar-profile-chevron {
  opacity: 0;
}

/* ── Avatar ─────────────────────────────────────────────── */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: #fff;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  flex-shrink: 0;
  user-select: none;
}

.avatar-sm {
  width: 28px;
  height: 28px;
  font-size: var(--text-xs);
}

.avatar-lg {
  width: 48px;
  height: 48px;
  font-size: var(--text-md);
}

/* ── Main Content ───────────────────────────────────────── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
}

/* ── Title Bar ──────────────────────────────────────────── */
.title-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--title-bar-height);
  padding: 0 var(--space-6);
  background: var(--bg-titlebar);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: var(--z-titlebar);
  gap: var(--space-4);
}

.title-bar-left {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  min-width: 0;
  flex: 1;
}

.page-title {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  white-space: nowrap;
}

.page-breadcrumb {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.page-breadcrumb:not(:empty)::before {
  content: '/';
  margin-right: var(--space-2);
  color: var(--text-disabled);
}

.title-bar-right {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-shrink: 0;
}

/* Search (hidden by default — will be enabled per page) */
.search-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  min-width: 220px;
  transition: box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.search-bar:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

.search-bar.hidden { display: none; }

.search-bar input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: var(--text-sm);
  color: var(--text-primary);
}

.search-bar input::placeholder { color: var(--text-tertiary); }

/* Icon buttons in title bar */
.icon-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  /* Reset browser button defaults */
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
  flex-shrink: 0;
}

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

.icon-btn.active {
  background: var(--bg-active);
  color: var(--color-primary);
}

.icon-btn .dot-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  background: var(--color-error);
  border-radius: var(--radius-full);
  border: 2px solid var(--bg-titlebar);
}

.icon-btn .count-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: var(--color-error);
  color: #fff;
  font-size: 10px;
  font-weight: var(--weight-bold);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-titlebar);
}

/* Profile button in title bar */
.profile-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2) var(--space-1) var(--space-1);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: background var(--transition-fast);
  position: relative;
  /* Override .icon-btn fixed size so name can show */
  width: auto;
  height: 36px;
}

.profile-btn:hover { background: var(--bg-hover); }

.profile-btn-name {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
  white-space: nowrap;
}

/* ── Page Content ───────────────────────────────────────── */
.page-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--page-padding);
  background: var(--bg-app);
}

/* ── Card Grid ──────────────────────────────────────────── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-4);
}

.card-grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-4); }
.card-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
.card-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-4); }

@media (max-width: 1200px) {
  .card-grid-4 { grid-template-columns: repeat(2, 1fr); }
  .card-grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .card-grid-4,
  .card-grid-3,
  .card-grid-2 { grid-template-columns: 1fr; }
  .card-grid    { grid-template-columns: 1fr; }
  .page-title   { font-size: var(--text-lg); }
  .page-content { padding: var(--space-4); }
  .title-bar    { padding: 0 var(--space-4); }
  .profile-btn-name { display: none; }
}

/* ── Notification Panel ─────────────────────────────────── */
.notification-panel {
  position: fixed;
  top: var(--title-bar-height);
  right: 0;
  width: 360px;
  height: calc(100vh - var(--title-bar-height));
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  z-index: var(--z-dropdown);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--transition-base);
  box-shadow: var(--shadow-lg);
}

.notification-panel.open {
  transform: translateX(0);
}

.notification-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.notification-panel-title {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.notification-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-2) 0;
}

.notification-item {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.notification-item:hover { background: var(--bg-hover); }

.notification-item.unread { background: var(--bg-active); }

.notification-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  flex-shrink: 0;
  margin-top: 6px;
}

.notification-item-body { flex: 1; min-width: 0; }

.notification-item-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
  margin-bottom: 2px;
}

.notification-item-msg {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notification-item-time {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

.notification-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-12) var(--space-6);
  color: var(--text-tertiary);
  font-size: var(--text-sm);
}

/* ── Profile Dropdown ───────────────────────────────────── */
.profile-dropdown {
  position: absolute;
  top: calc(var(--title-bar-height) - var(--space-2));
  right: var(--space-4);
  width: 230px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-dropdown);
  overflow: hidden;
  opacity: 0;
  transform: translateY(-8px) scale(0.97);
  pointer-events: none;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}

.profile-dropdown.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

.profile-dropdown-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
}

.profile-dropdown-info { min-width: 0; }

.profile-dropdown-name {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-dropdown-email {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-dropdown-menu { padding: var(--space-2) 0; }

.profile-dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition-fast);
  text-decoration: none;
  width: 100%;
  text-align: left;
}

.profile-dropdown-item:hover { background: var(--bg-hover); }
.profile-dropdown-item.danger { color: var(--color-error); }

.profile-dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: var(--space-1) 0;
}

/* ── Standalone Pages (login, register, reset) ────────── */
.standalone-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-app);
  font-family: var(--font-family);
  color: var(--text-primary);
  padding: var(--space-6);
}

.standalone-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-surface);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
  box-shadow: var(--shadow-lg);
}
