/* Redesign shell (Phase 1): page layout around the design-system sidebar and topbar.
   Tokens only (UndrAds-CRM-Design-System/tokens/tokens.css). Loaded last. The sidebar, topbar, menus, palette and
   toasts are data-ui="v2" areas and get the design-system component styles from ds/undrads-ui.css. */

:root { --ui-sb: var(--sidebar-w); --ua-header-h: var(--topbar-h); }
:root.ui-collapsed { --ui-sb: var(--sidebar-w-collapsed); }

/* App layout: sidebar | content (topbar + the existing section views) */
#app-container:not([style*="none"]) {
    display: grid !important; grid-template-columns: var(--ui-sb) minmax(0, 1fr);
    height: 100dvh; overflow: hidden; transition: grid-template-columns var(--t-med) var(--ease);
}
.ui-side { height: 100dvh; position: relative; z-index: 1600; }
.ui-side .sidebar { height: 100dvh; }
.ui-main { min-width: 0; height: 100dvh; overflow: hidden; display: flex; flex-direction: column; position: relative; }
.ui-main > main { flex: 1 1 auto; min-height: 0; height: auto !important; }
.ui-top { flex: none; position: relative; z-index: 1500; } /* above board columns, below the old pop-ups (2000+) */

/* Lucide icons inside redesigned areas use the text colour (the old screens tint them brand blue). */
[data-ui="v2"] .ua-ic { color: inherit; }
[data-ui="v2"] [data-icon] { display: flex; }
[data-ui="v2"] .nav-item[data-icon], [data-ui="v2"] .menu-item[data-icon] { display: flex; }
.ui-rel { position: relative; }

/* Sidebar details */
.ui-side .sidebar { gap: var(--s-1); }
.ui-side .new-btn { width: 100%; }
.ui-side .ui-menu { z-index: 1700; } /* placed by ui-shell.js (fixed, anchored to its button) */

.ui-side .me { width: 100%; text-align: left; border-radius: var(--r-md); }
.ui-me-avatar { position: relative; overflow: hidden; flex: none; }
.ui-me-avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.ui-me-avatar img[src=""], .ui-me-avatar img:not([src]) { display: none; }
.ui-theme-ic { display: inline-flex; flex: none; }
.ui-collapsed .ui-side .sidebar { padding-left: var(--s-2); padding-right: var(--s-2); }
.ui-collapsed .ui-side .nav-label, .ui-collapsed .ui-side .brand-name, .ui-collapsed .ui-side .nav-text,
.ui-collapsed .ui-side .me-meta, .ui-collapsed .ui-side .nav-item .count:not(.dot) { display: none; }
.ui-collapsed .ui-side .nav-item { justify-content: center; padding: 0; }
.ui-collapsed .ui-side .nav-item .count.dot { display: block; position: absolute; top: 6px; right: 10px; min-width: 8px; width: 8px; height: 8px; padding: 0; font-size: 0; }
.ui-collapsed .ui-side .new-btn { padding: 0; width: 40px; margin-left: auto; margin-right: auto; }
.ui-collapsed .ui-side .brand { justify-content: center; padding-left: 0; padding-right: 0; }
.ui-collapsed .ui-side .me { justify-content: center; }
.ui-collapsed .ui-side .nav-item.active::before { left: -8px; }

/* Topbar details */
.ui-top .topbar { gap: var(--s-3); }
.ui-top .crumbs a { color: var(--text-3); }
.ui-top .crumbs a:hover { color: var(--text); }
.ui-top .crumbs .ua-ic { color: var(--text-3); }
.ui-top .topbar .ui-nav-toggle { display: none; }
.ui-search-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ui-bell { position: relative; }
.ui-bell-dot { position: absolute; top: 6px; right: 7px; width: 8px; height: 8px; border-radius: var(--r-pill); background: var(--danger); box-shadow: 0 0 0 2px var(--surface-2); font-size: 0; }
.ui-reminders { left: auto; right: 0; top: calc(100% + 6px); width: 360px; max-height: min(460px, 70vh); overflow-y: auto; }
.ui-rem-head { display: flex; align-items: center; justify-content: space-between; }
.ui-rem-head .link { text-transform: none; letter-spacing: 0; font-size: var(--fs-12); }
.ui-rem-row { display: flex; align-items: flex-start; gap: 2px; }
.ui-rem-item { height: auto; padding: 8px 10px; align-items: flex-start; flex: 1; min-width: 0; }
.ui-rem-ic { display: inline-flex; margin-top: 2px; color: var(--text-3); }
.ui-rem-ic.danger, .ui-danger-text { color: var(--danger); }
.ui-rem-text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ui-rem-msg { font-weight: 500; overflow-wrap: anywhere; }
.ui-rem-text .hint { display: flex; align-items: center; gap: 6px; margin: 0; flex-wrap: wrap; }
.ui-rem-row .btn-icon { margin-top: 6px; }
.ui-rem-empty { padding: var(--s-6); }

