:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --line: #d8dee9;
  --accent: #3563ff;
  --accent-dark: #234bd6;
  --shadow: 0 18px 45px rgba(28, 39, 76, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top left, #e9edff 0, transparent 32rem), var(--bg);
  color: var(--ink);
}

button, input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  padding: 0.72rem 1rem;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

button:hover:not(:disabled) {
  border-color: #b9c3d8;
  box-shadow: 0 8px 22px rgba(29, 41, 57, 0.08);
  transform: translateY(-1px);
}

button:disabled { cursor: not-allowed; opacity: 0.55; }
button.primary { background: var(--accent); border-color: var(--accent); color: white; }
button.primary:hover:not(:disabled) { background: var(--accent-dark); }
button.active { background: #eef2ff; border-color: var(--accent); color: var(--accent-dark); }

.toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(216, 222, 233, 0.85);
}

.brand { display: flex; align-items: center; gap: 0.75rem; min-width: max-content; }
.brand-mark { display: grid; place-items: center; width: 2.4rem; height: 2.4rem; border-radius: 0.85rem; background: #111827; color: #fff; }
.brand small { display: block; color: var(--muted); font-size: 0.78rem; }
.toolbar-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: flex-end; }
.zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.22rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.75);
}
.zoom-controls button {
  display: grid;
  place-items: center;
  min-width: 2.35rem;
  padding: 0.5rem 0.75rem;
  font-size: 1.05rem;
  line-height: 1;
}
.zoom-controls output {
  min-width: 3.2rem;
  text-align: center;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.9rem;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(18rem, 24rem) 1fr;
  gap: 1rem;
  padding: 1rem;
}

.side-panel {
  position: sticky;
  top: 5rem;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-height: calc(100vh - 6rem);
  overflow-y: auto;
  padding-right: 0.25rem;
}
.card, .empty-state {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(216, 222, 233, 0.9);
  border-radius: 1.25rem;
  padding: 1rem;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 0.4rem; font-size: 1.05rem; }
.card p, .tips li { color: var(--muted); line-height: 1.45; }

#signature-pad {
  width: 100%;
  height: auto;
  border: 1px dashed #b8c1d6;
  border-radius: 1rem;
  background: #fff;
  touch-action: none;
  cursor: crosshair;
}

.row-actions { display: flex; gap: 0.5rem; margin-top: 0.75rem; flex-wrap: wrap; }
.project-card { border-color: rgba(53, 99, 255, 0.22); }
.project-name-field { display: grid; gap: 0.35rem; margin: 0.75rem 0; color: var(--muted); font-size: 0.9rem; }
.project-name-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.85rem;
  padding: 0.72rem 0.8rem;
  background: #fff;
  color: var(--ink);
}
.project-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.85rem; }
.project-list { display: grid; gap: 0.55rem; max-height: 16rem; overflow-y: auto; }
.project-empty { margin: 0; color: var(--muted); }
.project-item {
  display: grid;
  gap: 0.18rem;
  width: 100%;
  border-radius: 0.9rem;
  padding: 0.68rem 0.78rem;
  text-align: left;
  word-break: break-word;
}
.project-item.active { border-color: var(--accent); background: #eef2ff; color: var(--accent-dark); }
.project-item small { color: var(--muted); font-size: 0.74rem; }
.signature-gallery { display: grid; gap: 0.65rem; }
.signature-choice {
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  padding: 0.45rem;
  background: #fff;
  cursor: pointer;
}
.signature-choice.selected { outline: 3px solid rgba(53, 99, 255, 0.25); border-color: var(--accent); }
.signature-choice img { display: block; width: 100%; max-height: 72px; object-fit: contain; }

.document-panel {
  min-height: calc(100vh - 6rem);
  border: 1px solid rgba(216, 222, 233, 0.9);
  border-radius: 1.4rem;
  overflow: auto;
  background: rgba(226, 232, 240, 0.7);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.55);
}
.empty-state { margin: 2rem auto; max-width: 34rem; text-align: center; }
.empty-state h1 { margin-top: 0; }

.page-shell {
  display: grid;
  justify-content: center;
  gap: 1.5rem;
  padding: 1.5rem;
}
.pdf-page {
  position: relative;
  background: white;
  box-shadow: 0 16px 40px rgba(24, 35, 66, 0.20);
  line-height: 0;
}
.pdf-page canvas { display: block; max-width: 100%; height: auto; }
.annotation {
  position: absolute;
  z-index: 3;
  border: 1px solid transparent;
  line-height: 1.2;
  transform-origin: top left;
  touch-action: none;
}
.annotation:hover, .annotation.selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(53, 99, 255, 0.16); }
.annotation.signature { min-width: 90px; min-height: 36px; cursor: grab; }
.annotation.signature img { display: block; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.annotation.text {
  min-width: 40px;
  min-height: 24px;
  padding: 3px 5px;
  background: rgba(255,255,255,0.2);
  color: #0f172a;
  font-size: 18px;
  line-height: 1.25;
  cursor: text;
  white-space: pre-wrap;
}
.resize-handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  cursor: nwse-resize;
}

.modal {
  border: 0;
  border-radius: 1.35rem;
  width: min(92vw, 32rem);
  padding: 0;
  box-shadow: var(--shadow);
}
.modal::backdrop { background: rgba(15, 23, 42, 0.45); backdrop-filter: blur(3px); }
.modal form { display: grid; gap: 1rem; padding: 1.2rem; }
.modal h1 { margin: 0; }
.modal p { margin: 0; color: var(--muted); }
.modal label { display: grid; gap: 0.4rem; color: var(--muted); font-size: 0.92rem; }
.modal input { width: 100%; border: 1px solid var(--line); border-radius: 0.85rem; padding: 0.82rem; background: #fff; color: var(--ink); }
.modal menu { display: flex; justify-content: flex-end; gap: 0.65rem; padding: 0; margin: 0; }
.separator { display: flex; align-items: center; gap: 0.75rem; color: var(--muted); }
.separator::before, .separator::after { content: ""; height: 1px; background: var(--line); flex: 1; }

.status {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  max-width: min(24rem, calc(100vw - 2rem));
  background: #111827;
  color: white;
  border-radius: 0.9rem;
  padding: 0.75rem 1rem;
  opacity: 0;
  transform: translateY(0.5rem);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.status.show { opacity: 1; transform: translateY(0); }

@media (max-width: 720px) {
  .toolbar { align-items: flex-start; flex-direction: column; }
  .toolbar-actions { justify-content: flex-start; }
  .workspace { grid-template-columns: 1fr; padding: 0.75rem; }
  .side-panel {
    position: static;
    max-height: none;
    overflow-y: visible;
    padding-right: 0;
  }
  .document-panel { min-height: 55vh; }
  .page-shell { padding: 0.75rem; }
  button { padding: 0.68rem 0.86rem; }
}
