/* The app's frame, after Plane (shell.js): a slim top bar, a sidebar on the right holding the
   pages and the project tree, and the page beside it. Loaded after app.css, so it overrides the
   old top bar. */
:root { --topbar-h: 52px; --sidebar-w: 264px; --frame-gap: 8px; }

/* Plane's frame: the top bar sits on a light grey canvas, and the sidebar and the page share one
   white panel with rounded corners below it */
body:has(.app-shell) { background: var(--canvas); }
.app-shell { background: var(--canvas); min-height: 100vh; }
.shell-top { position: sticky; top: 0; z-index: 20; }
.topbar { position: static; background: var(--canvas); border-bottom: 0; }
.shell-body { margin: 0 var(--frame-gap) var(--frame-gap); background: var(--bg); border: 1px solid var(--border); border-radius: 10px; overflow: clip; min-height: calc(100vh - var(--topbar-h) - var(--frame-gap)); }

.topbar { height: var(--topbar-h); display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 560px) minmax(0, 1fr); gap: 16px; padding: 0 12px 0 16px; padding-inline-start: 12px; }
.topbar-start { display: flex; align-items: center; gap: 6px; min-width: 0; }
.topbar .search { max-width: none; width: 100%; justify-self: center; }
.cmd-search { display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--r-btn); background: var(--bg); color: var(--muted); font: inherit; font-size: 14px; cursor: pointer; text-align: start; }
.cmd-search:hover { border-color: color-mix(in srgb, var(--text) 22%, var(--border)); color: var(--text-2); }
.cmd-search svg { position: static; flex: none; }
.cmd-search .cmd-ph { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmd-search kbd { position: static; flex: none; }
.topbar-end { justify-self: end; margin: 0; }

.ws-switch { display: inline-flex; align-items: center; gap: 10px; min-width: 0; height: 36px; padding: 0 8px; border: 0; border-radius: var(--r-btn); background: none; color: var(--text); font: inherit; font-weight: 600; font-size: 15px; cursor: pointer; }
.ws-switch:hover { background: var(--surface-2); }
.ws-switch svg { flex: none; }
.ws-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-caret { display: inline-flex; color: var(--muted); }
.ws-caret[hidden] { display: none; }

.shell-body { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); align-items: start; }
.shell-main { min-width: 0; }
.sidebar { position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h) - var(--frame-gap) - 2px); height: calc(100dvh - var(--topbar-h) - var(--frame-gap) - 2px); background: var(--bg); border-inline-end: 1px solid var(--border); z-index: 15; }
.sb-scroll { height: 100%; overflow-y: auto; padding: 14px 12px 32px; display: flex; flex-direction: column; gap: 14px; scrollbar-width: thin; }
.sb-scrim { display: none; }
body.sb-hidden .shell-body { grid-template-columns: minmax(0, 1fr); }
body.sb-hidden .sidebar { display: none; }

.sb-head { display: flex; align-items: center; gap: 6px; }
.sb-new { flex: 1; display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--r-btn); background: var(--surface); color: var(--text); font-size: 14px; font-weight: 500; box-shadow: var(--shadow); }
.sb-new:hover { background: var(--surface-2); color: var(--text); }
.sb-icon-btn { flex: none; width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: var(--r-btn); background: none; color: var(--muted); cursor: pointer; }
.sb-icon-btn:hover { background: var(--surface-2); color: var(--text); }

.sb-group, .sb-section-body { display: flex; flex-direction: column; gap: 2px; }
.sb-link, .sb-project, .sb-sublink { display: flex; align-items: center; gap: 10px; width: 100%; min-width: 0; border: 0; background: none; color: var(--text-2); font: inherit; text-align: start; cursor: pointer; border-radius: var(--r-btn); text-decoration: none; }
.sb-link { height: 34px; padding: 0 10px; font-size: 14px; font-weight: 500; }
.sb-link svg, .sb-sublink svg { flex: none; color: var(--muted); }
.sb-link:hover, .sb-project:hover, .sb-sublink:hover { background: var(--surface-2); color: var(--text); }
.sb-link[aria-current="page"], .sb-sublink[aria-current="page"] { background: var(--surface-2); color: var(--text); font-weight: 600; }
.sb-link[aria-current="page"] svg, .sb-sublink[aria-current="page"] svg { color: var(--text); }
.sb-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-badge-count { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--st-blocked); color: var(--surface); font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; }
.sb-badge-count:empty { display: none; }

