/*
 * SmartSign web UI, based on the KURZ Digital Design System.
 * Tokens mirror the design system's palette, radii and elevation.
 */
:root {
  --kd-brand: #C8D400;
  --kd-brand-deep: #A8B400;
  --kd-brand-press: #7C8300;
  --kd-brand-wash-20: rgba(200, 212, 0, 0.2);
  --kd-brand-wash-40: rgba(200, 212, 0, 0.4);

  --kd-navy: #000038;
  --kd-subtitle: #33363F;
  --kd-body: #505268;
  --kd-white: #FFFFFF;
  --kd-bg: #F7F8FA;
  --kd-border: #E6E8EF;
  --kd-border-strong: #CCD0DD;
  --kd-error: #FF4B55;

  --kd-radius-sm: 4px;
  --kd-radius-md: 6px;
  --kd-radius-lg: 8px;
  --kd-radius-chip: 11px;
  --kd-radius-pill: 999px;

  --kd-shadow-paper: 0 4px 4px rgba(0, 0, 0, 0.25);
  --kd-shadow-pop: 0 8px 24px rgba(0, 0, 0, 0.18);

  --kd-font: Roboto, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --kd-font-mono: "Roboto Mono", ui-monospace, Menlo, Consolas, monospace;

  --header-height: 79px;
}

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

html, body { margin: 0; }

body {
  min-height: 100vh;
  background: var(--kd-bg);
  color: var(--kd-navy);
  font-family: var(--kd-font);
  font-size: 15px;
  line-height: 1.4;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }

a { color: var(--kd-navy); }
a:hover { color: var(--kd-subtitle); }

:focus-visible { outline: 2px solid var(--kd-brand-press); outline-offset: 2px; }

input::placeholder { color: var(--kd-body); opacity: 1; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

[hidden] { display: none !important; }

.icon {
  width: 18px; height: 18px; flex: 0 0 auto;
  fill: none; stroke: currentColor; stroke-width: 1.5;
  stroke-linecap: square; stroke-linejoin: miter;
}
.icon--sm { width: 14px; height: 14px; }
.icon--md { width: 16px; height: 16px; }
.icon--lg { width: 32px; height: 32px; }

/* ---------- Header ---------- */

.top-strip { height: 6px; background: var(--kd-subtitle); box-shadow: inset 0 4px 4px rgba(0, 0, 0, 0.25); }

.app-header { background: var(--kd-white); border-bottom: 1px solid var(--kd-border); }

.app-nav {
  max-width: 1600px; margin: 0 auto; min-height: 72px; padding: 0 24px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 32px;
}

.brand { display: flex; align-items: center; gap: 16px; padding: 12px 0; text-decoration: none; color: var(--kd-navy); }
/* logo.svg has wide margins around the artwork; crop them so the mark reads at header size */
.brand__logo-crop { display: block; height: 28px; overflow: hidden; }
.brand__logo { display: block; height: 84px; width: auto; margin: -28px -27px 0 -7px; }
.brand__divider { width: 1px; height: 28px; background: var(--kd-border-strong); }
.brand__product { font-size: 19px; font-weight: 700; }

.nav-links { display: flex; align-items: stretch; gap: 28px; margin-left: auto; align-self: stretch; }
.nav-link {
  position: relative; display: flex; align-items: center; min-height: 72px;
  font-size: 15px; font-weight: 500; color: var(--kd-body); text-decoration: none;
  transition: color 120ms ease;
}
.nav-link:hover { color: var(--kd-navy); }
.nav-link[aria-current="page"] { color: var(--kd-navy); }
.nav-link[aria-current="page"]::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px;
  border-radius: 3px 3px 0 0; background: var(--kd-brand);
}

@media (max-width: 640px) {
  .nav-links { margin-left: 0; }
  .nav-link { min-height: 52px; }
}

.user { display: flex; align-items: center; gap: 12px; padding: 12px 0; }
.user__name { font-size: 14px; font-weight: 500; }

/* ---------- Avatars, chips, badges ---------- */

.avatar {
  flex: 0 0 auto; width: 36px; height: 36px; border-radius: var(--kd-radius-pill);
  background: var(--kd-navy); color: var(--kd-brand);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 500; text-transform: uppercase;
}
.avatar--muted { background: var(--kd-border); color: var(--kd-navy); }
.avatar--sm { width: 28px; height: 28px; font-size: 11px; }

