:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-soft: #eef2ed;
  --text: #17201b;
  --muted: #667067;
  --line: #d9ded8;
  --primary: #136f63;
  --primary-dark: #0d4f47;
  --danger: #b42318;
  --focus: #e0a100;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

a {
  color: inherit;
}

.topbar {
  align-items: center;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 24px;
  min-height: 64px;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  color: var(--primary-dark);
  font-size: 18px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.nav {
  display: flex;
  gap: 8px;
  margin-right: auto;
}

.nav a,
.button,
button {
  align-items: center;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-weight: 650;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  text-decoration: none;
}

.nav a {
  color: var(--muted);
}

.nav a:hover {
  background: var(--surface-soft);
  color: var(--text);
}

.logout {
  margin: 0;
}

button,
.secondary {
  background: #ffffff;
  border-color: var(--line);
  color: var(--text);
}

.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.primary:hover {
  background: var(--primary-dark);
}

.danger {
  background: #fff5f5;
  border-color: #f2b8b5;
  color: var(--danger);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.shell {
  margin: 0 auto;
  max-width: 1220px;
  padding: 32px 28px 56px;
}

.page-head {
  align-items: flex-start;
  display: flex;
  gap: 24px;
  justify-content: space-between;
  margin-bottom: 24px;
}

h1,
h2 {
  letter-spacing: 0;
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.15;
}

h2 {
  font-size: 18px;
  margin-bottom: 14px;
}

.muted,
small {
  color: var(--muted);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.auth-layout {
  display: grid;
  min-height: calc(100vh - 128px);
  place-items: center;
}

.auth-panel,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
}

.auth-panel {
  max-width: 440px;
  width: 100%;
}

.stack {
  display: grid;
  gap: 14px;
}

label {
  color: var(--text);
  display: grid;
  font-size: 14px;
  font-weight: 650;
  gap: 7px;
}

input,
select {
  background: #ffffff;
  border: 1px solid #cbd3ca;
  border-radius: 7px;
  color: var(--text);
  font: inherit;
  min-height: 42px;
  padding: 9px 11px;
  width: 100%;
}

input:focus,
select:focus,
button:focus,
a:focus {
  outline: 3px solid color-mix(in srgb, var(--focus) 35%, transparent);
  outline-offset: 1px;
}

.full {
  width: 100%;
}

.divider {
  align-items: center;
  color: var(--muted);
  display: flex;
  gap: 14px;
  margin: 20px 0;
}

.divider::before,
.divider::after {
  background: var(--line);
  content: "";
  height: 1px;
  flex: 1;
}

.switch {
  margin: 20px 0 0;
}

.alert {
  background: #fff8e1;
  border: 1px solid #ead28a;
  border-radius: 8px;
  margin-bottom: 18px;
  padding: 12px 14px;
}

.metrics {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 28px;
}

.metrics div {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.metrics strong {
  display: block;
  font-size: 28px;
}

.metrics span {
  color: var(--muted);
  font-size: 14px;
}

.drop-home {
  display: grid;
  min-height: calc(100vh - 160px);
  place-items: center;
}

.pdf-dropzone {
  max-width: 760px;
  width: min(100%, 760px);
}

.pdf-dropzone input[type="file"] {
  height: 1px;
  opacity: 0;
  overflow: hidden;
  position: absolute;
  width: 1px;
}

.pdf-dropzone label {
  align-items: center;
  background: #ffffff;
  border: 2px dashed #aab6ac;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  justify-content: center;
  min-height: 300px;
  padding: 32px;
  text-align: center;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.pdf-dropzone label:hover,
.pdf-dropzone label.is-dragging {
  background: #eef7f4;
  border-color: var(--primary);
  transform: translateY(-1px);
}

.pdf-dropzone span {
  color: var(--primary-dark);
  font-size: 28px;
  font-weight: 800;
  line-height: 1.2;
}

.grid {
  display: grid;
  gap: 24px;
}

.grid.two {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.settings-columns {
  align-items: start;
  display: grid;
  gap: 24px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.settings-column {
  display: grid;
  gap: 22px;
}

.list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.row {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  min-height: 62px;
  padding: 12px 16px;
  text-decoration: none;
}

.row:last-child {
  border-bottom: 0;
}

.row:hover {
  background: #f9faf8;
}

.row small,
.row strong {
  display: block;
  overflow-wrap: anywhere;
}

.empty {
  color: var(--muted);
  margin: 0;
  padding: 18px;
}

.upload-band {
  align-items: end;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 1fr) auto;
  margin-bottom: 28px;
  padding: 18px;
}

.sign-layout {
  align-items: start;
  display: grid;
  gap: 24px;
  grid-template-columns: 360px minmax(0, 1fr);
  margin-bottom: 32px;
}

.toggle {
  align-items: center;
  display: flex;
  gap: 10px;
}

.toggle input {
  min-height: auto;
  width: auto;
}

.hidden {
  display: none !important;
}

.viewer {
  min-width: 0;
}

.viewer-toolbar {
  align-items: center;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  display: flex;
  gap: 10px;
  min-height: 52px;
  padding: 8px 12px;
}

.viewer-toolbar button {
  font-size: 24px;
  min-width: 42px;
  padding: 0;
}

.page-stage {
  background: #dfe4de;
  border: 1px solid var(--line);
  border-top: 0;
  min-height: 420px;
  overflow: auto;
  padding: 24px;
  position: relative;
  user-select: none;
}

.page-stage img {
  background: #ffffff;
  box-shadow: 0 10px 24px rgb(0 0 0 / 10%);
  display: block;
  height: auto;
  max-width: 100%;
  position: relative;
}

.signature-box {
  align-items: center;
  background: rgb(19 111 99 / 14%);
  border: 2px solid var(--primary);
  color: var(--primary-dark);
  cursor: move;
  display: flex;
  font-size: 14px;
  font-weight: 800;
  justify-content: center;
  min-height: 36px;
  min-width: 100px;
  position: absolute;
  touch-action: none;
  z-index: 5;
}

.signature-box i {
  background: var(--primary);
  border: 2px solid #ffffff;
  box-shadow: 0 1px 4px rgb(0 0 0 / 20%);
  position: absolute;
  touch-action: none;
}

.signature-box i[data-resize="n"],
.signature-box i[data-resize="s"] {
  cursor: ns-resize;
  height: 8px;
  left: 28px;
  right: 28px;
}

.signature-box i[data-resize="n"] {
  top: -5px;
}

.signature-box i[data-resize="s"] {
  bottom: -5px;
}

.signature-box i[data-resize="e"],
.signature-box i[data-resize="w"] {
  bottom: 22px;
  cursor: ew-resize;
  top: 22px;
  width: 8px;
}

.signature-box i[data-resize="e"] {
  right: -5px;
}

.signature-box i[data-resize="w"] {
  left: -5px;
}

.signature-box i[data-resize="nw"],
.signature-box i[data-resize="ne"],
.signature-box i[data-resize="se"],
.signature-box i[data-resize="sw"] {
  border-radius: 999px;
  height: 16px;
  width: 16px;
}

.signature-box i[data-resize="nw"] {
  cursor: nwse-resize;
  left: -8px;
  top: -8px;
}

.signature-box i[data-resize="ne"] {
  cursor: nesw-resize;
  right: -8px;
  top: -8px;
}

.signature-box i[data-resize="se"] {
  bottom: -8px;
  cursor: nwse-resize;
  right: -8px;
}

.signature-box i[data-resize="sw"] {
  bottom: -8px;
  cursor: nesw-resize;
  left: -8px;
}

.error-text {
  color: var(--danger);
}

.audit-row {
  align-items: flex-start;
}

@media (max-width: 820px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    padding: 14px 18px;
    position: static;
  }

  .nav {
    flex-wrap: wrap;
  }

  .shell {
    padding: 24px 16px 40px;
  }

  .page-head,
  .row {
    align-items: stretch;
    flex-direction: column;
  }

  .metrics,
  .grid.two,
  .settings-columns,
  .sign-layout,
  .upload-band {
    grid-template-columns: 1fr;
  }

  .drop-home {
    min-height: calc(100vh - 220px);
  }

  .pdf-dropzone label {
    min-height: 220px;
  }

  .pdf-dropzone span {
    font-size: 22px;
  }

  .sign-layout {
    gap: 16px;
  }

  .viewer-toolbar {
    align-items: flex-start;
    flex-wrap: wrap;
  }
}
