/* =========================================================================
   BuildSphere design system
   One stylesheet shared by BIM, WMS and (future) FMS screens.

   Principles
   - Neutral grey canvas, white working surfaces, navy navigation.
   - One accent (blue). Colour elsewhere is reserved for status.
   - 13px base type, 4/6px radii, 1px borders, no gradients or motion
     beyond colour transitions.
   - Section order: tokens > base > shell > page header > surfaces >
     buttons > forms > badges > dashboard blocks > overlays.
   ========================================================================= */

:root{
  /* Surfaces */
  --bg:#eef1f5; --surface:#ffffff; --surface-alt:#f6f8fb; --chip-bg:#eef1f5;
  --border:#d6dce5; --border-soft:#e6eaf0; --border-hover:#bcc5d2;
  /* Text */
  --text:#1a2332; --text-2:#444f5f; --text-3:#667182; --muted:#8892a1;
  /* Logo square: change this one line to recolour the logo everywhere */
  --logo-bg:linear-gradient(135deg, #2dd4bf, #0d9488);
  /* Brand accent */
  --primary:#1f5fbf; --primary-dark:#174b98; --primary-tint:#e7eefa; --primary-ring:rgba(31,95,191,0.22);
  --accent:#1f5fbf; --accent-dark:#174b98;
  /* Status (semantic only) */
  --good-bg:#e3f2e7; --good-text:#1b6e37; --good-ink:#1b6e37;
  --warn-bg:#fbefd0; --warn-text:#80560a; --warn-ink:#80560a;
  --bad-bg:#fae4e4;  --bad-text:#a82424;  --bad-ink:#b42323;
  --info-bg:#e7eefa; --info-text:#174b98;
  --ai-bg:#f3f1fb; --ai-border:#dcd7f2; --ai-chip:#e9e5f8; --ai-text:#5b3fb0;
  /* Navigation */
  --nav-bg:#193B61; --nav-bg-hover:#214670; --nav-bg-active:#264D7A; --nav-border:#2A5282;
  --nav-text:#d3dfee; --nav-muted:#8fa8c6; --nav-accent:#6ab8f5;
  /* Shape + type */
  --radius-lg:6px; --radius-md:6px; --radius-sm:4px;
  --font:'Inter','Segoe UI',-apple-system,BlinkMacSystemFont,Roboto,Arial,sans-serif;
  --overlay-surface:#ffffff; --overlay-divider:#e6eaf0; --overlay-hover:#f2f5f9;
  --shadow-pop:0 6px 24px rgba(15,28,46,0.16), 0 1px 3px rgba(15,28,46,0.10);
  color-scheme:light;
}
html[data-theme="dark"]{
  --bg:#0c121b; --surface:#141c28; --surface-alt:#182231; --chip-bg:#1b2636;
  --border:#2a3547; --border-soft:#202b3b; --border-hover:#3a4860;
  --text:#e8edf4; --text-2:#c0cad8; --text-3:#93a0b3; --muted:#6f7d92;
  --primary:#4d8ee8; --primary-dark:#8ab7f5; --primary-tint:rgba(77,142,232,0.16); --primary-ring:rgba(77,142,232,0.30);
  --accent:#4d8ee8; --accent-dark:#8ab7f5;
  --good-bg:rgba(52,168,92,0.16); --good-text:#6fd48f; --good-ink:#6fd48f;
  --warn-bg:rgba(230,170,40,0.16); --warn-text:#f0bf55; --warn-ink:#f0bf55;
  --bad-bg:rgba(220,70,70,0.18); --bad-text:#f58a8a; --bad-ink:#f58a8a;
  --info-bg:rgba(77,142,232,0.16); --info-text:#8ab7f5;
  --ai-bg:rgba(139,92,246,0.10); --ai-border:rgba(139,92,246,0.28); --ai-chip:rgba(139,92,246,0.20); --ai-text:#c4b5fd;
  --nav-bg:#0a1220; --nav-bg-hover:#131f33; --nav-bg-active:#1a2d4a; --nav-border:#1a2840;
  --overlay-surface:#141c28; --overlay-divider:#2a3547; --overlay-hover:#1b2636;
  --shadow-pop:0 8px 28px rgba(0,0,0,0.5);
  color-scheme:dark;
}

/* ---------- Base ---------- */
*{box-sizing:border-box;}
html,body{margin:0; padding:0; width:100%;}
body{
  font-family:var(--font); font-size:13px; line-height:1.45;
  color:var(--text); background:var(--bg);
  -webkit-font-smoothing:antialiased;
}
a{color:var(--primary); text-decoration:none;}
a:hover{color:var(--primary-dark); text-decoration:underline;}
img,svg{display:block;}
ul{list-style:none; margin:0; padding:0;}
button,input,select,textarea{font-family:inherit;}
:focus-visible{outline:2px solid var(--primary); outline-offset:1px;}
.sr-only{position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap;}

/* ---------- App shell ---------- */
.app{display:flex; width:100%; min-height:100vh;}
.main{flex:1; min-width:0; display:flex; flex-direction:column;}

/* Sidebar */
.sidebar{
  display:flex; flex-direction:column; width:232px; flex:0 0 232px;
  background:var(--nav-bg); color:var(--nav-text);
  position:sticky; top:0; height:100vh; overflow-y:auto; overflow-x:hidden;
  scrollbar-width:thin; scrollbar-color:#2f5688 transparent;
  z-index:60;
}
.sidebar::-webkit-scrollbar{width:6px;}
.sidebar::-webkit-scrollbar-thumb{background:#2f5688; border-radius:3px;}
.sidebar-top{display:flex; align-items:center; justify-content:space-between; height:52px; padding:0 12px 0 16px; border-bottom:1px solid var(--nav-border); flex:0 0 auto;}
.logo{display:flex; align-items:center; gap:9px; min-width:0;}
.logo-mark{width:24px; height:24px; border-radius:4px; flex:0 0 24px; background:var(--logo-bg, linear-gradient(135deg, #2dd4bf, #0d9488)); display:flex; align-items:center; justify-content:center;}
.logo-word{font-size:14.5px; font-weight:700; color:#fff; letter-spacing:-0.01em; white-space:nowrap;}
.sidebar-collapse-btn{width:26px; height:26px; border-radius:4px; display:flex; align-items:center; justify-content:center; color:var(--nav-muted); cursor:pointer; background:none; border:0; padding:0;}
.sidebar-collapse-btn:hover{background:var(--nav-bg-hover); color:#fff;}

.nav{display:flex; flex-direction:column; flex:1; padding:6px 8px 10px;}
.nav-group{display:flex; flex-direction:column; gap:1px; padding:8px 0 4px;}
.nav-group + .nav-group{border-top:1px solid var(--nav-border);}
.nav-group.nav-bottom{margin-top:0;}
.nav-label{padding:4px 10px 5px; font-size:10.5px; font-weight:600; letter-spacing:0.08em; text-transform:uppercase; color:var(--nav-muted); white-space:nowrap;}
.nav-item{
  position:relative; display:flex; align-items:center; gap:10px; min-height:32px; padding:5px 10px;
  border-radius:4px; color:var(--nav-text); font-size:13px; font-weight:500; cursor:pointer;
  text-decoration:none; transition:background .1s ease, color .1s ease;
}
.nav-item:hover{background:var(--nav-bg-hover); color:#fff; text-decoration:none;}
.nav-item.active{background:var(--nav-bg-active); color:#fff; font-weight:600;}
.nav-item.active::before{content:""; position:absolute; left:-8px; top:6px; bottom:6px; width:3px; border-radius:0 2px 2px 0; background:var(--nav-accent);}
.nav-item[aria-disabled="true"]{color:var(--nav-muted); cursor:default;}
.nav-item[aria-disabled="true"]:hover{background:none; color:var(--nav-muted);}
.nav-icon{width:16px; height:16px; flex:0 0 16px; display:flex; align-items:center; justify-content:center; opacity:0.85; background:none;}
.nav-item.active .nav-icon{opacity:1; color:var(--nav-accent);}
.nav-text{overflow:hidden; text-overflow:ellipsis; white-space:nowrap; min-width:0;}
.nav-badge{margin-left:auto; flex:0 0 auto; font-size:10.5px; font-weight:600; line-height:1; padding:3px 6px; border-radius:3px; background:#2a3f5e; color:#d8e3f3;}
.nav-badge.alert{background:#b42323; color:#fff;}
.nav-note{margin-left:auto; font-size:10px; letter-spacing:0.04em; text-transform:uppercase; color:var(--nav-muted);}

/* Collapsible groups */
.nav-dropdown{border:none;}
.nav-dropdown > summary.nav-item{list-style:none; user-select:none;}
.nav-dropdown > summary.nav-item::-webkit-details-marker{display:none;}
.nav-dropdown > summary.nav-item::marker{content:"";}
.nav-dropdown-chevron{margin-left:auto; flex:0 0 auto; opacity:0.6; transition:transform .12s ease;}
.nav-dropdown[open] > summary .nav-dropdown-chevron{transform:rotate(90deg);}
.nav-dropdown-body{display:flex; flex-direction:column; gap:1px; margin:1px 0 4px 17px; padding:0 0 0 10px; border-left:1px solid var(--nav-border);}
.nav-subitem{
  display:flex; align-items:center; gap:8px; min-height:28px; padding:4px 8px; border-radius:4px;
  color:var(--nav-text); font-size:12.5px; font-weight:500; text-decoration:none; position:relative;
}
.nav-subitem:hover{background:var(--nav-bg-hover); color:#fff; text-decoration:none;}
.nav-subitem.active{background:var(--nav-bg-active); color:#fff; font-weight:600;}
.nav-subitem .nav-icon{display:none;}
.sidebar-pagination{display:flex; align-items:center; justify-content:space-between; gap:8px; padding:6px 4px 2px; font-size:11px; color:var(--nav-muted);}
.sidebar-pagination button{width:24px; height:22px; border:1px solid var(--nav-border); border-radius:3px; background:none; color:var(--nav-text); cursor:pointer; font-size:15px; line-height:1; display:flex; align-items:center; justify-content:center;}
.sidebar-pagination button:hover:not(:disabled){background:var(--nav-bg-hover); color:#fff;}
.sidebar-pagination button:disabled{opacity:0.35; cursor:default;}

.sidebar-profile{display:flex; align-items:center; gap:9px; padding:10px 12px; border-top:1px solid var(--nav-border); cursor:pointer; flex:0 0 auto;}
.sidebar-profile:hover{background:var(--nav-bg-hover);}
.sidebar-profile .avatar{background:#2a3f5e; color:#fff;}
.sidebar-profile-info{flex:1; min-width:0;}
.sidebar-profile-name{font-size:12.5px; font-weight:600; color:#fff; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.sidebar-profile-role{font-size:11px; color:var(--nav-muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.sidebar-profile-chevron{flex:0 0 auto; color:var(--nav-muted);}

/* Collapsed rail (desktop, user-toggled) */
.sidebar.collapsed{width:56px; flex:0 0 56px;}
.sidebar.collapsed .sidebar-top{justify-content:center; padding:0;}
.sidebar.collapsed .logo{display:none;}
.sidebar.collapsed .nav-label, .sidebar.collapsed .nav-text, .sidebar.collapsed .nav-badge, .sidebar.collapsed .nav-note,
.sidebar.collapsed .sidebar-profile-info, .sidebar.collapsed .sidebar-profile-chevron, .sidebar.collapsed .nav-dropdown-chevron, .sidebar.collapsed .nav-dropdown-body{display:none;}
.sidebar.collapsed .nav-item{justify-content:center; padding:7px;}
.sidebar.collapsed .nav-item.active::before{left:-8px;}
.sidebar.collapsed .sidebar-profile{justify-content:center; padding:10px 0;}
.sidebar.collapsed .sidebar-collapse-btn{transform:rotate(180deg);}

/* Topbar */
.topbar{
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  min-height:60px; padding:0 24px; background:var(--surface); border-bottom:1px solid var(--border);
  position:sticky; top:0; z-index:40;
}
.topbar-left{display:flex; align-items:center; gap:12px; min-width:0;}
.nav-toggle{display:none; width:32px; height:32px; border-radius:4px; border:1px solid var(--border); background:var(--surface); color:var(--text-2); align-items:center; justify-content:center; cursor:pointer; flex:0 0 32px; padding:0;}
.nav-toggle:hover{background:var(--surface-alt);}
.crumbs{font-size:12px; color:var(--text-3); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; line-height:1.2;}
.crumbs .sep{margin:0 5px; color:var(--muted);}
.header-title{font-size:16.5px; font-weight:600; line-height:1.25; color:var(--text); white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.topbar-sub{font-size:13px; line-height:1.3; color:var(--text-3); white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.topbar-right{display:flex; align-items:center; gap:8px;}
.icon-btn{width:36px; height:36px; border-radius:4px; border:1px solid transparent; background:none; color:var(--text-2); display:flex; align-items:center; justify-content:center; position:relative; cursor:pointer; padding:0;}
.icon-btn:hover{background:var(--chip-bg); color:var(--text);}
.dot-badge{position:absolute; top:5px; right:6px; min-width:8px; height:8px; border-radius:4px; background:var(--bad-ink); border:1.5px solid var(--surface);}
.avatar{width:32px; height:32px; border-radius:50%; background:var(--primary); color:#fff; display:flex; align-items:center; justify-content:center; font-size:12px; font-weight:600; flex:0 0 auto;}
.profile{display:flex; align-items:center; gap:8px; cursor:pointer; border-radius:4px; padding:3px 6px;}
.profile:hover, .profile.menu-active{background:var(--chip-bg);}
.profile-name{font-size:13.5px; font-weight:600; line-height:1.2;}
.profile-role{font-size:12px; color:var(--text-3); line-height:1.2;}
.divider-v{width:1px; height:24px; background:var(--border);}

/* Notification panel */
.notif-panel{display:none; position:absolute; top:calc(100% + 8px); right:0; width:340px; max-width:88vw; background:var(--surface); border:1px solid var(--border); border-radius:6px; box-shadow:var(--shadow-pop); overflow:hidden; z-index:70;}
.notif-panel-head{display:flex; align-items:center; justify-content:space-between; padding:10px 14px; border-bottom:1px solid var(--border);}
.notif-panel-title{font-size:13px; font-weight:600; color:var(--text);}
.notif-link-btn{border:none; background:none; color:var(--primary); font-size:12px; font-weight:600; cursor:pointer; padding:0;}
.notif-link-btn:hover{text-decoration:underline;}
.notif-list{max-height:360px; overflow-y:auto;}
.notif-panel-foot{display:block; text-align:center; padding:9px; font-size:12px; font-weight:600; border-top:1px solid var(--border);}

/* Profile menu */
.menu-backdrop{position:fixed; inset:0; z-index:90; background:transparent; opacity:0; pointer-events:none;}
.menu-backdrop.open{opacity:1; pointer-events:auto;}
.profile-menu{
  position:fixed; z-index:91; width:230px; max-width:calc(100vw - 24px);
  background:var(--overlay-surface); border:1px solid var(--border); border-radius:6px; box-shadow:var(--shadow-pop);
  overflow:hidden; opacity:0; pointer-events:none; visibility:hidden;
}
.profile-menu.open{opacity:1; pointer-events:auto; visibility:visible;}
.profile-menu-header{display:flex; align-items:center; gap:10px; padding:12px 14px;}
.profile-menu-name{font-size:13px; font-weight:600; color:var(--text);}
.profile-menu-role{font-size:11.5px; color:var(--text-3);}
.profile-menu-divider{height:1px; background:var(--overlay-divider);}
.profile-menu-group{padding:4px;}
.profile-menu-item{display:flex; align-items:center; justify-content:space-between; gap:12px; padding:8px 10px; border-radius:4px; font-size:13px; font-weight:500; color:var(--text); cursor:pointer; text-decoration:none; font-family:inherit; text-align:left;}
.profile-menu-item:hover{background:var(--overlay-hover); text-decoration:none; color:var(--text);}
.profile-menu-item svg{flex:0 0 auto; color:var(--muted);}
.profile-menu-item.danger{color:var(--bad-ink);}
.profile-menu-item.danger svg{color:var(--bad-ink);}

/* Content area */
.content{flex:1; padding:20px 24px 32px; display:flex; flex-direction:column; gap:16px; width:100%; max-width:1680px;}
.nav-scrim{display:none;}

/* ---------- Page header (optional, for pages that want title + actions in-content) ---------- */
.page-head{display:flex; align-items:flex-end; justify-content:space-between; gap:16px; flex-wrap:wrap;}
.page-title{font-size:18px; font-weight:600; letter-spacing:-0.01em; margin:0;}
.page-sub{font-size:12.5px; color:var(--text-3); margin-top:2px;}
.page-actions{display:flex; align-items:center; gap:8px; flex-wrap:wrap;}

/* ---------- Surfaces ---------- */
.card{background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-lg);}
.card.ai{background:var(--ai-bg); border-color:var(--ai-border);}
.panel{padding:16px 20px;}
.panel-title{font-size:13.5px; font-weight:600;}
.panel-sub{font-size:12px; color:var(--text-3); margin-top:2px;}
.panel-head{display:flex; align-items:flex-start; justify-content:space-between; gap:10px; flex-wrap:wrap; margin-bottom:12px;}

/* Section header inside a card (title left, actions right) */
.module-head{display:flex; align-items:center; justify-content:space-between; gap:10px; margin:-16px -20px 14px; padding:11px 20px; border-bottom:1px solid var(--border-soft);}
.module-head-left{display:flex; align-items:center; gap:10px; min-width:0;}
.module-name{font-size:13.5px; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.icon-chip{display:none;}
.link-arrow{display:flex; align-items:center; gap:5px; font-size:12px; font-weight:500;}

/* Toolbar + segmented filter */
.toolbar{display:flex; align-items:center; justify-content:space-between; gap:12px; flex-wrap:wrap;}
.segmented{display:inline-flex; align-items:center; border:1px solid var(--border); border-radius:4px; background:var(--surface); overflow:hidden; max-width:100%;}
.pill{padding:5px 12px; font-size:12.5px; font-weight:500; color:var(--text-2); cursor:pointer; white-space:nowrap; border-right:1px solid var(--border);}
.pill:last-child{border-right:0;}
.pill:hover{background:var(--surface-alt);}
.pill.active{background:var(--primary); color:#fff; font-weight:600;}

/* ---------- Buttons ---------- */
.btn-primary{display:inline-flex; align-items:center; justify-content:center; gap:6px; height:32px; padding:0 14px; background:var(--primary); color:#fff; font-size:13px; font-weight:600; border-radius:4px; border:1px solid var(--primary-dark); cursor:pointer; white-space:nowrap; text-decoration:none; transition:background .1s ease;}
.btn-primary:hover{background:var(--primary-dark); color:#fff; text-decoration:none;}
.btn-primary:disabled{opacity:0.6; cursor:default;}
.btn-primary .btn-spinner{width:14px; height:14px; animation:formBtnSpin .7s linear infinite; display:none;}
.btn-primary.loading .btn-spinner{display:inline-block;}
.btn-primary.loading .btn-label{display:none;}
.btn-cancel,.btn-secondary{display:inline-flex; align-items:center; justify-content:center; gap:6px; height:32px; padding:0 14px; border-radius:4px; border:1px solid var(--border); background:var(--surface); font-size:13px; font-weight:600; color:var(--text-2); cursor:pointer; text-decoration:none; transition:background .1s ease, border-color .1s ease;}
.btn-cancel:hover,.btn-secondary:hover{background:var(--surface-alt); border-color:var(--border-hover); color:var(--text); text-decoration:none;}
.btn-danger-outline{display:inline-flex; align-items:center; justify-content:center; gap:6px; height:32px; padding:0 14px; border-radius:4px; border:1px solid #e3b4b4; background:var(--surface); font-size:13px; font-weight:600; color:var(--bad-ink); cursor:pointer; text-decoration:none;}
.btn-danger-outline:hover{background:var(--bad-bg); text-decoration:none;}
@keyframes formBtnSpin{to{transform:rotate(360deg);}}
.form-actions{display:flex; align-items:center; gap:8px; margin-top:8px; padding-top:14px; border-top:1px solid var(--border-soft); flex-wrap:wrap;}

/* ---------- Forms (single source for every Add/Edit screen) ---------- */
.edit-form-wrap{max-width:1080px; width:100%;}
.form-grid{display:flex; flex-wrap:wrap; gap:0 20px; max-width:100%;}
.form-grid .field{flex:1 1 240px; min-width:0; max-width:100%;}
.form-grid .field-span-2{flex-basis:100%;}
@media (max-width:640px){ .form-grid .field{flex-basis:100%;} }

.field{display:flex; flex-direction:column; gap:5px; margin-bottom:14px;}
.field-label{font-size:12px; font-weight:600; color:var(--text-2);}
.field-optional{font-size:11px; color:var(--muted); font-weight:400;}
.field-label-row{display:flex; align-items:center; justify-content:space-between;}
.field-input{display:flex; align-items:center; gap:10px; padding:0 14px; height:40px; border-radius:8px; border:1px solid var(--border); background:var(--surface); width:100%; transition:border-color .1s ease, box-shadow .1s ease;}
.field-input:hover{border-color:var(--border-hover);}
.field-input:focus-within{border-color:var(--primary); box-shadow:0 0 0 3px var(--primary-ring);}
.field-input svg{flex:0 0 auto; color:var(--muted); width:16px; height:16px;}
.field-input input, .field-input select{border:none; outline:none; background:none; flex:1; min-width:0; font-size:14px; color:var(--text); appearance:none; -webkit-appearance:none; height:100%;}
.field-input input::placeholder{color:var(--muted);}
.field-input select{cursor:pointer;}
.field-static{display:flex; align-items:center; gap:8px; padding:0 10px; height:34px; border-radius:4px; border:1px dashed var(--border); background:var(--surface-alt); color:var(--text-3); font-size:13px;}
.helper-text{font-size:11.5px; color:var(--text-3); display:flex; align-items:center; gap:5px;}
.helper-text.error{color:var(--bad-ink);}
.textarea-field{border-radius:8px; border:1px solid var(--border); background:var(--surface); padding:10px 14px; width:100%;}
.textarea-field:focus-within{border-color:var(--primary); box-shadow:0 0 0 3px var(--primary-ring);}
.textarea-field textarea{width:100%; border:none; outline:none; resize:vertical; min-height:88px; font-size:14px; color:var(--text); background:none;}
.textarea-field textarea::placeholder{color:var(--muted);}

.stepper{display:flex; align-items:center; border:1px solid var(--border); border-radius:8px; overflow:hidden; height:40px; width:100%; background:var(--surface);}
.stepper-btn{width:40px; height:100%; display:flex; align-items:center; justify-content:center; background:var(--surface-alt); color:var(--text-2); cursor:pointer; border:none; flex:0 0 40px;}
.stepper-btn:hover{background:var(--chip-bg);}
.stepper input{flex:1; width:0; text-align:center; border:none; outline:none; font-size:14px; font-weight:600; color:var(--text); background:none;}
.stepper input::-webkit-outer-spin-button,.stepper input::-webkit-inner-spin-button{-webkit-appearance:none; margin:0;}

.toggle-row{display:flex; align-items:center; justify-content:space-between; gap:12px; padding:10px 2px;}
.toggle-row + .toggle-row{border-top:1px solid var(--border-soft);}
.toggle-text{font-size:13px; font-weight:600; color:var(--text); display:flex; align-items:center; gap:8px;}
.toggle-sub{font-size:12px; color:var(--text-3); margin-top:1px; line-height:1.45;}
.toggle{position:relative; width:36px; height:20px; flex:0 0 36px; cursor:pointer;}
.toggle-input{position:absolute; opacity:0; width:0; height:0;}
.toggle-track{position:absolute; inset:0; border-radius:10px; background:#b7c0cd; transition:background .12s ease;}
.toggle-thumb{position:absolute; top:2px; left:2px; width:16px; height:16px; border-radius:50%; background:#fff; box-shadow:0 1px 2px rgba(0,0,0,0.3); transition:transform .12s ease;}
.toggle-input:checked + .toggle-track{background:var(--primary);}
.toggle-input:checked + .toggle-track .toggle-thumb{transform:translateX(16px);}
.toggle-input:focus-visible + .toggle-track{outline:2px solid var(--primary); outline-offset:2px;}

.radio-group{display:flex; flex-direction:column; gap:6px;}
.radio-row{display:flex; align-items:center; gap:10px; padding:8px 10px; border:1px solid var(--border); border-radius:4px; cursor:pointer;}
.radio-row:hover{border-color:var(--border-hover);}
.radio-row.checked{border-color:var(--radio-color, var(--primary)); background:var(--radio-tint, var(--primary-tint));}
.radio-input{position:absolute; opacity:0; width:0; height:0;}
.radio-dot{position:relative; width:16px; height:16px; border-radius:50%; border:1.5px solid var(--border-hover); flex:0 0 16px;}
.radio-dot::after{content:""; position:absolute; inset:3px; border-radius:50%; background:var(--radio-color, var(--primary)); opacity:0;}
.radio-row.checked .radio-dot{border-color:var(--radio-color, var(--primary));}
.radio-row.checked .radio-dot::after{opacity:1;}
.radio-label{font-size:13px; font-weight:600; color:var(--text);}
.radio-dash{width:8px; height:8px; border-radius:50%; background:var(--radio-color, var(--primary)); margin-left:auto; flex:0 0 8px;}

/* Custom select */
.select{position:relative; z-index:1;}
.select.open{z-index:50;}
.select-trigger{width:100%; cursor:pointer; text-align:left; font-size:14px; color:var(--text); outline:none;}
.select.open .select-trigger{border-color:var(--primary); box-shadow:0 0 0 3px var(--primary-ring);}
.select-value{flex:1; min-width:0; display:flex; align-items:center; gap:8px; font-weight:500; white-space:nowrap; overflow:hidden;}
.select-value.is-placeholder{color:var(--muted); font-weight:400;}
.select-chevron{transition:transform .12s ease;}
.select.open .select-chevron{transform:rotate(180deg);}
.select-menu{position:absolute; left:0; right:0; top:calc(100% + 4px); z-index:30; max-height:260px; overflow-y:auto; padding:4px; background:var(--surface); border:1px solid var(--border); border-radius:8px; box-shadow:var(--shadow-pop); opacity:0; visibility:hidden;}
.select.open .select-menu{opacity:1; visibility:visible;}
.select-menu-head{display:flex; align-items:center; justify-content:space-between; padding:5px 8px 6px; font-size:10.5px; font-weight:600; letter-spacing:0.06em; text-transform:uppercase; color:var(--muted);}
.select-option{display:flex; align-items:center; gap:10px; padding:8px 10px; border-radius:6px; cursor:pointer;}
.select-option.active{background:var(--surface-alt);}
.select-option[aria-selected="true"]{background:var(--primary-tint);}
.select-option-title{font-size:13px; font-weight:600; color:var(--text);}
.select-option-sub{font-size:11.5px; color:var(--text-3);}
.select-option-body{flex:1; min-width:0; display:flex; flex-direction:column; gap:1px;}
.select-check{flex:0 0 auto; color:var(--primary); opacity:0;}
.select-option[aria-selected="true"] .select-check{opacity:1;}

/* ---------- Status ---------- */
.badge{display:inline-flex; align-items:center; font-size:11px; font-weight:600; padding:2px 7px; border-radius:3px; white-space:nowrap;}
.badge.on-track{color:var(--good-text); background:var(--good-bg);}
.badge.at-risk{color:var(--warn-text); background:var(--warn-bg);}
.badge.near{color:var(--info-text); background:var(--info-bg);}
.sev{font-size:11px; font-weight:600; padding:2px 7px; border-radius:3px;}
.sev.medium{color:var(--warn-text); background:var(--warn-bg);}
.sev.high{color:var(--bad-text); background:var(--bad-bg);}
.legend{display:flex; align-items:center; gap:14px; flex-wrap:wrap; margin:10px 0 4px;}
.legend-item{display:flex; align-items:center; gap:6px; font-size:12px; color:var(--text-2);}
.swatch{width:8px; height:8px; border-radius:2px; flex:0 0 8px;}
.progress-track{height:6px; background:var(--border-soft); border-radius:3px; overflow:hidden; margin-bottom:8px;}
.progress-fill{height:100%; background:var(--primary); border-radius:3px;}
.section-label{font-size:11px; font-weight:600; color:var(--text-3); text-transform:uppercase; letter-spacing:0.05em; margin-bottom:6px;}

/* ---------- Dashboard blocks ---------- */
.dash-grid{display:grid; grid-template-columns:minmax(0,1fr); gap:16px; align-items:stretch;}
@media (min-width:1100px){ .dash-grid.cols-2{grid-template-columns:minmax(0,3fr) minmax(0,2fr);} .dash-grid.cols-3{grid-template-columns:repeat(3,minmax(0,1fr));} }

.metric-strip{display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); background:var(--surface); border:1px solid var(--border); border-radius:6px;}
@media (min-width:700px){ .metric-strip{grid-template-columns:repeat(3,minmax(0,1fr));} }
@media (min-width:1100px){ .metric-strip{grid-template-columns:repeat(6,minmax(0,1fr));} }
.metric{padding:12px 16px; border-right:1px solid var(--border-soft); border-bottom:1px solid var(--border-soft); min-width:0;}
.metric-label{font-size:11.5px; color:var(--text-3); white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.metric-value{font-size:20px; font-weight:600; letter-spacing:-0.01em; margin-top:2px; font-variant-numeric:tabular-nums;}
.metric-value.is-alert{color:var(--bad-ink);}
.metric-note{font-size:11.5px; color:var(--text-3); margin-top:1px;}

.dash-card{background:var(--surface); border:1px solid var(--border); border-radius:6px; min-width:0;}
.dash-card-head{display:flex; align-items:center; justify-content:space-between; gap:10px; padding:10px 16px; border-bottom:1px solid var(--border-soft);}
.dash-card-title{font-size:13px; font-weight:600;}
.dash-card-body{padding:12px 16px;}
.dash-card-body.flush{padding:0;}
.kv{display:grid; grid-template-columns:repeat(auto-fit,minmax(110px,1fr)); gap:12px 16px;}
.kv-label{font-size:11.5px; color:var(--text-3);}
.kv-value{font-size:16px; font-weight:600; margin-top:1px; font-variant-numeric:tabular-nums;}
.dash-empty{padding:18px 16px; font-size:12.5px; color:var(--text-3);}
.dash-empty strong{display:block; color:var(--text-2); font-weight:600; margin-bottom:2px;}

.list-rows{display:flex; flex-direction:column;}
.list-row{display:flex; align-items:center; justify-content:space-between; gap:12px; padding:8px 16px; border-bottom:1px solid var(--border-soft); color:inherit; text-decoration:none;}
.list-row:last-child{border-bottom:0;}
a.list-row:hover{background:var(--surface-alt); text-decoration:none;}
.list-row-main{min-width:0;}
.list-row-title{font-size:13px; font-weight:500; color:var(--text); white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.list-row-sub{font-size:11.5px; color:var(--text-3); white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.list-row-end{flex:0 0 auto; text-align:right; font-size:12.5px; font-variant-numeric:tabular-nums;}

.status-row{display:flex; align-items:center; justify-content:space-between; font-size:12.5px; padding:4px 0;}
.status-row .lbl{display:flex; align-items:center; gap:8px; color:var(--text-2);}
.status-row .num{font-weight:600; font-variant-numeric:tabular-nums;}
.sev-dot{width:8px; height:8px; border-radius:50%; flex:0 0 8px;}

/* ---------- Overlays: toastr ---------- */
#toast-container{z-index:9999;}
#toast-container > div{position:relative; opacity:1 !important; font-family:var(--font) !important; border-radius:4px !important; padding:11px 34px 11px 14px !important; margin:0 0 8px !important; width:320px !important; box-shadow:var(--shadow-pop) !important; background-image:none !important; border-left:4px solid transparent !important;}
#toast-container > .toast-success{background-color:var(--good-bg) !important; border-left-color:var(--good-text) !important;}
#toast-container > .toast-info{background-color:var(--info-bg) !important; border-left-color:var(--primary) !important;}
#toast-container > .toast-warning{background-color:var(--warn-bg) !important; border-left-color:#d49a14 !important;}
#toast-container > .toast-error{background-color:var(--bad-bg) !important; border-left-color:var(--bad-ink) !important;}
#toast-container > div .toast-title{font-weight:600 !important; font-size:13px !important; color:var(--text) !important; margin-bottom:2px !important;}
#toast-container > div .toast-message{color:var(--text) !important; font-size:12.5px !important; line-height:1.45 !important;}
.toast-close-button{position:absolute !important; top:8px !important; right:10px !important; color:var(--text) !important; opacity:0.45 !important; text-shadow:none !important; font-size:16px !important; font-weight:400 !important;}
.toast-close-button:hover{opacity:0.8 !important;}
.toast-progress{opacity:0.2 !important; height:2px !important;}

/* ---------- Responsive shell ---------- */
@media (max-width:1023px){
  .sidebar{position:fixed; left:0; top:0; bottom:0; width:248px; transform:translateX(-100%); transition:transform .18s ease; box-shadow:none;}
  .sidebar.collapsed{width:248px; flex:none;}
  body.nav-open .sidebar{transform:translateX(0); box-shadow:6px 0 24px rgba(0,0,0,0.3);}
  body.nav-open{overflow:hidden;}
  .nav-scrim{display:block; position:fixed; inset:0; z-index:55; background:rgba(10,18,32,0.5); opacity:0; pointer-events:none; transition:opacity .18s ease;}
  body.nav-open .nav-scrim{opacity:1; pointer-events:auto;}
  .nav-toggle{display:flex;}
  .sidebar-collapse-btn{display:none;}
}
@media (max-width:767px){
  .topbar{padding:0 12px;}
  .content{padding:14px 12px 28px; gap:12px;}
  .profile-name,.profile-role,.divider-v{display:none;}
  .panel{padding:14px;}
  .module-head{margin:-14px -14px 12px; padding:10px 14px;}
}
@media (prefers-reduced-motion:reduce){ *{transition:none !important; animation:none !important;} }

/* ---------- Normalisation for screens that still carry local rules ---------- */
.btn-primary-sm{display:inline-flex; align-items:center; justify-content:center; height:32px; padding:0 14px !important; border-radius:4px !important; border:1px solid var(--primary-dark) !important; background:var(--primary) !important; box-shadow:none !important; font-size:13px;}
.btn-primary-sm:hover{background:var(--primary-dark) !important; opacity:1;}
.btn-ghost{height:32px; padding:0 14px !important; border-radius:4px !important;}
.panel-card{padding:16px 20px !important;}
.settings-panel{animation:none !important;}
.content{padding:1.25rem 5rem 5rem !important; max-width:100% !important;}


@media (max-width: 1023px) {
    .content {
        padding: 1rem 1.5rem 1.5rem !important;
    }
  }

/* ---------- Responsive tables (all index pages) ----------
   >640px: table sits in .dt-scroll (added by footer script) and scrolls sideways when it can't fit.
   <=640px: DataTables rows become stacked cards; each cell is labelled from its column header (data-label). */
.dt-scroll{width:100%; max-width:100%; overflow-x:auto; -webkit-overflow-scrolling:touch;}
.dt-scroll > table{max-width:none;}
.dt-scroll > table.dataTable{min-width:680px;}
.dataTables_wrapper{max-width:100%;}
.dataTables_wrapper .dataTables_filter, .dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_paginate{max-width:100%;}
.dataTables_wrapper .dataTables_paginate{flex-wrap:wrap;}
@media (max-width:1100px){
  .panel, .card{min-width:0; max-width:100%;}
}
@media (max-width:640px){
  .dt-scroll{overflow-x:visible;}
  .dt-scroll > table.dataTable{min-width:0;}
  body table.dataTable{border-spacing:0 10px !important;}
  body table.dataTable thead{display:none !important;}
  body table.dataTable, body table.dataTable tbody, body table.dataTable tbody tr{display:block !important; width:100% !important;}
  body table.dataTable tbody tr{background:var(--surface); border:1px solid var(--border); border-radius:12px; padding:6px 0 !important; margin-bottom:10px; overflow:hidden;}
  body table.dataTable tbody td{display:block !important; width:100% !important; height:auto !important; padding:6px 14px !important; border:0 !important; border-radius:0 !important; background:transparent !important; box-shadow:none !important; text-align:left !important; white-space:normal !important;}
  body table.dataTable tbody td[data-label]::before{content:attr(data-label); display:block; font-size:10.5px; font-weight:600; letter-spacing:.04em; text-transform:uppercase; color:var(--text-3); margin-bottom:3px;}
  body table.dataTable tbody td.dataTables_empty{text-align:center !important;}
  body table.dataTable tbody td.ap-check{width:auto !important;}
}

/* ---------- Same buttons everywhere: show pages and alerts look like the create pages ---------- */
.form-actions .btn-primary,.form-actions .btn-cancel,.form-actions .btn-secondary,.form-actions .btn-danger-outline,.form-actions .btn-warn{height:36px; min-height:0; padding:0 18px; font-size:13px; line-height:1; border-radius:11px; gap:8px;}
.form-actions .btn-primary,.form-actions .btn-danger-outline,.form-actions .btn-warn{font-weight:700;}
body .swal2-popup .bs-swal-confirm,body .swal2-popup .bs-swal-cancel{display:inline-flex !important; align-items:center; justify-content:center; height:36px !important; min-height:0 !important; padding:0 18px !important; font-size:13px !important; line-height:1 !important; font-weight:700 !important; border-radius:11px !important; margin:0 4px !important; cursor:pointer !important; box-shadow:none !important;}
body .swal2-popup .bs-swal-confirm{background:var(--primary) !important; color:#fff !important; border:1px solid var(--primary-dark) !important;}
body .swal2-popup .bs-swal-confirm:hover{background:var(--primary-dark) !important; opacity:1 !important;}
body .swal2-popup .bs-swal-cancel{background:var(--surface) !important; color:var(--text-2) !important; border:1px solid var(--border) !important;}
body .swal2-popup .bs-swal-cancel:hover{background:var(--surface-alt) !important; border-color:var(--border-hover) !important; color:var(--text) !important;}

/* Page-header action buttons (module head, 3D viewer bar): same size and shape as the create-page buttons. */
.module-head-actions .btn-primary,.module-head-actions .btn-secondary,.module-head-actions .btn-cancel,.viewer-actions .btn-primary,.viewer-actions .btn-secondary,.viewer-actions .btn-cancel{height:36px; min-height:0; padding:0 18px; font-size:13px; line-height:1; border-radius:11px; gap:8px; text-decoration:none;}
.module-head-actions .btn-primary,.viewer-actions .btn-primary{font-weight:700; color:#fff;}

/* Delete alerts: same size and shape as every other button, but the Delete button stays red. */
body .swal-del-actions .swal-del-cancel,body .swal-del-actions .swal-del-confirm{display:inline-flex; align-items:center; justify-content:center; gap:8px; height:36px; min-height:0; padding:0 18px; font-size:13px; line-height:1; font-weight:700; border-radius:11px; cursor:pointer;}
body .swal-del-actions .swal-del-cancel{background:var(--surface); color:var(--text-2); border:1px solid var(--border);}
body .swal-del-actions .swal-del-confirm{background:#b42323; color:#fff; border:1px solid #8f1d1d;}
body .swal-del-actions .swal-del-confirm:hover{background:#9a1c1c;}
body .swal2-popup.bs-swal-danger .bs-swal-confirm{background:#b42323 !important; border-color:#8f1d1d !important; color:#fff !important;}
body .swal2-popup.bs-swal-danger .bs-swal-confirm:hover{background:#9a1c1c !important;}
body .swal2-popup.bs-swal-popup{border-radius:16px; border:1px solid var(--border); font-family:inherit;}
body .swal2-popup .bs-swal-title{font-size:17px; font-weight:800; color:var(--text);}
body .swal2-popup .bs-swal-text{font-size:13.5px; color:var(--text-2); line-height:1.55;}

/* Pager for lists that page on the server ($items->links()): same look as the DataTables pager */
.app-pager{display:flex; align-items:center; justify-content:space-between; gap:12px; flex-wrap:wrap;}
.app-pager-info{font-size:12.5px; color:var(--text-3);}
.app-pager-info b{color:var(--text-2); font-weight:600;}
.app-pager-list{display:flex; align-items:center; gap:4px; margin:0; padding:0; list-style:none;}
.app-pager-btn{min-width:28px; height:28px; padding:0 8px; border-radius:4px; border:1px solid transparent; font-size:12.5px; font-weight:500; line-height:1; color:var(--text-2); display:inline-flex; align-items:center; justify-content:center; text-decoration:none; cursor:pointer; transition:background .12s ease, color .12s ease;}
a.app-pager-btn:hover{background:var(--chip-bg); color:var(--text);}
.app-pager-btn.is-current{background:var(--primary); border-color:var(--primary-dark); color:#fff; font-weight:600; cursor:default;}
.app-pager-btn.is-disabled{opacity:.35; cursor:default;}
.app-pager-btn.is-gap{cursor:default; min-width:20px; padding:0 2px;}

/* Notification bell panel */
.notif-panel{width:380px !important; border-radius:16px !important; overflow:hidden;}
.np-head{background:linear-gradient(135deg,var(--primary-dark),var(--primary)); color:#fff; padding:14px 14px 12px;}
.np-top{display:flex; align-items:center; gap:10px;}
.np-logo{width:36px; height:36px; border-radius:10px; background:rgba(255,255,255,.22); display:flex; align-items:center; justify-content:center;}
.np-logo svg{width:18px; height:18px; stroke:#fff;}
.np-titles{flex:1; min-width:0;}
.np-title{font-weight:700; font-size:15px;}
.np-date{font-size:11.5px; opacity:.85;}
.np-iconbtn{width:30px; height:30px; border-radius:9px; border:1px solid rgba(255,255,255,.35); background:rgba(255,255,255,.18); color:#fff; display:flex; align-items:center; justify-content:center; cursor:pointer;}
.np-iconbtn:hover{background:rgba(255,255,255,.32);}
.np-tabs{display:flex; gap:4px; margin-top:12px; background:rgba(255,255,255,.16); border-radius:10px; padding:3px;}
.np-tab{flex:1; border:0; background:transparent; color:#fff; font-size:12px; font-weight:600; padding:6px 4px; border-radius:8px; cursor:pointer;}
.np-tab span{display:inline-block; min-width:18px; padding:0 5px; margin-left:3px; border-radius:9px; background:rgba(255,255,255,.25); font-size:10.5px;}
.np-tab.active{background:var(--surface); color:var(--primary);}
.np-tab.active span{background:var(--primary-tint);}
.notif-list{padding:8px; max-height:340px; overflow-y:auto;}
.np-item{display:flex; align-items:flex-start; gap:10px; padding:10px; border-radius:12px; margin-bottom:6px; background:var(--surface-alt); text-decoration:none !important; color:inherit; position:relative;}
.np-item:hover{background:var(--primary-tint);}
.np-item.unread{background:var(--primary-tint);}
.np-ico{flex:0 0 32px; width:32px; height:32px; border-radius:50%; background:var(--primary-tint); color:var(--primary); display:flex; align-items:center; justify-content:center; font-weight:700; font-size:13px; border:1px solid var(--border);}
.np-red{color:var(--bad-ink,#b91c1c); background:rgba(220,38,38,.10);} .np-green{color:#15803d; background:rgba(34,197,94,.12);} .np-amber{color:#b45309; background:rgba(245,158,11,.14);} .np-teal{color:#0f766e; background:rgba(20,184,166,.12);} .np-indigo{color:#4338ca; background:rgba(99,102,241,.12);}
.np-txt{flex:1; min-width:0; display:flex; flex-direction:column; gap:2px;}
.np-t{font-size:13px; font-weight:600; color:var(--text);}
.np-m{font-size:12px; color:var(--text-3); line-height:1.35;}
.np-meta{font-size:11px; color:var(--muted);}
.np-k{font-style:normal; font-weight:700; font-size:10px; letter-spacing:.04em; text-transform:uppercase; color:var(--primary); background:var(--surface); border-radius:6px; padding:1px 6px; margin-right:6px;}
.np-dot{width:8px; height:8px; border-radius:50%; background:var(--primary); margin-top:6px; flex:0 0 8px;}
.np-empty{padding:26px 14px; text-align:center; font-size:12.5px; color:var(--text-3);}
.np-foot{display:flex; align-items:center; justify-content:space-between; padding:10px 14px; border-top:1px solid var(--border);}
.np-live{font-size:11px; color:var(--text-3); display:flex; align-items:center; gap:5px;}
.np-live i{width:7px; height:7px; border-radius:50%; background:#22c55e;}
.np-viewall{background:var(--primary); color:#fff !important; font-size:12px; font-weight:700; padding:7px 14px; border-radius:9px; text-decoration:none !important;}

/* Create, edit and show pages all use the same card width: the full content area. */
.content > .card.panel,
.content .card.panel > .edit-form-wrap,
.content .edit-form-wrap{width:100%; max-width:100% !important;}

/* Unread count on the bell */
#notifDot.dot-badge{top:-5px; right:-6px; min-width:18px; height:18px; padding:0 5px; border-radius:9px; align-items:center; justify-content:center; font-size:10.5px; font-weight:700; line-height:1; color:#fff; background:#dc2626; border:2px solid var(--surface); box-sizing:border-box;}

/* List rows start with an icon chip */
.ap-doc-icon{display:flex; align-items:center; justify-content:center; flex:0 0 34px; width:34px; height:34px; margin-right:10px; border-radius:10px; background:var(--primary-tint); color:var(--primary);}
html[data-theme="dark"] .ap-doc-icon{background:rgba(77,142,232,.16);}
.ap-doc-icon svg{width:16px; height:16px; stroke:currentColor;}
.ap-ico-cell{display:flex; align-items:center;}
.ap-ico-text{min-width:0;}
