:root {
  --bg: #f4f7fb;
  --ink: #152033;
  --muted: #617089;
  --line: #d9e0ec;
  --panel: #ffffff;
  --navy: #133a6f;
  --blue: #276bd8;
  --cyan: #34c6e8;
  --green: #34b979;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(52, 198, 232, .2), transparent 32rem),
    linear-gradient(180deg, #f8fbff 0%, var(--bg) 44%, #eef3f9 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

.login-page {
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 12%, rgba(52, 198, 232, .22), transparent 28rem),
    linear-gradient(140deg, #eff6ff 0%, #ffffff 46%, #edf4f8 100%);
}

.login-shell {
  display: grid;
  width: min(520px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 32px 0;
  place-items: center;
}

.login-card {
  width: 100%;
  padding: 30px;
  border: 1px solid rgba(19, 58, 111, .12);
  border-radius: 8px;
  background: rgba(255, 255, 255, .88);
  box-shadow: 0 22px 60px rgba(19, 58, 111, .16);
}

.login-card h1 {
  margin: 10px 0 10px;
  font-size: clamp(2rem, 8vw, 3.3rem);
  line-height: .95;
  letter-spacing: 0;
}

.login-card p {
  margin: 0 0 20px;
  color: var(--muted);
  line-height: 1.55;
}

.login-card form {
  display: grid;
  gap: 14px;
}

.login-card label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: .9rem;
  font-weight: 800;
}

.login-error {
  padding: 10px 12px;
  border: 1px solid rgba(183, 43, 43, .24);
  border-radius: 8px;
  background: #fff1f1;
  color: #9f1d1d !important;
  font-weight: 800;
}

.logout-link {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 5;
  padding: 10px 14px;
  border: 1px solid rgba(19, 58, 111, .16);
  border-radius: 8px;
  background: rgba(255, 255, 255, .9);
  color: var(--navy);
  font-size: .88rem;
  font-weight: 900;
  text-decoration: none;
  box-shadow: 0 12px 34px rgba(19, 58, 111, .12);
}

.owner-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 0 8px;
}

.brand-mark {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark img {
  width: 132px;
  height: auto;
  filter: drop-shadow(0 0 18px rgba(39, 107, 216, .16));
}

.brand-mark span {
  padding: 7px 10px;
  border: 1px solid rgba(19, 58, 111, .14);
  border-radius: 999px;
  color: rgba(19, 58, 111, .72);
  font-size: .78rem;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.owner-topbar nav {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.ghost-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid rgba(19, 58, 111, .14);
  border-radius: 8px;
  background: rgba(255, 255, 255, .72);
  color: var(--navy);
  font-size: .88rem;
  font-weight: 900;
  box-shadow: 0 12px 34px rgba(19, 58, 111, .08);
}

.ghost-link.active {
  background: var(--navy);
  color: white;
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: .48;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.hero-band {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  align-items: stretch;
  padding: 32px 0 24px;
}

.hero-band h1 {
  max-width: 760px;
  margin: 10px 0 14px;
  font-size: clamp(2.4rem, 5vw, 5rem);
  line-height: .92;
  letter-spacing: 0;
}

.hero-band p {
  max-width: 720px;
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.65;
}

.eyebrow {
  margin: 0;
  color: var(--blue);
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.hero-card,
.contract-panel,
.preview-card,
.accepted-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .86);
  box-shadow: 0 18px 54px rgba(27, 47, 80, .08);
}

.hero-card {
  display: flex;
  min-height: 220px;
  flex-direction: column;
  justify-content: flex-end;
  gap: 10px;
  padding: 22px;
  color: white;
  background:
    linear-gradient(135deg, rgba(19, 58, 111, .92), rgba(39, 107, 216, .92)),
    repeating-linear-gradient(90deg, transparent 0 18px, rgba(255, 255, 255, .12) 18px 19px);
}

.hero-card span {
  width: fit-content;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .16);
  color: #dff7ff;
  font-weight: 900;
}

.hero-card strong {
  font-size: 1.6rem;
  line-height: 1.05;
}

.hero-card small {
  color: rgba(255, 255, 255, .74);
  line-height: 1.45;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(320px, .8fr);
  gap: 18px;
  align-items: start;
}

.contract-panel {
  padding: 22px;
}

.contract-panel--wide {
  margin-top: 18px;
}

.section-heading,
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.section-heading h2,
.topbar h1,
.signature-box h2,
.preview-card h3 {
  margin: 4px 0 0;
  line-height: 1.05;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: #33415a;
  font-size: .86rem;
  font-weight: 750;
}

.full {
  grid-column: 1 / -1;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  color: var(--ink);
  outline: none;
  padding: 12px 13px;
}

.file-label input[type="file"] {
  padding: 10px;
  background: #ffffff;
}

.file-label span {
  color: var(--muted);
  font-size: .82rem;
  font-weight: 650;
}

.ai-fill-row {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid rgba(39, 107, 216, .16);
  border-radius: 8px;
  background: #f7fbff;
}

.ai-fill-row .secondary-button {
  flex: 0 0 auto;
}

.ai-fill-row span {
  min-width: 0;
  color: var(--muted);
  font-size: .88rem;
  font-weight: 700;
  line-height: 1.45;
}

.ai-fill-row.is-working {
  background: #eef7ff;
}

.ai-fill-row.is-error {
  border-color: rgba(183, 43, 43, .24);
  background: #fff5f5;
}

.ai-fill-row.is-error span {
  color: #9f1d1d;
}

textarea {
  min-height: 108px;
  resize: vertical;
  line-height: 1.5;
}

input:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(39, 107, 216, .12);
}

.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  font-weight: 850;
}

