@font-face {
  font-family: "Dancing Script";
  src: url("/static/fonts/DancingScript.ttf") format("truetype");
  font-weight: 400 700;
  font-display: swap;
}

:root {
  --navy: #1b2735;
  --blue: #5c86d7;
  --blue-dark: #4a72c0;
  --bg: #eff4fc;
  --text: #535e6b;
  --line: #e0e0e0;
  --white: #ffffff;
  --green: #1f8a5b;
  --green-bg: #e6f5ee;
  --amber: #a86400;
  --amber-bg: #fdf3e1;
  --red: #c0392b;
  --red-bg: #fdecea;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Poppins", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { color: var(--navy); margin: 0; line-height: 1.25; }
h1 { font-size: 1.5rem; font-weight: 600; }
h2 { font-size: 1rem; font-weight: 600; }
a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--blue-dark); }
.muted { color: #8a94a1; font-size: 0.85rem; }
.small { font-size: 0.8rem; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 0.78rem; word-break: break-all; }

/* ── Layout ─────────────────────────────────────────────────────────────── */

.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.topbar img { height: 26px; display: block; }
.topbar nav { display: flex; gap: 18px; flex: 1; }
.topbar nav a { color: var(--text); font-weight: 500; font-size: 0.9rem; }
.topbar nav a.active, .topbar nav a:hover { color: var(--navy); }
.topbar .who { display: flex; align-items: center; gap: 12px; font-size: 0.85rem; }

.page { max-width: 1100px; margin: 0 auto; padding: 28px 16px 48px; }
.page-narrow { max-width: 720px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.back { font-size: 0.85rem; display: inline-block; margin-bottom: 8px; }

.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(27, 39, 53, 0.06);
  padding: 22px;
}
.card + .card, .grid + .card { margin-top: 16px; }
.grid > .card, .editor > .card { margin-top: 0; }
.card h2 { margin-bottom: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }

/* ── Buttons & forms ────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 999px;
  padding: 10px 22px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  background: var(--navy);
  color: var(--white);
}
.btn:hover { background: #2c3b4e; color: var(--white); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-blue { background: var(--blue); }
.btn-blue:hover { background: var(--blue-dark); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--bg); color: var(--navy); }
.btn-link { background: none; border: 0; padding: 0; font: inherit; color: var(--text); cursor: pointer; }
.btn-link:hover { color: var(--navy); }
.btn-block { width: 100%; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--navy); margin-bottom: 6px; }
label .opt { font-weight: 400; color: #8a94a1; }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], select {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  font-size: 0.9rem;
  color: var(--navy);
  background: var(--white);
}
input:focus { outline: 2px solid var(--blue); outline-offset: -1px; border-color: transparent; }
textarea {
  width: 100%;
  min-height: 360px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--navy);
  resize: vertical;
}
textarea:focus, select:focus { outline: 2px solid var(--blue); outline-offset: -1px; border-color: transparent; }
.preview-title { font-size: 1.05rem; margin: 0 0 12px; }
.field-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0; }
.field-chips button { border: 1px solid var(--line); background: var(--white); border-radius: 999px; padding: 3px 10px; font: inherit; font-size: 0.75rem; color: var(--navy); cursor: pointer; }
.field-chips button:hover { border-color: var(--blue); color: var(--blue); }
.editor { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .editor { grid-template-columns: 1fr; } }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; color: var(--text); font-size: 0.88rem; }
.check input { margin-top: 4px; width: 16px; height: 16px; accent-color: var(--navy); flex-shrink: 0; }
.form-actions { display: flex; align-items: center; gap: 16px; margin-top: 22px; }

.alert { border-radius: 10px; padding: 12px 14px; font-size: 0.88rem; margin-bottom: 16px; }
.alert-error { background: var(--red-bg); color: var(--red); }
.alert-info { background: var(--bg); color: var(--navy); }

/* ── Status badges ──────────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-signed { background: var(--green-bg); color: var(--green); }
.badge-pending { background: var(--amber-bg); color: var(--amber); }
.badge-expired { background: var(--red-bg); color: var(--red); }
.badge-plain { background: var(--bg); color: var(--text); }
.badge-plain::before { display: none; }

/* ── Dashboard ──────────────────────────────────────────────────────────── */

.toolbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 14px; }
.tabs { display: flex; gap: 4px; background: var(--white); padding: 4px; border-radius: 999px; }
.tabs a { padding: 6px 14px; border-radius: 999px; font-size: 0.83rem; font-weight: 500; color: var(--text); }
.tabs a.active { background: var(--navy); color: var(--white); }
.toolbar input[type="search"] { max-width: 300px; height: 38px; border-radius: 999px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th { text-align: left; font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: #8a94a1; padding: 10px 12px; border-bottom: 1px solid var(--line); }
td { padding: 12px; border-bottom: 1px solid #f0f2f5; vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f7f9fd; }
td strong { color: var(--navy); font-weight: 500; }
.empty { text-align: center; padding: 48px 16px; }

/* ── Details ────────────────────────────────────────────────────────────── */

dl.details { display: grid; grid-template-columns: 140px 1fr; gap: 8px 16px; margin: 0; font-size: 0.88rem; }
dl.details dt { color: #8a94a1; }
dl.details dd { margin: 0; color: var(--navy); word-break: break-word; }

.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; font-size: 0.8rem; background: var(--bg); }
.signature-img { background: var(--white); border: 1px solid var(--line); border-radius: 10px; padding: 8px; max-width: 100%; max-height: 110px; display: block; margin-bottom: 16px; }

.timeline { list-style: none; margin: 0; padding: 0; font-size: 0.86rem; }
.timeline li { display: grid; grid-template-columns: 170px 1fr; gap: 12px; padding: 8px 0; border-bottom: 1px solid #f0f2f5; }
.timeline li:last-child { border-bottom: 0; }
.timeline .what { color: var(--navy); font-weight: 500; }

/* ── Letter text (signing page + preview) ───────────────────────────────── */

.letter-text p { margin: 0 0 14px; white-space: pre-line; }
.letter-fields { background: var(--bg); border-radius: 10px; padding: 12px 16px; margin: 0 0 14px; }
.letter-fields div { padding: 3px 0; }
.letter-fields strong { color: var(--navy); font-weight: 600; }

/* ── Public (candidate) pages ───────────────────────────────────────────── */

.public { max-width: 560px; margin: 0 auto; padding: 32px 16px 48px; }
.public-logo { display: block; height: 30px; margin: 0 auto 24px; }
.public h1 { text-align: center; font-size: 1.3rem; margin-bottom: 20px; }
.center { text-align: center; }

.sig-box { position: relative; border: 2px dashed var(--line); border-radius: 12px; background: var(--white); }
.sig-box.active { border-style: solid; border-color: var(--navy); }
.sig-box canvas { display: block; width: 100%; height: 190px; touch-action: none; }
.sig-hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #b5bcc6; font-size: 0.9rem; pointer-events: none; }
.sig-hint[hidden] { display: none; }
.sig-actions { display: flex; gap: 10px; margin-top: 16px; }
.sig-tabs { display: inline-flex; background: var(--bg); margin-bottom: 16px; }
.sig-tabs button { border: 0; background: none; font: inherit; font-size: 0.85rem; font-weight: 500; color: var(--text); padding: 6px 18px; border-radius: 999px; cursor: pointer; }
.sig-tabs button.active { background: var(--navy); color: var(--white); }
.typed-preview { height: 120px; margin-top: 12px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.typed-text { font-family: "Dancing Script", cursive; font-size: 2.6rem; color: var(--navy); white-space: nowrap; padding: 0 12px; }
.typed-preview.active .sig-hint { display: none; }
.sig-actions .btn:last-child { flex: 1; }

.icon-circle { width: 56px; height: 56px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto 14px; }
.icon-circle svg { width: 28px; height: 28px; }
.icon-ok { background: var(--green-bg); color: var(--green); }
.icon-warn { background: var(--red-bg); color: var(--red); }

.login { max-width: 400px; margin: 10vh auto 0; padding: 0 16px; }
.login .card { padding: 28px; }
.login .field + .field { margin-top: 14px; }

@media (max-width: 640px) {
  .topbar-inner { gap: 14px; }
  .topbar .who span { display: none; }
  dl.details { grid-template-columns: 1fr; gap: 2px; }
  dl.details dd { margin-bottom: 8px; }
  .timeline li { grid-template-columns: 1fr; gap: 0; }
  .hide-mobile { display: none; }
  .toolbar input[type="search"] { max-width: none; }
}

details.card summary { cursor: pointer; list-style: none; }
details.card summary::-webkit-details-marker { display: none; }
details.card summary::before { content: "▸ "; color: var(--blue); }
details.card[open] summary::before { content: "▾ "; }
