/* R28 correspondence mobile app (/corr-app, PWA, phone first). Every class of this file starts with "ca-" (the employee app's me.css approach:
   360 px first, touch targets ≥ 44 px, logical properties for RTL, the app's colour tokens so dark mode follows the theme). The last section styles
   the approvers' signatures in the shared letter print (LetterSheet, desktop and app). */

/* ---------------------------------------------------------------- shell */
.ca-app { min-height: 100vh; min-height: 100dvh; background: var(--ground); color: var(--text); font-family: var(--font);
    padding-bottom: calc(72px + env(safe-area-inset-bottom)); -webkit-tap-highlight-color: transparent; }
.ca-top { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 4px; min-height: 56px;
    padding: env(safe-area-inset-top) 8px 0; background: var(--ink); color: #fff; box-shadow: 0 1px 0 rgba(0,0,0,.08); }
.ca-top a, .ca-top button { color: #fff; }
.ca-top-title { flex: 1; min-width: 0; padding-inline: 6px; }
.ca-top-title h1, .ca-title { margin: 0; font-size: 1.1rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.2; }
.ca-title small { display: block; font-size: .78rem; font-weight: 400; opacity: .8; }
.ca-top-btn, .ca-back { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px;
    border-radius: 50%; text-decoration: none; border: 0; background: transparent; cursor: pointer; flex: none; }
.ca-top-btn:hover, .ca-back:hover { background: rgba(255,255,255,.1); }
.ca-lang { font-weight: 700; font-size: .95rem; }
[dir="rtl"] .ca-back .icon { transform: scaleX(-1); }
.ca-badge { position: absolute; top: 4px; inset-inline-end: 2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
    background: var(--danger); color: #fff; font-size: .7rem; font-weight: 700; line-height: 18px; text-align: center; box-sizing: border-box; }
.ca-badge.static { position: static; margin-inline-start: auto; }

.ca-main { max-width: 720px; margin: 0 auto; padding: 12px 16px 24px; box-sizing: border-box; }
.ca-main > * + * { margin-top: 12px; }

/* bottom tab bar */
.ca-tabs { position: fixed; inset-inline: 0; bottom: 0; z-index: 30; display: flex; justify-content: center;
    background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
.ca-tab { position: relative; flex: 1; max-width: 144px; min-height: 60px; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; text-decoration: none; color: var(--muted); font-size: .72rem; border: 0; background: transparent; cursor: pointer; font-family: inherit; padding: 6px 2px; }
.ca-tab.active { color: var(--primary); font-weight: 600; }
.ca-tab .ca-badge { top: 4px; inset-inline-end: calc(50% - 22px); }
.ca-tab-main .ca-tab-disc { display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px; margin-top: -22px; border-radius: 50%;
    background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(0,0,0,.18); border: 3px solid var(--surface); }
.ca-tab-main.active .ca-tab-disc { background: var(--primary-dark); }

/* bottom sheets ("more", actions) */
.ca-sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.35); }
.ca-sheet { position: fixed; inset-inline: 0; bottom: 0; z-index: 41; max-width: 720px; margin: 0 auto; max-height: 88vh; overflow-y: auto;
    background: var(--surface); border-radius: 18px 18px 0 0; padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); box-shadow: 0 -8px 30px rgba(0,0,0,.2);
    animation: ca-up .18s ease-out; box-sizing: border-box; }
@keyframes ca-up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.ca-sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 4px auto 12px; }
.ca-sheet h2 { font-size: 1.05rem; margin: 0 0 12px; }
.ca-sheet-who { display: flex; align-items: center; gap: 12px; padding: 4px 0 12px; border-bottom: 1px solid var(--row-line); }
.ca-sheet-who div { display: flex; flex-direction: column; min-width: 0; }
.ca-avatar { flex: none; width: 44px; height: 44px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
    background: var(--accent); color: var(--ink); font-weight: 700; }
.ca-menu { display: flex; flex-direction: column; padding: 6px 0; }
.ca-menu-item { display: flex; align-items: center; gap: 14px; min-height: 52px; padding: 0 4px; color: var(--text); text-decoration: none; border-bottom: 1px solid var(--row-line); }
.ca-menu-item .icon { color: var(--primary); }
.ca-signout { margin-top: 12px; }
.ca-signout .btn { width: 100%; justify-content: center; min-height: 48px; }