.sb-section { display: flex; flex-direction: column; gap: 4px; }
.sb-section-head { display: flex; align-items: center; }
.sb-section-title { flex: 1; display: flex; align-items: center; justify-content: space-between; height: 30px; padding: 0 10px; border: 0; border-radius: var(--r-btn); background: none; color: var(--muted); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.sb-section-title:hover { color: var(--text); background: var(--surface-2); }
.sb-section-title svg { transition: transform .15s; }
.sb-section-title[aria-expanded="false"] svg { transform: rotate(90deg); }
.sb-section-body[hidden], .sb-children[hidden] { display: none; }

.sb-project { height: 34px; padding: 0 8px; font-size: 14px; font-weight: 500; color: var(--text); }
.sb-project.here { font-weight: 600; }
.sb-caret { display: inline-flex; color: var(--muted); opacity: 0; transition: transform .15s, opacity .12s; }
.sb-project:hover .sb-caret, .sb-project:focus-visible .sb-caret, .sb-project[aria-expanded="true"] .sb-caret { opacity: 1; }
.sb-project[aria-expanded="true"] .sb-caret { transform: rotate(-90deg); }
.sb-count { font-size: 11px; font-weight: 600; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 0 6px; line-height: 17px; }
.sb-badge { flex: none; width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center; border-radius: 6px; font-size: 12px; font-weight: 700; color: hsl(var(--hue) 60% 32%); background: hsl(var(--hue) 70% 92%); }
.sb-badge.sm { width: 18px; height: 18px; font-size: 10.5px; border-radius: 5px; }
:root[data-theme="dark"] .sb-badge { color: hsl(var(--hue) 70% 78%); background: hsl(var(--hue) 35% 22%); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .sb-badge { color: hsl(var(--hue) 70% 78%); background: hsl(var(--hue) 35% 22%); } }

.sb-children { display: flex; flex-direction: column; gap: 1px; margin-inline-start: 18px; padding-inline-start: 10px; border-inline-start: 1px solid var(--border); margin-block: 2px 6px; }
.sb-sublink { height: 32px; padding: 0 8px; font-size: 13.5px; }
.sb-modules { display: flex; flex-direction: column; gap: 1px; margin-top: 4px; padding-top: 4px; border-top: 1px dashed var(--border); }
.sb-modules .sb-project { height: 32px; font-size: 13.5px; }
.sb-empty { padding: 6px 10px; font-size: 13px; color: var(--muted); }

/* a project row: the row opens it, the star beside it keeps it in «المفضلة» */
.sb-row { position: relative; display: flex; align-items: center; }
.sb-row .sb-project { padding-inline-end: 34px; }
.sb-star { position: absolute; inset-inline-end: 4px; width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; opacity: 0; transition: opacity .12s; }
.sb-row:hover .sb-star, .sb-star:focus-visible, .sb-star.on { opacity: 1; }
.sb-star:hover { background: var(--surface-3); color: var(--text); }
.sb-star.on { color: #D99A00; }
.sb-star.on svg path { fill: currentColor; }
.sb-row:hover .sb-caret { opacity: 1; }
.sb-node[hidden] { display: none; }
.sb-section-head .sb-icon-btn.sm { width: 28px; height: 28px; }
.sb-filter-wrap { position: relative; display: block; margin-bottom: 4px; }
.sb-filter-wrap svg { position: absolute; inset-inline-start: 10px; top: 9px; color: var(--muted); pointer-events: none; }
.sb-filter { width: 100%; height: 32px; padding: 0 10px; padding-inline-start: 30px; border: 1px solid var(--border); border-radius: var(--r-btn); background: var(--surface-3); color: var(--text); font: inherit; font-size: 13px; }
.sb-filter:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); outline-offset: 0; background: var(--surface); }

/* the command palette (palette.js) */
dialog.cp-dialog { width: min(640px, calc(100% - 24px)); max-height: min(560px, calc(100dvh - 120px)); margin: 12vh auto auto; padding: 0; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); box-shadow: 0 24px 60px rgba(0,0,0,.25); display: flex; flex-direction: column; overflow: hidden; }
dialog.cp-dialog:not([open]) { display: none; }
dialog.cp-dialog::backdrop { background: rgba(15, 18, 24, .35); }
.cp-head { display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--border); color: var(--muted); }
.cp-input { flex: 1; min-width: 0; height: 54px; border: 0; background: none; color: var(--text); font: inherit; font-size: 16px; outline: none; }
.cp-head kbd, .cp-foot kbd { font: 11px "IBM Plex Mono", monospace; color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; background: var(--surface-2); margin-inline-end: 2px; }
.cp-list { flex: 1; overflow-y: auto; padding: 6px 8px 10px; }
.cp-group + .cp-group { margin-top: 4px; }
.cp-title { padding: 8px 10px 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.cp-item { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 6px 10px; border-radius: var(--r-btn); cursor: pointer; font-size: 14px; }
.cp-item svg { flex: none; color: var(--muted); }
.cp-item[aria-selected="true"] { background: var(--surface-2); }
.cp-item[aria-selected="true"] svg { color: var(--text); }
.cp-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cp-sub { flex: none; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; color: var(--muted); }
.cp-empty { padding: 28px 12px; text-align: center; color: var(--muted); font-size: 14px; }
.cp-foot { display: flex; gap: 18px; padding: 8px 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); background: var(--surface-3); }
@media (max-width: 860px) { dialog.cp-dialog { margin-top: 64px; } .cp-foot { display: none; } }

/* the editor fills the height under the new top bar */
.ed-grid { height: calc(100vh - var(--topbar-h) - var(--frame-gap) - 2px); height: calc(100dvh - var(--topbar-h) - var(--frame-gap) - 2px); }
.as-panel { top: calc(var(--topbar-h) + 12px); }

/* a phone: the sidebar becomes a drawer from the right, over a scrim */
@media (max-width: 860px) {
  .topbar { display: flex; height: var(--topbar-h); padding: 0 8px; }
  .topbar-end { margin-inline-start: auto; }
  .shell-body, body.sb-hidden .shell-body { grid-template-columns: minmax(0, 1fr); margin: 0; border-radius: 0; border-inline: 0; border-bottom: 0; }
  .sidebar, body.sb-hidden .sidebar { display: block; position: fixed; top: var(--topbar-h); inset-inline-start: 0; bottom: 0; height: auto; width: min(300px, 86vw); z-index: 40; transform: translateX(100%); transition: transform .2s ease; box-shadow: none; }
  body.sb-open .sidebar { transform: none; box-shadow: 0 10px 40px rgba(0,0,0,.22); }
  body.sb-open .sb-scrim { display: block; position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 39; background: rgba(15, 18, 24, .35); }
  .sb-head .sb-icon-btn { display: none; }
  .ed-grid.has-thread .ed-panel, .ed-grid.has-list .ed-panel, .ed-grid.side-open .ed-side { inset-block: var(--topbar-h) 0; }
}
@media (max-width: 860px) and (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }
.cp-input::-webkit-search-cancel-button { display: none; }
