:root {
  color-scheme: light;
  --bg: #eef1f4;
  --surface: #ffffff;
  --surface-soft: #f7f8fa;
  --ink: #17202a;
  --muted: #6b7580;
  --line: #d9dee5;
  --accent: #1c6d5a;
  --accent-strong: #115242;
  --danger: #b94136;
  --shadow: 0 22px 70px rgba(30, 42, 55, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input {
  font: inherit;
}

input[type="text"],
input[type="email"] {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 11px;
  outline: none;
}

input[type="text"]:focus,
input[type="email"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(28, 109, 90, 0.13);
}

button,
.file-button {
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  min-height: 42px;
  padding: 0 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 650;
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    color 140ms ease,
    transform 140ms ease;
}

button:disabled,
.file-button:has(input:disabled) {
  cursor: not-allowed;
  opacity: 0.48;
}

button:not(:disabled):active,
.file-button:active {
  transform: translateY(1px);
}

.primary,
.file-button {
  background: var(--accent);
  color: #fff;
}

.primary:hover,
.file-button:hover {
  background: var(--accent-strong);
}

.secondary {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
}

.secondary:hover {
  border-color: #aeb7c2;
}

.danger {
  background: #fff4f2;
  border-color: #f0b9b1;
  color: var(--danger);
  margin-left: auto;
}

.danger:hover {
  border-color: var(--danger);
}

.file-button input {
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  position: absolute;
  pointer-events: none;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 28px;
  background: rgba(255, 255, 255, 0.86);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar h1,
.dialog-header h2,
.empty-state h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(1.35rem, 2vw, 1.9rem);
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(240px, 280px) minmax(0, 1fr);
}

.sidebar {
  min-height: 0;
  border-right: 1px solid var(--line);
  background: #f9fafb;
  padding: 18px;
  overflow: auto;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.panel-title strong {
  color: var(--ink);
}

.identity-panel {
  display: grid;
  gap: 12px;
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.documents-panel {
  display: grid;
  gap: 10px;
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.identity-panel .panel-title {
  margin-bottom: 0;
}

.documents-panel .panel-title {
  margin-bottom: 0;
}

.small-button {
  min-height: 30px;
  padding: 0 9px;
  border-color: var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.75rem;
}

.document-list {
  display: grid;
  gap: 8px;
  max-height: 190px;
  overflow: auto;
}

.document-item {
  width: 100%;
  min-height: 0;
  display: grid;
  gap: 4px;
  justify-items: start;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
}

.document-item:hover {
  border-color: var(--accent);
}

.document-item strong {
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: 0.82rem;
}

.document-item span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

#identityState {
  color: var(--danger);
  font-size: 0.76rem;
}

#identityState.is-verified {
  color: var(--accent-strong);
}

.field {
  display: grid;
  gap: 5px;
}

.field span,
.consent-row span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.35;
}

.field.compact {
  min-width: 0;
}

.otp-row {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1fr);
  gap: 8px;
  align-items: end;
}

.full-width {
  width: 100%;
}

.consent-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}

.consent-row input {
  margin-top: 2px;
  accent-color: var(--accent);
}

