@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,400;0,500;1,300;1,400&family=DM+Sans:opsz,wght@9..40,300;9..40,400;9..40,500&family=JetBrains+Mono:wght@400;500&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* kxco.ai brand palette */
  --bg:          #EFE5C8;   /* void — warm cream */
  --surface:     #E8DCB4;   /* deep — secondary surface */
  --surface-2:   #E3D5A6;   /* card background */
  --border:      rgba(21,33,74,0.14);
  --border-md:   rgba(21,33,74,0.24);
  --text:        #0a0a0a;   /* black */
  --text-dim:    rgba(10,10,10,0.94);
  --muted:       rgba(10,10,10,0.52);
  --accent:      #9A7B1F;   /* gold */
  --accent-h:    #B8860B;   /* gold hover */
  --accent-bright:#D4AF37;  /* gold bright */
  --gold-faint:  rgba(154,123,31,0.12);
  --gold-bar:    linear-gradient(135deg, #7A5D17 0%, #B8860B 22%, #E5C661 48%, #C9A227 58%, #8B6C18 82%, #6E5510 100%);
  --indigo:      #4A4188;   /* secondary accent */
  --blue:        #15214A;   /* deep blue */
  --success:     #1D9E75;
  --error:       #C0392B;
  --radius:      8px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.75;
  min-height: 100vh;
}

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
.page { max-width: 720px; margin: 0 auto; padding: 48px 24px 80px; }

/* Branding */
.logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted);
  margin-bottom: 20px;
}
.logo-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

/* Trust bar */
.trust-bar {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-bottom: 40px;
}
.trust-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 500; letter-spacing: 0.04em;
  border: 1px solid var(--border-md);
  color: var(--muted);
  background: rgba(154,123,31,.08);
}
.trust-badge svg { flex-shrink: 0; }

/* Typography */
h1 {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 32px; font-weight: 400; line-height: 1.2;
  margin-bottom: 8px; letter-spacing: -0.01em;
}
h2 {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 24px; font-weight: 400;
}
.subtitle { color: var(--muted); font-size: 14px; margin-bottom: 32px; }

/* Cards */
.card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
  transition: border-color 0.15s;
}
.card:hover { border-color: var(--border-md); }
.card-title {
  font-size: 11px; font-weight: 600; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--muted);
  margin-bottom: 16px;
  display: flex; align-items: center; gap: 8px;
}
.card.step-complete { border-color: rgba(34,197,94,.3); }
.card.step-complete .card-title::after {
  content: '';
  display: inline-flex;
  width: 16px; height: 16px;
  background: var(--success);
  border-radius: 50%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
  background-size: 10px; background-repeat: no-repeat; background-position: center;
}

/* Drop zone */
.dropzone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.drag-over {
  border-color: var(--accent);
  background: rgba(154,123,31,.06);
}
.dropzone-icon { margin-bottom: 12px; color: var(--muted); }
.dropzone-label { font-size: 14px; color: var(--muted); }
.dropzone-label span { color: var(--accent); }
.file-info {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: rgba(154,123,31,.08);
  border: 1px solid rgba(154,123,31,.2);
  border-radius: 8px;
  font-size: 13px;
}
.file-info svg { color: var(--muted); flex-shrink: 0; }
.file-info-name { font-weight: 600; flex: 1; }
.file-info-size { color: var(--muted); }

/* Identity section */
.identity-row { display: flex; gap: 8px; margin-bottom: 12px; }
.seg-btn {
  flex: 1; padding: 9px 12px;
  background: none; border: 1px solid var(--border);
  border-radius: 8px; color: var(--muted);
  font-size: 13px; cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.seg-btn:hover { border-color: var(--border-md); color: var(--text); }
.seg-btn.active {
  background: rgba(154,123,31,.12);
  border-color: var(--accent);
  color: var(--accent);
}
.kid-display {
  font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
  font-size: 12px; color: var(--accent);
  background: rgba(154,123,31,.08);
  border: 1px solid rgba(154,123,31,.2);
  border-radius: 6px;
  padding: 10px 14px;
  letter-spacing: 0.05em;
  word-break: break-all;
}
textarea.import-box {
  width: 100%; height: 100px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text);
  font-family: monospace; font-size: 12px;
  padding: 10px 12px; resize: vertical;
  font-family: inherit;
}
textarea.import-box:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