.primary-button {
  width: 100%;
  margin-top: 18px;
  background: var(--blue);
  color: white;
}

.secondary-button {
  border: 1px solid var(--line);
  background: white;
  color: var(--navy);
}

.secondary-button--wide {
  width: 100%;
  margin-top: 10px;
}

.link-box {
  min-height: 132px;
  display: grid;
  align-items: stretch;
  margin-bottom: 12px;
}

.link-box p {
  display: grid;
  place-items: center;
  margin: 0;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
}

.link-box textarea {
  min-height: 132px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .78rem;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.success-line {
  margin: 12px 0 0;
  color: var(--green);
  font-weight: 800;
}

.preview-card {
  margin-top: 18px;
  padding: 18px;
  background: #f9fbff;
}

.draft-card {
  display: grid;
  gap: 12px;
}

.section-heading--compact {
  margin-bottom: 0;
  align-items: center;
}

.section-heading--compact span {
  display: grid;
  min-width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 999px;
  background: rgba(39, 107, 216, .1);
  color: var(--blue);
  font-weight: 900;
}

select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 10px 12px;
}

.draft-note {
  margin: 0;
  color: var(--muted);
  font-size: .86rem;
  line-height: 1.45;
}

.contract-panel .form-grid::before {
  content: "Gia precompilato per Doribene. Compila prezzo, dettagli preventivo, IBAN e allega il preventivo; i dati cliente possono essere completati anche dal destinatario.";
  grid-column: 1 / -1;
  border: 1px solid rgba(39, 107, 216, .18);
  border-radius: 8px;
  padding: 12px 14px;
  background: rgba(39, 107, 216, .08);
  color: var(--navy);
  font-size: .9rem;
  font-weight: 750;
}

.preview-card ul {
  display: grid;
  gap: 9px;
  margin: 14px 0 0;
  padding-left: 18px;
  color: var(--muted);
}

.client-page {
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(19, 58, 111, .96), rgba(22, 79, 123, .9) 42%, rgba(246, 249, 253, 0) 42.1%),
    radial-gradient(circle at 92% 12%, rgba(52, 198, 232, .18), transparent 24rem),
    #f5f8fc;
}

.client-hero {
  color: white;
  background:
    linear-gradient(135deg, #102d57 0%, #174b88 54%, #276bd8 100%);
}

.client-hero__inner,
.client-shell {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
}

.client-hero__inner {
  display: flex;
  min-height: 230px;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 34px 0 64px;
}

.client-hero h1 {
  max-width: 860px;
  margin: 8px 0 12px;
  font-size: clamp(2.1rem, 4vw, 4.6rem);
  line-height: .95;
  letter-spacing: 0;
}

.client-hero p:not(.eyebrow) {
  max-width: 680px;
  margin: 0;
  color: rgba(255, 255, 255, .78);
  font-size: 1.02rem;
  line-height: 1.55;
}

.client-hero .eyebrow {
  color: #aeeeff;
}

.client-shell {
  padding: 0 0 46px;
  transform: translateY(-36px);
}

.client-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.client-summary article {
  min-height: 104px;
  border: 1px solid rgba(217, 224, 236, .9);
  border-radius: 8px;
  padding: 16px;
  background: rgba(255, 255, 255, .94);
  box-shadow: 0 18px 46px rgba(12, 32, 58, .12);
}

.client-summary span,
.document-heading span,
.signature-steps strong {
  color: var(--muted);
  font-size: .76rem;
  font-weight: 850;
  text-transform: uppercase;
}

.client-summary strong {
  display: block;
  margin-top: 8px;
  color: var(--navy);
  font-size: 1.06rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.status-badge {
  border-radius: 999px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, .16);
  color: white;
  border: 1px solid rgba(255, 255, 255, .28);
  font-weight: 900;
  white-space: nowrap;
}

.reader-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 18px;
}

.client-contract-card {
  padding: 18px;
  background: rgba(255, 255, 255, .92);
}

.contract-reader {
  min-height: 700px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 0;
  overflow: hidden;
}

.document-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 20px 22px;
  background: linear-gradient(180deg, #ffffff, #f7faff);
}

