/* The app shell, like a chat app: a light side menu on the right (a new conversation and search first, then the
   work in groups from app/modules.py SIDEBAR, the recent conversations, the credit and the person's menu), foldable
   to icons; a slim bar over the page (who to talk to, charge, settings, guide); the tabs of the current section.
   On tablets the menu is a drawer, on phones a bottom bar too. */

.skip { position:absolute; right:-999px; top:8px; background:var(--primary); color:#fff; padding:8px 14px; border-radius:6px; z-index:1000; }
.skip:focus { right:8px; }

.app { display:grid; grid-template-columns:var(--side) 1fr; min-height:100dvh; transition:grid-template-columns .2s var(--ease); }
main { padding:12px 36px 60px; max-width:1240px; width:100%; margin:0 auto; min-width:0; }

/* ---- the side menu ---- */
.side { background:var(--surface); border-inline-start:0; border-left:1px solid var(--line); color:var(--ink-2);
        position:sticky; top:0; height:100dvh; display:flex; flex-direction:column; padding:14px 12px 12px; gap:4px; min-width:0; }
.side-top { display:flex; align-items:center; justify-content:space-between; gap:8px; padding:0 4px 10px; }
.brand { display:flex; align-items:center; gap:10px; color:var(--primary); font-weight:800; font-size:20px; line-height:1.4;
         text-decoration:none; min-width:0; }
.brand:hover { color:var(--primary); }
.brand .logo, .tb-brand .logo { width:34px; height:34px; border-radius:26%; background:var(--brand-grad); color:#fff; display:grid;
               place-items:center; flex:none; box-shadow:var(--glow); }
.side-btn { width:36px; height:36px; min-height:36px; padding:0; border-radius:10px; display:grid; place-items:center;
            background:transparent; color:var(--muted); border:0; box-shadow:none; }
.side-btn:hover { background:var(--surface-2); color:var(--ink); transform:none; box-shadow:none; }
.side .new-chat { display:flex; align-items:center; gap:10px; padding:10px 14px; min-height:46px; border-radius:14px;
                  background:var(--accent-soft); color:var(--accent); font-weight:700; text-decoration:none;
                  border:1px solid var(--soft-line); }
.side .new-chat:hover { background:var(--soft-hover); color:var(--accent); }
.side .side-search { display:flex; align-items:center; gap:10px; padding:8px 14px; min-height:42px; border-radius:12px;
                     color:var(--ink-2); text-decoration:none; font-size:14px; }
.side .side-search:hover, .side .side-search[aria-current] { background:var(--surface-2); color:var(--ink); }
.side-scroll { flex:1; overflow-y:auto; overflow-x:hidden; margin:6px -4px 0; padding:0 4px; border-top:1px solid var(--line); }
.side-group { padding:6px 0 4px; border-bottom:1px solid var(--line); }
.side-group:last-child { border-bottom:0; }
.side-group > summary { list-style:none; cursor:pointer; display:flex; align-items:center; justify-content:space-between;
                        padding:8px 10px 4px; font-size:12.5px; font-weight:700; color:var(--accent); border-radius:8px; }
.side-group > summary::-webkit-details-marker { display:none; }
.side-group > summary .ic { color:var(--muted); transition:transform .15s var(--ease); }
.side-group:not([open]) > summary .ic { transform:rotate(90deg); }
.side nav { display:flex; flex-direction:column; gap:1px; }
.side nav a { display:flex; align-items:center; gap:10px; color:var(--ink); padding:5px 8px; border-radius:12px; min-height:42px;
              font-weight:500; font-size:14.5px; text-decoration:none; transition:background .15s var(--ease); }
.side nav a .i { width:30px; height:30px; border-radius:9px; display:grid; place-items:center; flex:none;
                 background:var(--surface-2); color:var(--accent); }
.side nav a .label { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; min-width:0; }
.side nav a:hover { background:var(--surface-2); color:var(--ink); }
.side nav a[aria-current="page"] { background:var(--accent-soft); color:var(--accent); font-weight:600; }
.side nav a[aria-current="page"] .i { background:var(--accent); color:#fff; }
.side nav.chats a { min-height:38px; font-size:13.5px; font-weight:400; color:var(--ink-2); }
.side nav.chats a .i { background:transparent; color:var(--muted); width:22px; }
.side nav.chats a.all { color:var(--accent); }
.badge { margin-inline-start:auto; background:var(--spark); color:#fff; font-size:var(--t-xs); font-weight:700;
         border-radius:99px; padding:0 8px; min-width:22px; line-height:22px; text-align:center; flex:none; }
.side-foot { border-top:1px solid var(--line); padding-top:8px; display:flex; flex-direction:column; gap:4px; }
.side .wallet { display:flex; align-items:center; gap:10px; padding:6px 8px; border-radius:12px; color:var(--ink); text-decoration:none;
                font-size:13.5px; min-height:42px; }
.side .wallet .i { width:30px; height:30px; border-radius:9px; display:grid; place-items:center; background:var(--surface-2); color:var(--accent); flex:none; }
.side .wallet .label { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.side .wallet b { font-weight:700; }
.side .wallet .charge { margin-inline-start:auto; color:var(--spark); font-weight:700; font-size:13px; }
.side .wallet:hover { background:var(--surface-2); }
.me { position:relative; }
.me > summary { list-style:none; cursor:pointer; display:flex; align-items:center; gap:10px; padding:6px 8px; border-radius:12px; min-height:46px; }
.me > summary::-webkit-details-marker { display:none; }
.me > summary:hover, .me[open] > summary { background:var(--surface-2); }
.me > summary .label { display:flex; flex-direction:column; min-width:0; line-height:1.4; flex:1; }
.me > summary b { font-weight:600; color:var(--ink); font-size:14px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.me > summary small { color:var(--muted); font-size:11.5px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.me > summary > .ic { color:var(--muted); transform:rotate(-90deg); }
.avatar { width:32px; height:32px; border-radius:50%; background:var(--grad); color:#fff; display:grid; place-items:center;
          font-weight:700; flex:none; font-size:15px; }
.me-pop { position:absolute; bottom:calc(100% + 6px); inset-inline:0; z-index:30; background:var(--surface); border:1px solid var(--line);
          border-radius:14px; box-shadow:var(--shadow-lg); padding:8px; display:flex; flex-direction:column; gap:4px; }
.me-pop .me-who { font-size:12px; color:var(--muted); padding:2px 8px 4px; }
.me-pop a { display:flex; gap:8px; align-items:center; padding:8px; border-radius:10px; color:var(--ink); min-height:40px; text-decoration:none; }
.me-pop a:hover { background:var(--surface-2); }
.me-pop form { margin:0; }
.me-pop button { width:100%; justify-content:flex-start; }
.me-pop .hint { font-size:11.5px; color:var(--muted); }

/* folded: icons only (desktop) */
.app.folded { grid-template-columns:76px 1fr; }
.app.folded .side { padding-inline:10px; }
.app.folded .side .label, .app.folded .side-group > summary, .app.folded .side .badge, .app.folded .wallet .charge,
.app.folded .me > summary > .ic, .app.folded nav.chats { display:none; }
.app.folded .side-top { flex-direction:column; padding-inline:0; }
.app.folded .new-chat, .app.folded .side-search, .app.folded .side nav a, .app.folded .wallet, .app.folded .me > summary { justify-content:center; padding-inline:0; }
.app.folded .side-group { padding:4px 0; }
.app.folded .me-pop { inset-inline:0 auto; width:240px; }

/* ---- the bar over the page ---- */
.deskbar { display:flex; align-items:center; gap:8px; min-height:52px; margin:0 0 var(--s4); }
.deskbar .grow { flex:1; }
.icon-btn { width:40px; height:40px; border-radius:12px; display:grid; place-items:center; color:var(--ink-2); text-decoration:none; }
.icon-btn:hover { background:var(--surface-2); color:var(--ink); }
.pill-btn { display:inline-flex; align-items:center; gap:6px; padding:6px 14px; min-height:36px; border-radius:99px;
            background:var(--accent-soft); color:var(--accent); font-weight:600; font-size:13.5px; text-decoration:none; }
.pill-btn:hover { background:var(--soft-hover); color:var(--accent); }
.pick { position:relative; }
.pick > summary { list-style:none; cursor:pointer; display:inline-flex; align-items:center; gap:8px; padding:8px 16px; min-height:44px;
                  border-radius:99px; background:var(--surface); border:1px solid var(--line-2); font-weight:600; color:var(--ink); }
.pick > summary::-webkit-details-marker { display:none; }
.pick > summary .ic:first-child { color:var(--accent); }
.pick > summary:hover, .pick[open] > summary { border-color:var(--accent); }
.pick-menu { position:absolute; top:calc(100% + 6px); inset-inline-start:0; z-index:30; background:var(--surface); border:1px solid var(--line);
             border-radius:14px; box-shadow:var(--shadow-lg); padding:6px; min-width:280px; max-height:60vh; overflow:auto; }
.pick-menu a { display:flex; gap:8px; align-items:center; padding:8px 10px; border-radius:10px; color:var(--ink); min-height:42px; text-decoration:none; }
.pick-menu a .muted { margin-inline-start:auto; font-size:12px; }
.pick-menu a:hover, .pick-menu a[aria-current] { background:var(--surface-2); }
.topbar { display:none; }

/* ---- the current section's tabs ---- */
.hub-tabs { display:flex; gap:6px; margin:0 0 var(--s5); overflow-x:auto; scrollbar-width:none; padding-bottom:2px; }
.hub-tabs a { display:inline-flex; align-items:center; gap:6px; padding:6px 16px; font-weight:500; color:var(--ink-2);
              border-radius:99px; border:1px solid var(--line); background:var(--surface); white-space:nowrap; text-decoration:none; min-height:38px; }
.hub-tabs a:hover { color:var(--ink); border-color:var(--line-2); }
.hub-tabs a[aria-current="page"] { color:var(--accent); background:var(--accent-soft); border-color:var(--soft-line); font-weight:600; }
.hub-tabs .badge { margin-inline-start:2px; }

/* ---- a page's header: title, one line, one main action ---- */
.page-head, .page-title { display:flex; align-items:center; justify-content:space-between; gap:var(--s4); flex-wrap:wrap;
                          margin:0 0 var(--s5); animation:enter .3s var(--ease) both; }
.page-head h1, .page-title h1 { margin:0; font-size:var(--t-lg); font-weight:700; line-height:1.5; }
.page-head p { margin:2px 0 0; color:var(--muted); }
.page-head .actions { margin-inline-start:auto; }
.page-title .spacer { flex:1; }
@keyframes enter { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:none; } }

/* ---- tablet: the menu becomes a drawer ---- */
@media (max-width: 1023px) {
  .app, .app.folded { grid-template-columns:1fr; }
  .app.folded .side .label, .app.folded .side-group > summary, .app.folded nav.chats { display:revert; }
  /* closed menu: hidden, not just moved off-screen (in RTL an off-screen fixed element widens the page) */
  .side { position:fixed; top:0; bottom:0; right:0; width:min(300px, 88vw); height:100dvh; visibility:hidden;
          transform:translateX(100%); transition:transform .2s var(--ease), visibility 0s linear .2s; z-index:40;
          box-shadow:-8px 0 24px rgba(20,18,43,.18); }
  .side.open { transform:none; visibility:visible; transition:transform .2s var(--ease); }
  #side-fold { display:none; }
  .scrim { position:fixed; inset:0; background:rgba(27,24,64,.4); z-index:30; display:none; }
  .scrim.open { display:block; }
  .topbar { display:flex; align-items:center; gap:8px; background:var(--glass); color:var(--ink); padding:6px 10px;
            position:sticky; top:0; z-index:20; border-bottom:1px solid var(--line); backdrop-filter:blur(8px); }
  .topbar button { background:transparent; border:0; color:var(--ink); min-width:44px; min-height:44px; justify-content:center; box-shadow:none; }
  .topbar button:hover { background:transparent; transform:none; box-shadow:none; }
  .tb-brand { display:flex; align-items:center; gap:8px; color:var(--primary); font-weight:800; font-size:17px; text-decoration:none; }
  .tb-brand .logo { width:28px; height:28px; }
  .tb-new { margin-inline-start:auto; width:44px; height:44px; display:grid; place-items:center; color:var(--accent); border-radius:12px; }
  .deskbar { min-height:0; margin-bottom:var(--s3); }
  .deskbar .icon-btn, .deskbar .pill-btn { display:none; }
  main { padding:var(--s4) var(--s4) 48px; }
}

/* ---- phone: a bottom bar with the main sections ---- */
.bottombar { display:none; }
@media (max-width: 640px) {
  main { padding:var(--s3) var(--s3) 96px; }
  .page-head h1, .page-title h1 { font-size:20px; }
  .bottombar { display:flex; position:fixed; bottom:0; left:0; right:0; z-index:25; background:var(--glass);
               border-top:1px solid var(--line); padding:4px 4px calc(4px + env(safe-area-inset-bottom));
               box-shadow:0 -8px 24px -16px rgba(76,29,149,.35); }
  .bottombar a, .bottombar button { flex:1; display:flex; flex-direction:column; align-items:center; gap:2px; font-size:var(--t-xs);
               color:var(--muted); background:transparent; border:0; padding:6px 0; min-height:54px; text-decoration:none;
               position:relative; box-shadow:none; font-weight:500; }
  .bottombar button:hover { background:transparent; transform:none; box-shadow:none; color:var(--muted); }
  .bottombar a[aria-current="page"] { color:var(--accent); font-weight:600; }
  .bottombar a[aria-current="page"]::before { content:""; position:absolute; top:0; width:26px; height:3px; border-radius:0 0 4px 4px; background:var(--grad); }
  .bottombar .badge { position:absolute; top:2px; left:calc(50% - 24px); margin:0; }
  .toast { bottom:80px; }
}

/* the theme picker in the person's menu */
.theme-pick { display:flex; flex-wrap:wrap; align-items:center; gap:4px; padding:6px 8px 8px; border-top:1px solid var(--line); margin-top:4px; }
.theme-pick span { width:100%; font-size:12px; color:var(--muted); }
.theme-pick button { flex:1; min-height:34px; padding:0 6px; font-size:12px; font-weight:500; border-radius:9px; background:var(--surface-2);
                     color:var(--ink-2); border:1px solid transparent; box-shadow:none; }
.theme-pick button:hover { transform:none; box-shadow:none; color:var(--ink); background:var(--surface-2); }
.theme-pick button[aria-pressed="true"] { background:var(--accent-soft); color:var(--accent); border-color:var(--soft-line); font-weight:700; }