/* Toasts: bottom centre, design-system look; the old code adds .hide before removing */
#toastNotificationContainer { pointer-events: none; z-index: 5000; }
#toastNotificationContainer .toast { pointer-events: auto; min-width: 0; max-width: min(560px, calc(100vw - 32px)); }
#toastNotificationContainer .toast.hide { opacity: 0; transform: translateY(8px); transition: opacity var(--t-med) var(--ease), transform var(--t-med) var(--ease); }
.ui-toast-ic { display: inline-flex; }
.toast.error .ui-toast-ic { color: var(--danger); }
.toast.success .ui-toast-ic { color: var(--success); }
.ui-toast-msg { overflow-wrap: anywhere; }
.ui-toast-x { opacity: 0.6 !important; display: inline-flex; }

/* Command palette */
.ui-palette-root { position: fixed; inset: 0; z-index: 4500; }
.ui-palette { position: fixed; left: 50%; top: 14vh; transform: translateX(-50%); width: min(620px, calc(100vw - 32px)); z-index: 4501; }
.ui-palette-in { display: flex; align-items: center; gap: var(--s-3); padding: 14px 18px; border-bottom: 1px solid var(--divider); }
.ui-palette-in .ua-ic { color: var(--text-3); }
.ui-palette-in input { flex: 1; background: none; border: 0; outline: none; font-size: 16px; color: var(--text); min-width: 0; }
.ui-palette-list { padding: var(--s-2); max-height: 52vh; overflow: auto; }
.ui-palette-list .menu-item { height: 40px; }
.ui-palette-list .menu-item .ua-ic { color: var(--text-3); }
.ui-palette-list .ui-pal-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ui-palette-list .hint { margin-left: 0; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ui-palette-list .ui-pal-enter { margin-left: auto; display: none; }
.ui-palette-list .menu-item.hl .ui-pal-enter { display: inline-flex; }

/* Full-page records and drawers start right of the sidebar, below the topbar (until Phase 3 turns them into drawers) */
.modal.record-page { left: var(--ui-sb) !important; width: calc(100vw - var(--ui-sb)) !important; }
.mkt-drawer, .hc-drawer { left: auto !important; right: 0 !important; width: calc(100vw - var(--ui-sb)) !important; max-width: none !important; }

/* Below 1280px the sidebar folds to the icon rail; on phones it slides in from the left. */
@media (max-width: 1279px) {
    :root:not(.ui-expanded) { --ui-sb: var(--sidebar-w-collapsed); }
    :root:not(.ui-expanded) .ui-side .nav-label, :root:not(.ui-expanded) .ui-side .brand-name, :root:not(.ui-expanded) .ui-side .nav-text,
    :root:not(.ui-expanded) .ui-side .me-meta, :root:not(.ui-expanded) .ui-side .nav-item .count:not(.dot) { display: none; }
    :root:not(.ui-expanded) .ui-side .nav-item { justify-content: center; padding: 0; }
    :root:not(.ui-expanded) .ui-side .new-btn { padding: 0; width: 40px; margin-left: auto; margin-right: auto; }
    :root:not(.ui-expanded) .ui-side .brand { justify-content: center; padding-left: 0; padding-right: 0; }
    :root:not(.ui-expanded) .ui-side .sidebar { padding-left: var(--s-2); padding-right: var(--s-2); }
    :root:not(.ui-expanded) .ui-side .nav-item .count.dot { display: block; position: absolute; top: 6px; right: 10px; min-width: 8px; width: 8px; height: 8px; padding: 0; font-size: 0; }
}
@media (max-width: 767px) {
    :root { --ui-sb: 0px; }
    #app-container:not([style*="none"]) { grid-template-columns: minmax(0, 1fr); }
    .ui-side { position: fixed; left: 0; top: 0; bottom: 0; width: min(280px, 86vw); transform: translateX(-100%); transition: transform var(--t-med) var(--ease); z-index: 4200; box-shadow: var(--shadow-3); }
    :root.ui-nav-open .ui-side { transform: none; }
    :root.ui-nav-open .ui-scrim { display: block; }
    .ui-scrim { display: none; position: fixed; inset: 0; background: var(--overlay); z-index: 4100; }
    .ui-side .nav-label, .ui-side .brand-name, .ui-side .nav-text, .ui-side .me-meta { display: revert !important; }
    .ui-side .nav-item { justify-content: flex-start !important; padding: 0 10px !important; }
    .ui-side .brand { justify-content: flex-start !important; padding: 4px 6px 14px !important; }
    .ui-side .nav-item .count:not(.dot) { display: grid !important; }
    .ui-side .sidebar { padding-left: var(--s-3) !important; padding-right: var(--s-3) !important; }
    .ui-side .new-btn { width: 100% !important; padding: 0 var(--s-4) !important; }
    .ui-top .topbar .ui-nav-toggle { display: inline-flex; }
    .ui-top .topbar { padding: 0 var(--s-3); }
    .ui-top .search-trigger { width: auto; flex: 1; }
    .ui-top .search-trigger .kbd, .ui-top .crumbs { display: none; }
    #uiCollapseBtn { display: none; }
    .ui-reminders { width: min(360px, calc(100vw - 24px)); }
}
.ui-me-initials { line-height: 1; }

/* Drive tree under "Drive" in the sidebar (drive.js renderSideTree): Notion-style pages. */
.ui-drive-tree { margin: 2px 0 6px; max-height: 42vh; overflow: auto; }
.ui-drive-tree[hidden] { display: none; }
.ui-drive-tree .dt-head { padding: 2px 0 2px 10px; }
.ui-drive-tree .dt-all { display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; padding: 2px 4px; color: var(--text-3); font-size: var(--fs-11); font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; cursor: pointer; border-radius: var(--r-sm); }
.ui-drive-tree .dt-all:hover { color: var(--text-2); background: var(--surface-hover); }
.ui-drive-tree .dt-row { display: flex; align-items: center; gap: 2px; height: 28px; padding-left: calc(8px + var(--d) * 14px); padding-right: 6px; border-radius: var(--r-sm); position: relative; }
.ui-drive-tree .dt-row:hover { background: var(--surface-hover); }
.ui-drive-tree .dt-row.on { background: var(--brand-soft); }
.ui-drive-tree .dt-row.on .dt-link { color: var(--brand-text); font-weight: 600; }
.ui-drive-tree .dt-tog { width: 20px; height: 20px; flex: none; display: grid; place-items: center; border: 0; background: none; color: var(--text-3); border-radius: 4px; cursor: pointer; padding: 0; }
.ui-drive-tree .dt-tog:hover { background: var(--surface-3); color: var(--text); }
.ui-drive-tree .dt-tog.empty { visibility: hidden; }
.ui-drive-tree button.dt-tog.empty { visibility: visible; opacity: 0.35; }
.ui-drive-tree .dt-link { flex: 1; min-width: 0; display: flex; align-items: center; gap: 7px; color: var(--text-2); text-decoration: none; font-size: var(--fs-13); }
.ui-drive-tree .dt-link span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ui-drive-tree .dt-link .ua-ic { flex: none; color: var(--text-3); }
.ui-drive-tree .dt-link:hover { color: var(--text); }
.ui-drive-tree .dt-row:focus-within { outline: 2px solid var(--brand); outline-offset: -2px; }
.ui-collapsed .ui-drive-tree { display: none !important; }
@media (min-width: 768px) and (max-width: 1279px) { :root:not(.ui-expanded) .ui-drive-tree { display: none !important; } }
/* Keep the sidebar footer (help, admin, theme, account) on screen while the nav and Drive tree scroll above it. */
.ui-side .sidebar-foot { position: sticky; bottom: calc(-1 * var(--s-4)); z-index: 2; background: var(--bg-sunken); padding-bottom: var(--s-4); margin-bottom: calc(-1 * var(--s-4)); }