.badge {
  padding: 2px 10px; border-radius: var(--kd-radius-pill);
  background: var(--kd-bg); border: 1px solid var(--kd-border);
  font-size: 12px; font-weight: 500; color: var(--kd-navy); white-space: nowrap;
}

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px;
  border-radius: var(--kd-radius-chip); background: var(--kd-bg); border: 1px solid var(--kd-border);
  font-size: 13px; color: var(--kd-subtitle); max-width: 100%; overflow-wrap: anywhere;
}

.chip-button {
  min-height: 44px; padding: 0 12px; border-radius: var(--kd-radius-pill);
  background: var(--kd-bg); border: 1px solid var(--kd-border); color: var(--kd-subtitle);
  font-size: 13px; transition: background-color 120ms ease, border-color 120ms ease;
}
.chip-button:hover { background: var(--kd-white); border-color: var(--kd-border-strong); }

/* ---------- Buttons ---------- */

.btn {
  min-height: 44px; padding: 0 14px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: var(--kd-radius-md); border: 1px solid var(--kd-border-strong);
  background: var(--kd-white); color: var(--kd-navy); font-size: 14px; font-weight: 500;
  text-decoration: none; white-space: nowrap;
  transition: background-color 120ms ease, border-color 120ms ease;
}
.btn:hover:not(:disabled) { background: var(--kd-bg); color: var(--kd-navy); }
.btn:active:not(:disabled) { transform: scale(0.98); }

.btn--primary {
  min-height: 50px; padding: 0 22px; border: 0; background: var(--kd-brand);
  color: var(--kd-navy); font-size: 18px; font-weight: 500;
}
.btn--primary:hover:not(:disabled) { background: var(--kd-brand-deep); }
.btn--primary:active:not(:disabled) { background: var(--kd-brand-press); color: var(--kd-white); }
.btn--primary:disabled { opacity: 0.5; }

.btn[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }

.btn--secondary-lg { min-height: 50px; padding: 0 20px; font-size: 16px; }

.btn--block { width: 100%; }

.icon-button {
  flex: 0 0 auto; width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 0; border-radius: var(--kd-radius-md); color: var(--kd-body);
  transition: background-color 120ms ease, color 120ms ease;
}
.icon-button:hover { background: var(--kd-bg); color: var(--kd-navy); }

/* ---------- Cards ---------- */

.card {
  min-width: 0; background: var(--kd-white); border: 1px solid var(--kd-border);
  border-radius: var(--kd-radius-lg); display: flex; flex-direction: column; overflow: hidden;
}
.card__head { padding: 20px 20px 12px; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.card__body { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.card__foot { padding: 16px 20px 20px; border-top: 1px solid var(--kd-border); display: flex; flex-direction: column; gap: 12px; }

.eyebrow { font-family: var(--kd-font-mono); font-size: 12px; font-weight: 700; color: var(--kd-body); text-transform: uppercase; }
.card-title { margin: 4px 0 0; font-size: 20px; font-weight: 500; line-height: 1.15; }

.muted { color: var(--kd-body); }
.small { font-size: 13px; }

/* ---------- Form controls ---------- */

.field-label { display: block; font-size: 14px; font-weight: 500; color: var(--kd-navy); }

.input {
  width: 100%; height: 48px; padding: 0 12px; border: 1px solid var(--kd-border-strong);
  border-radius: var(--kd-radius-md); background: var(--kd-white); color: var(--kd-navy); font-size: 15px;
  transition: border-color 120ms ease;
}
.input:hover { border-color: var(--kd-body); }
.input--sm { height: 44px; font-size: 14px; }

.search-field { position: relative; }
.search-field .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--kd-body); pointer-events: none; }
.search-field .input { padding-left: 40px; }

.input-suffix { position: relative; }
.input-suffix .input { padding-right: 52px; }
.input-suffix__text { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--kd-body); font-size: 14px; pointer-events: none; }

.segmented { display: flex; gap: 4px; padding: 4px; background: var(--kd-border); border-radius: var(--kd-radius-md); }
.segmented button {
  flex: 1 1 0; min-width: 0; min-height: 44px; padding: 0 8px; border: 0; border-radius: var(--kd-radius-sm);
  background: transparent; color: var(--kd-subtitle); font-size: 14px;
  transition: background-color 120ms ease;
}
.segmented button:hover { background: rgba(255, 255, 255, 0.5); }
.segmented button[aria-pressed="true"] {
  background: var(--kd-white); color: var(--kd-navy); font-weight: 500;
  box-shadow: 0 1px 3px rgba(0, 0, 56, 0.18);
}

