/* Glow Docs */
:root {
  --bg: #0b0f17;
  --bg-2: #0f1522;
  --card: #121a29;
  --card-2: #172134;
  --border: #223049;
  --text: #e6edf3;
  --muted: #8b98ab;
  --accent: #3cc8e8;
  --accent-2: #1d5fd1;
  --accent-glow: rgba(60, 200, 232, 0.35);
  --success: #3ddc97;
  --danger: #ff6b6b;
  --warn: #ffc857;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 20% -10%, rgba(29, 95, 209, 0.22), transparent 60%),
              radial-gradient(900px 500px at 100% 0%, rgba(60, 200, 232, 0.14), transparent 60%),
              var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 10px; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 26px; }
h2 { font-size: 18px; }
h3 { font-size: 17px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.wrap { word-break: break-all; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.inline { display: inline; }

/* Inputs */
label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 14px; }
label .muted { font-weight: 400; }
input[type="text"], input[type="email"], input[type="password"], .upload-card input[type="date"] {
  display: block; width: 100%; margin-top: 6px;
  padding: 11px 13px; font: inherit; font-size: 15px; color: var(--text);
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
input[readonly] { color: var(--muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; font: inherit; font-size: 14px; font-weight: 600;
  border-radius: 10px; border: 1px solid transparent; cursor: pointer; text-decoration: none;
  white-space: nowrap; transition: transform .08s, box-shadow .15s, background .15s, border-color .15s;
  line-height: 1.2;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary {
  color: #fff;
  /* No border: a transparent border over a gradient leaves a 1px seam at the edge in some browsers. */
  border: 0; padding: 11px 17px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 20px -6px var(--accent-glow);
}
.btn-primary.btn-sm { padding: 7px 11px; }
.btn-primary:not(:disabled):hover { box-shadow: 0 8px 26px -6px var(--accent-glow); filter: brightness(1.06); }
.btn-ghost { color: var(--text); background: var(--card-2); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--accent); }
.btn-danger { color: var(--danger); background: transparent; border-color: var(--border); }
.btn-danger:hover { border-color: var(--danger); background: rgba(255, 107, 107, 0.08); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 10px; }
.btn.is-done { background: var(--success); color: #062; }

/* Flash */
.flash { padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; font-size: 14px; border: 1px solid; }
.flash-success { background: rgba(61, 220, 151, 0.1); border-color: rgba(61, 220, 151, 0.4); color: #b8f5d8; }
.flash-error { background: rgba(255, 107, 107, 0.1); border-color: rgba(255, 107, 107, 0.45); color: #ffc9c9; }

/* Auth / small centered pages */
.page-auth { display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 420px; background: var(--card); border: 1px solid var(--border);
  border-radius: 18px; padding: 32px 28px; box-shadow: 0 30px 80px -30px rgba(0, 0, 0, .8), 0 0 0 1px rgba(60, 200, 232, 0.05);
  text-align: center;
}
.auth-card form { text-align: left; margin-top: 18px; }
.auth-card .logo { border-radius: 18px; margin-bottom: 12px; }
.auth-card .btn-block { margin-top: 6px; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  background: rgba(11, 15, 23, 0.8); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: var(--text); text-decoration: none; }
.brand img { border-radius: 8px; }
.topbar nav { display: flex; gap: 8px; align-items: center; }

/* Dashboard */
.container { max-width: 960px; margin: 0 auto; padding: 24px 16px 60px; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; margin-bottom: 18px;
}
.upload-card h2 { margin-bottom: 16px; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: 28px 16px; margin-bottom: 18px; text-align: center; cursor: pointer;
  border: 2px dashed var(--border); border-radius: 12px; background: var(--bg-2);
  transition: border-color .15s, background .15s; font-weight: 500;
}
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone:hover, .dropzone.is-over { border-color: var(--accent); background: rgba(60, 200, 232, 0.05); }
.dropzone.has-file { border-style: solid; border-color: var(--success); }
.dz-icon { color: var(--accent); }
.dz-text { font-size: 15px; }
.dz-hint { font-size: 12px; color: var(--muted); font-weight: 400; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 16px; }
@media (max-width: 640px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.docs-head { display: flex; align-items: baseline; justify-content: space-between; margin: 28px 0 12px; }
.empty { color: var(--muted); text-align: center; padding: 36px; }
.doc { display: flex; gap: 20px; align-items: flex-start; }
.doc-main { flex: 1; min-width: 0; }
.doc-actions { display: flex; flex-direction: column; gap: 8px; align-items: stretch; min-width: 170px; }
.doc-actions .btn { width: 100%; }
.doc-actions form { display: block; }
.doc-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.doc-title h3 { margin: 0; overflow-wrap: anywhere; }
.badge { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; padding: 4px 8px; border-radius: 999px; }
.badge-pending { background: rgba(255, 200, 87, 0.14); color: var(--warn); }
.badge-signed { background: rgba(61, 220, 151, 0.14); color: var(--success); }
.badge-draft { background: rgba(139, 152, 171, 0.16); color: var(--muted); }
.doc-pending { border-left: 3px solid var(--warn); }
.doc-signed { border-left: 3px solid var(--success); }
.doc-draft { border-left: 3px solid var(--muted); }
.is-highlighted { box-shadow: 0 0 0 3px var(--accent-glow); transition: box-shadow .4s; }
.signed-line { margin: 10px 0 6px; }
.linkrow, .emailrow { display: flex; gap: 8px; margin-top: 10px; }
.linkrow input, .emailrow input { margin: 0; flex: 1; min-width: 0; font-size: 13px; }
.audit summary { cursor: pointer; color: var(--accent); font-size: 14px; }
.audit dl { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; font-size: 13px; margin: 10px 0 0; }
.audit dt { color: var(--muted); }
.audit dd { margin: 0; }
@media (max-width: 720px) {
  .doc { flex-direction: column; }
  .doc-actions { flex-direction: row; flex-wrap: wrap; width: 100%; min-width: 0; }
  .doc-actions .btn { width: auto; flex: 1; }
  .audit dl { grid-template-columns: 1fr; }
}
.settings { margin-top: 36px; }
.settings-advanced { margin: 6px 0 18px; border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; }
.settings-advanced summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.settings-advanced summary .muted { font-weight: 400; }
.settings-advanced p { margin: 10px 0 12px; }
.settings-advanced .grid-3 { margin-top: 2px; }
.settings-actions { justify-content: flex-start; }
.settings-test { margin-top: 12px; }

/* ---------------------------------------------------------------- Signer */
.page-sign { background: #e8ecf1; color: #101418; display: flex; flex-direction: column; min-height: 100vh; }
.page-sign #app { display: flex; flex-direction: column; min-height: 100vh; }
.sign-topbar { color: var(--text); }
.sign-doc-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 15px; color: var(--text); text-align: center; }
.sign-message { background: #fff8dc; color: #4a3b00; border-bottom: 1px solid #efe0a0; padding: 10px 20px; font-size: 14px; }
.sign-banner {
  position: sticky; top: 57px; z-index: 15; text-align: center; padding: 9px 14px; font-size: 14px; font-weight: 600;
  background: #d9f3fa; color: #0a4d60; border-bottom: 1px solid #b4e3ef;
}
.sign-banner[hidden] { display: none; }
.sign-banner.is-error { background: #ffe1e1; color: #7a1010; border-color: #f4b4b4; }
.viewer { flex: 1; padding: 20px 8px 30px; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.page {
  position: relative; background: #fff; box-shadow: 0 10px 30px -12px rgba(0, 0, 0, .35), 0 0 0 1px rgba(0, 0, 0, .06);
  max-width: 100%; user-select: none; -webkit-user-select: none;
}
.page canvas { display: block; pointer-events: none; }
.page-num { position: absolute; right: 8px; bottom: 6px; font-size: 11px; color: #9aa3ad; pointer-events: none; }
.is-placing .page { cursor: crosshair; outline: 2px dashed var(--accent); outline-offset: 2px; }

.placement {
  position: absolute; cursor: grab; touch-action: none;
  outline: 2px solid rgba(60, 200, 232, 0.9); outline-offset: 2px; border-radius: 3px;
  background: rgba(60, 200, 232, 0.06);
}
.placement.is-active { cursor: grabbing; outline-color: var(--accent-2); }
.placement img { display: block; width: 100%; height: 100%; pointer-events: none; }
.placement-caption {
  position: absolute; left: 0; top: 100%; margin-top: 2px; white-space: nowrap;
  font: 9px/1.2 Helvetica, Arial, sans-serif; color: #40474f; pointer-events: none;
}
.placement.no-caption .placement-caption { display: none; }
.box-del {
  position: absolute; top: -12px; right: -12px; width: 24px; height: 24px; border-radius: 50%;
  border: none; background: var(--danger); color: #fff; font-size: 12px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center; line-height: 1; padding: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
}
.box-del[hidden] { display: none; }
.box-resize {
  position: absolute; right: -8px; bottom: -8px; width: 16px; height: 16px; border-radius: 4px;
  background: var(--accent-2); border: 2px solid #fff; cursor: nwse-resize; touch-action: none;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
}

.sign-footer {
  position: sticky; bottom: 0; z-index: 20; background: #fff; border-top: 1px solid #d5dbe3;
  padding: 12px 20px 14px; box-shadow: 0 -10px 30px -20px rgba(0,0,0,.4);
}
.finish-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; max-width: 760px; margin: 0 auto; }
.sign-footer label { margin-bottom: 10px; color: #233; }
.sign-footer input[type="text"], .sign-footer input[type="email"] { background: #fff; color: #101418; border-color: #cfd6df; padding: 9px 12px; }
.sign-footer .check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; font-size: 13px; max-width: 760px; margin: 0 auto 8px; }
.sign-footer .check input { margin: 3px 0 0; width: 16px; height: 16px; flex: none; accent-color: var(--accent-2); }
.finish-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; max-width: 760px; margin: 4px auto 0; }
.sign-footer .muted { color: #5c6673; }
@media (max-width: 640px) {
  .finish-fields { grid-template-columns: 1fr; }
  .sign-topbar .brand span { display: none; }
  .sign-footer { padding: 10px 14px 12px; }
  /* Keep the document visible on phones until a signature has been placed. */
  body.page-sign:not(.page-prepare):not(.has-placements) .finish-fields,
  body.page-sign:not(.page-prepare):not(.has-placements) .sign-footer .check { display: none; }
}

/* Modal */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(5, 8, 14, 0.65); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-card { width: 100%; max-width: 640px; background: #fff; color: #101418; border-radius: 16px; padding: 18px 20px 20px; box-shadow: 0 40px 80px -30px rgba(0,0,0,.8); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.modal-head h2 { margin: 0; }
.modal .btn-ghost { background: #f1f4f8; color: #101418; border-color: #d5dbe3; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tab { font: inherit; font-weight: 600; font-size: 14px; padding: 7px 14px; border-radius: 999px; border: 1px solid #d5dbe3; background: #fff; cursor: pointer; }
.tab.is-active { background: #101418; color: #fff; border-color: #101418; }
.sig-pad {
  display: block; width: 100%; height: 220px; background: #fbfcfe; border: 1px solid #cfd6df; border-radius: 10px;
  touch-action: none; cursor: crosshair;
  background-image: linear-gradient(to top, #cfd6df 1px, transparent 1px); background-size: 100% 100%; background-position: 0 -50px;
}
#sig-text { margin: 0 0 10px; background: #fff; color: #101418; border-color: #cfd6df; }
.modal-option { display: flex; align-items: center; gap: 8px; margin: 12px 0 0; font-size: 13px; font-weight: 400; color: #3a434d; cursor: pointer; }
.modal-option input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent-2); }
.modal-option[hidden] { display: none; }
.modal-name { margin: 10px 0 0; font-size: 13px; color: #3a434d; }
.modal-name input { margin-top: 4px; background: #fff; color: #101418; border-color: #cfd6df; padding: 8px 11px; font-size: 14px; }
.modal-name[hidden] { display: none; }
.banner-action { margin-left: 10px; padding: 4px 10px; font-size: 12px; vertical-align: middle; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
body.modal-open { overflow: hidden; }

/* Date boxes (sender's own, and the signer's date fields) */
.placement-date, .field-date { container-type: size; }
.placement-date { background: rgba(255, 255, 255, 0.92); display: flex; align-items: center; justify-content: center; }
.placement-date .date-text { font: 600 48cqh/1 var(--font); color: #101418; white-space: nowrap; pointer-events: none; }
.placement-date .date-input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; pointer-events: none; margin: 0; padding: 0 6px; border: 0; }
.placement-date.is-editing .date-input { opacity: 1; pointer-events: auto; background: #fff; color: #101418; font: 600 48cqh/1 var(--font); text-align: center; border-radius: 3px; }
.placement-date.is-editing .date-text { visibility: hidden; }
.field-date input {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; padding: 0 6px; border: 0; border-radius: 0;
  background: transparent; color: #101418; font: 600 48cqh/1 var(--font); text-align: center; box-shadow: none;
}
.field-date input:focus, .placement-date .date-input:focus { outline: none; box-shadow: none; }
.field-date input[hidden] { display: none; }

/* Preview that follows the pointer while placing */
.ghost {
  position: fixed; left: 0; top: 0; z-index: 30; pointer-events: none; opacity: 0.45; border-radius: 3px;
  display: flex; align-items: center; justify-content: center; container-type: size;
  outline: 2px solid var(--accent-2); outline-offset: 2px; background: rgba(60, 200, 232, 0.12);
}
.ghost.is-over-page { opacity: 0.85; }
.ghost[hidden] { display: none; }
.ghost img { width: 100%; height: 100%; object-fit: contain; }
.ghost-date { background: rgba(255, 255, 255, 0.95); }
.ghost-date .date-text { font: 600 48cqh/1 var(--font); color: #101418; white-space: nowrap; }
.ghost-field { outline-style: dashed; }
.toolbar .btn.is-active { background: var(--danger); color: #fff; border-color: var(--danger); }
.toolbar-group { display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px 3px 8px; border: 1px solid var(--border); border-radius: 12px; }
.toolbar-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-right: 2px; }

/* Prepare page toolbar row (below the header) */
.toolbar-row {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center; justify-content: center;
  padding: 8px 12px; background: rgba(11, 15, 23, 0.9); border-bottom: 1px solid var(--border);
  position: sticky; top: 57px; z-index: 19;
}
.page-prepare .sign-banner { top: 110px; }
.placement-initials { background: rgba(60, 200, 232, 0.06); }
.verifyrow { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin-top: 10px; flex-wrap: wrap; }
.lock { font-size: 13px; color: var(--success); }
.icon { vertical-align: -2px; margin-right: 2px; }
.gate-alt { margin-top: 8px; }
.upload-card .check-inline { margin-top: -6px; margin-bottom: 14px; font-weight: 400; font-size: 13px; display: flex; gap: 10px; align-items: flex-start; }
.upload-card .check-inline input { margin-top: 3px; width: 16px; height: 16px; flex: none; accent-color: var(--accent-2); }
.upload-card .paper-toggle { margin-top: 0; font-size: 14px; }
.upload-card [hidden] { display: none; }

/* Sign-here fields */
.field {
  position: absolute; border-radius: 4px; cursor: pointer; touch-action: none;
  background: rgba(60, 200, 232, 0.14); outline: 2px dashed var(--accent-2); outline-offset: 1px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.field:hover { background: rgba(60, 200, 232, 0.24); }
.field-label {
  font: 600 12px/1 var(--font); color: #0a4d60; background: rgba(255,255,255,.85); padding: 4px 8px; border-radius: 999px;
  pointer-events: none; white-space: nowrap; max-width: 95%; overflow: hidden; text-overflow: ellipsis;
}
.field.is-editable { cursor: grab; }
.field.is-editable.is-active { cursor: grabbing; }
.field.is-filled { background: transparent; outline-color: rgba(60, 200, 232, 0.9); outline-style: solid; cursor: default; }
.field.is-filled .field-label { display: none; }
.field img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.field .placement-caption { top: auto; margin-top: 2px; }
.field.no-caption .placement-caption, .field:not(.is-filled) .placement-caption { display: none; }
.page-sign:not(.has-placements) .field:not(.is-filled) { animation: field-pulse 1.6s ease-in-out infinite; }
@keyframes field-pulse { 0%, 100% { outline-color: var(--accent-2); } 50% { outline-color: var(--accent); } }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.check-inline { margin-top: 28px; }
@media (max-width: 640px) {
  .check-inline { margin-top: 0; }
  .toolbar-row .btn { padding: 7px 9px; font-size: 13px; }
  .toolbar-row { gap: 6px; }
  .page-prepare .sign-banner { top: 150px; }
  body.page-prepare .finish-fields { display: grid; }
}

/* Done */
.done { position: fixed; inset: 0; z-index: 60; background: var(--bg); color: var(--text); display: flex; align-items: center; justify-content: center; padding: 16px; }
.done[hidden] { display: none; }
