/* ==========================================================================
   App shell: sidebar, top bar, page
   One flat canvas: the menu has the application's colour by default (palette "neutro.menu"),
   separated by a hairline; no gradients, glows or glass effects.
   ========================================================================== */

body { background: var(--bg); }

.app {
  --sidebar-current: var(--sidebar-width);
  display: grid;
  grid-template-columns: var(--sidebar-current) minmax(0, 1fr);
  min-height: 100vh;
}

/* ---------------------------------- sidebar ---------------------------------- */
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  padding: 14px 10px 10px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-line);
  color: var(--sidebar-fg);
  z-index: 40;
}

/* the product mark: the Duria AI ring (in the menu text colour) and the "duria ai" wordmark, with the accent in --sidebar-accent */
.sidebar__brand { display: flex; align-items: center; justify-content: space-between; gap: 8px; height: 32px; padding: 0 2px 0 10px; margin-bottom: 14px; }
/* collapses the menu (wide screens) or closes it (small screens); drawn with the menu colours */
.sidebar__toggle {
  width: 32px; height: 32px; flex: none; display: grid; place-items: center; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--sidebar-fg-muted); transition: background .12s, color .12s;
}
.sidebar__toggle:hover { background: var(--sidebar-hover); color: var(--sidebar-fg-strong); }
.sidebar__toggle .icon { width: 18px; height: 18px; }
.brand { display: inline-flex; align-items: center; gap: 7px; color: var(--sidebar-fg-strong); font-weight: 800; font-size: 16.5px; letter-spacing: -.01em; line-height: 1; }
.brand__mark { width: 28px; height: 28px; flex: none; } /* lockup proportions: letters about 0.4 of the ring, gap 0.25 */
.brand__mark circle:first-child { fill: none; stroke: currentColor; }
.brand__mark circle:last-child, .brand__name span { fill: var(--sidebar-accent); color: var(--sidebar-accent); }
.brand__name { padding-bottom: 2px; } /* lowercase letters: optically centred on the ring */
.brand:hover { text-decoration: none; color: var(--sidebar-fg-strong); }

