:root {
  --ink: #2d2730;
  --muted: #716873;
  --plum: #684b60;
  --plum-dark: #4b3446;
  --rose: #b58b96;
  --gold: #bd9255;
  --cream: #f7f3ef;
  --paper: #fffdfb;
  --line: #e6ddd8;
  --success: #376c58;
  --success-soft: #e9f3ee;
  --warning: #825c20;
  --warning-soft: #fff5dd;
  --danger: #9c3f48;
  --danger-soft: #fff0f1;
  --shadow: 0 16px 42px rgba(65, 45, 60, 0.08);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--cream);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--cream); }
body { margin: 0; min-height: 100vh; background: var(--cream); color: var(--ink); }
button, input, select, textarea { font: inherit; color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--plum); text-underline-offset: 3px; }
h1, h2, h3 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-weight: 500; line-height: 1.08; }
h1 { font-size: clamp(2.1rem, 4vw, 3.8rem); letter-spacing: -0.035em; }
h2 { font-size: clamp(1.35rem, 2vw, 1.9rem); }
p { line-height: 1.55; }
small { color: var(--muted); line-height: 1.35; }

.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 0.55rem; color: var(--plum); font-size: 0.73rem; font-weight: 800; letter-spacing: 0.13em; text-transform: uppercase; }
.lede { max-width: 760px; margin: 0.8rem 0 0; color: var(--muted); font-size: 1.05rem; }

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: grid;
  grid-template-columns: minmax(230px, 1fr) auto minmax(230px, 1fr);
  gap: 1rem;
  align-items: center;
  min-height: 82px;
  padding: 0.75rem clamp(1rem, 3vw, 3rem);
  border-bottom: 1px solid rgba(104, 75, 96, 0.12);
  background: rgba(255, 253, 251, 0.94);
  backdrop-filter: blur(18px);
}
.brand { display: inline-flex; gap: 0.75rem; align-items: center; width: fit-content; color: var(--ink); text-decoration: none; }
.brand span:last-child { display: flex; flex-direction: column; }
.brand strong { font-family: Georgia, serif; font-size: 1.3rem; font-weight: 500; }
.brand small { font-size: 0.68rem; letter-spacing: 0.04em; }
.brand-mark { display: inline-grid; place-items: center; width: 42px; height: 42px; border: 1px solid var(--gold); border-radius: 50%; background: var(--plum); color: white; font-family: Georgia, serif; font-size: 1.3rem; }
.brand-mark-large { width: 68px; height: 68px; margin-bottom: 2rem; font-size: 2rem; }
.app-header nav { display: flex; gap: 0.2rem; align-items: center; }
.app-header nav a { padding: 0.7rem 0.8rem; border-radius: 999px; color: var(--ink); font-size: 0.88rem; font-weight: 650; text-decoration: none; }
.app-header nav a:hover { background: var(--cream); color: var(--plum); }
.logout-form { display: flex; gap: 0.75rem; align-items: center; justify-content: flex-end; }
.user-name { color: var(--muted); font-size: 0.85rem; }

.page-shell { width: min(1480px, 100%); min-height: calc(100vh - 145px); margin: 0 auto; padding: clamp(2rem, 4vw, 4.5rem) clamp(1rem, 4vw, 4rem); }
.app-footer { display: flex; justify-content: space-between; padding: 1.25rem clamp(1rem, 4vw, 4rem); border-top: 1px solid var(--line); color: var(--muted); font-size: 0.78rem; }
.page-heading, .record-header { display: flex; gap: 2rem; align-items: flex-start; justify-content: space-between; margin-bottom: 2rem; }
.back-link { display: inline-block; margin-bottom: 1.5rem; color: var(--muted); font-size: 0.88rem; text-decoration: none; }
.header-meta { display: flex; flex-wrap: wrap; gap: 0.75rem 1rem; align-items: center; margin-top: 1rem; color: var(--muted); font-size: 0.9rem; }

