:root {
  color-scheme: dark;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  --navy: #062f61;
  --navy-deep: #031f43;
  --blue: #118be0;
  --orange: #ff7a00;
  --green: #43a915;
  --white: #f8fbff;
  --muted: #b9cee4;
  --line: rgba(120, 180, 232, .32);
  --danger: #d63432;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; background: var(--navy-deep); color: var(--white); }
body { min-height: 100dvh; background: radial-gradient(circle at 82% 12%, rgba(17, 139, 224, .24), transparent 36%), linear-gradient(145deg, #042955, #031b3b 72%); }
button, input { font: inherit; }
button { touch-action: manipulation; }

.tablet-header {
  min-height: 88px;
  display: grid;
  grid-template-columns: 190px 1fr 64px;
  align-items: center;
  gap: 22px;
  padding: 10px 24px;
  background: rgba(4, 46, 94, .96);
  border-bottom: 1px solid var(--line);
}
.tablet-header img { width: 176px; max-height: 66px; object-fit: contain; background: #fff; }
.tablet-header div { display: grid; gap: 4px; }
.tablet-header span { color: #65bcf5; font-weight: 800; font-size: 13px; letter-spacing: .08em; }
.tablet-header strong { font-size: clamp(18px, 2.2vw, 28px); }
.tablet-header button { width: 58px; height: 58px; border: 1px solid var(--line); color: #fff; background: #073c77; font-size: 28px; cursor: pointer; }

#signature-app { width: min(1560px, 100%); margin: 0 auto; padding: clamp(22px, 3vw, 48px); }
.pairing-screen { min-height: calc(100dvh - 170px); display: grid; place-content: center; justify-items: center; gap: 28px; text-align: center; }
.pairing-mark { width: 112px; height: 112px; display: grid; place-items: center; border: 3px solid var(--orange); color: var(--orange); font-size: 54px; transform: rotate(-4deg); }
.pairing-intro h1 { margin: 18px 0 8px; font-size: clamp(34px, 5vw, 62px); letter-spacing: 0; }
.pairing-intro p { max-width: 660px; margin: 0; color: var(--muted); font-size: clamp(17px, 2vw, 23px); line-height: 1.5; }
.pairing-form { width: min(520px, 90vw); display: grid; gap: 14px; }
.pairing-form label { font-weight: 800; font-size: 18px; }
.pairing-code-input { width: 100%; height: 92px; border: 2px solid #3f91d4; background: #052b58; color: #fff; text-align: center; font-size: 52px; font-weight: 900; letter-spacing: .3em; padding-left: .3em; outline: none; }
.pairing-code-input:focus { border-color: var(--orange); box-shadow: 0 0 0 5px rgba(255, 122, 0, .18); }
.primary-action, .secondary-action { min-height: 64px; padding: 14px 22px; border: 0; color: #fff; font-weight: 900; font-size: 19px; cursor: pointer; }
.primary-action { background: var(--green); }
.primary-action:disabled { opacity: .5; cursor: wait; }
.secondary-action { background: #14518e; border: 1px solid #4e99d7; }
.form-error { min-height: 24px; margin: 0; color: #ffb8b8; font-weight: 700; }

.waiting-screen, .success-screen { min-height: calc(100dvh - 170px); display: grid; place-content: center; justify-items: center; text-align: center; gap: 16px; }
.waiting-icon, .success-icon { width: 132px; height: 132px; display: grid; place-items: center; border-radius: 50%; font-size: 62px; border: 3px solid currentColor; position: relative; }
.waiting-icon { color: #55b9f5; }
.waiting-icon::after { content: ""; position: absolute; inset: -15px; border: 2px solid rgba(85, 185, 245, .25); border-radius: 50%; animation: pulse 1.8s ease-out infinite; }
.success-icon { color: #73d348; }
.waiting-screen h1, .success-screen h1 { margin: 8px 0 0; font-size: clamp(36px, 5vw, 64px); }
.waiting-screen p, .success-screen p { max-width: 760px; margin: 0; color: var(--muted); font-size: 21px; line-height: 1.5; }
.success-screen small { color: #8cd86a; font-size: 17px; font-weight: 800; }
@keyframes pulse { 0% { transform: scale(.8); opacity: .8; } 100% { transform: scale(1.3); opacity: 0; } }

.signature-heading { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 22px; }
.signature-heading span { color: var(--orange); font-weight: 900; }
.signature-heading h1 { margin: 4px 0 0; font-size: clamp(30px, 4vw, 48px); }
.signature-heading strong { color: #8cd86a; font-size: clamp(28px, 4vw, 48px); white-space: nowrap; }
.signature-layout { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(420px, .95fr); gap: 22px; align-items: start; }
.contract-pane, .signature-pane { border: 1px solid var(--line); background: rgba(5, 50, 99, .86); }
.contract-pane { max-height: calc(100dvh - 225px); overflow: auto; overscroll-behavior: contain; }
.contract-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; padding: 18px 22px; color: var(--muted); border-bottom: 1px solid var(--line); }
.contract-meta code { flex-basis: 100%; color: #7ec7f7; overflow-wrap: anywhere; }
.client-block { padding: 20px 22px; border-bottom: 1px solid var(--line); }
.client-block span, .products-title { color: #7ec7f7; font-size: 13px; font-weight: 900; }
.client-block h2 { margin: 7px 0 0; font-size: 29px; }
.client-block p { margin: 7px 0 0; color: var(--muted); line-height: 1.45; }
.products-title { display: block; padding: 18px 22px 8px; }
.contract-products { padding: 0 22px; }
.contract-product { display: grid; grid-template-columns: 1fr auto; gap: 16px; padding: 16px 0; border-bottom: 1px solid var(--line); }
.contract-product div { display: grid; gap: 5px; }
.contract-product small { color: var(--muted); }
.contract-product b { font-size: 20px; }
.contract-payments { margin: 18px 22px 0; padding: 16px; border-left: 4px solid var(--orange); background: rgba(3, 31, 67, .65); }
.contract-payments h3 { margin: 0 0 10px; font-size: 18px; }
.contract-payments p { display: flex; justify-content: space-between; gap: 18px; margin: 8px 0; }
.contract-payments p span { color: var(--muted); }
.contract-clauses { padding: 18px 22px 26px; }
.contract-clauses h3 { margin: 0 0 14px; font-size: 18px; }
.contract-clauses p { display: grid; grid-template-columns: 24px 1fr; gap: 10px; margin: 12px 0; color: #d9e7f5; line-height: 1.45; }
.contract-clauses i { color: #6ac73d; font-style: normal; font-weight: 900; }

.signature-pane { padding: 22px; display: grid; gap: 16px; }
.signature-pane h2 { margin: 0; font-size: 27px; }
.signature-pane > p { margin: -8px 0 0; color: var(--muted); }
#signature-canvas { width: 100%; height: min(34dvh, 340px); min-height: 230px; display: block; background: #fff; border: 4px solid #d9e4ed; touch-action: none; cursor: crosshair; }
.reading-confirmation { display: grid; grid-template-columns: 32px 1fr; gap: 12px; align-items: center; min-height: 56px; padding: 10px 14px; background: rgba(3, 31, 67, .6); cursor: pointer; }
.reading-confirmation input { width: 26px; height: 26px; accent-color: var(--green); }
.signature-actions { display: grid; grid-template-columns: .7fr 1.3fr; gap: 12px; }
.signature-expiry { color: var(--muted); text-align: center; font-size: 13px; }
#tablet-toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 120px); opacity: 0; background: #102a43; border: 1px solid #61b4ee; padding: 14px 20px; font-weight: 800; transition: .2s ease; z-index: 4; }
#tablet-toast.visible { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 980px) {
  .tablet-header { grid-template-columns: 150px 1fr 54px; padding-inline: 16px; }
  .tablet-header img { width: 140px; }
  .signature-layout { grid-template-columns: 1fr; }
  .contract-pane { max-height: 38dvh; }
  #signature-canvas { height: 250px; min-height: 220px; }
}

@media (max-width: 600px) {
  .tablet-header { grid-template-columns: 110px 1fr 48px; gap: 10px; min-height: 72px; }
  .tablet-header img { width: 104px; max-height: 52px; }
  .tablet-header span { font-size: 10px; }
  .tablet-header strong { font-size: 15px; }
  .tablet-header button { width: 44px; height: 44px; }
  #signature-app { padding: 18px 12px; }
  .signature-heading { align-items: start; }
  .signature-heading strong { font-size: 26px; }
  .signature-actions { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
