:root {
  --page: #070b10;
  --panel: #111720;
  --panel-strong: #0b111a;
  --line: rgba(255, 255, 255, 0.11);
  --text: #f6f8fb;
  --muted: #9ca8b8;
  --teal: #2dd4bf;
  --teal-dark: #14b8a6;
  --gold: #f2b84b;
  --red: #f04452;
  --green: #2dcf84;
}

/* Il prospetto A4 viene creato solo quando il cliente preme "Stampa risultati". */
.client-work-print-frame{position:fixed;left:-10000px;top:0;width:1px;height:1px;border:0;pointer-events:none}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    linear-gradient(115deg, rgba(45, 212, 191, 0.13) 0 8%, transparent 8% 69%, rgba(240, 68, 82, 0.1) 69% 73%, transparent 73%),
    linear-gradient(180deg, #08111a 0%, var(--page) 48%, #090d13 100%);
  font-family: "Segoe UI", Inter, system-ui, sans-serif;
}

body::before {
  position: fixed;
  inset: 0;
  pointer-events: none;
  content: "";
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 42px 42px;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }

.portal-shell {
  position: relative;
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.login-layout {
  min-height: calc(100vh - 76px);
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  align-items: center;
  gap: 32px;
}

.login-brand, .login-panel, .portal-header, .kpi-strip, .portal-view {
  border: 1px solid var(--line);
  background: rgba(17, 23, 32, 0.94);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
}

.login-brand {
  min-height: 500px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 54px;
  border-radius: 8px;
}

.login-brand img { width: 132px; margin-bottom: 28px; }
.login-brand h1 { margin: 0 0 12px; font-size: clamp(40px, 6vw, 76px); }
.login-brand > p:last-child { max-width: 620px; color: #d7dee8; font-size: 20px; }

.login-panel {
  display: grid;
  gap: 22px;
  padding: 38px;
  border-radius: 8px;
}

.login-panel label, .message-form label {
  display: grid;
  gap: 8px;
  color: #d7dee8;
  font-weight: 700;
}

input, textarea, select {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 6px;
  padding: 13px 14px;
  color: var(--text);
  background: #080e15;
  outline: none;
}

input:focus, textarea:focus, select:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.13); }
textarea { resize: vertical; }

.eyebrow {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }
h2 { margin-bottom: 6px; font-size: 27px; }
h3 { margin: 0 0 14px; font-size: 18px; }

.primary-button, .secondary-button, .tab-button {
  min-height: 44px;
  border-radius: 6px;
  padding: 10px 16px;
  font-weight: 800;
}

.primary-button {
  border: 0;
  color: #06120f;
  background: linear-gradient(135deg, var(--teal), var(--gold));
}

