/* Shared responsive layout: phone, tablet, laptop and large desktop. */
:root { --page-max:1920px; --page-pad:clamp(12px,2vw,32px); }
[hidden] { display:none !important; }
dialog:not([open]) { display:none !important; }
html,body { min-width:0; max-width:100%; }
body { overflow-wrap:break-word; }
.wrap { width:100%; max-width:var(--page-max); min-width:0; margin-inline:auto; padding:20px var(--page-pad); }
.wrap > *, .row > *, .grid > *, form, fieldset { min-width:0; }
img,video,canvas { max-width:100%; }
input,select,textarea { max-width:100%; }
input[type="checkbox"],input[type="radio"] { width:auto; }
button,a.btn { touch-action:manipulation; }
.card { box-shadow:var(--shadow); }
.topbar { gap:14px; padding-inline:var(--page-pad); }
.brand { min-width:0; margin-inline-end:auto; }
.brand span { overflow-wrap:anywhere; }
.who { flex:0 1 auto; }
.nav,.nav.admin-nav { max-width:var(--page-max); margin-inline:auto; overflow-x:auto; overscroll-behavior-inline:contain; scrollbar-width:thin; flex-wrap:nowrap; }
.nav a { flex:0 0 auto; white-space:nowrap; min-height:44px; }
.smart-table-scroll,.table-wrap,.scroll { max-width:100%; overflow-x:auto; overscroll-behavior-inline:contain; -webkit-overflow-scrolling:touch; }
.smart-table-scroll > table { width:100%; }
.task-filter-form { display:flex; flex-wrap:wrap; align-items:flex-end; gap:12px; }
.task-filter-form label:first-child { flex:2 1 260px; }
.task-filter-form label { flex:1 1 160px; font-size:13px; font-weight:700; }
.task-filter-form input,.task-filter-form select { display:block; margin-top:5px; }
.pagination { display:flex; flex-wrap:wrap; gap:10px; align-items:center; margin-top:12px; color:var(--muted); font-size:13px; }
dialog { max-width:min(94vw,960px); max-height:calc(var(--viewport-height,100dvh) - 32px); overflow-y:auto; }
html.chat-page-root,html.chat-page-root body { height:var(--viewport-height,100dvh); }
html.chat-page-root body > main.wrap { width:100%; max-width:var(--page-max); padding:12px var(--page-pad); }
.chat-sidebar { flex-basis:clamp(300px,27vw,400px); max-width:400px; }
.chat-messages { padding:20px clamp(12px,3vw,64px); }
.chat-msg { max-width:min(76%,700px); }
.chat-msg-content,.cw-msg-bubble { overflow-wrap:anywhere; white-space:pre-wrap; }
.chat-msg-bubble { min-width:0; }
.chat-composer { padding-bottom:calc(10px + env(safe-area-inset-bottom)); }
.chat-composer textarea,.cw-composer textarea { max-height:120px; overflow-y:auto; }
.chat-main-title,.chat-item-body,.cw-item-body { min-width:0; }
.chat-main-title strong { display:block; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.chat-main-head { min-height:66px; }
.cw-root { right:max(16px,env(safe-area-inset-right)); bottom:20px; z-index:1100; }
.cw-panel { width:min(400px,calc(100vw - 28px)); height:min(640px,calc(var(--viewport-height,100dvh) - 40px)); max-height:calc(var(--viewport-height,100dvh) - 40px); }
.cw-msg { max-width:90%; }
.cw-messages { min-height:0; overscroll-behavior-y:contain; }
.cw-msg-bubble { max-width:100%; }
.cw-composer { flex-shrink:0; padding-bottom:calc(10px + env(safe-area-inset-bottom)); }
@media (min-width:800px) {
    body { padding-bottom:0; }
    .nav,.nav.admin-nav { position:static !important; inset:auto !important; display:flex !important; width:100%; height:auto !important; padding:10px var(--page-pad) !important; background:transparent; border:0; gap:4px; }
    .nav a { flex-direction:row; gap:8px; padding:8px 12px; border-radius:12px; font-size:13px; }
    .nav a.on { background:var(--accent-soft); color:var(--in); box-shadow:none; }
}
@media (min-width:1920px) {
    :root { --page-max:2200px; }
    body { font-size:17px; }
    .card { padding:20px; }
    table { font-size:15px; }
    .chat-sidebar { flex-basis:380px; max-width:420px; }
    .chat-msg-content { font-size:16px; }
}
@media (min-width:3200px) {
    :root { --page-max:2800px; --page-pad:40px; }
    body { font-size:19px; }
    .nav a { font-size:16px; min-height:52px; }
    .chat-sidebar { flex-basis:460px; max-width:460px; }
    .chat-msg-content { font-size:18px; }
    .chat-msg { max-width:min(65%,900px); }
}
@media (max-width:1024px) {
    .row { flex-wrap:wrap; }
    .row > * { flex-basis:240px; }
    .smart-table-scroll > table:not(.tasks-compact) { min-width:600px; }
}
@media (max-width:799px) {
    body,body.admin-view { padding-bottom:calc(var(--nav-height) + env(safe-area-inset-bottom) + 14px) !important; }
    .nav,.nav.admin-nav,body.admin-view .nav,body.admin-view .nav.admin-nav {
        position:fixed !important; top:auto !important; bottom:0 !important; left:0 !important; right:0 !important;
        display:flex !important; flex-direction:row !important; flex-wrap:nowrap !important;
        width:100% !important; max-width:100% !important; height:calc(var(--nav-height) + env(safe-area-inset-bottom)) !important;
        padding:5px 6px calc(5px + env(safe-area-inset-bottom)) !important; margin:0 !important;
        background:var(--card) !important; border-top:1px solid var(--line) !important; z-index:1000 !important;
        overflow-x:auto !important; overflow-y:hidden !important; scrollbar-width:none;
        box-shadow:0 -4px 18px rgba(0,0,0,.06);
    }
    .nav a,body.admin-view .nav > a { flex:0 0 78px !important; flex-direction:column !important; justify-content:center; padding:7px 4px !important; font-size:10px !important; color:var(--muted) !important; border-radius:10px; }
    .nav a.on,body.admin-view .nav > a.on { background:var(--accent-soft) !important; color:var(--in) !important; box-shadow:none; }
    .nav a span { max-width:100%; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
    .nav a svg { width:22px; height:22px; }
    .nav::-webkit-scrollbar { display:none; }
    .wrap { padding:14px 12px; }
    .topbar { display:grid; grid-template-columns:minmax(0,1fr) auto; gap:10px; padding:12px; }
    .brand { margin:0; font-size:14px; grid-column:1; }
    .brand img { width:34px; height:34px; flex-basis:34px; border-radius:9px; }
    .who { grid-row:2; grid-column:1 / -1; width:100%; justify-content:flex-end; }
    .who-info { margin-inline-end:auto; max-width:75%; align-items:flex-start; text-align:start; }
    .theme-toggle { grid-row:1; grid-column:2; }
    .who-name { font-size:12px; }
    .btn,.chat-icon-btn,.chat-back-btn,.chat-attach-btn,.chat-send-btn,.cw-icon-btn { min-height:42px; }
    input,select,textarea { font-size:16px; min-height:44px; }
    .grid { grid-template-columns:repeat(2,minmax(0,1fr)); }
    .card { padding:14px; }
    .row > * { flex:1 1 100%; }
    .cw-root { bottom:calc(var(--nav-height) + env(safe-area-inset-bottom) + 14px); right:12px; }
    .cw-panel { width:min(400px,calc(100vw - 24px)); height:calc(var(--viewport-height,100dvh) - var(--nav-height) - 30px); max-height:calc(var(--viewport-height,100dvh) - var(--nav-height) - 30px); }
    .cw-fab { width:52px; height:52px; }
    html.chat-page-root body > main.wrap { padding:8px 8px calc(var(--nav-height) + env(safe-area-inset-bottom) + 8px); }
    html.chat-page-root body,html.chat-page-root body.admin-view { padding-bottom:0 !important; }
    .chat-app { border-radius:12px; }
    .chat-sidebar { flex-basis:100%; max-width:100%; }
    .chat-app.chat-conv-open .chat-sidebar { display:none; }
    .chat-app:not(.chat-conv-open) .chat-main { display:none; }
    .chat-app.chat-conv-open .chat-main { display:flex; }
    .chat-messages { padding:14px 10px; }
    .chat-msg { max-width:90%; }
    .chat-back-btn { display:inline-flex !important; }
    body.keyboard-open .nav,body.keyboard-open .nav.admin-nav { display:none !important; }
    html.chat-page-root body.keyboard-open > main.wrap { padding-bottom:4px !important; }
    body.keyboard-open .cw-root { bottom:8px; }
    body.keyboard-open .cw-panel { height:calc(var(--viewport-height,100dvh) - 20px); max-height:calc(var(--viewport-height,100dvh) - 20px); }
}
@media (max-width:640px) {
    .smart-table-scroll { overflow-x:auto !important; background:transparent; border-radius:12px; }
    table.smart-cards { display:block; min-width:0 !important; width:100% !important; }
    table.smart-cards thead { display:none; }
    table.smart-cards tbody { display:block; }
    table.smart-cards tbody > tr { display:block; margin-bottom:10px; border:1px solid var(--line); background:var(--card); border-radius:12px; padding:8px 12px; }
    table.smart-cards td { display:flex; gap:12px; align-items:center; justify-content:space-between; width:auto !important; min-width:0 !important; max-width:100%; white-space:normal; padding:9px 0; border-bottom:1px dashed var(--line); overflow-wrap:anywhere; }
    table.smart-cards td:last-child { border:0; }
    table.smart-cards td[data-label]::before { content:attr(data-label); color:var(--muted); font-weight:700; font-size:11px; flex:0 0 35%; }
    table.smart-cards td[colspan] { display:block; text-align:center; }
    table.smart-cards td[colspan]::before { display:none; }
    table.smart-cards td:has(form) { flex-wrap:wrap; }
    table.smart-cards td form { width:100%; }
    .task-filter-form label { flex-basis:100%; }
    .task-filter-form .btn { flex:1; }
    .task-detail-grid,.detail-grid,.ec-grid { grid-template-columns:minmax(0,1fr) !important; }
    .clock { font-size:clamp(32px,10vw,44px); }
    .chat-modal { width:calc(100vw - 16px); max-width:calc(100vw - 16px); height:auto; border-radius:16px; }
}
@media (max-width:360px) {
    .brand span { font-size:12px; }
    .theme-toggle [data-theme-label] { display:none; }
    .chat-composer { gap:4px; padding-inline:6px; }
    .chat-composer textarea { min-width:0; }
    .cw-panel { width:calc(100vw - 20px); }
}
