/* ============================================================
   AIAI Portal — Shell + shared components
   Requires tokens.css. Link tokens.css first.
   Page-specific styles go in the page, not here.
   ============================================================ */

*,*::before,*::after{box-sizing:border-box;}
html,body{margin:0;padding:0;}
body{
  font-family:var(--font-sans);font-size:var(--text-base);line-height:var(--leading-normal);
  color:var(--text-primary);background:var(--bg-app);-webkit-font-smoothing:antialiased;
  opacity:0;transition:opacity var(--duration-base);
}
body.ready{opacity:1;}
h1,h2,h3,p{margin:0;}
ul{margin:0;padding:0;list-style:none;}
a{color:var(--text-link);text-decoration:none;}
a:hover{color:var(--text-link-hover);}
button,select,input,textarea{font-family:inherit;font-size:inherit;color:inherit;}
:focus-visible{outline:none;box-shadow:var(--focus-ring);border-radius:var(--radius-sm);}
.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0;}

/* ---------- app frame ---------- */
.app{display:grid;grid-template-columns:var(--sidebar-width) minmax(0,1fr);min-height:100vh;}
.app-main{min-width:0;display:flex;flex-direction:column;}

/* ---------- sidebar ---------- */
.sidebar{background:var(--bg-nav);color:var(--text-on-dark);display:flex;flex-direction:column;position:sticky;top:0;height:100vh;}
.brand{display:flex;flex-direction:column;align-items:flex-start;padding:var(--space-5) var(--space-5) var(--space-4);flex-shrink:0;color:var(--text-on-dark);}
.brand:hover{color:var(--text-on-dark);}
/* The logo is painted, not embedded: the SVG is a mask and the colour
   comes from currentColor, inherited from .brand. That's what lets one
   file render white on the blue chrome and brand blue on a light
   background later, with no second asset to keep in sync. */
.brand-mark{
  display:block;width:105px;height:36px;
  background-color:currentColor;
  -webkit-mask:url('aiai-logo.svg') no-repeat center/contain;
  mask:url('aiai-logo.svg') no-repeat center/contain;
  margin-bottom:var(--space-1);
}
.brand-sub{font-size:var(--text-xs);font-weight:var(--weight-bold);text-transform:uppercase;letter-spacing:var(--tracking-wide);color:var(--text-on-dark);margin-top:var(--space-1);line-height:1.3;}

.nav{
  flex:1;overflow-y:auto;padding:var(--space-1) var(--space-3) var(--space-3);
  scrollbar-width:thin;scrollbar-color:rgba(255,255,255,.22) transparent;
}
.nav::-webkit-scrollbar{width:6px;}
.nav::-webkit-scrollbar-track{background:transparent;}
.nav::-webkit-scrollbar-thumb{background:rgba(255,255,255,.18);border-radius:var(--radius-full);}
.nav::-webkit-scrollbar-thumb:hover{background:rgba(255,255,255,.32);}
.nav-eyebrow{font-size:var(--text-xs);text-transform:uppercase;letter-spacing:var(--tracking-wide);color:var(--text-on-dark-muted);padding:var(--space-4) var(--space-3) var(--space-1);}
.nav-toggle{display:flex;align-items:center;justify-content:space-between;width:100%;background:none;border:0;font-family:inherit;cursor:pointer;text-align:left;border-radius:var(--radius-md);}
.nav-toggle:hover{color:var(--text-on-dark);}
.nav-toggle:focus-visible{outline:2px solid var(--text-on-dark);outline-offset:-2px;}
.nav-chev{width:14px;height:14px;flex:none;transition:transform var(--duration-fast) var(--ease);}
.nav-toggle[aria-expanded="false"] .nav-chev{transform:rotate(-90deg);}
.nav-group[hidden]{display:none;}
.nav-allbar{display:flex;justify-content:flex-end;padding:var(--space-1) var(--space-3) 0;}
.nav-all{background:none;border:0;font-family:inherit;font-size:var(--text-xs);color:var(--text-on-dark-muted);cursor:pointer;padding:2px 0;}
.nav-all:hover{color:var(--text-on-dark);text-decoration:underline;}
.nav-all:focus-visible{outline:2px solid var(--text-on-dark);outline-offset:2px;border-radius:var(--radius-sm);}
.nav-item{
  display:flex;align-items:center;gap:var(--space-3);
  padding:var(--space-2) var(--space-3);margin-bottom:1px;
  border-radius:var(--radius-md);
  color:var(--text-on-dark);font-size:var(--text-base);font-weight:var(--weight-semibold);
  line-height:1.35;
  transition:background var(--duration-fast) var(--ease);
}
.nav-item:hover{background:var(--navy-raised);color:var(--text-on-dark);}
.nav-item[aria-current="page"]{background:var(--navy-active);color:var(--text-on-dark);}
.nav-item[aria-current="page"]:hover{background:var(--navy-active);}
/* Unbuilt modules stay legible — they open the "in development" dialog. */
.nav-item[data-unbuilt]{color:rgba(255,255,255,.72);cursor:pointer;}
.nav-item[data-unbuilt]:hover{background:var(--navy-raised);color:var(--text-on-dark);}
.nav-icon{width:19px;height:19px;flex-shrink:0;opacity:.9;}