.org-avatar {
  width: 32px; height: 32px; border-radius: 8px; flex: none; overflow: hidden;
  display: grid; place-items: center; font-weight: 650; font-size: 12px; letter-spacing: .02em; color: var(--on-brand);
  background: var(--brand-strong);
}
.org-avatar img { width: 100%; height: 100%; object-fit: cover; background: #fff; }
.org-avatar--sm { width: 24px; height: 24px; border-radius: 6px; font-size: 10px; }
/* logos keep their proportions inside the square */
.org-avatar--logo { background: #fff; box-shadow: inset 0 0 0 1px var(--line); }
.org-avatar--logo img { object-fit: contain; padding: 2px; }

.sidebar__nav { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; display: grid; gap: 1px; align-content: start; }
.sidebar__section { margin: 18px 10px 4px; font-size: 12px; font-weight: 500; color: var(--sidebar-fg-muted); }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 10px;
  min-height: 34px; padding: 0 10px; border-radius: var(--radius-sm);
  color: var(--sidebar-fg); font-weight: 450; font-size: 14px; text-decoration: none;
  transition: background .12s, color .12s;
}
.nav-item .icon { width: 18px; height: 18px; color: var(--sidebar-fg-muted); }
.nav-item:hover { background: var(--sidebar-hover); color: var(--sidebar-fg-strong); text-decoration: none; }
.nav-item[aria-current="page"], .nav-item.is-active { background: var(--sidebar-active); color: var(--sidebar-fg-strong); font-weight: 550; }
.nav-item[aria-current="page"] .icon, .nav-item.is-active .icon { color: var(--sidebar-fg-strong); }
.nav-item__count {
  margin-left: auto; font-size: 11.5px; font-weight: 600; padding: 0 7px; border-radius: 999px;
  background: var(--sidebar-active); color: var(--sidebar-fg-strong);
}

/* minmax(0, 1fr): a grid item would otherwise grow to its unwrapped text, and a long organization name would push the
   chevron out of the menu instead of being truncated */
.sidebar__footer { padding-top: 8px; border-top: 1px solid var(--sidebar-line); margin-top: 8px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; }
.user-menu { display: block; min-width: 0; }
.user-menu__menu { min-width: 260px; color: var(--text); }
.user-chip {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: var(--radius); width: 100%;
  background: transparent; border: 0; text-align: left; color: var(--sidebar-fg-strong);
}
.user-chip:hover { background: var(--sidebar-hover); }
.user-chip > .icon { flex: none; color: var(--sidebar-fg-muted); }
.user-chip__meta { min-width: 0; flex: 1; line-height: 1.25; }
.user-chip__name { display: block; font-weight: 550; font-size: 13.5px; }
.user-chip__role { display: block; font-size: 12px; color: var(--sidebar-fg-muted); }

/* "Recentes": like the conversation history of an AI app, names only (the code and site are in the tooltip) */
.recent-list { display: grid; gap: 1px; }
.nav-item--recent { min-height: 32px; font-size: 13.5px; }

/* ----------------------------------- main ------------------------------------ */
.main { min-width: 0; display: flex; flex-direction: column; transition: margin-right .3s var(--ease); }

/* Header: menu toggle and organization | the global search, centred | chat and notifications */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-height);
  display: grid; grid-template-columns: minmax(max-content, 1fr) minmax(0, 560px) minmax(max-content, 1fr); align-items: center; gap: 16px;
  padding: 0 clamp(12px, 2.5vw, 24px); background: var(--bg); border-bottom: 1px solid var(--line);
}
.topbar__start { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar__end { display: flex; align-items: center; justify-content: flex-end; gap: 4px; }
.topbar .topbar__menu { display: none; } /* small screens only, see the media query below */
.topbar__org { display: inline-flex; align-items: center; gap: 9px; min-width: 0; color: var(--text); font-weight: 600; font-size: 14px; }
.topbar__org:hover { text-decoration: none; color: var(--text); }
.topbar__logo { display: block; height: 28px; width: auto; max-width: 180px; object-fit: contain; }

/* Sub-header: the breadcrumb, aligned with the page content */
.subheader {
  width: 100%; max-width: var(--page-max); margin: 0 auto; padding: 14px clamp(16px, 3.5vw, 40px) 0;
  display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 13px; color: var(--text-3); white-space: nowrap; overflow: hidden;
}
.subheader > * { flex: none; }
.subheader > strong { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--text-2); font-weight: 500; }
.subheader a { color: var(--text-3); }
.subheader a:hover { color: var(--text); text-decoration: none; }
.subheader .icon { color: var(--line-strong); width: 14px; height: 14px; }