.document-heading h2 {
  margin: 4px 0 0;
  color: var(--navy);
}

.document-heading > span {
  border-radius: 999px;
  padding: 8px 11px;
  background: rgba(39, 107, 216, .08);
  color: var(--blue);
  white-space: nowrap;
}

.contract-reader pre {
  margin: 0;
  white-space: pre-wrap;
  color: #253149;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
  line-height: 1.78;
  padding: 28px 34px;
}

.attachment-panel {
  display: grid;
  gap: 8px;
  margin: 0 34px 30px;
  border: 1px solid rgba(39, 107, 216, .18);
  border-radius: 8px;
  padding: 18px;
  background: linear-gradient(135deg, rgba(39, 107, 216, .08), rgba(52, 198, 232, .08));
}

.attachment-panel strong {
  color: var(--navy);
}

.attachment-panel span {
  color: var(--muted);
  font-size: .86rem;
}

.signature-box {
  display: grid;
  gap: 14px;
  align-content: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  background: white;
  position: sticky;
  top: 18px;
  box-shadow: 0 18px 42px rgba(27, 47, 80, .08);
}

.signature-heading h2 {
  margin: 4px 0 0;
  color: var(--navy);
}

.signature-steps {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 8px 10px;
  border: 1px solid rgba(39, 107, 216, .14);
  border-radius: 8px;
  padding: 12px;
  background: #f8fbff;
}

.signature-steps span {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 999px;
  background: var(--blue);
  color: white;
  font-size: .8rem;
  font-weight: 900;
}

.signature-steps strong {
  align-self: center;
  color: #33415a;
}

.otp-note {
  margin: 0;
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(52, 198, 232, .12);
  color: var(--navy);
  font-weight: 850;
}

.email-status {
  margin: -2px 0 0;
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(52, 185, 121, .1);
  color: #147548;
  font-size: .88rem;
  font-weight: 800;
  line-height: 1.4;
}

.email-status--error {
  background: rgba(210, 64, 64, .1);
  color: #9f2d2d;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  line-height: 1.4;
}

.check-row input {
  width: 18px;
  height: 18px;
  margin-top: 1px;
}

.accepted-box {
  display: grid;
  gap: 10px;
  padding: 14px;
  background: #f3fbf7;
  color: #164f35;
}

.accepted-box span {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .78rem;
  overflow-wrap: anywhere;
}

.accepted-box textarea {
  min-height: 170px;
  border-color: rgba(20, 117, 72, .22);
  background: #ffffff;
  color: #173525;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .78rem;
}

.accepted-box button {
  border: 1px solid rgba(20, 117, 72, .28);
  background: white;
  color: #147548;
  font-weight: 850;
}

@media (max-width: 900px) {
  .hero-band,
  .workspace-grid,
  .reader-grid {
    grid-template-columns: 1fr;
  }

  .client-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .signature-box {
    position: static;
  }

  .hero-card {
    min-height: 160px;
  }
}

@media (max-width: 640px) {
  .app-shell,
  .client-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 14px;
  }

  .owner-topbar,
  .owner-topbar nav {
    display: grid;
    grid-template-columns: 1fr;
  }

  .ghost-link {
    width: 100%;
  }

  .client-page {
    background: #f5f8fc;
  }

  .client-hero__inner {
    display: grid;
    min-height: auto;
    padding: 26px 0 48px;
  }

  .client-hero h1 {
    font-size: 2.1rem;
  }

  .client-shell {
    transform: translateY(-28px);
    padding-top: 0;
  }

  .client-summary {
    grid-template-columns: 1fr;
  }

  .hero-band h1 {
    font-size: 2.3rem;
  }

  .form-grid,
  .action-row {
    grid-template-columns: 1fr;
  }

  .ai-fill-row {
    display: grid;
  }

  .ai-fill-row .secondary-button {
    width: 100%;
  }

  .contract-panel {
    padding: 16px;
  }

  .section-heading {
    display: grid;
  }

  .client-contract-card {
    padding: 12px;
  }

  .document-heading {
    display: grid;
    padding: 16px;
  }

  .document-heading > span {
    width: fit-content;
  }

  .contract-reader pre {
    padding: 20px 18px;
    font-size: .95rem;
    line-height: 1.65;
  }

  .attachment-panel {
    margin: 0 18px 22px;
  }
}

@media print {
  body {
    background: white;
  }

  .client-hero,
  .client-summary,
  .signature-box,
  .hero-band,
  .workspace-grid {
    display: none;
  }

  .app-shell,
  .client-shell {
    width: 100%;
    padding: 0;
    transform: none;
  }

  .contract-panel,
  .contract-reader {
    border: 0;
    box-shadow: none;
    padding: 0;
  }

  .reader-grid {
    display: block;
  }

  .contract-reader pre {
    color: #111827;
    font-size: 11pt;
    line-height: 1.5;
  }
}