.sidebar-foot{padding:var(--space-3) var(--space-5) var(--space-4);flex-shrink:0;border-top:1px solid rgba(255,255,255,.10);}
.who{font-size:var(--text-sm);font-weight:var(--weight-medium);}
.who-org{font-size:var(--text-xs);color:var(--text-on-dark-muted);margin-top:2px;line-height:1.35;}
.tagline{margin-top:var(--space-3);padding-top:var(--space-2);border-top:2px solid var(--aiai-yellow);font-size:10px;line-height:1.45;text-transform:uppercase;letter-spacing:var(--tracking-wide);color:var(--aiai-yellow);}
.build{display:inline-block;margin-top:var(--space-2);font-size:10px;color:var(--text-on-dark-muted);font-variant-numeric:tabular-nums;opacity:.7;}

/* ---------- topbar (dark, per concept screens) ---------- */
.topbar{
  height:var(--topbar-height);background:var(--bg-topbar);
  display:flex;align-items:center;gap:var(--space-4);
  padding:0 var(--content-pad);position:sticky;top:0;z-index:20;
}
.topbar-title{font-size:var(--text-lg);font-weight:var(--weight-bold);color:var(--text-on-dark);letter-spacing:-.01em;white-space:nowrap;}
.topbar-right{margin-left:auto;display:flex;align-items:center;gap:var(--space-3);flex-shrink:0;}

.tsearch{position:relative;flex:0 1 220px;min-width:140px;}
.tsearch input{
  width:100%;height:34px;border:0;border-radius:var(--radius-md);
  background:var(--bg-surface);color:var(--text-heading);
  font-size:var(--text-sm);padding:0 34px 0 var(--space-3);cursor:pointer;
}
.tsearch input::placeholder{color:var(--ink-400);}
.tsearch-icon{position:absolute;right:11px;top:50%;transform:translateY(-50%);width:16px;height:16px;color:var(--action-primary);pointer-events:none;}

.tbell{position:relative;color:var(--text-on-dark);background:none;border:0;padding:var(--space-1);cursor:pointer;display:flex;flex-shrink:0;}
.tbell svg{width:20px;height:20px;}

.avibtn{flex-shrink:0;}

.signout{height:32px;padding:0 var(--space-3);border:1px solid rgba(255,255,255,.32);background:transparent;border-radius:var(--radius-md);font-size:var(--text-sm);font-weight:var(--weight-medium);color:var(--text-on-dark);cursor:pointer;white-space:nowrap;flex-shrink:0;line-height:1;transition:background var(--duration-fast) var(--ease);}
.signout:hover{background:rgba(255,255,255,.12);}

/* ---------- content ---------- */
.content{max-width:var(--content-max);padding:var(--space-6) var(--content-pad) var(--space-12);}
.page-head{display:flex;align-items:baseline;gap:var(--space-3);flex-wrap:wrap;margin-bottom:var(--space-5);}
.page-title{font-size:var(--text-2xl);letter-spacing:var(--tracking-tight);color:var(--text-heading);font-weight:var(--weight-semibold);}
.page-sub{font-size:var(--text-sm);color:var(--text-muted);}

