/* layout.css — app shell, sidebar, topbar, responsive breakpoints.
 * Ported from Archive/src/ui_style.html, consuming Theme.md tokens. */

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

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: #fff;
  position: fixed;
  inset: 0 auto 0 0;
  padding: 14px 10px;
  z-index: var(--z-sidebar);
  overflow: auto;
  display: flex;
  flex-direction: column;
}

/* Nav fills the rail; the logout button is pinned to the bottom. */
.sidebar .nav { flex: 1 1 auto; }
.sidebar-foot {
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, .1);
}
.sidebar-logout { width: 100%; }

/* Dim layer behind the mobile drawer (tap to close). Hidden on desktop. */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: var(--z-backdrop);
}
body.sidebar-lock { overflow: hidden; }

.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: var(--fw-bold); font-size: var(--fs-base);
  padding: 6px 10px 12px;
}
.brand-logo { height: 30px; width: 30px; object-fit: contain; border-radius: var(--radius-sm); display: none; background: #fff; }
.brand-text small { display: block; color: #9ca3af; font-weight: var(--fw-medium); font-size: 11px; margin-top: 2px; }

.nav button {
  display: flex; align-items: center; gap: 8px;
  width: 100%; border: 0; background: transparent;
  color: var(--sidebar-text); text-align: left;
  padding: 5px 10px; border-radius: 7px; margin: 0;
  font: inherit; font-size: var(--fs-sm); cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav-ico { flex: 0 0 16px; display: grid; place-items: center; opacity: .85; }
.nav-group {
  padding: 7px 10px 2px;
  font-size: 10px; font-weight: var(--fw-semibold);
  letter-spacing: .07em; text-transform: uppercase;
  color: var(--sidebar-text); opacity: .55;
}
.nav-ico svg { width: 16px; height: 16px; display: block; }
.nav-txt { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav button:hover .nav-ico, .nav button.active .nav-ico { opacity: 1; }
.nav button:hover { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); }
.nav button.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); font-weight: var(--fw-semibold); }

.main { margin-left: var(--sidebar-w); width: calc(100% - var(--sidebar-w)); min-width: 0; }

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  position: sticky; top: 0;
  z-index: var(--z-topbar);
  gap: 12px;
}
.topbar-left { display: flex; gap: 10px; align-items: center; min-width: 0; }
.topbar-right { display: flex; gap: 8px; align-items: center; }
.topbar .menu { display: none; }

/* Profile chip — icon + name, links to Settings → Account. */
.profile {
  display: flex; align-items: center; gap: 8px;
  background: transparent; border: 1px solid transparent; border-radius: 999px;
  padding: 3px 10px 3px 3px; cursor: pointer; font: inherit; color: inherit;
}
.profile:hover { background: var(--surface-2); }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: var(--fw-semibold); font-size: var(--fs-sm); text-transform: uppercase;
}
.profile-name {
  font-size: var(--fs-sm); color: var(--text-muted);
  max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Topbar icon button + notification popover */
.icon-btn {
  width: 36px; height: 36px; padding: 0;
  display: inline-grid; place-items: center;
  border-radius: 10px; position: relative;
}
.icon-btn svg { width: 18px; height: 18px; display: block; }
.notif-dot {
  position: absolute; top: 4px; right: 4px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: var(--radius-pill);
  background: var(--danger); color: #fff;
  border: 2px solid var(--surface);
  font-size: 9px; font-weight: var(--fw-bold); line-height: 1;
  display: grid; place-items: center;
}
.notif-dot[hidden] { display: none; }
.menu-wrap { position: relative; }
.pop-menu {
  position: absolute; right: 0; top: calc(100% + 8px);
  min-width: 240px; max-width: min(340px, calc(100vw - 32px));
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-3); padding: 6px;
  z-index: var(--z-dropdown); display: none;
}
.pop-menu.open { display: block; }
.pop-head { padding: 8px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.pop-head b { display: block; font-size: var(--fs-sm); }
.pop-head .muted { font-size: 11px; }
.pop-item {
  display: flex; align-items: flex-start; gap: 9px;
  width: 100%; border: 0; background: transparent; color: var(--text);
  text-align: left; padding: 9px 10px; border-radius: 8px;
  font: inherit; font-size: var(--fs-sm); cursor: pointer;
}
.pop-item:hover { background: var(--surface-2); }
.pop-empty { padding: 12px 10px; color: var(--text-muted); font-size: var(--fs-sm); }
.notif-bullet { width: 8px; height: 8px; border-radius: 50%; flex: none; margin-top: 5px; background: var(--info); }
.notif-bullet.danger { background: var(--danger); }
.notif-bullet.warn { background: var(--warning); }
.notif-bullet.info { background: var(--info); }
.notif-copy { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.notif-copy b { font-weight: var(--fw-semibold); font-size: var(--fs-sm); }
.notif-copy small { font-size: 11px; color: var(--text-muted); }

.content { padding: 24px; max-width: 1500px; margin: auto; }
.page-title { font-size: var(--fs-xl); font-weight: var(--fw-bold); margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Responsive (Theme §5) */
@media (max-width: 1050px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-row { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .sidebar { transform: translateX(-100%); transition: transform var(--dur) var(--ease); z-index: var(--z-sidebar-mobile); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.show { display: block; }
  .main { margin-left: 0; width: 100%; }
  .topbar { padding: 0 14px; }
  .topbar .menu { display: block; }
  .topbar-right #userInfo { display: none; }
  .content { padding: 15px; }
  .card { padding: 14px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .full { grid-column: auto; }
  .contact-row { grid-template-columns: 1fr; }
  .search { min-width: 160px; }
  .page-title { font-size: var(--fs-lg); }
  .status-cols { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .toolbar { align-items: stretch; }
  .toolbar .left, .toolbar .right { width: 100%; }
  .toolbar .btn { flex: 1; }
  .modal { padding: 8px; }
  .modal-box { max-height: 96vh; }
  .content { padding: 12px; }
}