.text-button {
  justify-self: start;
  border: 0;
  padding: 0;
  color: #8beade;
  background: transparent;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.text-button:hover { color: #fff; }
.auth-description, .password-help { margin: 0; color: var(--muted); line-height: 1.55; }
.password-help { font-size: 13px; }

.auth-success {
  margin-bottom: 16px;
  border: 1px solid rgba(45, 207, 132, 0.45);
  border-left: 4px solid var(--green);
  border-radius: 7px;
  padding: 13px 16px;
  color: #d9ffec;
  background: rgba(45, 207, 132, 0.12);
  font-weight: 800;
}

.secondary-button, .tab-button {
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.form-message, #messageStatus { min-height: 20px; margin: 0; color: var(--muted); }

.portal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 26px;
  border-radius: 8px;
  background: linear-gradient(135deg, #101722, #121820 58%, #1d1417);
}

.brand-lockup { display: flex; align-items: center; gap: 18px; }
.brand-lockup img { width: 74px; height: 74px; }
.brand-lockup h1 { margin: 0 0 4px; font-size: 30px; }
.brand-lockup p:last-child { margin: 0; color: var(--muted); }
.header-actions { display: flex; align-items: center; gap: 12px; }

.readonly-badge {
  border: 1px solid rgba(45, 212, 191, 0.36);
  border-radius: 999px;
  padding: 8px 12px;
  color: #bffbf2;
  background: rgba(45, 212, 191, 0.11);
  font-size: 13px;
  font-weight: 800;
}

.kpi-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  margin-top: 16px;
  border-radius: 8px;
  overflow: hidden;
}

.kpi-strip article { min-height: 112px; padding: 18px; border-right: 1px solid var(--line); }
.kpi-strip article:last-child { border-right: 0; }
.kpi-strip span, .kpi-strip small { display: block; color: var(--muted); }
.kpi-strip strong { display: block; margin: 7px 0 2px; font-size: 25px; }

.portal-tabs { display: flex; gap: 8px; margin: 22px 0 12px; }
.portal-ticket-link { display: inline-flex; align-items: center; text-decoration: none; white-space: nowrap; }
.tab-button.active { color: #06120f; border-color: transparent; background: var(--teal); }
.client-unread-badge{display:inline-grid;place-items:center;min-width:22px;height:22px;margin-left:6px;border-radius:999px;padding:0 6px;color:#07111e;background:#f2c14f;font-size:11px;font-weight:950;vertical-align:middle;box-shadow:0 0 0 3px rgba(242,193,79,.13)}
.client-unread-badge[hidden]{display:none}.client-message-toast{position:fixed;z-index:9999;top:18px;right:18px;width:min(390px,calc(100vw - 36px));border:1px solid rgba(61,204,190,.48);border-radius:14px;padding:16px 18px;color:#eefbff;background:#101d2d;box-shadow:0 22px 70px rgba(0,0,0,.55);transform:translateY(-8px);opacity:0;pointer-events:none;transition:.2s ease}.client-message-toast.show{transform:none;opacity:1;pointer-events:auto}.client-message-toast strong{display:block;margin-bottom:5px}.client-message-toast button{margin-top:10px;border:0;padding:0;color:#63d5ca;background:none;font-weight:850;cursor:pointer}@media(max-width:700px){.client-message-toast{top:10px;right:10px;width:calc(100vw - 20px)}}@media print{.client-message-toast{display:none!important}}

.portal-view { display: none; padding: 24px; border-radius: 8px; }
.portal-view.active { display: block; }

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.status-banner {
  margin: 16px 0;
  border-left: 4px solid var(--teal);
  padding: 11px 14px;
  color: #d7dee8;
  background: rgba(45, 212, 191, 0.07);
}

.filters-panel {
  display: grid;
  grid-template-columns: repeat(5, minmax(145px, 1fr));
  gap: 12px;
  margin: 18px 0 8px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #0b111a;
}
.filter-field { display: grid; gap: 7px; color: #b9c2cf; font-size: 12px; font-weight: 800; text-transform: uppercase; }
.filter-field input, .filter-field select { min-height: 43px; padding: 10px 11px; text-transform: none; }
.filter-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 10px; }
.filter-summary { margin: 10px 0 0; color: var(--muted); font-size: 13px; }
.filter-summary strong { color: var(--text); }
.professional-print-report { display: none; }

.data-block { margin-top: 24px; }
.table-wrap { width: 100%; overflow-x: auto; }

table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: #b9c2cf; background: #0b111a; font-size: 12px; text-transform: uppercase; }
td { color: #e7ebf1; }
td strong { color: #fff; }

.pill {
  display: inline-block;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}
.pill.green { color: #052216; background: var(--green); }
.pill.gold { color: #251901; background: var(--gold); }
.pill.red { color: #fff; background: #9d2531; }
.pill.teal { color: #05201b; background: var(--teal); }

.empty-state { padding: 34px 18px; color: var(--muted); text-align: center; }
.muted { color: var(--muted); }

.fiscal-deadlines-summary {
  margin-top: 18px;
}

.fiscal-deadline-description {
  min-width: 240px;
  white-space: normal;
}

.fiscal-deadline-description small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.fiscal-notice-link {
  min-width: max-content;
  padding: 7px 10px;
}

.portal-disclaimer {
  margin: 20px 0 0;
  border-left: 4px solid var(--teal);
  padding: 12px 14px;
  color: var(--muted);
  background: rgba(67, 202, 169, 0.08);
  font-size: 13px;
  line-height: 1.5;
}

.client-document-preview { display: grid; gap: 8px; margin-top: 12px; }
.client-document-preview-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 14px; border: 1px solid var(--line); border-radius: 7px; background: rgba(255,255,255,.025); }
.client-document-preview-row strong, .client-document-preview-row span { display: block; }
.client-document-preview-row span { margin-top: 4px; color: var(--muted); font-size: 12px; }
.client-document-groups { display: grid; gap: 18px; margin-top: 20px; }
.client-document-group { overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: rgba(10,17,27,.78); }
.client-document-group-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 17px; border-bottom: 1px solid var(--line); background: linear-gradient(90deg,rgba(48,93,148,.24),transparent); }
.client-document-group-heading h3 { margin: 0; }
.client-document-group-heading span { min-width: 30px; border-radius: 999px; padding: 5px 9px; color: #dbeaff; background: rgba(63,119,184,.28); font-weight: 900; text-align: center; }
.client-document-list { display: grid; }
.client-document-row { display: grid; grid-template-columns: minmax(250px,1.5fr) minmax(180px,1fr) minmax(130px,.65fr) auto; gap: 14px; align-items: center; padding: 14px 17px; border-bottom: 1px solid var(--line); }
.client-document-row:last-child { border-bottom: 0; }
.client-document-row strong, .client-document-row span { display: block; }
.client-document-row span { margin-top: 4px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.client-document-download[aria-disabled="true"] { cursor: not-allowed; opacity: .58; }
.client-document-privacy { margin-top: 18px; border-left: 4px solid var(--teal); padding: 13px 15px; color: var(--muted); background: rgba(45,212,191,.06); }
.client-document-privacy strong { color: var(--text); }
.client-document-filters { grid-template-columns: 2fr repeat(4,minmax(135px,1fr)); }

.message-thread {
  min-height: 330px;
  max-height: 520px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  background: #080e15;
}

.message-bubble {
  max-width: min(760px, 86%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: #141c27;
}
.message-bubble.cliente { align-self: flex-end; border-color: rgba(45, 212, 191, 0.3); background: rgba(45, 212, 191, 0.12); }
.message-bubble p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-meta { display: flex; gap: 8px; margin-bottom: 7px; color: var(--muted); font-size: 12px; }

.message-form { margin-top: 14px; padding: 18px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.025); }
.message-form-footer { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-top: 12px; }

.client-thread-form { margin-bottom: 14px; border: 1px solid rgba(66, 126, 191, 0.42); border-radius: 10px; padding: 18px; background: rgba(36, 76, 125, 0.16); }
.client-thread-form label { display: grid; gap: 7px; color: #d7dee8; font-weight: 700; }
.client-thread-fields { display: grid; grid-template-columns: minmax(180px, .65fr) minmax(260px, 2fr); gap: 12px; margin-bottom: 12px; }
.client-communications-layout { display: grid; grid-template-columns: minmax(250px, 340px) minmax(0, 1fr); min-height: 570px; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: rgba(5, 12, 21, .35); }
.client-thread-panel { border-right: 1px solid var(--line); background: rgba(7, 15, 25, .55); }
.client-thread-heading, .client-conversation-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 70px; padding: 15px 17px; border-bottom: 1px solid var(--line); }
.client-thread-heading span { min-width: 30px; border-radius: 999px; padding: 5px 8px; color: #fff; background: #285b94; text-align: center; font-weight: 800; }
.client-thread-button { width: 100%; border: 0; border-bottom: 1px solid var(--line); padding: 14px 16px; color: var(--text); background: transparent; text-align: left; }
.client-thread-button:hover, .client-thread-button.active { background: linear-gradient(90deg, rgba(62, 118, 184, .28), rgba(62, 118, 184, .06)); }
.client-thread-button strong, .client-thread-button span { display: block; }
.client-thread-button span { margin-top: 5px; color: var(--muted); font-size: 12px; }
.client-thread-app { display: inline-block !important; width: max-content; border-radius: 5px; padding: 3px 7px; color: #d7eaff !important; background: rgba(62, 118, 184, .22); font-size: 10px !important; font-weight: 900; text-transform: uppercase; }
.client-conversation-panel { display: flex; min-width: 0; flex-direction: column; }
.client-conversation-heading h3 { margin: 2px 0 0; }
.client-conversation-panel .message-thread { flex: 1; max-height: 500px; border: 0; border-radius: 0; }
.client-conversation-panel .message-form { margin: 0; border-width: 1px 0 0; }
.client-financial-plans { display: grid; gap: 16px; margin-top: 18px; }
.client-financial-card { overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: rgba(7, 15, 25, .5); }
.client-financial-card header { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px; }
.client-financial-card header span { color: #64d8ef; font-size: 11px; font-weight: 900; text-transform: uppercase; }
.client-financial-card header h3 { margin: 4px 0 0; }
.client-financial-card header > div:last-child { text-align: right; }
.client-financial-card header strong, .client-financial-card header small { display: block; }
.client-financial-card header small { margin-top: 4px; color: var(--muted); }
.client-financial-summary { display: flex; flex-wrap: wrap; gap: 10px 24px; padding: 12px 18px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); color: var(--muted); }
.client-financial-summary b { color: var(--text); }
.client-financial-card details summary { padding: 14px 18px; cursor: pointer; color: #64d8ef; font-weight: 800; }
.client-financial-card table { min-width: 820px; }
.client-plan-state { display: inline-block; border-radius: 999px; padding: 5px 9px; color: #ffc46b; background: rgba(255, 166, 43, .12); font-size: 11px; font-weight: 800; }
.client-plan-state.done { color: #71e0b5; background: rgba(41, 190, 132, .12); }
.client-financial-empty { padding: 32px; border: 1px dashed var(--line); border-radius: 12px; color: var(--muted); text-align: center; }

@media (max-width: 900px) {
  .login-layout { grid-template-columns: 1fr; padding: 24px 0; }
  .login-brand { min-height: 300px; padding: 32px; }
  .portal-header, .section-heading { align-items: flex-start; flex-direction: column; }
  .kpi-strip { grid-template-columns: repeat(2, 1fr); }
  .kpi-strip article:nth-child(2) { border-right: 0; }
  .kpi-strip article:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .portal-tabs { overflow-x: auto; }
  .filters-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tab-button { white-space: nowrap; }
  .client-document-row { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
  .portal-shell { width: min(100% - 20px, 1440px); padding-top: 10px; }
  .brand-lockup { align-items: flex-start; }
  .brand-lockup img { width: 58px; height: 58px; }
  .brand-lockup h1 { font-size: 23px; }
  .header-actions { width: 100%; justify-content: space-between; }
  .kpi-strip { grid-template-columns: 1fr; }
  .kpi-strip article { border-right: 0; border-bottom: 1px solid var(--line); }
  .portal-view { padding: 16px; }
  .message-form-footer { align-items: stretch; flex-direction: column; }
  .filters-panel { grid-template-columns: 1fr; }
  .filter-actions { align-items: stretch; flex-direction: column; }
  .client-communications-layout { grid-template-columns: 1fr; }
  .client-thread-panel { max-height: 260px; overflow: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .client-thread-fields { grid-template-columns: 1fr; }
  .client-document-row, .client-document-filters { grid-template-columns: 1fr; }
}

@media print {
  @page { size: A4 landscape; margin: 12mm; }
  body { color: #000; background: #fff; }
  body::before, .portal-header, .kpi-strip, .portal-tabs, .filters-panel, .print-button, .secondary-button, .message-form { display: none !important; }
  .portal-shell { width: 100%; margin: 0; padding: 0; }
  #loginView, #portalView { display: none !important; }
  .professional-print-report { display: block !important; color: #111; background: #fff; font-family: Arial, Helvetica, sans-serif; }
  .print-report-header { display: flex; align-items: center; justify-content: space-between; padding-bottom: 4mm; border-bottom: 2px solid #17243a; }
  .print-report-header img { width: 17mm; height: 17mm; }
  .print-studio-name { color: #17243a; font-size: 17pt; font-weight: 900; letter-spacing: .4px; }
  .print-studio-subtitle { margin-top: 1.5mm; color: #475569; font-size: 9pt; font-weight: 700; text-transform: uppercase; }
  .print-client-heading { display: grid; grid-template-columns: 1.25fr 1fr .75fr; gap: 3mm; margin: 4mm 0; }
  .print-client-heading div, .print-total-grid div { padding: 2.5mm; border: 1px solid #cad3df; background: #f5f7fa; }
  .print-client-heading span, .print-total-grid span { display: block; margin-bottom: 1mm; color: #64748b; font-size: 7pt; font-weight: 800; text-transform: uppercase; }
  .print-client-heading strong, .print-total-grid strong { color: #111827; font-size: 10pt; }
  .print-filter-line { margin: 3mm 0; padding: 2.5mm; border-left: 3px solid #14b8a6; background: #eefbf9; color: #17243a; font-size: 8pt; }
  .print-total-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3mm; margin-bottom: 4mm; }
  .print-report-section { margin-top: 4mm; break-inside: auto; }
  .print-report-section h2 { margin: 0 0 2mm; padding-bottom: 1.5mm; border-bottom: 1px solid #17243a; color: #17243a; font-size: 11pt; text-transform: uppercase; }
  .professional-print-report table { width: 100%; min-width: 0; border-collapse: collapse; font-size: 7.5pt; }
  .professional-print-report th, .professional-print-report td { padding: 1.6mm; border: 1px solid #cbd5e1; color: #111; }
  .professional-print-report th { background: #e7edf5; font-weight: 900; text-transform: uppercase; }
  .professional-print-report tbody tr:nth-child(even) { background: #f8fafc; }
  .professional-print-report tfoot th { background: #dbe5f1; }
  .print-report-footer { display: flex; justify-content: space-between; margin-top: 5mm; padding-top: 2mm; border-top: 1px solid #94a3b8; color: #64748b; font-size: 7pt; }
  .section-heading { border-bottom: 2px solid #1f315e; }
  .eyebrow, h2, h3, td, th, .status-banner { color: #000 !important; }
  .status-banner { border-left-color: #1f315e; background: #eef2f7; }
  .filter-summary { margin: 3mm 0; color: #000; font-size: 10px; }
  .filter-summary strong { color: #000; }
  table { min-width: 0; font-size: 10px; }
  th { color: #000; background: #e8edf4; }
  th, td { padding: 5px; border-bottom: 1px solid #aab2bf; }
}