/* ---------- shared components ---------- */
.card{background:var(--bg-surface);border:1px solid var(--border-default);border-radius:var(--radius-md);box-shadow:var(--shadow-card);position:relative;overflow:hidden;}
.card-pad{padding:var(--space-5);}
.card-title{font-size:var(--text-lg);color:var(--text-heading);font-weight:var(--weight-semibold);}
.card-lead{font-size:var(--text-md);font-weight:var(--weight-semibold);color:var(--text-heading);line-height:var(--leading-tight);margin:var(--space-1) 0 var(--space-3);}
.card-foot{margin-top:var(--space-4);padding-top:var(--space-3);border-top:1px solid var(--border-default);font-size:var(--text-xs);color:var(--text-muted);line-height:var(--leading-normal);}

/* Coloured bottom rule, per concept screens */
.card--accent::after{content:"";position:absolute;left:0;right:0;bottom:0;height:4px;background:var(--card-accent,transparent);}
.card--accent-teal{--card-accent:var(--accent-teal);}
.card--accent-yellow{--card-accent:var(--accent-yellow);}
.card--accent-blue{--card-accent:var(--accent-blue);}

/* Circular icon badge */
.badge{width:44px;height:44px;border-radius:var(--radius-full);display:grid;place-items:center;color:var(--white);flex-shrink:0;}
.badge svg{width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round;}
.badge--blue{background:var(--action-primary);}
.badge--teal{background:var(--aiai-teal);}
.badge--navy{background:var(--navy);}

.section-head{display:flex;align-items:center;justify-content:space-between;gap:var(--space-3);margin-bottom:var(--space-3);}
.section-title{font-size:var(--text-xs);text-transform:uppercase;letter-spacing:var(--tracking-wide);color:var(--text-muted);font-weight:var(--weight-semibold);}
.section-meta{font-size:var(--text-xs);color:var(--ink-400);}

.pill{display:inline-flex;align-items:center;border-radius:var(--radius-full);padding:2px var(--space-2);font-size:var(--text-xs);font-weight:var(--weight-medium);white-space:nowrap;flex-shrink:0;}
.pill-success{background:var(--success-tint);color:var(--success-ink);}
.pill-warning{background:var(--warning-tint);color:var(--warning);}
.pill-danger{background:var(--danger-tint);color:var(--danger);}
.pill-info{background:var(--info-tint);color:var(--blue-700);}
.pill-neutral{background:var(--bg-sunken);color:var(--text-muted);}

.btn{display:inline-flex;align-items:center;justify-content:center;gap:var(--space-2);border-radius:var(--radius-md);font-size:var(--text-sm);font-weight:var(--weight-medium);padding:var(--space-2) var(--space-4);cursor:pointer;white-space:nowrap;border:1px solid transparent;background:transparent;transition:background var(--duration-fast) var(--ease);}
.btn-primary{background:var(--action-primary);color:var(--action-primary-text);}
.btn-primary:hover{background:var(--action-primary-hover);color:var(--action-primary-text);}
.btn-secondary{border-color:var(--border-strong);color:var(--text-heading);}
.btn-secondary:hover{background:var(--bg-sunken);color:var(--text-heading);}
.btn-danger{border-color:var(--border-strong);color:var(--danger);background:var(--bg-surface);}
.btn-danger:hover{background:var(--danger-tint);}
.btn svg{width:15px;height:15px;stroke:currentColor;stroke-width:2.2;fill:none;}

.state{padding:var(--space-10) var(--space-5);text-align:center;}
.state .t{color:var(--text-heading);font-weight:var(--weight-medium);}
.state .b{font-size:var(--text-sm);color:var(--text-muted);margin-top:var(--space-1);}

.kv{display:flex;justify-content:space-between;gap:var(--space-3);padding:var(--space-2) 0;font-size:var(--text-sm);}
.kv+.kv{border-top:1px solid var(--border-default);}
.kv-k{color:var(--text-muted);}
.kv-v{color:var(--text-heading);font-weight:var(--weight-medium);text-align:right;}

