:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --ink: #172026;
  --muted: #63717b;
  --line: #d8e0e5;
  --line-strong: #aab7c2;
  --brand: #126b68;
  --brand-dark: #0d4f4c;
  --accent: #9b5f14;
  --danger: #a83b3b;
  --ok: #23744d;
  --field: rgba(18, 107, 104, 0.12);
  --field-border: #126b68;
  --shadow: 0 10px 30px rgba(23, 32, 38, 0.08);
  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: var(--bg);
  color: var(--ink);
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 650;
  padding: 8px 12px;
}

a,
.button-link {
  color: var(--brand-dark);
  font-weight: 700;
  text-decoration: none;
}

a:hover,
.button-link:hover {
  text-decoration: underline;
}

button:hover {
  border-color: var(--brand);
}

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

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

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

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

.ghost {
  background: transparent;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  min-height: 38px;
  padding: 8px 10px;
}

textarea {
  min-height: 112px;
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.app-shell,
.sign-shell {
  min-height: 100vh;
}

.center-screen {
  width: min(440px, calc(100vw - 32px));
  margin: 0 auto;
  min-height: 100vh;
  display: grid;
  align-content: center;
  gap: 16px;
}

.auth-panel,
.empty-panel,
.side-panel,
.main-panel,
.export-panel,
.sign-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.auth-panel {
  padding: 24px;
  display: grid;
  gap: 16px;
}

.auth-panel h1,
.sign-card h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

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

.error {
  color: var(--danger);
  font-weight: 650;
}

.success {
  color: var(--ok);
  font-weight: 650;
}

.topbar {
  height: 64px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--brand), #2f8e63);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
}

.brand-title {
  font-size: 16px;
  font-weight: 800;
}

.layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  min-height: calc(100vh - 64px);
}

.side-panel {
  align-self: start;
  max-height: calc(100vh - 96px);
  overflow: auto;
}

.panel-head {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-head h2,
.section h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
}

.upload-form,
.field-form,
.invite-form,
.export-panel {
  padding: 14px;
  display: grid;
  gap: 12px;
}

.compact-form {
  padding: 0;
  justify-items: start;
}

.compact-link {
  margin-top: 4px;
}

.doc-list {
  display: grid;
}

.doc-row {
  width: 100%;
  display: grid;
  gap: 5px;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 12px 14px;
  background: #fff;
}

.doc-row.active {
  background: #edf6f4;
  border-left: 4px solid var(--brand);
  padding-left: 10px;
}

.doc-row strong {
  overflow-wrap: anywhere;
}

.doc-meta,
.tiny-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f9fbfc;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.main-panel {
  min-width: 0;
  overflow: hidden;
}

.doc-titlebar {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.doc-titlebar h1 {
  margin: 0 0 4px;
  font-size: 20px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

.tab {
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  min-width: 112px;
}

.tab.active {
  color: var(--brand);
  background: #fff;
  box-shadow: inset 0 -2px 0 var(--brand);
}

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

.pdf-stage {
  min-width: 0;
  overflow: auto;
  padding: 18px;
  background: #e8edf0;
}

.pdf-page {
  position: relative;
  width: max-content;
  margin: 0 auto 18px;
  background: #fff;
  box-shadow: 0 5px 18px rgba(23, 32, 38, 0.16);
}

.pdf-page canvas {
  display: block;
}

.field-box {
  position: absolute;
  display: grid;
  align-items: center;
  border: 2px solid var(--field-border);
  background: var(--field);
  color: var(--brand-dark);
  padding: 4px 7px;
  min-width: 28px;
  min-height: 20px;
  overflow: hidden;
  cursor: move;
  user-select: none;
}

.field-box.signature {
  border-color: var(--accent);
  background: rgba(155, 95, 20, 0.12);
  color: #6d410c;
}

.field-box.selected {
  outline: 3px solid rgba(18, 107, 104, 0.22);
}

.field-box span {
  font-size: 12px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.resize-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  right: -7px;
  bottom: -7px;
  border: 2px solid #fff;
  background: var(--brand);
  cursor: nwse-resize;
}

.tools-panel {
  border-left: 1px solid var(--line);
  background: #fff;
  overflow: auto;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.tool-button {
  min-height: 54px;
  display: grid;
  place-items: center;
  gap: 3px;
  padding: 7px 6px;
}

.tool-button.active {
  border-color: var(--brand);
  background: #edf6f4;
  color: var(--brand);
}

.tool-icon {
  font-size: 18px;
  line-height: 1;
  font-weight: 900;
}

.section {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 12px;
}

.field-list {
  display: grid;
  gap: 8px;
}

.field-list button {
  text-align: left;
  display: grid;
  gap: 4px;
}

.empty-panel {
  min-height: calc(100vh - 96px);
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
}

.links-table,
.submissions-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

.links-table th,
.links-table td,
.submissions-table th,
.submissions-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}

.links-table th,
.submissions-table th {
  color: var(--muted);
  font-size: 12px;
}

.generated-links {
  display: grid;
  gap: 8px;
}

.link-box {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.link-url {
  word-break: break-all;
  color: var(--brand-dark);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.sign-topbar {
  min-height: 64px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sign-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  min-height: calc(100vh - 64px);
}

.sign-sidebar {
  border-left: 1px solid var(--line);
  background: #fff;
  padding: 14px;
  display: grid;
  align-content: start;
  gap: 14px;
}

.sign-fields {
  display: grid;
  gap: 12px;
}

.sign-field {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 8px;
}

.signature-pad {
  width: 100%;
  height: 150px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  touch-action: none;
}

.sign-overlay {
  position: absolute;
  border: 2px solid rgba(18, 107, 104, 0.7);
  background: rgba(255, 255, 255, 0.76);
  display: grid;
  place-items: center;
  padding: 3px;
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 800;
  pointer-events: none;
  overflow: hidden;
}

.sign-overlay.signature {
  border-color: rgba(155, 95, 20, 0.8);
  color: #6d410c;
}

.busy {
  opacity: 0.7;
  pointer-events: none;
}

@media (max-width: 980px) {
  .layout,
  .workspace,
  .sign-layout {
    grid-template-columns: 1fr;
  }

  .side-panel {
    max-height: none;
  }

  .tools-panel,
  .sign-sidebar {
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 620px) {
  .topbar,
  .doc-titlebar,
  .sign-topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .tabs {
    overflow-x: auto;
  }

  .tab {
    min-width: 96px;
  }

  .layout {
    padding: 10px;
  }

  .pdf-stage {
    padding: 10px;
  }
}
