* { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Scrollbars ── Themed globally; each design preset overrides --sb-thumb /
   --sb-thumb-hover (and shape) to its own accent. Applies to every scroll area,
   now and in future, via the universal selector + webkit pseudo-elements. */
:root {
  --sb-size: 12px;
  --sb-thumb: #ccccc6;
  --sb-thumb-hover: #b0b0a9;
  --sb-track: transparent;
  --sb-radius: 10px;
}
[data-theme="dark"] {
  --sb-thumb: #45453f;
  --sb-thumb-hover: #59594f;
}
* { scrollbar-width: thin; scrollbar-color: var(--sb-thumb) var(--sb-track); }
::-webkit-scrollbar { width: var(--sb-size); height: var(--sb-size); }
::-webkit-scrollbar-track { background: var(--sb-track); }
::-webkit-scrollbar-thumb { background: var(--sb-thumb); border-radius: var(--sb-radius); border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--sb-thumb-hover); }
::-webkit-scrollbar-corner { background: transparent; }

body {
  font-family: system-ui, sans-serif;
  background: #f5f5f3;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  position: fixed; top: 0; left: 0;
  width: 56px; height: 100vh;
  background: white; border-right: 1px solid #e5e5e3;
  display: flex; flex-direction: column;
  padding: 16px 8px; gap: 4px;
  overflow: hidden; transition: width 0.2s ease; z-index: 100;
}
.sidebar:hover { width: 240px; }
.sidebar-logo {
  font-size: 13px; font-weight: 500; color: #111;
  padding: 0 8px; margin-bottom: 16px;
  white-space: nowrap; opacity: 0; transition: opacity 0.15s ease;
}
.sidebar:hover .sidebar-logo { opacity: 1; }
.tab-btn {
  background: none; border: none; border-radius: 8px;
  padding: 8px; font-size: 14px; color: #555;
  cursor: pointer; text-align: left; width: 100%;
  display: flex; align-items: center; gap: 10px; white-space: nowrap;
}
.tab-btn:hover { background: #f5f5f3; color: #111; }
.tab-btn.active { background: #111; color: white; }
.tab-btn.active svg { stroke: white; }
.tab-icon { min-width: 20px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.tab-label { opacity: 0; transition: opacity 0.15s ease; }
.sidebar:hover .tab-label { opacity: 1; }
.sidebar-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 4px; }
.sidebar-user {
  font-size: 12px; color: #888; padding: 0 8px; margin-bottom: 4px;
  white-space: nowrap; opacity: 0; transition: opacity 0.15s ease;
}
.sidebar:hover .sidebar-user { opacity: 1; }
.sidebar-version {
  font-size: 11px; color: #bbb; padding: 2px 8px 6px;
  white-space: nowrap; opacity: 0; transition: opacity 0.15s ease;
}
.sidebar:hover .sidebar-version { opacity: 1; }
.logout-btn {
  background: none; border: 1px solid #e5e5e3; border-radius: 8px;
  padding: 8px; font-size: 14px; color: #555; cursor: pointer;
  text-align: left; width: 100%; display: flex; align-items: center; gap: 10px; white-space: nowrap;
}
.logout-btn:hover { background: #f5f5f3; }

/* Main content area */
.main { margin-left: 56px; padding: 32px; min-height: 100vh; }
.page-header {
  display: grid;
  grid-template-columns: 1fr minmax(0, auto) 1fr;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
  padding-bottom: 18px;
  border-bottom: 1px solid #e5e5e3;
}
.header-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.header-center { display: flex; justify-content: center; min-width: 0; }
.header-right { display: flex; align-items: center; justify-content: flex-end; gap: 14px; }

.page-title {
  font-size: 18px;
  font-weight: 500;
  color: #111;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-search {
  width: 100%;
  max-width: 360px;
  background: #f5f5f3;
  border: 1px solid #e5e5e3;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  color: #111;
  outline: none;
}

.header-search:focus { border-color: #aaa; }

.header-datetime {
  font-size: 12px;
  color: #888;
  white-space: nowrap;
}

mark.search-highlight {
  background: #fff0a0;
  color: #111;
  border-radius: 2px;
  padding: 0 1px;
}
.sidebar:hover a .tab-label { opacity: 1; }

[data-theme="dark"] body {
  background: #1a1a18;
  color: #e5e5e3;
}

[data-theme="dark"] .sidebar {
  background: #222220;
  border-color: #333331;
}

[data-theme="dark"] .tab-btn { color: #aaa; }
[data-theme="dark"] .tab-btn:hover { background: #2a2a28; color: #fff; }
[data-theme="dark"] .tab-btn.active { background: #e5e5e3; color: #111; }
[data-theme="dark"] .tab-btn.active svg { stroke: #111; }
[data-theme="dark"] .sidebar-user { color: #555; }
[data-theme="dark"] .sidebar-version { color: #444; }
[data-theme="dark"] .logout-btn { border-color: #333331; color: #aaa; }
[data-theme="dark"] .logout-btn:hover { background: #2a2a28; }

[data-theme="dark"] .main { background: #1a1a18; }
[data-theme="dark"] .page-header { border-color: #333331; }
[data-theme="dark"] .page-title { color: #e5e5e3; }
[data-theme="dark"] .header-search { background: #222220; border-color: #333331; color: #e5e5e3; }
[data-theme="dark"] .header-datetime { color: #555; }

[data-theme="dark"] .grid-stack-item-content { background: #222220; border-color: #333331; }
[data-theme="dark"] .card-header { border-color: #333331; }
[data-theme="dark"] .card-title { color: #e5e5e3; }
[data-theme="dark"] .card-remove { color: #555; }
[data-theme="dark"] .card-remove:hover { color: #e5e5e3; }
[data-theme="dark"] .card-body { color: #e5e5e3; }
[data-theme="dark"] .notes-editor { color: #e5e5e3; }
[data-theme="dark"] .tally-count { color: #e5e5e3; }
[data-theme="dark"] .tally-btn { background: #2a2a28; border-color: #333331; color: #e5e5e3; }
[data-theme="dark"] .tally-reset { color: #555; }

[data-theme="dark"] .right-sidebar { background: #222220; border-color: #333331; }
[data-theme="dark"] .linktree-header { border-color: #333331; }
[data-theme="dark"] .linktree-title { color: #e5e5e3; }
[data-theme="dark"] .link-entry-anchor { color: #e5e5e3; }
[data-theme="dark"] .panel-divider { background: #333331; }
[data-theme="dark"] .archived-note-item { border-color: #333331; }
[data-theme="dark"] .archived-note-item:hover { background: #2a2a28; }
[data-theme="dark"] .archived-note-title { color: #e5e5e3; }

[data-theme="dark"] .modal { background: #222220; }
[data-theme="dark"] .modal-title { color: #e5e5e3; }
[data-theme="dark"] .card-option { border-color: #333331; }
[data-theme="dark"] .card-option:hover { background: #2a2a28; }
[data-theme="dark"] .card-option-name { color: #e5e5e3; }
[data-theme="dark"] .modal-close { border-color: #333331; color: #aaa; }

[data-theme="dark"] .tile { background: #222220; border-color: #333331; }
[data-theme="dark"] .tile:hover { border-color: #555; }
[data-theme="dark"] .tile-name { color: #e5e5e3; }
[data-theme="dark"] .tile-icon { background: #2a2a28; }
[data-theme="dark"] .tile-icon svg { stroke: #aaa; }
[data-theme="dark"] .linktree-pin { color: #555; }
[data-theme="dark"] .linktree-pin.pinned { color: #e5e5e3; }
[data-theme="dark"] .linktree-pin.pinned svg { fill: #e5e5e3; }

[data-theme="dark"] .link-category-add button { background: #e5e5e3; color: #111; }
[data-theme="dark"] .link-category-add input { background: #2a2a28; border-color: #333331; color: #e5e5e3; }
[data-theme="dark"] .link-add-btn { background: #e5e5e3; color: #111; }
[data-theme="dark"] .link-input { background: #2a2a28; border-color: #333331; color: #e5e5e3; }
[data-theme="dark"] .link-entry-edit-btn { color: #444; }
[data-theme="dark"] .link-entry-del { color: #444; }
[data-theme="dark"] .note-filter input[type="date"] { background: #2a2a28; border-color: #333331; color: #e5e5e3; }
[data-theme="dark"] #notes-search { background: #2a2a28 !important; border-color: #333331 !important; color: #e5e5e3 !important; }
[data-theme="dark"] .note-filter-clear { color: #555; }
[data-theme="dark"] .note-filter-header span { color: #555 !important; }
[data-theme="dark"] .archived-note-btn { border-color: #333331; color: #aaa; }
[data-theme="dark"] .archived-note-body { color: #888; }
[data-theme="dark"] .archived-note-date { color: #555; }
[data-theme="dark"] .panel-section-fixed { border-color: #333331; }
[data-theme="dark"] .right-sidebar-collapsed-icon { color: #555; }
[data-theme="dark"] .link-item a { color: #e5e5e3; }
[data-theme="dark"] .link-delete { color: #444; }
[data-theme="dark"] .link-delete:hover { color: #e5e5e3; }
[data-theme="dark"] .ticket-input { background: #2a2a28; border-color: #333331; color: #e5e5e3; }
[data-theme="dark"] .ticket-editor { background: #2a2a28; border-color: #333331; color: #e5e5e3; }
[data-theme="dark"] .ticket-label { color: #555; }
[data-theme="dark"] .ticket-timestamp { color: #555; }
[data-theme="dark"] .ticket-divider { background: #333331; }

/* ───────────────────────── Mobile (drawer nav + responsive base) ─────────────────────────
   The sidebar + a .page-header top bar are injected on every authenticated page by sidebar.js.
   On phones the sidebar becomes an off-canvas drawer opened by the ☰ in the header; content
   takes the full width. Desktop is untouched — every rule below is inside the media query
   except the base "hidden" state of the two mobile-only elements. */
.nav-toggle { display: none; }
#sidebar-backdrop { display: none; }

@media (max-width: 768px) {
  /* Never let a page scroll/zoom sideways — content reflows within the viewport.
     The off-canvas drawer lives off the left edge but is position:fixed, so this
     doesn't clip it; child elements that need it (e.g. the schedule calendar) keep
     their own overflow-x:auto. */
  /* Clip horizontal overflow at the root only. Putting overflow-x:hidden on BODY
     turns body into a (non-scrolling) scroll container, which kills position:sticky
     on its descendants (e.g. the pinned .page-header) — so keep it off body. */
  html { overflow-x: hidden; }
  body { max-width: 100%; }
  /* Sidebar → off-canvas drawer */
  .sidebar { transform: translateX(-100%); width: 240px; z-index: 200; box-shadow: 2px 0 16px rgba(0,0,0,.18); }
  .sidebar:hover { width: 240px; }              /* neutralise the desktop hover-expand on touch */
  .sidebar .tab-label,
  .sidebar:hover a .tab-label { opacity: 1; }   /* labels always visible inside the open drawer */
  .sidebar.open { transform: translateX(0); }

  /* Dimmed backdrop behind the open drawer */
  #sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 150; opacity: 0; pointer-events: none; transition: opacity .2s ease; }
  #sidebar-backdrop.show { opacity: 1; pointer-events: auto; }

  /* Content uses the full width */
  .main { margin-left: 0; padding: 14px; }

  /* Header → compact top bar with the hamburger */
  .nav-toggle { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; padding: 4px; margin-right: 4px; background: none; border: none; color: inherit; cursor: pointer; }
  .nav-toggle svg { width: 24px; height: 24px; }
  /* Pinned top app-bar: the header stays put while the content scrolls under it,
     so the ☰ (drawer toggle) + title are always reachable. Full-bleed via negative
     margins that cancel .main's 14px padding; opaque background covers scrolled
     content; the base rule's bottom border is the divider. */
  .page-header {
    display: flex; align-items: center; gap: 10px;
    position: sticky; top: 0; z-index: 100;
    margin: 0 -14px 14px; padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
    background: #fff;
  }
  [data-theme="dark"] .page-header { background: #1a1a18; }
  .header-left { flex: 0 1 auto; min-width: 0; gap: 8px; }
  .header-center { flex: 1 1 auto; }
  .header-right { flex: 0 0 auto; }
  .page-title { flex: 0 1 auto; overflow: hidden; text-overflow: ellipsis; }
  .header-search { max-width: none; }
  .header-datetime { display: none; }

  /* The MFA gate normally leaves the 56px rail uncovered; the rail is off-canvas here, so cover all */
  #mfa-gate-overlay { left: 0; }

  /* Safety net for fixed-width dialogs that lack a max-width */
  .cm-modal, .modal, .qo-modal, .drill-modal { max-width: 95vw; }
}

/* ── Notification bell (page-header) ───────────────────────────────────────── */
.notif-wrap { position: relative; flex: 0 0 auto; }
.notif-bell { position: relative; background: none; border: none; cursor: pointer; color: #b0b0ad; padding: 4px; border-radius: 8px; display: flex; align-items: center; opacity: .85; }
.notif-bell svg { width: 17px; height: 17px; }
.notif-bell:hover { color: #555; opacity: 1; background: #f5f5f3; }
.notif-badge { position: absolute; top: -2px; right: -2px; min-width: 16px; height: 16px; padding: 0 4px; box-sizing: border-box; background: #e23b3b; color: #fff; font-size: 10px; line-height: 16px; text-align: center; border-radius: 8px; }
.notif-panel { position: absolute; top: calc(100% + 8px); right: 0; width: 320px; max-height: 420px; overflow-y: auto; background: #fff; border: 1px solid #e5e5e3; border-radius: 12px; box-shadow: 0 8px 28px rgba(0,0,0,0.12); z-index: 1000; }
.notif-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid #f0f0ee; font-size: 13px; font-weight: 600; color: #111; }
.notif-readall { background: none; border: none; color: #888; font-size: 12px; cursor: pointer; }
.notif-readall:hover { color: #111; }
.notif-empty { padding: 24px; text-align: center; color: #888; font-size: 13px; }
.notif-item { display: block; padding: 12px 14px; border-bottom: 1px solid #f5f5f3; text-decoration: none; color: inherit; }
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: #fafafa; }
.notif-item.unread { background: #f4f8ff; }
.notif-item.unread:hover { background: #eaf2ff; }
.notif-title { font-size: 13px; color: #111; font-weight: 500; }
.notif-body { font-size: 12px; color: #666; margin-top: 2px; }
.notif-time { font-size: 11px; color: #aaa; margin-top: 4px; }
[data-theme="dark"] .notif-bell { color: #aaa; }
[data-theme="dark"] .notif-bell:hover { background: #2a2a28; }
[data-theme="dark"] .notif-panel { background: #222220; border-color: #333331; }
[data-theme="dark"] .notif-head { color: #e5e5e3; border-color: #333331; }
[data-theme="dark"] .notif-empty { color: #888; }
[data-theme="dark"] .notif-item { border-color: #2a2a28; }
[data-theme="dark"] .notif-item:hover { background: #2a2a28; }
[data-theme="dark"] .notif-item.unread { background: #1e2733; }
[data-theme="dark"] .notif-item.unread:hover { background: #243040; }
[data-theme="dark"] .notif-readall:hover { color: #e5e5e3; }
[data-theme="dark"] .notif-title { color: #e5e5e3; }
[data-theme="dark"] .notif-body { color: #aaa; }