.avi{display:inline-block;border-radius:var(--radius-full);background-size:cover;background-position:center;flex-shrink:0;vertical-align:middle;}
.avi--ph{background:var(--ink-100);display:inline-flex;align-items:center;justify-content:center;}
.avi--ph svg{width:62%;height:62%;fill:var(--ink-400);}
.avibtn{width:32px;height:32px;padding:0;border:1px solid rgba(255,255,255,.32);border-radius:var(--radius-full);background:var(--ink-100);cursor:pointer;overflow:hidden;background-size:cover;background-position:center;display:inline-flex;align-items:center;justify-content:center;}
.avibtn svg{width:60%;height:60%;fill:var(--ink-400);}
.avibtn:hover{border-color:var(--white);}

.foot{border-top:1px solid var(--border-default);margin-top:var(--space-10);padding:var(--space-5) 0;display:flex;gap:var(--space-4);align-items:center;flex-wrap:wrap;font-size:var(--text-xs);color:var(--text-muted);}
.foot a{color:var(--text-muted);}
.foot-copy{margin-left:auto;}

/* ---------- Tech Support side panel (shell.js mountSupportPanel) ----------
   Sits above page modals (z-index 100) so it can open from anywhere. */
.spanel[hidden]{display:none;}
.spanel{position:fixed;inset:0;z-index:200;}
.spanel__bd{position:absolute;inset:0;background:rgba(7,34,64,.35);}
.spanel__box{position:absolute;top:0;right:0;bottom:0;width:min(520px,100%);background:var(--bg-app);box-shadow:var(--shadow-lg);display:flex;flex-direction:column;animation:spanel-in .18s ease-out;}
@keyframes spanel-in{from{transform:translateX(24px);opacity:.6;}to{transform:none;opacity:1;}}
@media (prefers-reduced-motion:reduce){.spanel__box{animation:none;}}
.spanel__head{display:flex;align-items:center;gap:var(--space-3);padding:var(--space-3) var(--space-3) var(--space-3) var(--space-5);border-bottom:1px solid var(--border-default);background:var(--bg-surface);}
.spanel__head h3{flex:1;font-size:var(--text-lg);font-weight:var(--weight-bold);color:var(--text-heading);}
.spanel__head .soon-close{position:static;}
.spanel__full{font-size:var(--text-sm);color:var(--text-muted);}
.spanel__full:hover{color:var(--text-heading);}
.spanel__frame{flex:1;width:100%;border:0;display:block;background:var(--bg-app);}
html.spanel-open,html.spanel-open body{overflow:hidden;}

/* ---------- modals ---------- */
.modal[hidden]{display:none;}
.modal{position:fixed;inset:0;z-index:100;display:flex;align-items:center;justify-content:center;padding:var(--space-6);}
.modal__backdrop,.modal__bd{position:absolute;inset:0;background:rgba(7,34,64,.55);}
.modal__box{position:relative;background:var(--bg-surface);border-radius:var(--radius-lg);max-width:440px;width:100%;box-shadow:var(--shadow-lg);padding:var(--space-6);}
.modal__box h3{font-size:var(--text-lg);font-weight:var(--weight-semibold);color:var(--text-heading);margin-bottom:var(--space-4);}
.modal__actions{display:flex;justify-content:flex-end;gap:var(--space-2);margin-top:var(--space-4);}
.modal__err{color:var(--danger);font-size:var(--text-sm);margin-top:var(--space-1);min-height:0;}
.fld{margin-bottom:var(--space-4);}
.fld label{display:block;font-size:var(--text-xs);font-weight:var(--weight-medium);color:var(--text-muted);margin-bottom:var(--space-2);text-transform:uppercase;letter-spacing:var(--tracking-wide);}
.fld input,.fld textarea,.fld select{width:100%;padding:var(--space-2) var(--space-3);font-size:var(--text-base);color:var(--text-heading);background:var(--bg-surface);border:1px solid var(--border-strong);border-radius:var(--radius-sm);}
.fld textarea{min-height:70px;resize:vertical;}
.fld input:focus,.fld textarea:focus,.fld select:focus{outline:none;border-color:var(--border-focus);box-shadow:var(--focus-ring);}

/* ---------- "in development" dialog ----------
   Injected by shell.js. Opens for anything with [data-unbuilt]. */