.switch-row {
  width: 100%; min-height: 44px; padding: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: transparent; border: 0; color: var(--kd-navy); font-size: 14px; font-weight: 500; text-align: left;
}
.switch {
  flex: 0 0 auto; position: relative; width: 44px; height: 24px; border-radius: var(--kd-radius-pill);
  background: var(--kd-white); border: 1.5px solid var(--kd-body); transition: background-color 120ms ease, border-color 120ms ease;
}
.switch::after {
  content: ""; position: absolute; top: 50%; left: 3px; width: 16px; height: 16px; border-radius: var(--kd-radius-pill);
  background: var(--kd-body); transform: translateY(-50%); transition: left 120ms ease, background-color 120ms ease;
}
.switch-row[aria-checked="true"] .switch { background: var(--kd-navy); border-color: var(--kd-navy); }
.switch-row[aria-checked="true"] .switch::after { left: 22px; background: var(--kd-white); }

/* ---------- Autocomplete ---------- */

.autocomplete { position: relative; }
.autocomplete__list {
  position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; right: 0; max-height: 320px; overflow-y: auto;
  margin: 0; padding: 4px; list-style: none; background: var(--kd-white);
  border: 1px solid var(--kd-border-strong); border-radius: var(--kd-radius-md); box-shadow: var(--kd-shadow-pop);
}
.autocomplete__option {
  display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: var(--kd-radius-sm);
  font-size: 14px; cursor: pointer;
}
.autocomplete__option[aria-selected="true"], .autocomplete__option:hover { background: var(--kd-bg); }
.autocomplete__code { font-family: var(--kd-font-mono); font-size: 12px; color: var(--kd-body); white-space: nowrap; }

/* ---------- Toast ---------- */

.toast {
  position: fixed; z-index: 50; left: 50%; bottom: 24px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; max-width: calc(100% - 32px); padding: 14px 18px;
  background: var(--kd-navy); color: var(--kd-white); border-radius: var(--kd-radius-lg); box-shadow: var(--kd-shadow-pop);
  font-size: 14px;
}
.toast__icon {
  flex: 0 0 auto; width: 24px; height: 24px; border-radius: var(--kd-radius-pill);
  background: var(--kd-brand); color: var(--kd-navy); display: flex; align-items: center; justify-content: center;
}
.toast--error .toast__icon { background: var(--kd-error); color: var(--kd-white); }

/* ---------- Halo (design-system motif) ---------- */

.halo {
  width: 120px; height: 120px; border-radius: var(--kd-radius-pill); background: var(--kd-brand-wash-20);
  display: flex; align-items: center; justify-content: center; flex: 0 0 auto;
}
.halo__inner {
  width: 80px; height: 80px; border-radius: var(--kd-radius-pill); background: var(--kd-brand-wash-40);
  display: flex; align-items: center; justify-content: center; color: var(--kd-navy);
}

/* ---------- Loading ---------- */

.spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 4px solid var(--kd-border); border-top-color: var(--kd-brand-deep);
  animation: kd-spin 0.9s linear infinite;
}
@keyframes kd-spin { to { transform: rotate(360deg); } }

.page-loading { min-height: 100vh; display: flex; align-items: center; justify-content: center; }

/* ---------- Classify page ---------- */

.classify {
  max-width: 1600px; margin: 0 auto; padding: 24px;
  display: flex; flex-wrap: wrap; align-items: stretch; gap: 24px;
}
.classify__docs { flex: 1 1 280px; }
.classify__preview { flex: 999 1 480px; }
.classify__settings { flex: 1 1 380px; }

@media (min-width: 1200px) {
  .classify > .card { height: calc(100vh - var(--header-height) - 48px); min-height: 640px; }
}
@media (max-width: 1199px) {
  .classify__docs .card__body { max-height: 360px; }
  .preview-stage { min-height: 70vh; }
}

