/* ===========================================================================
   layout.css - application shell: sidebar, topbar, content area, footer
   =========================================================================== */

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

/* ------------------------------------------------------------------ sidebar */

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  z-index: 60;
  transition: width var(--t), transform var(--t);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  height: var(--topbar-h);
  padding: 0 18px;
  border-bottom: 1px solid rgba(148, 163, 184, .14);
  flex: none;
}

.brand-mark {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  flex: none;
}

.brand-mark.has-logo { background: transparent; padding: 0; overflow: hidden; }
.brand-mark.has-logo img { width: 100%; height: 100%; object-fit: contain; display: block; border-radius: 9px; }

.brand-text { min-width: 0; }
.brand-name {
  display: block;
  font-weight: 600;
  font-size: 14.5px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-sub {
  display: block;
  font-size: 11px;
  color: var(--sidebar-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 12px 20px;
}
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(148,163,184,.22); border-radius: 3px; }

.nav-group + .nav-group { margin-top: 18px; }

.nav-label {
  padding: 0 12px 8px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--sidebar-muted);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  color: var(--sidebar-text);
  font-size: 13.5px;
  white-space: nowrap;
  transition: background var(--t-fast), color var(--t-fast);
}
.nav-link:hover { background: rgba(148, 163, 184, .1); color: #fff; text-decoration: none; }
.nav-link .icon { flex: none; opacity: .85; }

.nav-link.active {
  background: var(--sidebar-active);
  color: #fff;
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--accent);
}
.nav-link.active .icon { opacity: 1; color: var(--accent-hover); }

.nav-text { overflow: hidden; text-overflow: ellipsis; }

.sidebar-foot {
  flex: none;
  padding: 12px;
  border-top: 1px solid rgba(148, 163, 184, .14);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  color: var(--sidebar-text);
}
.sidebar-user:hover { background: rgba(148,163,184,.1); text-decoration: none; color: #fff; }
.sidebar-user .avatar { background: var(--accent); color: #fff; }
.sidebar-user small { display: block; color: var(--sidebar-muted); font-size: 11.5px; }

/* collapsed state (desktop) */
.app.is-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
.app.is-collapsed .sidebar .brand-text,
.app.is-collapsed .sidebar .nav-text,
.app.is-collapsed .sidebar .nav-label,
.app.is-collapsed .sidebar .sidebar-user span { display: none; }
.app.is-collapsed .sidebar .nav-link { justify-content: center; padding: 10px 0; }
.app.is-collapsed .sidebar .sidebar-brand { justify-content: center; padding: 0; }
.app.is-collapsed .sidebar .sidebar-user { justify-content: center; }
.app.is-collapsed .main { margin-left: var(--sidebar-w-collapsed); }

/* ------------------------------------------------------------------- main */

.main {
  flex: 1 1 auto;
  min-width: 0;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  transition: margin var(--t);
}

/* ----------------------------------------------------------------- topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  position: relative;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.is-open { background: var(--surface-3); color: var(--text); border-color: var(--border); }

.topbar-search {
  position: relative;
  flex: 0 1 380px;
  min-width: 0;
}
.topbar-search .icon {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--text-3); pointer-events: none;
}
.topbar-search input {
  width: 100%;
  height: 38px;
  padding: 0 12px 0 36px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text);
}
.topbar-search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
  background: var(--surface);
}

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }

.badge-count {
  position: absolute;
  top: 3px; right: 3px;
  min-width: 17px; height: 17px;
  padding: 0 4px;
  border-radius: var(--r-pill);
  background: var(--danger);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
  border: 2px solid var(--surface);
}
html[data-theme="dark"] .badge-count { color: #1a0505; }

/* ------------------------------------------------------------- dropdowns */

.dropdown { position: relative; }

.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 240px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  display: none;
  z-index: 70;
}
.dropdown.is-open .dropdown-menu { display: block; }

/* A menu on the last column of a table would run off the right edge, so it
   hangs from the button instead of from the card. */
.dropdown-menu.dropdown-right { right: 0; left: auto; }

.dropdown-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  color: var(--text-2);
  font-size: .875rem;
  white-space: nowrap;
}
.dropdown-item:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.dropdown-item.is-danger { color: var(--danger); }
.dropdown-item.is-danger:hover { background: var(--danger-soft, var(--surface-3)); }
.dropdown-sep { height: 1px; background: var(--border); margin: 6px 4px; }

.dropdown-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.dropdown-head strong { font-size: 13px; }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: 13.5px;
  width: 100%;
  background: none;
  border: 0;
  text-align: left;
  cursor: pointer;
}
.dropdown-item:hover { background: var(--surface-3); text-decoration: none; }
.dropdown-item .icon { color: var(--text-2); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item.danger .icon { color: var(--danger); }

.dropdown-sep { height: 1px; background: var(--border); margin: 6px 0; }

.dropdown-user {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: none; cursor: pointer;
}
.dropdown-user:hover { background: var(--surface-3); }
.dropdown-user .meta { text-align: left; line-height: 1.25; }
.dropdown-user .meta strong { display: block; font-size: 13px; }
.dropdown-user .meta small { color: var(--text-3); font-size: 11.5px; }

.notif-list { max-height: 340px; overflow-y: auto; }
.notif-item {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px;
  border-radius: var(--r-sm);
  color: var(--text);
}
.notif-item:hover { background: var(--surface-3); text-decoration: none; }
.notif-item .dot-unread {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); margin-top: 6px; flex: none;
}
.notif-item .dot-unread.read { background: transparent; }
.notif-body { min-width: 0; }
.notif-body strong { display: block; font-size: 13px; font-weight: 500; }
.notif-body small { color: var(--text-3); font-size: 11.5px; }

/* ---------------------------------------------------------------- content */

.content {
  flex: 1 1 auto;
  padding: 22px;
  max-width: 1600px;
  width: 100%;
}

.page-head {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.page-head .titles { min-width: 0; flex: 1 1 320px; }
.page-head h1 { display: flex; align-items: center; gap: 10px; }
.page-head p { color: var(--text-2); margin: 4px 0 0; font-size: 13.5px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.breadcrumb {
  display: flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--text-3);
  margin-bottom: 6px;
}
.breadcrumb a { color: var(--text-2); }
.breadcrumb .sep { color: var(--border-strong); }

/* ----------------------------------------------------------------- footer */

.footer {
  flex: none;
  padding: 16px 22px 22px;
  color: var(--text-3);
  font-size: 12.5px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}
.footer a { color: var(--text-2); }

/* --------------------------------------------------------------- backdrop */

.backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .5);
  z-index: 55;
  display: none;
}
.backdrop.is-visible { display: block; }