.button { display: inline-flex; min-height: 44px; padding: 0.68rem 1.05rem; border: 1px solid transparent; border-radius: 999px; align-items: center; justify-content: center; font-weight: 750; line-height: 1; text-decoration: none; cursor: pointer; }
.button:hover { transform: translateY(-1px); }
.button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible, canvas:focus-visible { outline: 3px solid rgba(189, 146, 85, 0.42); outline-offset: 2px; }
.button-primary { border-color: var(--plum); background: var(--plum); color: white; box-shadow: 0 7px 18px rgba(104, 75, 96, 0.2); }
.button-primary:hover { background: var(--plum-dark); }
.button-secondary { border-color: var(--plum); background: transparent; color: var(--plum); }
.button-quiet { border-color: var(--line); background: var(--paper); color: var(--ink); }
.button-danger { border-color: var(--danger); background: var(--danger); color: white; }
.button-large { min-height: 52px; padding-inline: 1.5rem; }

.notice { margin: 1.2rem 0; padding: 1rem 1.2rem; border: 1px solid var(--line); border-radius: 13px; background: var(--paper); line-height: 1.5; }
.notice ul { margin: 0.6rem 0 0; padding-left: 1.3rem; }
.notice-success { border-color: #b9d6c9; background: var(--success-soft); color: #285341; }
.notice-warning { border-color: #efd79b; background: var(--warning-soft); color: #654613; }
.notice-error { border-color: #e7b6bb; background: var(--danger-soft); color: #772f36; }
.notice-neutral { border-color: #d9ced4; background: #f8f4f6; }

.search-bar { display: grid; grid-template-columns: minmax(240px, 1fr) auto auto; gap: 0.8rem; align-items: center; margin: 1.5rem 0; padding: 0.8rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); box-shadow: var(--shadow); }
input, select, textarea { width: 100%; min-height: 46px; margin-top: 0.42rem; padding: 0.7rem 0.8rem; border: 1px solid #d7ccc7; border-radius: 10px; background: #fff; }
textarea { min-height: 104px; resize: vertical; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: #a79da4; }
label, legend { color: #4e4550; font-size: 0.88rem; font-weight: 720; line-height: 1.4; }
label small, fieldset > small { display: block; margin-top: 0.4rem; font-weight: 450; }

.customer-grid { display: grid; gap: 0.7rem; }
.customer-card { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: 1rem; align-items: center; min-height: 86px; padding: 1rem 1.2rem; border: 1px solid var(--line); border-radius: 15px; background: var(--paper); box-shadow: 0 5px 20px rgba(65, 45, 60, 0.04); color: var(--ink); text-decoration: none; }
.customer-card:hover { border-color: #cdbbc4; box-shadow: var(--shadow); transform: translateY(-1px); }
.avatar { display: grid; width: 48px; height: 48px; border-radius: 50%; place-items: center; background: #eee4e8; color: var(--plum); font-family: Georgia, serif; font-weight: 700; }
.customer-main { display: flex; min-width: 0; flex-direction: column; gap: 0.35rem; }
.customer-main strong { overflow: hidden; font-size: 1.02rem; text-overflow: ellipsis; white-space: nowrap; }
.chevron { color: var(--rose); font-family: Georgia, serif; font-size: 2rem; }
.status { display: inline-flex; width: fit-content; padding: 0.35rem 0.62rem; border-radius: 999px; background: #efebed; color: #5e555d; font-size: 0.72rem; font-weight: 800; line-height: 1; white-space: nowrap; }
.status-active { background: var(--success-soft); color: var(--success); }
.status-prospect { background: #f5ebd9; color: #785a28; }
.status-archived { background: #eee9ec; color: #675e65; }

.empty-state { display: grid; min-height: 330px; padding: 3rem; border: 1px dashed #d0c2c9; border-radius: var(--radius); place-items: center; align-content: center; background: rgba(255,255,255,0.55); text-align: center; }
.empty-state p { max-width: 560px; color: var(--muted); }

.document-form { display: grid; gap: 1.2rem; }
.form-section, .panel, .info-card, .signed-document { padding: clamp(1.2rem, 3vw, 2.2rem); border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); box-shadow: var(--shadow); }
.section-heading { display: grid; grid-template-columns: 48px 1fr; gap: 1rem; align-items: start; margin-bottom: 1.5rem; }
.section-heading > span { display: grid; width: 42px; height: 42px; border: 1px solid #d4bdc7; border-radius: 50%; place-items: center; color: var(--plum); font-family: Georgia, serif; }
.section-heading p { margin: 0.35rem 0 0; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.15rem; }
.span-2 { grid-column: 1 / -1; }
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.choice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.65rem; margin-top: 0.5rem; }
.choice-card { display: flex; min-height: 50px; margin: 0; padding: 0.75rem; border: 1px solid var(--line); border-radius: 10px; align-items: flex-start; gap: 0.7rem; background: #fff; cursor: pointer; font-weight: 590; }
.choice-card:has(input:checked) { border-color: var(--plum); background: #f8f2f5; box-shadow: inset 0 0 0 1px var(--plum); }
.choice-card input, .compact-check input { width: 20px; min-height: 20px; margin: 0; flex: 0 0 auto; accent-color: var(--plum); }
.choice-card span { line-height: 1.4; }
.form-actions { display: flex; gap: 1rem; align-items: center; justify-content: flex-end; padding: 1rem 0; }
.form-actions p { margin: 0 auto; color: var(--muted); font-size: 0.78rem; }
.sticky-actions { position: sticky; z-index: 10; bottom: 0.75rem; padding: 0.8rem; border: 1px solid var(--line); border-radius: 999px; background: rgba(255,253,251,0.96); box-shadow: 0 12px 35px rgba(65,45,60,0.14); backdrop-filter: blur(14px); }
.compact-check { display: inline-flex; width: fit-content; align-items: center; gap: 0.5rem; font-weight: 600; white-space: nowrap; }

.record-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 1.2rem; align-items: start; }
.record-sidebar { display: grid; gap: 1rem; position: sticky; top: 102px; }
.record-content { display: grid; gap: 1.2rem; min-width: 0; }
.info-card h2 { margin-bottom: 1rem; font-size: 1.35rem; }
.info-card dl { display: grid; gap: 0.8rem; margin: 0; }
.info-card dt { color: var(--muted); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.07em; text-transform: uppercase; }
.info-card dd { overflow-wrap: anywhere; margin: 0.15rem 0 0; line-height: 1.45; }
.device-mini { background: var(--plum); color: white; }
.device-mini .eyebrow, .device-mini p, .device-mini small { color: #eadfe5; }
.panel-heading { display: flex; gap: 1rem; align-items: flex-start; justify-content: space-between; margin-bottom: 1.3rem; }
.panel-heading > p { max-width: 420px; margin: 0; color: var(--muted); font-size: 0.84rem; }
.workflow-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.7rem; }
.workflow-card { display: grid; grid-template-columns: 34px 1fr; gap: 0.7rem; min-height: 72px; padding: 0.85rem; border: 1px solid var(--line); border-radius: 12px; align-items: center; color: var(--ink); text-decoration: none; }
.workflow-card:hover { border-color: var(--plum); }
.workflow-card > span:last-child { display: flex; min-width: 0; flex-direction: column; gap: 0.25rem; }
.workflow-card small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.workflow-state { display: grid; width: 32px; height: 32px; border-radius: 50%; place-items: center; background: #f0e7eb; color: var(--plum); font-weight: 800; }
.workflow-card.is-complete .workflow-state { background: var(--success-soft); color: var(--success); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
th { padding: 0.75rem; border-bottom: 1px solid #d9cdca; color: var(--muted); font-size: 0.68rem; letter-spacing: 0.08em; text-align: left; text-transform: uppercase; }
td { padding: 0.85rem 0.75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
td a { font-weight: 750; }

.photo-upload { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.8rem; margin-bottom: 1.5rem; padding: 1rem; border: 1px dashed #ccb9c2; border-radius: 13px; background: #fbf7f8; }
.photo-upload > button { align-self: end; justify-self: start; }
.camera-field input { padding: 0.5rem; background: white; }
.photo-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.photo-card { overflow: hidden; border: 1px solid var(--line); border-radius: 13px; background: white; }
.photo-card > img { display: block; width: 100%; aspect-ratio: 4/3; object-fit: cover; background: #eee; }
.photo-card > div, .photo-card > details { padding: 0.8rem; }
.photo-card > div { display: flex; flex-direction: column; gap: 0.2rem; }
.photo-card p { margin: 0.3rem 0 0; font-size: 0.82rem; }
.danger-details { border-top: 1px solid var(--line); }
.danger-details summary { color: var(--danger); cursor: pointer; font-size: 0.78rem; font-weight: 700; }
.danger-details form { display: grid; gap: 0.75rem; margin-top: 0.8rem; }

.document-heading { align-items: flex-end; }
.version-chip { padding: 0.45rem 0.7rem; border: 1px solid #d5c6cd; border-radius: 999px; color: var(--muted); font-size: 0.72rem; white-space: nowrap; }
.device-banner { display: grid; grid-template-columns: auto 1fr auto; gap: 1rem; align-items: center; padding: 0.8rem 1rem; border-radius: 12px; background: var(--plum); color: white; }
.device-banner span { color: #e4d7de; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.device-banner small { color: #e4d7de; }
.signature-pad { position: relative; overflow: hidden; margin: 0.6rem 0; border: 1px dashed #bba7b1; border-radius: 12px; background: linear-gradient(to bottom, #fff 84%, #eadfe3 85%, #fff 86%); }
.signature-pad canvas { display: block; width: 100%; height: 230px; touch-action: none; }
.signature-hint { position: absolute; right: 1rem; bottom: 1rem; color: #9c9097; font-size: 0.75rem; pointer-events: none; }
.signature-missing .signature-pad { border: 2px solid var(--danger); }

.signed-document { max-width: 1050px; margin: 0 auto 1.5rem; }
.signed-meta { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; padding-bottom: 1.4rem; border-bottom: 1px solid var(--line); }
.signed-meta div, .signature-proof > div { display: flex; flex-direction: column; gap: 0.35rem; }
.signed-meta span, .signature-proof span { color: var(--muted); font-size: 0.68rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.signed-meta strong { font-size: 0.85rem; }
.document-section { padding: 1.7rem 0; border-bottom: 1px solid var(--line); }
.document-section h2 { margin-bottom: 1rem; }
.document-values { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; margin: 0; }
.document-values > div { padding: 0.8rem 1rem 0.8rem 0; border-bottom: 1px dotted #ddd1d5; }
.document-values dt { color: var(--muted); font-size: 0.73rem; font-weight: 700; }
.document-values dd { margin: 0.3rem 0 0; line-height: 1.45; white-space: pre-wrap; }
.signature-proof { display: flex; min-height: 150px; padding: 1.5rem 0; align-items: center; justify-content: space-between; }
.signature-proof img { width: 280px; max-height: 120px; object-fit: contain; }
.integrity-proof { padding: 0.8rem; border-radius: 10px; background: #f5f1f3; color: var(--muted); font-size: 0.75rem; }
.integrity-proof code { display: block; overflow-wrap: anywhere; margin: 0.7rem 0; color: var(--ink); }
.danger-zone { max-width: 1050px; margin: 0 auto; border-color: #e7b6bb; }
.danger-zone form { display: grid; gap: 0.8rem; }
.danger-zone .button { justify-self: start; }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.2rem; margin-bottom: 1.2rem; }
.settings-grid .form-section { align-self: start; }
.settings-grid .button { margin-top: 1rem; }

.legal-document { max-width: 900px; margin: 0 auto; padding: clamp(1.5rem, 5vw, 4.5rem); border: 1px solid var(--line); background: var(--paper); box-shadow: var(--shadow); }
.legal-document header { position: relative; padding-bottom: 2rem; border-bottom: 2px solid var(--plum); }
.legal-document header > .button { position: absolute; top: 0; right: 0; }
.legal-document header > p:last-of-type { color: var(--muted); font-size: 1.08rem; }
.legal-document section { padding: 1.5rem 0; border-bottom: 1px solid var(--line); }
.legal-document section h2 { margin-bottom: 0.8rem; font-size: 1.35rem; }
.legal-document section p, .legal-document li { line-height: 1.65; }
.legal-document ul { padding-left: 1.25rem; }
.warning-section { padding-inline: 1.2rem !important; border: 1px solid #e1bd84 !important; border-radius: 12px; background: var(--warning-soft); }

.login-page { display: grid; min-height: 100vh; place-items: center; padding: 2rem; background: linear-gradient(130deg, var(--plum-dark) 0 45%, var(--cream) 45% 100%); }
.login-shell { display: grid; grid-template-columns: 1fr 1fr; overflow: hidden; width: min(1000px, 100%); min-height: 600px; border-radius: 24px; background: var(--paper); box-shadow: 0 28px 80px rgba(40,26,38,0.28); }
.login-brand { display: flex; padding: clamp(2rem, 5vw, 4.5rem); flex-direction: column; justify-content: center; background: var(--plum); color: white; }
.login-brand .eyebrow, .login-brand p { color: #eadfe5; }
.login-brand h1 { font-size: clamp(3rem, 6vw, 5.3rem); }
.login-card { display: flex; padding: clamp(2rem, 5vw, 4.5rem); flex-direction: column; justify-content: center; }
.login-card h2 { font-size: 2.2rem; }
.stack-form { display: grid; gap: 1rem; margin-top: 1rem; }
.security-note { margin-top: 1.4rem; color: var(--muted); font-size: 0.75rem; text-align: center; }

@media (max-width: 1050px) {
  .app-header { grid-template-columns: 1fr auto; }
  .app-header nav { grid-column: 1 / -1; grid-row: 2; overflow-x: auto; justify-content: center; }
  .user-name { display: none; }
  .record-layout { grid-template-columns: 1fr; }
  .record-sidebar { position: static; grid-template-columns: 1fr 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .page-shell { padding-top: 2rem; }
  .app-header { min-height: 68px; padding: 0.6rem 0.8rem; }
  .app-header nav { justify-content: flex-start; }
  .brand small { display: none; }
  .logout-form .button { padding-inline: 0.8rem; }
  .page-heading, .record-header { align-items: stretch; flex-direction: column; }
  .page-heading > .button, .record-header > .button { align-self: flex-start; }
  .search-bar { grid-template-columns: 1fr; }
  .customer-card { grid-template-columns: auto minmax(0, 1fr) auto; }
  .customer-card .status { grid-column: 2; }
  .customer-card .chevron { grid-column: 3; grid-row: 1 / 3; }
  .form-grid, .choice-grid, .workflow-grid, .photo-upload, .document-values, .settings-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .record-sidebar { grid-template-columns: 1fr; }
  .photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .signed-meta { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sticky-actions { border-radius: 18px; align-items: stretch; flex-direction: column; }
  .sticky-actions p { order: -1; text-align: center; }
  .device-banner { grid-template-columns: 1fr; }
  .login-page { padding: 0; background: var(--plum); }
  .login-shell { min-height: 100vh; border-radius: 0; grid-template-columns: 1fr; }
  .login-brand { min-height: 260px; padding: 2rem; }
  .login-brand h1 { font-size: 3rem; }
  .brand-mark-large { margin-bottom: 1rem; }
  .login-card { padding: 2rem; }
  .app-footer { gap: 0.5rem; align-items: center; flex-direction: column; }
}

@media (max-width: 460px) {
  .photo-grid { grid-template-columns: 1fr; }
  .signed-meta { grid-template-columns: 1fr; }
  .signature-proof { gap: 1rem; align-items: stretch; flex-direction: column; }
  .signature-proof img { width: 100%; }
}

@media print {
  :root { background: white; }
  body { background: white; font-size: 10.5pt; }
  .print-hidden, .app-header, .app-footer, .danger-zone { display: none !important; }
  .page-shell { width: 100%; padding: 0; }
  .page-heading { margin-bottom: 1rem; }
  .page-heading h1 { font-size: 24pt; }
  .signed-document, .legal-document { max-width: none; padding: 0; border: 0; box-shadow: none; }
  .document-section { break-inside: avoid; }
  .signature-proof { break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
  @page { size: A4; margin: 14mm; }
}
