@media (display-mode: standalone) {
  html { background:#f4f6f8; }
  body { padding-top:env(safe-area-inset-top); }
  .app { height:calc(100dvh - env(safe-area-inset-top)); }
}

.kwb-offline #persistenceStatus {
  color:#ad2731 !important;
  border-color:#efc7c7 !important;
}

@media (max-width: 760px) {
  html, body { width:100%; max-width:100%; overscroll-behavior:none; }
  body { font-size:13px; }
  .login-screen { min-height:100dvh; }
  .login-panel { padding:24px 20px max(24px,env(safe-area-inset-bottom)); }
  .brand-mark { width:min(290px,92%); margin-bottom:22px; }
  .login-panel h1 { font-size:22px; }
  .field input, .field select, .field textarea { min-height:44px; font-size:16px; }

  .app { grid-template-columns:1fr; grid-template-rows:60px minmax(0,1fr); }
  .rail { height:60px; padding:0 8px; gap:7px; overflow:hidden; }
  .logo { width:86px; height:48px; }
  .nav { height:60px; gap:0; scrollbar-width:none; }
  .nav::-webkit-scrollbar { display:none; }
  .nav button { min-width:64px; min-height:60px; padding:6px 7px; font-size:9px; }
  .nav button .nav-icon { font-size:15px; margin-bottom:2px; }

  .top { min-height:52px; height:52px; padding:7px 9px; gap:6px; flex-wrap:nowrap; }
  .top h2 { max-width:34vw; overflow:hidden; text-overflow:ellipsis; font-size:15px; }
  .top .user-pill { max-width:31vw; overflow:hidden; text-overflow:ellipsis; padding:6px 8px; }
  .top .btn { min-height:36px; padding:7px 9px; }
  #newProjectButton { white-space:nowrap; }
  #logoutButton { font-size:0; width:38px; padding:7px; }
  #logoutButton::before { content:"×"; font-size:22px; line-height:1; }

  .page { height:calc(100dvh - 112px); padding:9px 8px max(82px,calc(env(safe-area-inset-bottom) + 70px)); scroll-padding-bottom:max(82px,calc(env(safe-area-inset-bottom) + 70px)); }
  .panelhead, .panelbody { padding:10px; }
  .cards, .two, .grid2, .grid3, .time-summary, .time-filters { grid-template-columns:1fr !important; }
  .card { padding:10px; }
  .modal { padding:6px; align-items:flex-end; }
  .modalbox, .modalbox.compact { width:calc(100vw - 12px); max-width:none; max-height:calc(100dvh - 12px); padding:14px; border-radius:8px 8px 0 0; }
  .actions { position:sticky; bottom:0; padding:9px 0 max(2px,env(safe-area-inset-bottom)); background:inherit; }
  .actions .btn { min-height:42px; }
  .table-wrap { max-width:100%; overflow-x:auto; -webkit-overflow-scrolling:touch; }
  .project-workspace { grid-template-columns:minmax(180px,42vw) minmax(440px,1fr) !important; }
  .toast {
    top:auto;
    left:8px;
    right:8px;
    bottom:max(8px,env(safe-area-inset-bottom));
    width:auto;
    height:auto;
    min-height:0;
    max-width:none;
    max-height:min(120px,30dvh);
    transform:none;
    overflow:auto;
  }

  #hr, #hr .hr-layout, #hr .hr-record, #hr .personal-workspace,
  #hr .personal-workspace-head, #hr .personal-change-panel {
    width:100%;
    min-width:0;
    max-width:100%;
    box-sizing:border-box;
  }
  #hr .hr-record { overflow:hidden; }
  #hr .hr-record-tabs { width:100%; max-width:100%; overflow-x:auto; }
  #hr .hr-metrics { grid-template-columns:1fr; }
  #hr .hr-metric { width:100%; }
  #hr .personal-contract-strip { grid-template-columns:1fr; }
  #hr .personal-change-row { grid-template-columns:1fr; gap:3px; }
  #hr .hr-change-list, #hr .table-wrap { width:100%; max-width:100%; overflow-x:auto; }
  #hr .hr-record-head .actions { width:100%; justify-content:flex-start; }

  .commission-detail-table { overflow:visible; }
  .commission-detail-table table,
  .commission-detail-table tbody { display:block; width:100%; }
  .commission-detail-table thead { display:none; }
  .commission-detail-table tr {
    position:relative;
    display:block;
    margin:0 0 10px;
    padding:10px 10px 10px 48px;
    border:1px solid var(--line);
    border-radius:7px;
    background:#fff;
  }
  .commission-detail-table td {
    display:grid;
    grid-template-columns:105px minmax(0,1fr);
    gap:8px;
    width:100%;
    padding:5px 0;
    border:0;
    overflow-wrap:anywhere;
    white-space:normal;
  }
  .commission-detail-table td::before { color:var(--muted); font-size:10px; font-weight:700; text-transform:uppercase; }
  .commission-detail-table td:nth-child(1) { position:absolute; left:12px; top:12px; display:block; width:auto; padding:0; }
  .commission-detail-table td:nth-child(1)::before { content:none; }
  .commission-detail-table td:nth-child(2)::before { content:"Artikel"; }
  .commission-detail-table td:nth-child(3)::before { content:"Material"; }
  .commission-detail-table td:nth-child(4)::before { content:"Angefordert"; }
  .commission-detail-table td:nth-child(5)::before { content:"Hauptlager"; }
  .commission-detail-table td:nth-child(6)::before { content:"Bestellung"; }
  .commission-detail-table .btn { width:100%; max-width:100%; white-space:normal; overflow-wrap:anywhere; }

  #billingModal .modalbox { overflow-x:hidden; }
  #billingModal .billing-preview-column .doc-preview,
  .project-billing-preview-body { padding:8px; overflow-x:hidden; }
  #billingModal .billing-preview-column .kwb-document,
  .project-billing-preview-body .kwb-document {
    width:794px;
    max-width:none;
    zoom:.72;
    transform:none;
    transform-origin:top left;
  }
  #billingModal .kwb-doc-top,
  .project-billing-preview-body .kwb-doc-top { display:table; width:100%; height:290px; table-layout:fixed; border-collapse:collapse; }
  #billingModal .kwb-doc-top > div,
  .project-billing-preview-body .kwb-doc-top > div { display:table-cell; width:auto; padding-right:0; vertical-align:top; }
  #billingModal .kwb-doc-top > div:first-child,
  .project-billing-preview-body .kwb-doc-top > div:first-child { padding-right:60px; }
  #billingModal .kwb-doc-top > div:last-child,
  .project-billing-preview-body .kwb-doc-top > div:last-child { width:332px; }
  #billingModal .kwb-sender,
  .project-billing-preview-body .kwb-sender { margin-top:91px; }
  #billingModal .kwb-footer,
  .project-billing-preview-body .kwb-footer { display:block; }
  #billingModal .billing-document-actions { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); }
  #billingModal .billing-document-actions .billing-action { width:100%; min-width:0; }
  .project-billing-preview .modalbox { width:calc(100vw - 12px); max-width:none; }
  .project-billing-preview-head { flex-wrap:wrap; }
}

@media (max-width: 430px) {
  .logo { width:72px; }
  .nav button { min-width:58px; }
  .top h2 { max-width:27vw; }
  .top .user-pill { display:none; }
  #newProjectButton { font-size:11px; }
  #billingModal .billing-preview-column .kwb-document,
  .project-billing-preview-body .kwb-document { zoom:.4; }
}

@media (min-width: 431px) and (max-width: 480px) {
  #billingModal .billing-preview-column .kwb-document,
  .project-billing-preview-body .kwb-document { zoom:.46; }
}