/* Labels + inputs */
.purpose-label {
  display: block;
  font-size: 12px; font-weight: 500;
  color: var(--muted); margin-bottom: 8px;
}
input.purpose-input {
  width: 100%; padding: 10px 14px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s;
}
input.purpose-input:hover { border-color: #444; }
input.purpose-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 24px; border-radius: 8px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  border: none; transition: all 0.15s; width: 100%;
  font-family: inherit;
}
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn-primary { background: var(--accent); color: var(--bg); }
.btn-primary:hover { background: var(--accent-h); }
.btn-primary:disabled { background: rgba(154,123,31,.25); color: rgba(154,123,31,.5); cursor: not-allowed; }
.btn-secondary { background: none; border: 1px solid var(--border-md); color: var(--text); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-sm { padding: 10px 16px; font-size: 13px; width: auto; min-height: 44px; }

/* Result card */
.result-card {
  border: 1px solid rgba(154,123,31,.35);
  background: rgba(154,123,31,.06);
}
.result-row {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.result-row:last-child { border-bottom: none; }
.result-key { color: var(--muted); flex-shrink: 0; margin-right: 16px; }
.result-val { font-family: monospace; font-size: 12px; text-align: right; word-break: break-all; max-width: 65%; }

/* QR section */
.qr-wrap { display: flex; gap: 24px; align-items: flex-start; }
.qr-img {
  width: 148px; height: 148px; border-radius: 8px;
  flex-shrink: 0;
  background: #fff;                /* white quiet zone for scanner reliability */
  padding: 8px;
}
.qr-info { flex: 1; }
.qr-url {
  font-family: monospace; font-size: 11px; color: var(--muted);
  word-break: break-all; margin: 8px 0 16px;
}

/* Action row */
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.badge svg { flex-shrink: 0; }
.badge-success { background: rgba(34,197,94,.15); color: var(--success); }
.badge-error   { background: rgba(239,68,68,.15);  color: var(--error); }

/* Spinner */
.spinner {
  width: 16px; height: 16px; border: 2px solid rgba(14,24,56,.2);
  border-top-color: var(--bg); border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Verify page */
.verify-status { text-align: center; padding: 40px 24px; }
.verify-icon { margin-bottom: 16px; display: flex; justify-content: center; }
.verify-title { font-family: 'EB Garamond', serif; font-size: 26px; font-weight: 500; margin-bottom: 8px; }
.verify-sub   { color: var(--muted); font-size: 14px; max-width: 400px; margin: 0 auto; }

.meta-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px;
}
.meta-item { padding: 14px; background: var(--bg); border-radius: 8px; }
.meta-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px; font-weight: 600; }
.meta-value { font-size: 13px; font-weight: 600; word-break: break-all; }

/* ESIGN consent */
.esign-card { border-color: rgba(245,158,11,.2); }
.esign-label {
  display: flex; gap: 12px; align-items: flex-start;
  font-size: 13px; color: var(--muted); cursor: pointer; line-height: 1.6;
}
.esign-label input[type="checkbox"] {
  margin-top: 3px; flex-shrink: 0; accent-color: var(--accent-amber);
  width: 16px; height: 16px; cursor: pointer;
}

/* Template fields */
.tpl-field-group { margin-bottom: 10px; }

/* Signer link row */
.signer-link-row {
  display: flex; gap: 12px; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.signer-link-row:last-child { border-bottom: none; }

/* Signer row in form (multi-party) */
.signer-row {
  display: grid; grid-template-columns: 1fr 1fr auto;
  gap: 8px; align-items: flex-end; margin-bottom: 10px;
}

/* Print styles */
@media print {
  body { background: white; color: black; }
  .card { border: 1px solid #ddd; background: white; box-shadow: none; }
  .trust-bar { display: none; }
  .no-print { display: none !important; }
  .print-only { display: block !important; }
  .btn { display: none; }
  h1, h2 { color: black; }
}
.print-only { display: none; }

/* ── App shell layout ─────────────────────────────────────────────────────── */

body.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
body.app-shell .shell-main {
  flex: 1;
  overflow-y: auto;
  min-width: 0;
}
body.app-shell .page {
  max-width: 860px;
}
body.sb-body-lock { overflow: hidden; }

/* ── Sidebar ──────────────────────────────────────────────────────────────── */

.kxco-sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border-md);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  z-index: 40;
  transition: transform 0.22s cubic-bezier(.4,0,.2,1);
}

.sb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sb-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}
.sb-logo:hover { text-decoration: none; }
.sb-logo-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}
.sb-logo-text {
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--text);
}
.sb-close-btn {
  display: none;
  background: none; border: none;
  color: var(--muted); cursor: pointer;
  padding: 4px; border-radius: 6px;
  transition: color 0.15s;
}
.sb-close-btn:hover { color: var(--text); }

.sb-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}
.sb-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  border-left: 2px solid transparent;
}
.sb-item:hover { background: rgba(154,123,31,.08); color: var(--text); text-decoration: none; }
.sb-item.sb-active {
  background: rgba(154,123,31,.12);
  color: var(--accent);
  border-left-color: var(--accent);
}
.sb-icon { display: flex; align-items: center; flex-shrink: 0; }
.sb-label { flex: 1; }