.doc-search { padding: 0 20px 12px; }
.doc-list { list-style: none; margin: 0; padding: 4px 12px 12px; display: flex; flex-direction: column; gap: 4px; }
.doc-item {
  position: relative; width: 100%; min-height: 56px; padding: 8px 12px 8px 18px;
  display: flex; align-items: center; gap: 12px; text-align: left;
  background: var(--kd-white); border: 1px solid transparent; border-radius: var(--kd-radius-md);
  transition: background-color 120ms ease;
}
.doc-item:hover { background: var(--kd-bg); }
.doc-item[aria-current="true"] { background: var(--kd-bg); border-color: var(--kd-border-strong); }
.doc-item[aria-current="true"]::before {
  content: ""; position: absolute; left: 5px; top: 12px; bottom: 12px; width: 4px;
  border-radius: var(--kd-radius-pill); background: var(--kd-brand);
}
.doc-item__type {
  flex: 0 0 auto; width: 36px; height: 40px; border-radius: var(--kd-radius-sm); background: var(--kd-border);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--kd-font-mono); font-size: 10px; font-weight: 700; color: var(--kd-navy);
}
.doc-item__name { flex: 1 1 auto; min-width: 0; font-size: 14px; font-weight: 500; color: var(--kd-navy); overflow-wrap: anywhere; }

.empty-hint { margin: 16px 8px; padding: 20px; border: 1px dashed var(--kd-border-strong); border-radius: var(--kd-radius-lg); font-size: 14px; color: var(--kd-body); }

.preview-head { padding: 20px 20px 12px; display: flex; flex-direction: column; gap: 8px; }
.preview-head__row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; }
.preview-head__name { flex: 1 1 240px; min-width: 0; }
.preview-toolbar { padding: 0 20px 12px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.preview-toolbar .segmented { flex: 0 1 360px; }

.preview-stage {
  position: relative; flex: 1 1 auto; margin: 0 20px 20px; border-radius: var(--kd-radius-md);
  background: var(--kd-border); overflow: auto; display: flex;
}
.preview-stage iframe { flex: 1 1 auto; width: 100%; min-height: 100%; border: 0; background: var(--kd-border); }
.preview-stage__image { margin: auto; padding: 24px; }
.preview-stage__image img { display: block; max-width: 100%; height: auto; background: var(--kd-white); box-shadow: var(--kd-shadow-paper); }
.preview-stage__loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(230, 232, 239, 0.7); }

.empty-state { margin: auto; max-width: 360px; padding: 24px; display: flex; flex-direction: column; align-items: center; gap: 16px; text-align: center; }
.empty-state h3 { margin: 0; font-size: 22px; font-weight: 500; }
.empty-state p { margin: 0; color: var(--kd-body); }

.settings-section { padding: 16px 20px; border-top: 1px solid var(--kd-border); display: flex; flex-direction: column; gap: 8px; }
.settings-section__head { display: flex; align-items: center; gap: 8px; }
.settings-group { display: flex; flex-direction: column; gap: 8px; }
.settings-section > .settings-group + .settings-group { margin-top: 8px; }

