/* Responsive presentation layer; existing CRM behavior stays in app.js. */
:root { --crm-purple: #6548c7; --crm-purple-deep: #45308f; --crm-border: #e2e8f0; --crm-surface: #fff; --crm-ink: #18213b; }
.dark { --crm-border: #2a3155; --crm-surface: #141a33; --crm-ink: #f1f5f9; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 12rem; }
body { margin: 0; }
button, input, select, textarea { font-family: inherit; }
button, [role="button"], label.att { touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .65; }
:focus-visible { outline: 3px solid #ad75f4; outline-offset: 3px; }
#app-shell > div, #app-shell main, #app-shell section, #app-shell .grid > *, #client-drawer-content .grid > * { min-width: 0; }
.auth-screen { min-height: 100vh; min-height: 100svh; display: flex; align-items: center; justify-content: center; padding: 40px 24px; background: radial-gradient(ellipse at 90% 10%, #ece6fc, transparent 55%), #f5f4f9; }
.dark .auth-screen { background: radial-gradient(ellipse at 90% 10%, #30224d, transparent 55%), #0b0f20; }
.auth-layout { display: grid; grid-template-columns: 1.15fr 1fr; width: min(1080px, 100%); min-height: 660px; border: 1px solid var(--crm-border); border-radius: 28px; background: var(--crm-surface); overflow: hidden; box-shadow: 0 24px 70px #35255a12; }
.auth-story { position: relative; isolation: isolate; display: flex; flex-direction: column; padding: 44px; color: #fff; background: linear-gradient(155deg, #45308f 0%, #6548c7 60%, #8058d5 100%); overflow: hidden; }
.auth-story::before, .auth-story::after { content: ''; position: absolute; z-index: -1; width: 360px; height: 360px; border: 1px solid #ffffff16; border-radius: 50%; inset-inline-end: -190px; bottom: -130px; }
.auth-story::after { width: 470px; height: 470px; inset-inline-end: -245px; bottom: -185px; }
.auth-brand { display: flex; align-items: center; gap: 18px; }
.auth-brand-logo, .dark .auth-brand-logo { width: 76px; height: 86px; object-fit: contain; background: #fff; border-radius: 15px; padding: 8px; flex-shrink: 0; }
.auth-eyebrow { display: block; font-size: 11px; font-weight: 600; letter-spacing: .08em; color: #ddd2ff; }
.auth-brand h1 { font-family: 'IBM Plex Sans', sans-serif; margin: 4px 0 0; font-size: clamp(25px, 3vw, 34px); line-height: 1.2; letter-spacing: -.045em; }
.auth-story-copy { margin-top: 44px; }
.auth-secure { display: inline-flex; align-items: center; gap: 7px; padding: 6px 11px; border-radius: 99px; background: #ffffff12; border: 1px solid #ffffff30; font-size: 11px; font-weight: 600; }
.auth-secure svg { width: 16px; height: 16px; }
.auth-story-copy h2 { max-width: 410px; margin: 20px 0 12px; font-size: clamp(25px, 3vw, 33px); line-height: 1.6; font-weight: 700; letter-spacing: -.02em; }
.auth-story-copy p { max-width: 405px; color: #e4dcf8; font-size: 14px; line-height: 1.95; margin: 0; }
.auth-features { display: flex; flex-direction: column; gap: 18px; padding: 0; margin: 32px 0; list-style: none; }
.auth-features li { display: flex; align-items: flex-start; gap: 12px; }
.auth-feature-mark { display: flex; align-items: center; justify-content: center; width: 27px; height: 27px; border-radius: 9px; background: #ffffff15; color: #f2cf8b; flex-shrink: 0; font-size: 15px; }
.auth-features strong { display: block; font-size: 13px; font-weight: 600; }
.auth-features li div > span { display: block; color: #ddd2f4; font-size: 11px; margin-top: 2px; }
.auth-story-footer { margin: auto 0 0; padding-top: 18px; border-top: 1px solid #ffffff20; font-size: 11px; color: #ddd2f4; }
.auth-form-panel { display: flex; flex-direction: column; justify-content: center; padding: 52px 48px; }
.auth-form-heading { margin-bottom: 30px; }
.auth-form-heading .auth-eyebrow { color: var(--crm-purple); letter-spacing: 0; }
.dark .auth-form-heading .auth-eyebrow { color: #ad75f4; }
.auth-form-heading h2 { margin: 7px 0 9px; font-size: 28px; font-weight: 700; color: var(--crm-ink); }
.auth-form-heading p { font-size: 13px; color: #64748b; margin: 0; }
.dark .auth-form-heading p { color: #a7b0c5; }
.auth-form-panel .lbl { font-size: 13px; }
.auth-form-panel .fld { min-height: 49px; font-size: 16px; background: #f9f9fc; }
.dark .auth-form-panel .fld { background: #1c2340; }
.auth-form-panel .fld[dir="ltr"] { text-align: left; }
.auth-submit { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 48px; border: 0; border-radius: 12px; padding: 11px 18px; color: #fff; background: var(--crm-purple); font-size: 14px; font-weight: 700; box-shadow: 0 5px 12px #6548c71a; transition: background .15s, transform .15s; }
.auth-submit:hover { background: #553ab0; }
.auth-submit:active { transform: translateY(1px); }
.auth-password-help { color: #64748b; font-size: 11px; text-align: center; line-height: 1.9; padding-top: 3px; }
.dark .auth-password-help { color: #a7b0c5; }
.auth-form-footer { display: flex; align-items: flex-start; justify-content: center; gap: 8px; border-top: 1px solid var(--crm-border); padding-top: 22px; margin-top: 26px; font-size: 11px; color: #64748b; line-height: 1.9; }
.auth-footer-dot { width: 6px; height: 6px; margin-top: 7px; background: var(--crm-purple); border-radius: 50%; flex-shrink: 0; }
.auth-install { margin: 18px auto 0; }
.crm-nav-toggle, .crm-nav-close { display: none; }
.crm-nav-overlay { position: fixed; inset: 0; z-index: 45; border: 0; padding: 0; background: #0b0f2099; backdrop-filter: blur(3px); }
.crm-status-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.crm-mobile-status { display: none; color: #64748b; font-size: 11px; overflow-wrap: anywhere; }
.dark .crm-mobile-status { color: #b1bbd0; }
.crm-mobile-status::before { content: ''; display: inline-block; width: 6px; height: 6px; margin-inline-end: 7px; border-radius: 50%; background: #94a3b8; }
.crm-mobile-status[data-cloud-status="saved"]::before, .crm-mobile-status[data-cloud-status="ready"]::before { background: #10b981; }
.crm-mobile-status[data-cloud-status="saving"]::before, .crm-mobile-status[data-cloud-status="pending"]::before { background: #d39a29; }
.crm-mobile-status[data-cloud-status="error"]::before, .crm-mobile-status[data-cloud-status="offline"]::before { background: #e45e63; }
.crm-status-row:has(.pwa-install:not([hidden])) { margin-top: 8px; }
.pwa-install { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 40px; flex-shrink: 0; padding: 7px 12px; border: 1px solid #6548c730; border-radius: 11px; background: #6548c709; color: var(--crm-purple); font-size: 11px; font-weight: 700; }
.pwa-install svg { width: 16px; height: 16px; }
.dark .pwa-install { color: #c6a0ff; border-color: #ad75f440; background: #ad75f410; }
.connection-notice { display: flex; align-items: flex-start; gap: 12px; padding: 14px 18px; margin-bottom: 22px; border-radius: 14px; border: 1px solid #e9d5a5; color: #77501d; background: #fffaf0; }
.connection-notice { font-size: 12px; line-height: 1.85; }
.dark .connection-notice { color: #edd2a4; background: #392c1a; border-color: #635034; }
.crm-table-scroll { min-width: 0; max-width: 100%; overflow-x: auto; overscroll-behavior-inline: contain; -webkit-overflow-scrolling: touch; }
.crm-table-scroll:focus-visible { outline-offset: -3px; }
#app-shell .overflow-x-auto, #client-drawer .overflow-x-auto { max-width: 100%; overscroll-behavior-inline: contain; -webkit-overflow-scrolling: touch; }
.financial-tabs { flex-wrap: nowrap !important; overflow-x: auto; width: 100%; max-width: 100%; min-width: 0; -webkit-overflow-scrolling: touch; overscroll-behavior-inline: contain; scrollbar-width: thin; }
.financial-tabs .fsub-btn { flex-shrink: 0; white-space: nowrap; }
.pwa-help { width: min(440px, calc(100% - 32px)); padding: 25px; border: 1px solid var(--crm-border); border-radius: 20px; background: var(--crm-surface); color: var(--crm-ink); box-shadow: 0 25px 80px #0b0f2040; }
.pwa-help::backdrop { background: #0b0f2099; backdrop-filter: blur(4px); }
.pwa-help-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.pwa-help h2 { font-size: 18px; font-weight: 700; margin: 0; }
.pwa-help-heading button { width: 44px; height: 44px; background: transparent; border: 0; border-radius: 10px; }
.pwa-help p { font-size: 13px; line-height: 1.95; margin: 14px 0; }
.pwa-help .pwa-help-note { color: #64748b; font-size: 11px; }
.dark .pwa-help .pwa-help-note { color: #b1bbd0; }
@media (max-width: 1279px) {
  .crm-status-row { margin-top: 8px; min-height: 20px; }
  .crm-mobile-status { display: inline; }
}
@media (max-width: 1023px) {
  body.crm-nav-open { overflow: hidden; }
  .crm-nav-toggle, .crm-nav-close { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 10px; border-radius: 11px; border: 1px solid var(--crm-border); background: var(--crm-surface); color: var(--crm-purple); flex-shrink: 0; }
  .crm-nav-toggle svg { width: 21px; height: 21px; }
  .crm-nav-close { margin-inline-start: auto; border: 0; font-size: 17px; }
  #crm-sidebar { display: flex !important; position: fixed; inset-block: 0; inset-inline-start: 0; width: min(304px, 86vw); height: 100vh; height: 100dvh; z-index: 46; transform: translateX(105%); visibility: hidden; transition: transform .2s ease, visibility .2s; box-shadow: 0 0 50px #0b0f2030; }
  html[dir="ltr"] #crm-sidebar { transform: translateX(-105%); }
  body.crm-nav-open #crm-sidebar { visibility: visible; transform: translateX(0); }
  #crm-sidebar > div:first-child { padding-inline: 14px; gap: 10px; }
  #crm-sidebar nav { overscroll-behavior: contain; }
  #crm-sidebar .side-btn { min-height: 48px; }
  .crm-toolbar { flex-wrap: wrap; gap: 8px; }
  #global-search-wrap { order: 3; flex-basis: 100%; max-width: none; }
  #owner-pills { order: 4; }
  .crm-mobile-tabs { padding-bottom: 3px; scrollbar-width: thin; }
  .crm-mobile-tabs .mtab { flex-shrink: 0; min-height: 44px; }
  #owner-pills-m button, #owner-pills button { min-height: 40px; }
}
@media (max-width: 767px) {
  .auth-screen { padding: 18px; align-items: flex-start; }
  .auth-layout { display: flex; flex-direction: column; min-height: auto; max-width: 540px; border-radius: 22px; }
  .auth-story { padding: 26px; }
  .auth-brand { gap: 14px; }
  .auth-brand-logo, .dark .auth-brand-logo { width: 54px; height: 62px; border-radius: 12px; padding: 6px; }
  .auth-brand h1 { font-size: 27px; }
  .auth-story-copy { margin-top: 20px; }
  .auth-story-copy h2 { font-size: 23px; margin: 12px 0 5px; line-height: 1.6; }
  .auth-story-copy p { font-size: 12px; line-height: 1.9; }
  .auth-secure { font-size: 10px; padding: 4px 9px; }
  .auth-features, .auth-story-footer { display: none; }
  .auth-form-panel { padding: 28px 26px; }
  .auth-form-heading { margin-bottom: 22px; }
  .auth-form-heading h2 { font-size: 23px; }
  #app-shell input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), #app-shell select, #app-shell textarea,
  #project-modal input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), #project-modal select, #project-modal textarea,
  #client-drawer input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), #client-drawer select, #client-drawer textarea,
  #cat-modal input, #extra-modal input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), #extra-modal select, #extra-modal textarea { font-size: 16px !important; min-height: 44px; min-width: 0; }
  #app-shell input[type="checkbox"], #app-shell input[type="radio"], #project-modal input[type="checkbox"], #perm-editor input[type="checkbox"], #perm-editor input[type="radio"] { min-width: 18px; min-height: 18px; }
  #app-shell button, #project-modal button, #client-drawer button, #doc-viewer button, #extra-modal button, #cat-modal button, #perm-editor button, label.att, label:has(> input[type="file"]), #project-modal label:has(> input[type="checkbox"]), #perm-editor label { min-height: 44px; }
  #app-shell button, #project-modal button, #client-drawer button, #doc-viewer button, #cat-modal button, #perm-editor button { min-width: 44px; }
  #app-shell main { padding: 14px; }
  #app-shell main .p-6, #app-shell main .p-7 { padding: 18px; }
  #app-shell main .px-6 { padding-inline: 18px; }
  #app-shell main .space-y-6 > :not([hidden]) ~ :not([hidden]) { margin-top: 18px; }
  #hero-value { font-size: clamp(27px, 8vw, 40px); white-space: normal; overflow-wrap: anywhere; }
  #summary-cost, #summary-margin, #summary-sales, #summary-total { font-size: clamp(24px, 7vw, 30px); white-space: normal; overflow-wrap: anywhere; }
  #projects-table-body, #projects-table-head { white-space: nowrap; }
  #tab-clients table { min-width: 820px; }
  #printable-financial-doc table { min-width: 640px; }
  #fin-main > div:first-child > div:last-child { white-space: normal; align-items: flex-start; line-height: 1.8; }
  #fin-main > div:first-child > div:last-child > span:first-child { margin-top: 6px; flex-shrink: 0; }
  #financial-content-budget .grid-cols-3 { grid-template-columns: 1fr; }
  #pnl-cards, #rep-kpis, #archive-kpis, #exp-cards, #petty-cards { grid-template-columns: 1fr; }
  #exp-cards .whitespace-nowrap, #petty-cards .whitespace-nowrap { white-space: normal; overflow-wrap: anywhere; }
  #financial-content-delivery > div:first-child > .grid-cols-2 { grid-template-columns: 1fr; }
  #financial-content-delivery > div:first-child > .grid-cols-2 > .col-span-2 { grid-column: span 1 / span 1; }
  #client-drawer-content .pt-2.flex { flex-wrap: wrap; }
  #client-drawer-content select { max-width: 100%; }
  #client-drawer-content p { overflow-wrap: anywhere; }
  #doc-header > div:first-child { align-items: flex-start; gap: 12px; }
  #doc-header img { width: 58px; height: 64px; }
  #doc-header h2 { font-size: 15px; }
  #doc-body > div:first-child .flex { flex-wrap: wrap; gap: 4px 8px; }
  #doc-body > div:first-child .flex > :last-child { overflow-wrap: anywhere; }
  #doc-totals .flex { flex-wrap: wrap; gap: 5px; }
  #doc-bank-text, #doc-payment-text, #doc-terms-text { overflow-wrap: anywhere; }
  #project-modal, #doc-viewer, #extra-modal, #cat-modal, #perm-editor { padding: 8px; }
  #project-modal > div, #doc-viewer > div, #extra-modal > div, #cat-modal > div, #perm-editor > div { max-width: 100%; max-height: calc(100dvh - 16px); }
  #project-modal > div { height: min(94dvh, 900px); }
  #project-modal > div > div:first-child { padding: 16px; gap: 8px; }
  #project-modal h3 { font-size: 16px; }
  #new-project-form { padding: 16px; min-height: 0; overscroll-behavior: contain; }
  #new-project-form .inline-flex { width: 100%; flex-wrap: wrap; }
  #new-project-form .mode-btn { flex: 1 1 130px; padding-inline: 10px; }
  #project-modal > div > div:last-child { padding: 12px 16px max(12px, env(safe-area-inset-bottom)); flex-wrap: wrap; }
  #project-modal > div > div:last-child button { flex: 1 1 120px; padding-inline: 12px; white-space: normal; }
  #client-drawer-content { padding: 18px 16px max(18px, env(safe-area-inset-bottom)); overscroll-behavior: contain; max-width: 100%; }
  #client-drawer-content .grid-cols-2, #auth-setup .grid-cols-2, #tab-users form .grid-cols-2 { grid-template-columns: 1fr; }
  #client-drawer-content .flex:has(> .att), #client-drawer-content .flex:has(> label > input[type="file"]) { flex-wrap: wrap; }
  #client-drawer-content button, #new-project-form button { overflow-wrap: anywhere; }
  #client-drawer-content .whitespace-nowrap { white-space: normal; }
  #doc-viewer > div { height: 92dvh; }
  #doc-viewer > div > div:first-child { flex-wrap: wrap; }
  #doc-viewer-name { flex: 1 1 120px; min-width: 0; }
  #perm-editor > div > div:last-child { flex-direction: column; min-height: 0; }
  #perm-editor aside { width: 100%; max-height: 180px; border-inline-end: 0; border-bottom: 1px solid var(--crm-border); flex-shrink: 0; overflow-y: auto; }
  #perm-main { min-width: 0; min-height: 0; }
  #perm-main section > div:first-child { flex-wrap: wrap; }
  #extra-modal > div { overflow-y: auto; }
  #cat-modal .grid-cols-2 { grid-template-columns: 1fr; }
  #toast-wrap { bottom: max(16px, env(safe-area-inset-bottom)); }
}
@media (max-width: 639px) {
  #app-shell header { padding: 10px 12px; }
  .crm-toolbar > .app-logo { width: 32px; height: 36px; }
  .crm-toolbar-actions { gap: 5px; }
  .crm-toolbar-actions > button, #notif-wrap > button { min-width: 40px; width: 40px; min-height: 44px; padding: 8px; }
  .crm-toolbar-actions > button:has(#lang-label) svg { display: none; }
  #user-chip { display: flex !important; padding: 0; background: transparent; flex-shrink: 0; }
  #user-chip > button { min-width: 44px; justify-content: center; gap: 0; }
  #user-chip > button > span:nth-child(2) { display: none; }
  #user-menu { position: fixed; inset-inline: 12px; top: 64px; width: auto; max-height: calc(100dvh - 80px); overflow-y: auto; z-index: 50; text-align: start; }
  #notif-panel { position: fixed; inset-inline: 12px; top: 64px; width: auto; max-width: none; max-height: calc(100dvh - 80px); overflow-y: auto; }
  #tab-clients > div:first-child > div:last-child, #tab-financial > div:first-child > div:last-child { flex-wrap: wrap; max-width: 100%; }
  #tab-financial > div:first-child > div:last-child button { white-space: normal; text-align: start; }
  #new-project-form .flex:has(> input):has(> .att) { flex-wrap: wrap; }
  #new-project-form .flex > .att { min-height: 44px; }
  #new-project-form .flex:has(> input):has(> .att) > input { flex-basis: 100%; }
  .connection-notice { padding: 12px; margin-bottom: 16px; gap: 9px; }
  .crm-status-row { gap: 8px; }
  .crm-mobile-status { font-size: 10px; }
  .pwa-install { min-height: 44px; padding-inline: 9px; font-size: 10px; }
}
@media (max-width: 374px) {
  .auth-screen { padding: 10px; }
  .auth-story { padding: 20px; }
  .auth-form-panel { padding: 24px 20px; }
  .auth-brand h1 { font-size: 25px; }
  .auth-story-copy h2 { font-size: 21px; }
  .crm-toolbar { gap: 5px; }
  .crm-toolbar-actions { gap: 3px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
@media print {
  .connection-notice, .crm-nav-toggle, .crm-nav-overlay, .crm-status-row, .pwa-help { display: none !important; }
  .crm-table-scroll, .financial-tabs { overflow: visible !important; }
  #printable-financial-doc table { min-width: 0 !important; }
}