.modal__box--soon{max-width:430px;text-align:center;padding:var(--space-8) var(--space-8) var(--space-6);overflow:hidden;}
.modal__box--soon::before{content:"";position:absolute;left:0;right:0;top:0;height:4px;background:var(--aiai-yellow);border-radius:var(--radius-lg) var(--radius-lg) 0 0;}
.soon-eyebrow{font-size:var(--text-xs);font-weight:var(--weight-bold);text-transform:uppercase;letter-spacing:var(--tracking-wide);color:var(--aiai-teal-deep);margin-bottom:var(--space-3);min-height:16px;}
.modal__box--soon h3{font-size:var(--text-xl);font-weight:var(--weight-bold);line-height:var(--leading-tight);margin-bottom:var(--space-3);}
.soon-body{font-size:var(--text-base);line-height:var(--leading-relaxed);color:var(--text-primary);}
.soon-ok{margin-top:var(--space-6);}
.soon-close{position:absolute;top:var(--space-3);right:var(--space-3);width:30px;height:30px;border:0;border-radius:var(--radius-sm);background:transparent;color:var(--text-muted);cursor:pointer;display:grid;place-items:center;}
.soon-close:hover{background:var(--bg-sunken);color:var(--text-heading);}
.soon-close svg{width:17px;height:17px;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;}

/* ---------- profile dialog ----------
   Injected by shell.js, opened by the topbar avatar button. Shared, so it
   works on every module page — it was page-local to the dashboard before.
   The email is the signed-in account address; keep it selectable, it gets
   read and copied during multi-account testing. */
.modal__box--pf{max-width:380px;text-align:center;}
.pf-avi{width:120px;height:120px;margin:0 auto var(--space-4);}
.pf-who{margin-bottom:var(--space-5);}
.pf-name{font-size:var(--text-md);font-weight:var(--weight-semibold);color:var(--text-heading);line-height:var(--leading-tight);}
.pf-eyebrow{font-size:var(--text-xs);text-transform:uppercase;letter-spacing:var(--tracking-wide);color:var(--text-muted);margin-top:var(--space-3);}
.pf-email{font-size:var(--text-sm);color:var(--text-heading);margin-top:2px;word-break:break-all;user-select:text;}
.pf-actions{display:flex;flex-direction:column;gap:var(--space-2);}
.pf-btn{height:40px;border-radius:var(--radius-md);font-size:var(--text-sm);font-weight:var(--weight-medium);cursor:pointer;border:1px solid transparent;display:flex;align-items:center;justify-content:center;}
.pf-upload{background:var(--action-primary);color:var(--action-primary-text);}
.pf-upload:hover{background:var(--action-primary-hover);}
.pf-remove{background:var(--bg-surface);border-color:var(--border-strong);color:var(--danger);}
.pf-remove:hover{background:var(--danger-tint);}
.pf-close{background:var(--bg-surface);border-color:var(--border-strong);color:var(--text-heading);}
.pf-close:hover{background:var(--bg-sunken);}
.pf-msg{font-size:var(--text-xs);color:var(--text-muted);min-height:16px;margin-top:var(--space-3);text-align:center;}
.pf-cropview{width:240px;height:240px;margin:0 auto var(--space-4);border-radius:var(--radius-full);overflow:hidden;position:relative;background:var(--ink-100);cursor:grab;touch-action:none;user-select:none;}
.pf-cropview:active{cursor:grabbing;}
.pf-cropview img{position:absolute;left:0;top:0;max-width:none;pointer-events:none;-webkit-user-drag:none;}
.pf-zoom{width:100%;margin:0 0 var(--space-2);accent-color:var(--action-primary);}
.pf-hint{font-size:var(--text-xs);color:var(--text-muted);margin-bottom:var(--space-4);text-align:center;}

@media (max-width:820px){
  .app{grid-template-columns:1fr;}
  .sidebar{position:static;height:auto;}
  .nav{max-height:none;}
}
@media (max-width:520px){
  :root{--content-pad:var(--space-4);}
  .topbar-title{display:none;}
  .tsearch{flex:1 1 auto;min-width:0;}
  .signout{display:none;}
}

/* The `hidden` attribute is only display:none in the UA stylesheet, so any
   author-level display rule (.btn uses flex) silently defeats it. This makes
   hidden win globally. */
[hidden]{display:none!important;}

/* Modal action rows can carry four buttons and need to wrap on narrow screens. */
.modal__actions{flex-wrap:wrap;gap:var(--space-2);}