.sb-footer {
  padding: 12px 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.sb-user { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.sb-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: rgba(154,123,31,.18);
  border: 1px solid var(--border-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: var(--accent);
  flex-shrink: 0;
}
.sb-user-info { min-width: 0; }
.sb-user-name {
  font-size: 12px; font-weight: 600;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sb-plan-badge {
  font-size: 10px; font-weight: 700;
  padding: 1px 7px; border-radius: 999px;
  text-transform: capitalize;
  margin-top: 2px; display: inline-block;
}
.sb-logout-btn {
  background: none; border: none;
  color: var(--muted); cursor: pointer;
  padding: 6px; border-radius: 6px;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0; display: flex; align-items: center;
}
.sb-logout-btn:hover { color: var(--error); background: rgba(192,57,43,.08); }

/* ── Mobile top bar ───────────────────────────────────────────────────────── */

.sb-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 30;
}
.sb-topbar-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.sb-menu-btn, .sb-close-btn {
  background: none; border: none;
  color: var(--muted); cursor: pointer;
  padding: 6px; border-radius: 8px;
  display: flex; align-items: center;
  transition: color 0.15s, background 0.15s;
}
.sb-menu-btn:hover { color: var(--text); background: rgba(255,255,255,.05); }

/* ── Mobile overlay ───────────────────────────────────────────────────────── */

.sb-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 38;
  backdrop-filter: blur(2px);
}
.sb-overlay.sb-overlay-visible { display: block; }

/* ── Mobile breakpoint ────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  body.app-shell {
    flex-direction: column;
    height: auto;
    overflow: auto;
  }
  body.app-shell .shell-main {
    height: auto;
    overflow: visible;
  }
  .sb-topbar { display: flex; }
  .kxco-sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    z-index: 39;
    transform: translateX(-100%);
  }
  .kxco-sidebar.sb-open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,.5);
  }
  .sb-close-btn { display: flex; }
}

@media (min-width: 769px) {
  body.app-shell {
    flex-direction: row;
  }
  .sb-topbar { display: none; }
}

/* ── Progress stepper ─────────────────────────────────────────────────────── */
.stepper {
  display: flex; align-items: flex-start; gap: 0;
  margin-bottom: 32px;
  counter-reset: step;
}
.stepper-step {
  display: flex; flex-direction: column; align-items: center;
  flex: 1; position: relative; text-align: center;
}
.stepper-step:not(:last-child)::after {
  content: '';
  position: absolute; top: 15px; left: calc(50% + 18px);
  width: calc(100% - 36px); height: 1px;
  background: var(--border);
  transition: background 0.3s;
}
.stepper-step.complete:not(:last-child)::after { background: var(--success); }
.stepper-node {
  width: 30px; height: 30px; border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--surface); color: var(--muted);
  font-size: 12px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s; margin-bottom: 6px; position: relative; z-index: 1;
  flex-shrink: 0;
}
.stepper-step.active .stepper-node {
  border-color: var(--accent); background: var(--accent);
  color: #fff; box-shadow: 0 0 0 4px rgba(154,123,31,.14);
}
.stepper-step.complete .stepper-node {
  border-color: var(--success); background: var(--success); color: #000;
}
.stepper-label {
  font-size: 11px; color: var(--muted); font-weight: 500;
  transition: color 0.2s;
}
.stepper-step.active .stepper-label { color: var(--accent); }
.stepper-step.complete .stepper-label { color: var(--success); }

/* ── Document preview ─────────────────────────────────────────────────────── */
.doc-preview {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden;
}
.doc-preview-bar {
  background: var(--bg); padding: 8px 14px;
  font-size: 11px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .08em;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.doc-preview-body {
  padding: 16px; max-height: 200px; overflow-y: auto;
  font-family: 'SF Mono','Fira Code',monospace; font-size: 12px;
  line-height: 1.7; color: var(--muted);
  white-space: pre-wrap; word-break: break-word;
}

/* ── Certificate ─────────────────────────────────────────────────────────── */
.cert-btn {
  background: linear-gradient(135deg, rgba(154,123,31,.14), rgba(154,123,31,.06));
  border: 1px solid rgba(154,123,31,.3);
}
.cert-btn:hover { border-color: var(--accent); background: rgba(154,123,31,.14); }

/* Mobile */
@media (max-width: 480px) {
  .page { padding: 32px 16px 64px; }
  h1 { font-size: 24px; }
  .qr-wrap { flex-direction: column; }
  .qr-img { width: 160px; height: 160px; }
  .meta-grid { grid-template-columns: 1fr; }
  .signer-row { grid-template-columns: 1fr 1fr; }
  .signer-row button { grid-column: 1/-1; }
}
