/* Shared responsive foundations. Loaded after each page's existing styles. */
html { -webkit-text-size-adjust:100%; text-size-adjust:100%; }
[hidden] { display:none !important; }
button, a, input, select, textarea, summary { -webkit-tap-highlight-color:transparent; }
button, .btn, summary { touch-action:manipulation; }
button:disabled { opacity:.55; cursor:default; }
:focus-visible { outline:3px solid #2563eb; outline-offset:3px; }
.mobile-menu-toggle, .mobile-account, .mobile-document-actions, .filter-toggle, .selection-count, .mobile-company-picker { display:none; }
.document-tools { display:contents; }
.document-tools > summary { display:none; }
.document-tools-content { display:contents; }
.document-title { padding:0; margin:0; border:0; border-radius:4px; background:transparent; color:inherit; font:inherit; text-align:left; overflow-wrap:anywhere; }
.document-title:hover { color:#245a93; text-decoration:underline; }
.documents-table td { overflow-wrap:anywhere; }
.modal-backdrop { box-sizing:border-box; padding:18px; }
.modal-backdrop > .modal { box-sizing:border-box; max-width:100%; max-height:calc(100vh - 36px); max-height:calc(100dvh - 36px); overflow-y:auto; overscroll-behavior:contain; }
.dialog-close { position:absolute; top:10px; right:10px; width:44px; height:44px; padding:0; margin:0; border-radius:10px; background:#f1f5f9; color:#334155; font-size:26px; line-height:1; }
.modal.has-dialog-close { position:relative; }
.has-dialog-close > h3:first-of-type { padding-right:42px; }
body.overlay-open { overflow:hidden; }
.dashboard-page .modal-backdrop { top:var(--portal-viewport-top,0px); bottom:auto; height:var(--portal-viewport-height,100vh); height:var(--portal-viewport-height,100dvh); }
#fp_xml_preview { height:100%; overflow:auto; }
#fp_xml_preview pre { margin:0; overflow-wrap:anywhere; }
@media (prefers-reduced-motion:reduce) {
  *, *::before, *::after { animation:none !important; transition:none !important; scroll-behavior:auto !important; }
}

@media (max-width:900px) {
  *, *::before, *::after { box-sizing:border-box; }
  body { padding:16px 12px; padding-right:max(12px,env(safe-area-inset-right)); padding-left:max(12px,env(safe-area-inset-left)); font-size:16px; }
  input:not([type=checkbox]):not([type=radio]):not([type=hidden]), select, textarea { min-width:0; max-width:100%; font-size:16px !important; }
  input:not([type=checkbox]):not([type=radio]):not([type=hidden]), select { min-height:46px; }
  button, .btn, .btn-add, .btn-send, .btn-secondary, .logout, summary { min-height:44px; line-height:1.4; }
  input[type=checkbox], input[type=radio] { flex:0 0 auto; width:24px; height:24px; margin:8px; accent-color:#2b6cb0; }
  p, h1, h2, h3, h4, label { overflow-wrap:anywhere; }
  textarea { resize:vertical; }
  .dashboard-page header { display:grid; grid-template-columns:minmax(0,1fr) auto; gap:12px; align-items:center; padding:4px 0 16px; margin:0 0 12px; border-bottom:1px solid #dfe5ed; }
  .dashboard-page header .left { min-width:0; max-width:100%; }
  .dashboard-page header h1 { font-size:21px; line-height:1.3; letter-spacing:-.4px; }
  .dashboard-page .portal-description { display:none; }
  .dashboard-page .mobile-account { display:block; margin:3px 0 0; font-size:13px; color:#64748b; }
  .mobile-menu-toggle { display:block; padding:10px 12px; margin:0; background:#fff; color:#334155; border:1px solid #d4dce8; font-size:14px; }
  .dashboard-page header .right { grid-column:1/-1; width:100%; display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); align-items:stretch; gap:8px; text-align:left; }
  .dashboard-page.mobile-ready header .right:not(.is-open) { display:none; }
  .dashboard-page header .right .logout { display:flex; align-items:center; justify-content:center; min-width:0; margin:0; padding:10px 8px; font-size:13px; text-align:center; }
  .dashboard-page .who { grid-column:1/-1; font-size:13px; }
  .dashboard-page .controls { display:flex; align-items:stretch; gap:10px; margin:0 0 14px; }
  .dashboard-page .controls > .btn-add { flex:1 1 100%; display:flex; align-items:center; justify-content:center; padding:13px 16px; border-radius:12px; font-size:16px; font-weight:700; box-shadow:0 3px 8px #6b46c11a; }
  .dashboard-page .document-tools { display:block; flex:1 1 100%; min-width:0; border:1px solid #dce3ed; border-radius:10px; background:#fff; }
  .document-tools > summary { display:flex; align-items:center; justify-content:space-between; gap:8px; cursor:pointer; padding:11px 13px; color:#334155; font-size:14px; font-weight:600; list-style:none; }
  .document-tools > summary::-webkit-details-marker { display:none; }
  .document-tools[open] > summary { border-bottom:1px solid #e5e7eb; }
  .document-tools[open] > summary span { transform:rotate(180deg); }
  .dashboard-page .document-tools-content { display:flex; flex-wrap:wrap; gap:8px; padding:10px; min-width:0; }
  .document-tools-content > button { flex:1 1 140px; margin:0; font-size:14px; }
  .dashboard-page .package-controls { flex:1 1 100%; display:grid !important; grid-template-columns:minmax(0,1fr); min-width:0; gap:8px !important; }
  .package-controls select { margin:0; }
  .package-controls button, .package-controls > div { width:100%; margin:0; }
  .dashboard-page #downloadMenu { left:0; right:0; width:100%; min-width:0; z-index:1400; }
  .dashboard-page .download-option { white-space:normal; text-align:left; padding:12px; }
  .dashboard-page #send_form_top { display:flex !important; flex:1 1 100%; width:100%; margin:0 !important; }
  .dashboard-page:not(.has-selection) #send_form_top { display:none !important; }
  #send_form_top > button { width:100%; margin:0; font-size:14px; }
  .dashboard-page .controls > .badge { width:100%; font-size:12px; padding:0 2px; background:transparent; }
  .dashboard-page .filters { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:10px; padding:12px; border:1px solid #dfe5ed; border-radius:12px; background:#fff; margin:0 0 16px !important; }
  .dashboard-page .filters label { display:flex; flex-direction:column; align-items:stretch; gap:3px; min-width:0; font-size:12px; font-weight:600; color:#475569; }
  .dashboard-page .filters label:first-of-type { grid-column:1/-1; }
  .dashboard-page .filters input, .dashboard-page .filters select { width:100%; min-width:0 !important; margin:0; border:1px solid #ccd6e3; border-radius:8px; background:#fff; padding:10px; }
  .filters-ready:not(.filters-expanded) > label:not(:first-of-type) { display:none; }
  .dashboard-page .filter-toggle { display:block; background:#f1f5f9; color:#334155; border:1px solid #d4dce8; padding:10px; margin:0; font-weight:600; font-size:14px; }
  .dashboard-page .filters > button[type=submit] { margin:0; padding:10px !important; color:#fff; background:#2b6cb0; font-size:14px; }
  .dashboard-page .company-list { display:grid; gap:8px; list-style:none; padding:0 !important; }
  .dashboard-page .company-list, .dashboard-page .company-list-heading { display:none; }
  .dashboard-page .mobile-company-picker { display:block; font-size:13px; font-weight:600; color:#475569; }
  .mobile-company-picker select { width:100%; border:1px solid #ccd6e3; border-radius:10px; padding:10px; background:#fff; }
  .company-list li { margin:0 !important; display:flex; align-items:center; gap:8px; padding:6px 12px; background:#fff; border:1px solid #dfe5ed; border-radius:10px; }
  .company-list a { display:flex; align-items:center; flex:1; min-height:44px; overflow-wrap:anywhere; color:#245a93; }
  .dashboard-page #table_container { min-width:0; }
  .documents-table, .documents-table thead, .documents-table tbody { display:block; width:100%; background:transparent; box-shadow:none; }
  .documents-table thead tr { display:block; margin:0 0 10px; }
  .documents-table thead th { display:none; }
  .documents-table thead th:first-child { display:block; width:100% !important; min-width:0 !important; padding:8px; border:1px solid #dfe5ed; border-radius:10px; background:#fff; }
  .documents-table thead th:first-child > div { min-width:0; }
  .documents-table .selection-menu { flex:1; width:100%; min-width:0; margin:0; font-size:14px !important; }
  .documents-table .custom-checkbox { flex:0 0 44px; min-height:44px; padding:10px; }
  .documents-table .custom-checkbox input { display:block; position:absolute; opacity:0; width:24px; height:24px; margin:0; }
  .custom-checkbox:focus-within .checkbox-box { outline:3px solid #2563eb; outline-offset:2px; }
  .documents-table tr.clickable { display:grid; grid-template-columns:minmax(0,1fr) minmax(70px,auto); grid-auto-flow:row dense; gap:10px 12px; position:relative; margin:0 0 12px; padding:14px; border:1px solid #dce3ed; border-radius:14px; background:#fff; box-shadow:0 2px 5px #0f172a04; }
  .documents-table tr.clickable::after { content:none; }
  .documents-table tr.clickable:has(input.file_checkbox:checked) { border-color:#2b6cb0; box-shadow:0 0 0 2px #2b6cb020; }
  .documents-table tr.clickable > td { display:block; min-width:0; border:0; padding:0; font-size:14px; line-height:1.5; }
  .documents-table tr.clickable > .document-select { grid-column:2; grid-row:1; justify-self:end; align-self:start; order:0; }
  .documents-table .document-select > input { margin:10px; }
  .documents-table .document-name { grid-column:1; grid-row:1; order:0; align-self:center; }
  .documents-table .document-title { display:block; min-height:44px; padding:0; font-size:15px; line-height:1.5; font-weight:700; }
  .documents-table .source-badge { margin:4px 0; font-size:11px; }
  .documents-table .document-description { grid-column:1/-1; order:2; color:#64748b; }
  .documents-table .document-description:empty { display:none; }
  .documents-table .status-cell { grid-column:1/-1; order:1; color:#245a93; font-weight:600; font-size:12px; text-transform:capitalize; }
  .documents-table .category-cell { grid-column:1; order:3; }
  .documents-table .document-amount { grid-column:2; order:3; text-align:right; }
  .documents-table .category-cell::before, .documents-table .document-amount::before { display:block; content:attr(data-label); font-size:11px; color:#64748b; font-weight:400; margin-bottom:4px; }
  .documents-table .category-badge { max-width:100%; white-space:normal; padding:5px 8px; font-size:12px; }
  .documents-table tr.clickable > .document-detail { display:grid; grid-template-columns:110px minmax(0,1fr); align-items:center; gap:6px; grid-column:1/-1; order:4; padding-top:8px; border-top:1px solid #edf1f5; font-size:13px; }
  .documents-table .document-detail[data-empty=true] { display:none !important; }
  .documents-table.mobile-ready tr:not(.details-expanded) .document-detail { display:none; }
  .documents-table .document-detail::before { content:attr(data-label); display:block; color:#64748b; font-size:11px; }
  .documents-table .accounting-month-cell select { width:100%; }
  .documents-table .document-actions { grid-column:1/-1; order:5; }
  .documents-table .document-actions button { width:100%; justify-content:center; }
  .documents-table .action-menu { position:static !important; width:100%; min-width:0 !important; margin-top:6px; }
  .documents-table .action-menu a, .documents-table .action-menu button { min-height:44px; padding:12px !important; font-size:14px; }
  .documents-table tr.clickable > .mobile-document-actions { display:flex; grid-column:1/-1; order:6; gap:8px; padding-top:10px; border-top:1px solid #e8edf3; }
  .mobile-document-actions button { flex:1; min-width:0; margin:0; padding:10px; font-size:13px; border-radius:8px; }
  .ksef-not-ours-controls { min-width:0; }
  .documents-table .ksef-not-ours-toggle { font-size:12px; padding:8px; margin-top:6px; }
  .documents-table .ksef-not-ours-badge { white-space:normal; }
  .dashboard-page.has-selection { padding-bottom:110px; }
  .has-selection #send_form_top, .has-selection #download_form_top { position:fixed; bottom:0; left:0; right:0; z-index:1400; display:flex !important; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:8px; width:100%; margin:0 !important; padding:12px; padding-bottom:max(12px,env(safe-area-inset-bottom)); background:#fff; border-top:1px solid #d4dce8; box-shadow:0 -4px 18px #0f172a0d; }
  .has-selection .selection-count { display:block; flex:1; font-size:13px; color:#334155; white-space:nowrap; }
  .has-selection #send_form_top > button, .has-selection #download_form_top > button { width:auto; flex:1; margin:0; font-size:13px; }
  .has-selection #download_form_top .badge { display:none; }
  .overlay-open #send_form_top, .overlay-open #download_form_top { visibility:hidden; }
  .modal-backdrop { padding:10px; padding-top:max(10px,env(safe-area-inset-top)); padding-bottom:max(10px,env(safe-area-inset-bottom)); }
  .modal-backdrop > .modal { max-height:calc(100vh - 20px); max-height:calc(100dvh - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); padding:18px; border-radius:14px; overflow-wrap:anywhere; }
  .dashboard-page .modal-backdrop > .modal { max-height:calc(var(--portal-viewport-height,100dvh) - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) !important; }
  .modal h3 { font-size:19px; line-height:1.4; margin-top:0; }
  .modal p { font-size:14px; line-height:1.6; }
  .modal form > div:last-child, .modal > div:last-child:not(#message_list):not(.message-conversation):not(#msg_preview) { flex-wrap:wrap; }
  .modal input[type=email], .modal input[type=password], .modal input[type=text], .modal textarea { border:1px solid #cbd5e1; border-radius:8px; padding:11px 12px; }
  #full_preview { padding:12px; padding-top:max(12px,env(safe-area-inset-top)); padding-bottom:max(20px,env(safe-area-inset-bottom)); overscroll-behavior:contain; }
  #full_preview .top-actions { position:sticky; top:-12px; z-index:2; padding:10px 0; margin-top:-12px; background:#fff; border-bottom:1px solid #e5e7eb; flex-wrap:wrap; }
  #fp_title { font-size:18px; line-height:1.5; overflow-wrap:anywhere; }
  #full_preview .preview-box { height:44vh; height:44dvh; min-height:230px; }
  #full_preview .preview-box:has(#fp_xml_preview:not([hidden])) { height:auto; min-height:120px; max-height:44dvh; overflow:auto; }
  .preview-edit-actions { flex-wrap:wrap; }
  .preview-edit-actions button { flex:1 1 140px; margin:0; }
  #modal_messages > .modal { flex-direction:column; gap:12px !important; }
  #modal_messages .message-conversation { flex:none !important; min-width:0; max-height:none !important; }
  #message_list { flex:none !important; height:32vh; height:32dvh; min-height:160px; max-height:360px; padding:8px !important; overflow-wrap:anywhere; }
  #msg_preview { flex:none !important; width:100%; max-height:260px; overflow:auto; }
  #msg_preview:not(:has(#preview_body > *)) { display:none !important; }
  #preview_body img, #preview_body iframe { max-width:100%; max-height:220px; object-fit:contain; }
  #modal_full_preview > div { max-width:100% !important; max-height:calc(100dvh - 20px) !important; padding:60px 12px 12px !important; }
  #full_preview_body { max-width:100%; max-height:calc(100dvh - 100px) !important; overflow:auto; }
  #full_preview_body img { height:auto; object-fit:contain; }
  .ksef-invoices-table, .ksef-invoices-table tbody { display:block; background:transparent; box-shadow:none; }
  .ksef-invoices-table thead { display:none; }
  .ksef-invoices-table tbody tr { display:grid; grid-template-columns:minmax(0,1fr) auto; gap:8px; margin:0 0 12px; padding:12px; border:1px solid #dfe5ed; border-radius:12px; }
  .ksef-invoices-table td { display:block; padding:0 !important; border:0; font-size:14px; overflow-wrap:anywhere; min-width:0; }
  .ksef-invoices-table td:first-child { grid-row:1; grid-column:2; }
  .ksef-invoices-table td:nth-child(2) { grid-row:1; grid-column:1; font-weight:700; }
  .ksef-invoices-table td:nth-child(n+3) { grid-column:1/-1; }
  .ksef-invoices-table td:nth-child(n+3)::before { content:attr(data-label) ': '; font-size:12px; color:#64748b; }
  .ksef-invoices-table td[colspan] { grid-column:1/-1; }
  #modal_ksef_invoice_list .modal > div { flex-wrap:wrap; }
}
@media (min-width:901px) {
  .dashboard-page #table_container { overflow-x:auto; }
  .documents-table { min-width:1150px; }
}
@media (min-width:901px) and (max-width:1100px) {
  .dashboard-page header .left { max-width:60%; }
}
@media (max-height:500px) and (max-width:1000px) {
  .modal-backdrop { padding:8px; }
  .modal-backdrop > .modal { max-height:calc(100vh - 16px); max-height:calc(100dvh - 16px); }
  #full_preview .preview-box { height:60vh; height:60dvh; }
}