.search-trigger {
  display: flex; align-items: center; gap: 10px; width: 100%; min-width: 0; height: 38px; padding: 0 6px 0 12px; justify-self: center;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text-3);
  transition: border-color .15s;
}
.search-trigger:hover { border-color: var(--line-strong); }
.search-trigger .icon { width: 16px; height: 16px; }
.search-trigger span { flex: 1; text-align: left; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kbd {
  display: inline-flex; align-items: center; gap: 2px; padding: 1px 6px; border-radius: 5px; font-size: 11px; font-weight: 500;
  font-family: var(--font); color: var(--text-3); background: var(--surface-2); border: 1px solid var(--line);
}

.icon-button {
  position: relative; width: 36px; height: 36px; border-radius: var(--radius); display: grid; place-items: center;
  border: 0; background: transparent; color: var(--text-2); transition: background .15s, color .15s;
}
.icon-button:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.icon-button[aria-expanded="true"], .icon-button.is-active { background: var(--surface-3); color: var(--text); }
.icon-button .icon { width: 19px; height: 19px; }
.badge-dot {
  position: absolute; top: 2px; right: 1px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px;
  background: var(--state-danger); color: #fff; font-size: 10.5px; font-weight: 650; line-height: 16px; text-align: center;
  box-shadow: 0 0 0 2px var(--bg);
}
.badge-dot:empty, .badge-dot[data-count="0"] { display: none; }

/* The page is a size container: grids and heroes adapt to the width they really have (e.g. with the chat drawer open). */
.page { width: 100%; max-width: var(--page-max); margin: 0 auto; padding: 18px clamp(16px, 3.5vw, 40px) 80px; flex: 1; container: page / inline-size; }
.page--narrow { max-width: 820px; }

.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-header__title { display: grid; gap: 4px; min-width: 0; }
.page-header__eyebrow { font-size: 13px; font-weight: 500; color: var(--text-3); }
.page-header__sub { color: var(--text-2); max-width: 68ch; }
.page-header__actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Toolbar of list pages: the main action on the left, the view options on the right */
.page-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: -6px 0 16px; }
.page-toolbar__end { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* mobile navigation overlay (hidden on desktop; must never take a grid cell) */
.nav-scrim { position: fixed; inset: 0; z-index: 35; display: none; background: rgba(15, 28, 46, .32); opacity: 0; pointer-events: none; transition: opacity .2s; }

/* chat drawer pushes the content on wide screens */
.app[data-chat-open="true"] .main { margin-right: var(--drawer-width); }

/* --------------------------- collapsed menu (wide screens) --------------------------- */
@media (min-width: 901px) {
  .app[data-sidebar="collapsed"] { --sidebar-current: 64px; }
  .app[data-sidebar="collapsed"] .sidebar { padding: 14px 10px 10px; }
  /* collapsed: the button takes the place of the mark, at the top of the icons */
  .app[data-sidebar="collapsed"] .sidebar__brand { justify-content: center; padding: 0; }
  .app[data-sidebar="collapsed"] .brand { display: none; }
  .app[data-sidebar="collapsed"] .nav-item,
  .app[data-sidebar="collapsed"] .settings-nav__back { justify-content: center; padding: 0; min-height: 36px; }
  /* labels stay readable by screen readers; sighted people get a tooltip */
  .app[data-sidebar="collapsed"] .nav-item > span,
  .app[data-sidebar="collapsed"] .settings-nav__back > span,
  .app[data-sidebar="collapsed"] .settings-nav__title > span {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap;
  }
  .app[data-sidebar="collapsed"] .nav-item[data-label]:hover::after,
  .app[data-sidebar="collapsed"] .settings-nav__back[data-label]:hover::after {
    content: attr(data-label); position: absolute; z-index: 80; left: calc(100% + 10px); top: 50%; transform: translateY(-50%);
    white-space: nowrap; padding: 5px 9px; border-radius: 7px; background: var(--ink); color: #fff; font-size: 12px; font-weight: 500; pointer-events: none;
  }
  .app[data-sidebar="collapsed"] .sidebar__section,
  .app[data-sidebar="collapsed"] .sidebar__recent { display: none; }
  .app[data-sidebar="collapsed"] .settings-nav__title { justify-content: center; margin: 14px 0 8px; }
  .app[data-sidebar="collapsed"] .user-chip { justify-content: center; padding: 6px 0; }
  .app[data-sidebar="collapsed"] .user-chip__meta, .app[data-sidebar="collapsed"] .user-chip > .icon { display: none; }
}

@media (max-width: 1100px) {
  .app[data-chat-open="true"] .main { margin-right: 0; }
}

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(86vw, var(--sidebar-width)); transform: translateX(-102%);
    transition: transform .28s var(--ease); box-shadow: var(--shadow-3);
  }
  .app[data-nav-open="true"] .sidebar { transform: none; }
  .nav-scrim { display: block; }
  .app[data-nav-open="true"] .nav-scrim { opacity: 1; pointer-events: auto; }
  .topbar { grid-template-columns: minmax(0, 1fr) auto auto; gap: 4px; }
  .topbar .topbar__menu { display: grid; }
  .search-trigger { min-width: 0; width: 36px; padding: 0; justify-content: center; border: 0; background: transparent; }
  .search-trigger span, .search-trigger .kbd { display: none; }
  .topbar__logo { height: 24px; max-width: 140px; }
}

/* ---------------------------------- print ---------------------------------- */
/* Printing a page (a work order, an asset) gives the content alone: no shell, no chat, no toolbars or buttons. */
@media print {
  .sidebar, .topbar, .nav-scrim, .chat-drawer, .toasts, .page-toolbar, .list-toolbar, .filter-panel, .hero__actions,
  .pagination, .btn, .icon-button, .tabs, dialog { display: none !important; }
  .app { display: block; }
  .main { margin: 0 !important; }
  .page { max-width: none; padding: 0; }
  .card { break-inside: avoid; box-shadow: none; }
  a { color: inherit; text-decoration: none; }
  body { background: #fff; color: #000; }
}