/* install banner */
.ca-install { display: flex; align-items: center; gap: 10px; max-width: 720px; margin: 8px auto 0; padding: 10px 12px; box-sizing: border-box;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.ca-install img { border-radius: 10px; flex: none; }
.ca-install-text { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: .85rem; }
.ca-install-text span { color: var(--muted); }
@media (max-width: 760px) { .ca-install { margin: 8px 16px 0; } }
.ca-icon-btn { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border: 0; border-radius: 50%;
    background: transparent; color: var(--muted); cursor: pointer; flex: none; text-decoration: none; }
.ca-icon-btn:hover { background: var(--gray-bg); }
.ca-icon-btn.on { color: var(--primary); }
.ca-icon-btn.light { color: #fff; }
.ca-icon-btn .ca-badge { top: 2px; inset-inline-end: 0; }

/* ---------------------------------------------------------------- building blocks */
.ca-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.ca-card.flush { padding: 0; overflow: hidden; }
.ca-card > h2, .ca-section-title { font-size: .95rem; font-weight: 600; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ca-card-head { padding: 12px 16px 8px; margin: 0 !important; }
.ca-more { margin-inline-start: auto; font-size: .82rem; font-weight: 500; color: var(--primary); text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }
.ca-pad { padding: 0 16px 14px; margin: 0; }
.ca-hidden { display: none; }
.ca-center { text-align: center; }
.ca-empty { text-align: center; padding: 28px 16px; }
.ca-empty .icon { color: var(--muted); }
.ca-empty h2 { justify-content: center; font-size: 1.05rem; margin: 10px 0 6px; }
.ca-empty p { margin: 0 0 14px; }
.ca-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.ca-actions.start { justify-content: flex-start; }
.ca-actions .btn, .ca-btn-lg { min-height: 48px; padding-inline: 18px; font-size: 1rem; justify-content: center; }
.ca-warn, .ca-bad, .ca-good, .ca-info { padding: 10px 12px; border-radius: var(--radius-sm); font-size: .88rem; }
.ca-warn { background: var(--amber-bg); color: var(--amber-fg); }
.ca-bad { background: var(--red-bg); color: var(--red-fg); }
.ca-good { background: var(--green-bg); color: var(--green-fg); }
.ca-info { background: var(--blue-bg); color: var(--blue-fg); }
.ca-good-card { border-color: var(--green-fg); }
.ca-good-card h2 { color: var(--green-fg); }
.ca-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; align-items: center; }
.ca-chip-btn { min-height: 36px; padding: 0 12px; border-radius: 18px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: .85rem; cursor: pointer; }
.ca-chip-btn.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.ca-subject { font-size: 1.1rem; margin: 0 0 10px; line-height: 1.35; overflow-wrap: anywhere; }
.ca-body { white-space: pre-wrap; line-height: 1.7; font-size: .95rem; margin-top: 12px; max-height: 11.5em; overflow: hidden; overflow-wrap: anywhere;
    -webkit-mask-image: linear-gradient(to bottom, #000 70%, transparent); mask-image: linear-gradient(to bottom, #000 70%, transparent); }
.ca-body.open { max-height: none; -webkit-mask-image: none; mask-image: none; }
.ca-note { background: var(--ground); border-radius: 8px; padding: 8px 10px; margin: 6px 0; white-space: pre-wrap; font-size: .9rem; }
.ca-clip { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: normal; }
.ca-mine { border-inline-start: 4px solid var(--primary); }

/* key / value rows */
.ca-kv { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; font-size: .92rem; margin: 0; }
.ca-kv dt { color: var(--muted); }
.ca-kv dd { margin: 0; text-align: end; font-weight: 500; overflow-wrap: anywhere; }

/* list rows */
.ca-list { display: flex; flex-direction: column; }
.ca-item { position: relative; display: flex; align-items: center; gap: 12px; min-height: 62px; padding: 10px 16px; text-decoration: none; color: var(--text);
    border-bottom: 1px solid var(--row-line); background: transparent; border-inline: 0; border-top: 0; width: 100%; text-align: start; font: inherit; cursor: pointer; box-sizing: border-box; }
.ca-item:last-child { border-bottom: 0; }
a.ca-item:hover, button.ca-item:hover { background: var(--ground); }
.ca-item.unread .ca-item-body strong { font-weight: 700; }
.ca-item.unread::before { content: ""; position: absolute; inset-inline-start: 5px; top: 50%; width: 7px; height: 7px; margin-top: -3px; border-radius: 50%; background: var(--primary); }
.ca-item-icon { flex: none; width: 40px; height: 40px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center;
    background: var(--green-bg); color: var(--green-fg); }
.ca-item-icon.amber { background: var(--amber-bg); color: var(--amber-fg); }
.ca-item-icon.red { background: var(--red-bg); color: var(--red-fg); }
.ca-item-icon.blue { background: var(--blue-bg); color: var(--blue-fg); }
.ca-item-icon.gray { background: var(--gray-bg); color: var(--gray-fg); }
.ca-item-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ca-item-body strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ca-item-body > span { font-size: .82rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.ca-item-end { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; text-align: end; max-width: 40%; }
.ca-item-end .status-chip, .ca-item-end .chip { white-space: nowrap; }
.ca-item > .icon:last-child { color: var(--muted); flex: none; }
[dir="rtl"] .ca-item > .icon:last-child { transform: scaleX(-1); }
.ca-item progress { width: 100%; height: 6px; }

/* segmented control / filter pills */
.ca-seg { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.ca-seg::-webkit-scrollbar { display: none; }
.ca-seg button, .ca-seg a { flex: none; min-height: 40px; padding: 0 14px; border-radius: 20px; border: 1px solid var(--border); background: var(--surface);
    color: var(--text); font: inherit; font-size: .88rem; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.ca-seg.small button { min-height: 34px; font-size: .82rem; }
.ca-seg .on { background: var(--primary); border-color: var(--primary); color: #fff; }
.ca-seg .count { font-size: .72rem; font-weight: 700; background: var(--danger); color: #fff; border-radius: 9px; padding: 0 6px; line-height: 18px; }

/* search bar */
.ca-search { display: flex; align-items: center; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 24px; padding: 2px 4px 2px 14px; }
[dir="rtl"] .ca-search { padding: 2px 14px 2px 4px; }
.ca-search input { flex: 1; min-width: 0; border: 0; background: transparent; min-height: 44px; font-size: 1rem; color: var(--text); outline: none; box-shadow: none; }

/* forms: one column, large fields */
.ca-form { display: flex; flex-direction: column; gap: 12px; }
.ca-form label.field, .ca-form div.field { display: flex; flex-direction: column; gap: 4px; }
.ca-form .field > span { font-size: .85rem; color: var(--muted); }
.ca-form input:not([type=checkbox]):not([type=radio]):not([type=file]), .ca-form select, .ca-form textarea { min-height: 46px; font-size: 1rem; width: 100%; box-sizing: border-box; }
.ca-form textarea { min-height: 84px; }
.ca-row2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.ca-checks { display: flex; flex-direction: column; max-height: 38vh; overflow-y: auto; border: 1px solid var(--row-line); border-radius: var(--radius-sm); }
.ca-checks label.check { min-height: 44px; display: flex; align-items: center; gap: 10px; padding: 0 10px; border-bottom: 1px solid var(--row-line); }
.ca-checks label.check input, .ca-consent input { width: 22px; height: 22px; flex: none; }
.ca-consent { display: flex; gap: 10px; align-items: flex-start; font-size: .88rem; line-height: 1.5; }

/* the transaction: actions, chain, timeline */
.ca-action-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(76px, 1fr)); gap: 8px; }
.ca-action-grid:empty { display: none; }
.ca-action-grid button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 72px; padding: 8px 4px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font: inherit; font-size: .8rem; cursor: pointer; }
.ca-action-grid button .icon { color: var(--primary); }
.ca-chain { list-style: none; margin: 0; padding: 0; }
.ca-chain li { padding: 8px 0; border-bottom: 1px solid var(--row-line); display: flex; flex-direction: column; gap: 2px; }
.ca-chain li:last-child { border-bottom: 0; }
.ca-answer { color: var(--primary); }
.ca-timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.ca-timeline li { position: relative; padding: 0 0 12px; padding-inline-start: 22px; display: flex; flex-direction: column; gap: 2px; font-size: .9rem; }
.ca-timeline li::before { content: ""; position: absolute; inset-inline-start: 4px; top: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--primary); }
.ca-timeline li::after { content: ""; position: absolute; inset-inline-start: 8px; top: 18px; bottom: 0; width: 1px; background: var(--border); }
.ca-timeline li:last-child::after { display: none; }
.ca-timeline li.ca-tl-approved::before { background: var(--green-fg); }
.ca-timeline li.ca-tl-rejected::before, .ca-timeline li.ca-tl-returned::before { background: var(--red-fg); }
.ca-timeline li.ca-tl-note::before { background: var(--accent); }
.ca-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.ca-tile { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 4px; border-radius: var(--radius-sm); background: var(--ground);
    text-decoration: none; color: var(--text); font-size: .74rem; text-align: center; }
.ca-tile strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.ca-tile.bad strong { color: var(--red-fg); }
.ca-steps { margin: 0 0 14px; padding-inline-start: 20px; line-height: 1.6; }

/* attachment viewer (pictures) */
.ca-viewer { position: fixed; inset: 0; z-index: 60; background: #000; display: flex; flex-direction: column; }
.ca-viewer-bar { display: flex; align-items: center; gap: 4px; padding: env(safe-area-inset-top) 8px 0; min-height: 56px; color: #fff; }
.ca-viewer-bar strong { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-inline: 8px; }
.ca-viewer-stage { flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center; touch-action: pinch-zoom; }
.ca-viewer-stage img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* approval: the letter preview on a "sheet of paper", the decision, signatures */
.ca-paper { overflow-x: auto; }
.ca-paper .ca-sheet-doc { min-width: 0; font-size: .9rem; }
.ca-paper .ca-sheet-doc .letter-body { min-height: 120px; }
.ca-decide { border-top: 4px solid var(--primary); }
.ca-btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.ca-sign .cc-sign-canvas { height: 180px; }
.ca-sign { display: flex; flex-direction: column; gap: 10px; }
.ca-sign-current { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.ca-sign-current img { max-width: 260px; max-height: 110px; background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 4px; }
.ca-picked { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--ground); border-radius: var(--radius-sm); }
.ca-picked span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ca-pick-list { max-height: 42vh; overflow-y: auto; border: 1px solid var(--row-line); border-radius: var(--radius-sm); }

/* ---------------------------------------------------------------- scan */
.ca-capture { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.ca-capture .btn { position: relative; overflow: hidden; cursor: pointer; }
.ca-file { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; font-size: 0; }
.ca-thumbs { list-style: none; margin: 12px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.ca-thumbs:empty { display: none; }
.ca-thumb { position: relative; background: var(--ground); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; display: flex; flex-direction: column; }
.ca-thumb img { display: block; width: 100%; aspect-ratio: 3 / 4; object-fit: contain; background: #fff; cursor: zoom-in; }
.ca-thumb-no { position: absolute; top: 6px; inset-inline-start: 6px; min-width: 22px; height: 22px; border-radius: 11px; background: var(--ink); color: #fff;
    font-size: .75rem; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; padding: 0 6px; box-sizing: border-box; }
.ca-thumb-bar { display: flex; justify-content: space-around; border-top: 1px solid var(--border); background: var(--surface); }
.ca-thumb-btn { flex: 1; min-height: 44px; border: 0; background: transparent; color: var(--text); font-size: 1.1rem; cursor: pointer; }
.ca-thumb-btn:hover { background: var(--ground); }
.ca-progress { width: 100%; height: 8px; }
.ca-crop { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.92); display: flex; flex-direction: column; padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom); box-sizing: border-box; }
.ca-crop-stage { position: relative; margin: auto; max-width: 100%; max-height: calc(100% - 80px); touch-action: none; user-select: none; }
.ca-crop-stage img { display: block; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.ca-crop-box { position: absolute; border: 2px solid var(--accent); box-shadow: 0 0 0 9999px rgba(0,0,0,.45); box-sizing: border-box; cursor: move; touch-action: none; }
.ca-crop-h { position: absolute; width: 28px; height: 28px; border-radius: 50%; background: var(--accent); border: 3px solid #fff; box-sizing: border-box; touch-action: none; }
.ca-crop-nw { top: -14px; left: -14px; cursor: nwse-resize; }
.ca-crop-ne { top: -14px; right: -14px; cursor: nesw-resize; }
.ca-crop-sw { bottom: -14px; left: -14px; cursor: nesw-resize; }
.ca-crop-se { bottom: -14px; right: -14px; cursor: nwse-resize; }
.ca-crop-bar { display: flex; gap: 8px; justify-content: center; padding: 12px 0; }
.ca-crop-bar .btn { min-height: 46px; }

/* desktop overview: the "open the mobile app" card with its QR code */
.ca-qr-card { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.ca-qr { background: #fff; padding: 8px; border-radius: 8px; border: 1px solid var(--border); line-height: 0; }
.ca-qr svg { width: 132px; height: 132px; }
.ca-qr-text { flex: 1; min-width: 220px; }

/* ---------------------------------------------------------------- shared letter print (LetterSheet): approvers' signatures (R28) */
.letter-doc .letter-signatures { display: flex; flex-wrap: wrap; gap: 24px; justify-content: flex-end; }
.letter-doc .letter-signature { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 160px; }
.letter-doc .letter-signature img { max-width: 200px; max-height: 80px; object-fit: contain; }
.letter-doc .letter-signature figcaption { display: flex; flex-direction: column; align-items: center; font-size: .85rem; }

@media print {
    .ca-top, .ca-tabs, .ca-install, .ca-actions, .ca-sheet, .ca-sheet-backdrop { display: none !important; }
    .ca-app { padding: 0; background: #fff; }
    .ca-main { max-width: none; padding: 0; }
}