.recent { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

.signer-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.signer { display: flex; align-items: center; gap: 12px; padding: 4px 0; }
.signer__text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.signer__name { font-size: 14px; font-weight: 500; }
.signer__email { font-size: 12px; color: var(--kd-body); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.warning {
  display: flex; align-items: flex-start; gap: 8px; padding: 10px 12px; border-radius: var(--kd-radius-md);
  border: 1px solid var(--kd-error); background: var(--kd-white); font-size: 13px; color: var(--kd-navy);
}
.warning .icon { color: var(--kd-error); margin-top: 1px; }

.recipients { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- Signer dialog ---------- */

.dialog {
  width: 640px; max-width: calc(100% - 32px); max-height: calc(100% - 64px); padding: 0;
  border: 0; border-radius: var(--kd-radius-lg); box-shadow: var(--kd-shadow-pop); color: var(--kd-navy);
}
.dialog[open] { display: flex; flex-direction: column; }
.dialog::backdrop { background: rgba(0, 0, 56, 0.48); }
.dialog__head { padding: 24px 24px 16px; display: flex; align-items: flex-start; gap: 16px; }
.dialog__title { margin: 4px 0 8px; font-size: 24px; font-weight: 500; line-height: 1.1; }
.dialog__desc { margin: 0; color: var(--kd-body); }
.dialog__tools { padding: 0 24px 16px; display: flex; flex-direction: column; gap: 12px; }
.dialog__chips { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-height: 40px; }
.dialog__list {
  flex: 1 1 auto; min-height: 120px; overflow-y: auto; margin: 0; padding: 8px 12px; list-style: none;
  border-top: 1px solid var(--kd-border); border-bottom: 1px solid var(--kd-border);
}
.dialog__foot { padding: 16px 24px 20px; display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.dialog__count { flex: 1 1 auto; font-size: 13px; color: var(--kd-body); }

.person-chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 2px 2px 2px 4px; border-radius: var(--kd-radius-pill);
  background: var(--kd-bg); border: 1px solid var(--kd-border); font-size: 13px;
}
.person-chip .icon-button { width: 36px; height: 36px; border-radius: var(--kd-radius-pill); }

.person-row {
  display: flex; align-items: center; gap: 14px; min-height: 56px; padding: 6px 12px;
  border-radius: var(--kd-radius-md); cursor: pointer;
}
.person-row:hover { background: var(--kd-bg); }
.person-row input { flex: 0 0 auto; width: 20px; height: 20px; margin: 0; accent-color: var(--kd-navy); cursor: pointer; }
.person-row:has(input:checked) { background: var(--kd-bg); }

/* ---------- Upload page ---------- */

.upload { max-width: 960px; margin: 0 auto; padding: 48px 24px 64px; display: flex; flex-direction: column; gap: 32px; }
.page-intro { display: flex; flex-direction: column; gap: 12px; }
.page-title { margin: 0; font-size: 36px; font-weight: 500; line-height: 1.05; }
.page-underline { width: 251px; max-width: 100%; height: 3px; background: var(--kd-brand); }
.page-lead { margin: 4px 0 0; max-width: 640px; font-size: 16px; color: var(--kd-body); }

.dropzone {
  background: var(--kd-white); border: 2px dashed var(--kd-border-strong); border-radius: var(--kd-radius-lg);
  padding: 48px 24px; display: flex; flex-direction: column; align-items: center; gap: 16px; text-align: center;
  transition: border-color 120ms ease, background-color 120ms ease;
}
.dropzone.is-dragover { border-color: var(--kd-brand-deep); background: var(--kd-bg); }
.dropzone h2 { margin: 0; font-size: 22px; font-weight: 500; }
.dropzone__picker { cursor: pointer; }
.dropzone__picker:focus-within { outline: 2px solid var(--kd-brand-press); outline-offset: 2px; }

.notice {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; padding: 16px 20px;
  background: var(--kd-white); border: 1px solid var(--kd-border); border-radius: var(--kd-radius-lg);
}
.notice__icon {
  flex: 0 0 auto; width: 28px; height: 28px; border-radius: var(--kd-radius-pill);
  background: var(--kd-brand); color: var(--kd-navy); display: flex; align-items: center; justify-content: center;
}
.notice__text { flex: 1 1 280px; }

.arrow-link {
  display: inline-flex; align-items: center; gap: 16px; min-height: 44px;
  font-size: 15px; font-weight: 500; color: var(--kd-navy); text-decoration: none;
}
.arrow-link::before { content: ""; width: 29px; height: 2px; background: currentColor; transition: background-color 120ms ease; }
.arrow-link:hover::before { background: var(--kd-brand-deep); }

.section-title { margin: 0; font-size: 20px; font-weight: 500; }

.file-list { list-style: none; margin: 0; padding: 0; background: var(--kd-white); border: 1px solid var(--kd-border); border-radius: var(--kd-radius-lg); }
.file-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; padding: 16px 20px; }
.file-row + .file-row { border-top: 1px solid var(--kd-border); }
.file-row__main { flex: 1 1 240px; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.file-row__top { display: flex; justify-content: space-between; gap: 12px; }
.file-row__name { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row__meta { font-size: 12px; color: var(--kd-body); white-space: nowrap; }

.progress { display: block; height: 6px; border-radius: var(--kd-radius-pill); background: var(--kd-border); overflow: hidden; }
.progress__bar { display: block; width: 0; height: 100%; border-radius: var(--kd-radius-pill); background: var(--kd-brand-deep); transition: width 120ms ease; }

.status {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: var(--kd-radius-chip);
  background: var(--kd-bg); border: 1px solid var(--kd-border); font-size: 12px; font-weight: 500; color: var(--kd-subtitle);
}
.status--error { background: var(--kd-white); border-color: var(--kd-error); color: var(--kd-navy); }
.status--error .icon { color: var(--kd-error); }
