/* Screen layouts shared by the app and administration pages. */
html { -webkit-text-size-adjust:100%; text-size-adjust:100%; }
body { min-width:0; }
body:has(.modal:not(.hidden)) { overflow:hidden; }
img, video { max-width:100%; }
input, select, textarea { min-width:0; max-width:100%; }
button, a, input, select, textarea { touch-action:manipulation; }
button, .button { white-space:normal; overflow-wrap:anywhere; }
button:focus-visible, a:focus-visible, .table-scroll:focus-visible { outline:3px solid #eea65f; outline-offset:3px; }
.brand-mark, .icon-button { flex-shrink:0; }
.main-content { min-width:0; min-height:100dvh; container:workspace / inline-size; }
.view, .admin-main, .portal-admin-main { width:100%; min-width:0; }
.panel, .portal-card, .form-grid > *, .workbench > *, .dashboard-grid > *, .portal-grid > *, .expert-admin-layout > *, .process-layout > *, .admin-grid > *, .modal-head > div, .page-head > div, .portal-head > div { min-width:0; }
.panel-head, .table-toolbar, .lookup-meta, .table-total, .chat-header, .modal-foot, .page-head, .portal-head { flex-wrap:wrap; }
.panel-head > *, .table-toolbar > *, .portal-row > *, .hb-reader-head > *, .hb-pdf-toolbar > * { min-width:0; }
.page-head p, .portal-head p, .portal-card, .info-strip, .caption, .summary-note, .new-key-box, .customer-detail-grid, .project-node, .license-permission-note { overflow-wrap:anywhere; }
.workbench.two-col { grid-template-columns:minmax(0,.95fr) minmax(0,1.05fr); }
.kpi-grid, .result-cards { grid-template-columns:repeat(auto-fit,minmax(min(100%,13rem),1fr)); }
.kpi-card strong, .result-cards strong, .summary-banner strong { overflow-wrap:anywhere; }
.lookup-filters { flex-wrap:wrap; }
.lookup-filters label { flex:1 1 180px; min-width:0; }
.lookup-filters .grow { flex:2 1 260px; }
.bar-row { grid-template-columns:minmax(100px,1fr) minmax(30px,1fr) auto; }
.bar-row strong { overflow-wrap:anywhere; }
.table-scroll { max-width:100%; min-width:0; overscroll-behavior-x:contain; -webkit-overflow-scrolling:touch; }
.table-scroll-hint { margin:0; padding:10px 16px; font-size:14px; line-height:1.5; color:#355e70; background:#edf6f8; border-bottom:1px solid var(--line); }
.table-scroll-hint[hidden] { display:none; }
.table-scroll table { font-variant-numeric:tabular-nums; }
.table-scroll th, .table-scroll td { font-size:14px; }
.table-scroll input { font-size:16px; }
.table-scroll input.line-spec-input { font-size:14px; }
.table-scroll button, .project-actions button { min-height:40px; font-size:14px; }
.table-scroll .delete-line { min-width:40px; }
.table-total { gap:8px 20px; }
.clean-table { table-layout:fixed; }
.clean-table th { width:65%; padding-right:12px; }
.clean-table td { overflow-wrap:anywhere; }
.admin-grid { grid-template-columns:minmax(0,.7fr) minmax(0,1.3fr); }
.admin-topbar { height:auto; min-height:72px; gap:16px; flex-wrap:wrap; padding-block:16px; }
.admin-topbar .top-actions .button { display:inline-flex; align-items:center; justify-content:center; width:auto; height:auto; padding:10px 14px; font-size:14px; min-height:44px; }
.admin-topbar .top-actions .button::after { display:none; }
.new-key-box { grid-template-columns:minmax(0,1fr) auto; }
.new-key-box strong { min-width:0; }
.modal { padding:16px; }
.modal-card { max-width:100%; height:min(780px,calc(100dvh - 32px)); max-height:calc(100dvh - 32px); }
.modal-card.compact-modal, .admin-detail-modal { height:auto; max-height:calc(100dvh - 32px); }
.modal-head, .modal-foot { flex-shrink:0; }
.modal-filters { flex-shrink:0; }
.modal-list, .admin-detail-body, .project-form { min-height:0; overscroll-behavior:contain; }
.project-form { overflow:auto; }
.toast { max-width:min(380px,calc(100vw - 32px)); overflow-wrap:anywhere; }
.sidebar { padding-bottom:max(24px,env(safe-area-inset-bottom)); }
.sidebar-foot { flex-shrink:0; }
.license-permission-note { display:block; margin-top:12px; color:#bed3dd; font-size:12px; line-height:1.6; }
.sidebar-close, .menu-backdrop { display:none; }
.hb-book-card, .hb-entry-title, .hb-group > summary span, .thread-button { min-width:0; overflow-wrap:anywhere; }
.hb-pdf-frame { min-height:240px; height:70dvh; }
.chat-message { overflow-wrap:anywhere; }
.chat-log { max-height:min(540px,65dvh); }
.drawing-preview iframe { height:min(600px,70dvh); }

@container workspace (max-width:1000px) {
  .workbench.two-col, .dashboard-grid, .quick-bridge { grid-template-columns:minmax(0,1fr); }
  .dashboard-grid .span-2, .dashboard-grid .span-3 { grid-column:1; }
  .quick-components-head { flex-direction:column; align-items:stretch; }
  .quick-component-actions { justify-content:flex-start; }
  .portal-grid, .process-layout { grid-template-columns:minmax(0,1fr); }
  .portal-grid .side-panel { position:static; }
  .process-list { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .hb-books, .handbook-grid { grid-template-columns:repeat(2,minmax(0,1fr)); }
}
@container workspace (max-width:640px) {
  .hb-books, .handbook-grid, .portal-fields, .stage-controls, .process-list { grid-template-columns:minmax(0,1fr); }
  .summary-banner { grid-template-columns:minmax(0,1fr); }
}
@media (max-width:1023px) {
  .main-content { margin-left:0; }
  .menu-button { display:grid; margin:0; width:44px; height:44px; }
  .sidebar { width:min(320px,calc(100vw - 40px)); height:100dvh; z-index:70; transform:translateX(-105%); visibility:hidden; transition:transform .2s ease,visibility .2s; overscroll-behavior:contain; }
  .sidebar.open { transform:translateX(0); visibility:visible; }
  .sidebar .brand-lockup { padding-right:28px; }
  .sidebar-close { display:grid; position:absolute; right:12px; top:22px; width:40px; height:40px; color:#fff; background:#ffffff18; }
  .menu-backdrop:not([hidden]) { display:block; position:fixed; inset:0; z-index:60; border:0; padding:0; background:#08253280; backdrop-filter:blur(2px); }
  body.menu-open { overflow:hidden; }
  .topbar { display:grid; grid-template-columns:44px minmax(0,1fr); align-items:center; gap:8px 12px; padding:12px max(16px,env(safe-area-inset-right)) 12px max(16px,env(safe-area-inset-left)); min-height:72px; }
  .topbar .top-actions { grid-column:1/-1; width:100%; justify-content:flex-end; gap:8px; }
  .topbar .top-actions .button { font-size:14px; min-height:44px; height:auto; width:auto; padding:10px 14px; }
  .topbar .top-actions .button::after { display:none; }
  .topbar #reset-project { display:inline-flex; }
  .topbar .save-state { display:inline; margin-right:auto; font-size:12px; }
  .topbar .project-heading input { font-size:16px; }
  .topbar .top-actions:has(> .permission-locked):not(:has(> :not(.permission-locked):not(#go-summary))) { display:none; }
  .view, .portal-view { padding:24px max(16px,env(safe-area-inset-right)) 36px max(16px,env(safe-area-inset-left)); }
  .admin-grid, .expert-admin-layout { grid-template-columns:minmax(0,1fr); }
  .admin-main, .portal-admin-main { padding:24px 16px 40px; }
  .activation-screen { grid-template-columns:minmax(0,1fr); }
  .activation-card { min-height:100dvh; padding:32px max(24px,env(safe-area-inset-left)); }
  .activation-visual { display:none; }
  .activation-card .brand-lockup.large { margin-bottom:36px; }
  input:not([type=checkbox]):not([type=radio]), select, textarea, .portal-view input, .portal-view select, .portal-view textarea { font-size:16px; }
  .button, .permission-presets button, .check-tabs button, .estimate-tab, .nav-item { min-height:44px; }
  label, .field-hint, .caption, .info-strip, .clean-table th, .clean-table td, .panel-head p, .check-list li { font-size:14px; line-height:1.5; }
  .field-hint, .caption { font-size:12px; }
  .table-scroll input.line-spec-input { font-size:16px; }
}
@media (max-width:640px) {
  .topbar { position:relative; }
  .topbar .top-actions { justify-content:stretch; }
  .topbar .top-actions .button { flex:1; padding-inline:10px; }
  .topbar .save-state { flex-basis:100%; }
  .page-head, .portal-head { gap:14px; align-items:stretch; }
  .page-head h1, .portal-head h1 { font-size:28px; line-height:1.25; }
  .page-head p { font-size:15px; }
  .page-actions { justify-content:flex-start; width:100%; }
  .page-actions .button { flex:1 1 125px; }
  .export-scope { text-align:left; }
  .kpi-grid, .form-grid, .result-cards, .project-stats { grid-template-columns:minmax(0,1fr); }
  .project-stats article:last-child { grid-column:auto; }
  .panel:not(.table-panel):not(.quick-components-panel), .portal-card { padding:16px; }
  .panel-head { gap:12px; }
  .panel-head .text-button { min-height:36px; font-size:14px; }
  .bar-row { grid-template-columns:minmax(0,1fr) minmax(0,1fr); }
  .bar-row strong { grid-column:2; }
  .table-toolbar, .lookup-filters { align-items:stretch; flex-direction:column; padding:14px; }
  .table-toolbar > *, .lookup-filters > label { width:100%; min-width:0; flex:initial; }
  .lookup-filters label, .lookup-filters .grow { flex:0 0 auto; }
  .inline-field { display:block; white-space:normal; }
  .inline-field input { width:100%; margin-top:6px; }
  .segmented { flex-wrap:wrap; }
  .segmented button { flex:1; min-height:44px; font-size:14px; }
  .table-total { padding:16px; justify-content:space-between; }
  .table-total strong { font-size:20px; overflow-wrap:anywhere; }
  .tree-groups { margin-left:4px; padding-left:12px; }
  .tree-group::before { left:-12px; width:12px; }
  .tree-children { margin-left:0; padding-left:8px; }
  .project-node { grid-template-columns:minmax(0,1fr); }
  .project-file { display:none; }
  .project-actions { grid-column:1; flex-wrap:wrap; }
  .project-actions button { flex:1; }
  .project-main strong { white-space:normal; }
  .admin-topbar { padding:16px; }
  .admin-topbar .top-actions, .admin-topbar > .portal-row { width:100%; justify-content:flex-start; }
  .admin-topbar .button { flex:1; min-height:44px; font-size:14px; text-align:center; text-decoration:none; }
  .admin-list-actions { display:flex; flex-wrap:wrap; }
  .license-table, .license-table tbody { display:block; min-width:0; width:100%; }
  .license-table thead { position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%); }
  .license-table tbody tr { display:block; padding:14px 16px; border-top:1px solid var(--line); }
  .license-table td { display:grid; grid-template-columns:90px minmax(0,1fr); gap:4px 12px; padding:8px 0; border:0; white-space:normal; min-width:0; overflow-wrap:anywhere; }
  .license-table td[data-label]::before { content:attr(data-label); grid-column:1; color:var(--muted); font-size:12px; font-weight:600; }
  .license-table td > * { grid-column:2; min-width:0; }
  .license-table td:last-child, .license-table td[colspan] { display:block; }
  .license-table td:last-child::before { display:block; margin-bottom:8px; }
  .license-table .license-permissions { min-width:0; max-width:none; font-size:14px; }
  .license-table .row-actions { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; }
  .license-table .row-actions button { min-height:44px; }
  .new-key-box { grid-template-columns:minmax(0,1fr); }
  .new-key-box strong { font-size:18px; letter-spacing:.03em; }
  .new-key-box .button { justify-self:start; }
  .modal { padding:0; }
  .modal-card, .admin-detail-modal { width:100%; height:100dvh; max-height:100dvh; border-radius:0; }
  .modal-card.compact-modal { height:auto; width:calc(100% - 24px); max-height:calc(100dvh - 24px); border-radius:12px; }
  .modal-head { padding:16px; gap:12px; }
  .modal-head h2 { font-size:20px; overflow-wrap:anywhere; }
  .modal-foot { padding:12px 16px max(12px,env(safe-area-inset-bottom)); gap:10px; }
  .modal-list { padding:12px; }
  .shortlist-item { grid-template-columns:56px minmax(0,1fr); }
  .shortlist-item .spec, .shortlist-item .unit, .shortlist-item .price { display:block; grid-column:2; text-align:left; }
  .shortlist-item .name, .shortlist-item .price { font-size:14px; }
  .shortlist-item .button { grid-column:1/-1; min-height:44px; }
  .detail-action-grid, .customer-detail-grid, .extend-control, .permission-options { grid-template-columns:minmax(0,1fr); }
  .device-detail-item { grid-template-columns:28px minmax(0,1fr); }
  .permission-options label { align-items:center; min-height:44px; }
  .permission-options input[type=checkbox] { width:22px; height:22px; flex-basis:22px; margin:0; }
  .hb-book-card { display:flex; flex-direction:column; align-items:flex-start; gap:6px; }
  .hb-book-number { margin-bottom:6px; }
  .hb-book-card .hb-book-link { align-self:flex-start; font-size:14px; }
  .hb-entry { grid-template-columns:32px minmax(0,1fr); }
  .hb-entry-page { grid-column:2; }
  .hb-search-panel .portal-toolbar { grid-template-columns:minmax(0,1fr); }
  .check-row-head { grid-template-columns:24px minmax(0,1fr); }
  .check-row-head select { grid-column:2; }
  .check-row .check-note { margin-left:0; width:100%; }
  .chat-compose .portal-row { flex-direction:column; align-items:stretch; }
  .admin-connect-row { flex-wrap:wrap; }
  .admin-connect-row label { flex:1 0 100%; max-width:none; }
  .admin-connect-row .button { flex:1 1 120px; }
  .toast { right:16px; bottom:max(16px,env(safe-area-inset-bottom)); font-size:14px; }
}
@media (max-height:540px) {
  .topbar { position:relative; }
  #shortlist-modal .modal-card { display:block; overflow-y:auto; }
  #shortlist-modal .modal-list { overflow:visible; }
  #shortlist-modal .modal-head { position:sticky; top:0; z-index:3; background:white; }
  #shortlist-modal .modal-foot { position:sticky; bottom:0; background:white; }
}
@media (prefers-reduced-motion:reduce) {
  .sidebar { transition:none; }
  .button:hover, .project-node:hover { transform:none; }
}