.identity-message {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

.identity-message.is-error {
  color: var(--danger);
}

.identity-message.is-ok {
  color: var(--accent-strong);
}

.thumbnail-list {
  display: grid;
  gap: 12px;
}

.thumbnail {
  border: 2px solid transparent;
  border-radius: 8px;
  background: var(--surface);
  padding: 8px;
  box-shadow: 0 8px 24px rgba(24, 35, 47, 0.08);
  text-align: left;
  width: 100%;
  min-height: 0;
}

.thumbnail.is-active {
  border-color: var(--accent);
}

.thumbnail canvas {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: white;
}

.thumbnail span {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.document-area {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: auto;
}

.empty-state {
  width: min(560px, 100%);
  text-align: center;
  padding: 48px 34px;
}

.empty-icon {
  width: 86px;
  height: 112px;
  margin: 0 auto 24px;
  display: grid;
  place-items: center;
  border-radius: 8px 8px 18px 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  color: var(--accent);
  font-weight: 900;
}

.empty-state h2 {
  font-size: clamp(1.5rem, 4vw, 2.6rem);
}

.empty-state p {
  margin: 12px auto 0;
  max-width: 430px;
  color: var(--muted);
  line-height: 1.5;
}

.viewer {
  width: 100%;
  min-height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
  align-items: start;
  justify-items: center;
  gap: 18px;
}

.is-hidden {
  display: none !important;
}

.viewer-toolbar {
  width: min(980px, 100%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 40px rgba(30, 42, 55, 0.1);
  position: sticky;
  top: 10px;
  z-index: 10;
}

.icon-button {
  width: 42px;
  padding: 0;
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 1.4rem;
  line-height: 1;
}

.icon-button:hover {
  border-color: #aeb7c2;
}

.page-indicator,
.zoom-label {
  min-width: 96px;
  display: inline-flex;
  justify-content: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.page-indicator strong {
  color: var(--ink);
}

.toolbar-divider {
  width: 1px;
  height: 30px;
  background: var(--line);
  margin: 0 4px;
}

.page-stage {
  position: relative;
  border-radius: 8px;
  background: white;
  box-shadow: var(--shadow);
  overflow: hidden;
  touch-action: none;
}

#pdfCanvas {
  display: block;
  max-width: none;
}

.signature-layer {
  position: absolute;
  inset: 0;
}

.signature-box {
  position: absolute;
  width: 210px;
  height: 82px;
  border: 2px solid rgba(28, 109, 90, 0.7);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.55);
  cursor: move;
  touch-action: none;
  user-select: none;
}

.signature-box.is-selected {
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 4px rgba(28, 109, 90, 0.16);
}

.signature-box img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.resize-handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 2px solid white;
  background: var(--accent);
  cursor: nwse-resize;
}

.placement-hint {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  min-height: 0;
  padding: 11px 14px;
  background: #17202a;
  color: white;
  border-radius: 8px;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.2);
  pointer-events: none;
}

.page-stage.is-placing {
  cursor: crosshair;
}

.signature-dialog {
  width: min(760px, calc(100vw - 28px));
  border: 0;
  border-radius: 12px;
  padding: 0;
  box-shadow: 0 26px 90px rgba(0, 0, 0, 0.28);
}

.signature-dialog::backdrop {
  background: rgba(17, 24, 31, 0.54);
  backdrop-filter: blur(4px);
}

.signature-dialog form {
  padding: 20px;
}

.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.signature-pad {
  width: 100%;
  height: 270px;
  margin: 18px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(to bottom, transparent 72%, rgba(28, 109, 90, 0.18) 72.4%, transparent 73%),
    #fff;
  touch-action: none;
}

.dialog-actions {
  justify-content: flex-end;
}

@media (max-width: 860px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    justify-content: stretch;
  }

  .topbar-actions > * {
    flex: 1 1 150px;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: none;
    overflow: visible;
  }

  .identity-panel,
  .documents-panel {
    gap: 10px;
  }

  .document-list {
    max-height: 160px;
  }

  .thumbnail-list {
    display: flex;
    overflow-x: auto;
    padding-bottom: 6px;
  }

  .thumbnail {
    min-width: 112px;
  }

  .document-area {
    padding: 14px;
  }

  .viewer-toolbar {
    flex-wrap: wrap;
  }

  .danger {
    width: 100%;
    margin-left: 0;
  }
}

@media (min-width: 620px) and (max-width: 860px) {
  .sidebar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    align-items: start;
  }

  .identity-panel,
  .documents-panel {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: 0;
  }

  .sidebar > .panel-title,
  .thumbnail-list {
    grid-column: 1 / -1;
  }
}

@media (max-width: 520px) {
  .topbar {
    padding: 16px;
  }

  .topbar-actions {
    gap: 8px;
  }

  .topbar-actions > *,
  .viewer-toolbar > button,
  .viewer-toolbar > .page-indicator,
  .viewer-toolbar > .zoom-label {
    flex: 1 1 130px;
  }

  .otp-row {
    grid-template-columns: 1fr;
  }

  .signature-dialog form {
    padding: 14px;
  }

  .signature-pad {
    height: 220px;
  }
}
