/* ==========================================================================
   Skyhotel Contract eSign — HTML/CSS thuần, responsive
   ========================================================================== */
:root {
  --brand: #0f6fd6;
  --brand-dark: #0b5aad;
  --brand-light: #e8f2fd;
  --green: #16a34a;
  --green-light: #e7f7ee;
  --red: #dc2626;
  --amber: #d97706;
  --gray-50: #f7f8fa;
  --gray-100: #eef0f4;
  --gray-200: #e2e6ec;
  --gray-400: #9aa4b2;
  --gray-600: #5b6675;
  --gray-800: #23303f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: var(--gray-800);
  background: var(--gray-50);
  -webkit-text-size-adjust: 100%;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ------------------------------ Layout ---------------------------------- */
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar .inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.logo {
  font-weight: 700;
  font-size: 17px;
  color: var(--brand);
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo .mark {
  width: 28px; height: 28px;
  border-radius: 7px;
  background: var(--brand);
  color: #fff;
  display: grid; place-items: center;
  font-size: 15px;
}
.spacer { flex: 1 1 auto; }

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}
.container.narrow { max-width: 760px; }

/* ------------------------------- Card ----------------------------------- */
.card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
}
.card > h2 {
  margin: 0 0 4px;
  font-size: 17px;
}
.card > .sub {
  margin: 0 0 16px;
  color: var(--gray-600);
  font-size: 13.5px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ------------------------------ Form ------------------------------------ */
label {
  display: block;
  font-weight: 600;
  font-size: 13.5px;
  margin-bottom: 6px;
}
input[type=text], input[type=email], input[type=password], input[type=number],
select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  background: #fff;
  color: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-light);
}
.field { margin-bottom: 14px; }
.hint { font-size: 12.5px; color: var(--gray-600); margin-top: 5px; }

input[type=file] {
  width: 100%;
  padding: 22px 12px;
  border: 2px dashed var(--gray-200);
  border-radius: 8px;
  background: var(--gray-50);
  font-size: 14px;
}

/* ------------------------------ Button ---------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-size: 14.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  min-height: 42px;
}
.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--gray-800); border-color: var(--gray-200); }
.btn.secondary:hover { background: var(--gray-50); }
.btn.success { background: var(--green); }
.btn.success:hover { background: #128a3e; }
.btn.danger { background: var(--red); }
.btn.small { padding: 6px 12px; font-size: 13px; min-height: 34px; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ------------------------------ Badge ----------------------------------- */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.pending   { background: #fff7e6; color: var(--amber); }
.badge.viewed    { background: var(--brand-light); color: var(--brand-dark); }
.badge.signed    { background: var(--green-light); color: var(--green); }
.badge.expired   { background: var(--gray-100); color: var(--gray-600); }
.badge.cancelled { background: #fdeaea; color: var(--red); }

/* ------------------------------ Table ----------------------------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}
th {
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: .3px;
  color: var(--gray-600);
  background: var(--gray-50);
  white-space: nowrap;
}
tbody tr:hover { background: #fbfcfe; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

/* ------------------------------ Alert ----------------------------------- */
.alert {
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 14px;
  border: 1px solid transparent;
}
.alert.error   { background: #fdeaea; color: #99201f; border-color: #f5c6c6; }
.alert.ok      { background: var(--green-light); color: #106b34; border-color: #b7e6c8; }
.alert.info    { background: var(--brand-light); color: var(--brand-dark); border-color: #c5dcf6; }
.alert.warn    { background: #fff7e6; color: #92600a; border-color: #f5dda8; }
.hidden { display: none !important; }

/* --------------------------- PDF viewer --------------------------------- */
.pdf-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  font-size: 14px;
}
.pdf-stage {
  border: 1px solid var(--gray-200);
  border-radius: 0 0 var(--radius) var(--radius);
  background: #525a64;
  padding: 14px;
  overflow: auto;
  max-height: 72vh;
  -webkit-overflow-scrolling: touch;
}
.pdf-page-wrap {
  position: relative;
  margin: 0 auto;
  background: #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .3);
  width: max-content;
}
#pdfCanvas { display: block; max-width: 100%; height: auto; }

/* Ô chữ ký kéo-thả */
.sig-box {
  position: absolute;
  border: 2px dashed var(--brand);
  background: rgba(15, 111, 214, .12);
  cursor: move;
  touch-action: none;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--brand-dark);
  user-select: none;
}
.sig-box .handle {
  position: absolute;
  right: -8px; bottom: -8px;
  width: 18px; height: 18px;
  background: var(--brand);
  border: 2px solid #fff;
  border-radius: 50%;
  cursor: nwse-resize;
  touch-action: none;
}

/* --------------------------- Canvas ký tay ------------------------------ */
.draw-area {
  border: 2px dashed var(--gray-200);
  border-radius: var(--radius);
  background: #fff;
  position: relative;
  touch-action: none;
}
#drawCanvas { display: block; width: 100%; height: 220px; touch-action: none; cursor: crosshair; }
.draw-baseline {
  position: absolute;
  left: 8%; right: 8%; bottom: 46px;
  border-bottom: 1px solid var(--gray-200);
  pointer-events: none;
}

/* --------------------------- Chọn cách ký ------------------------------- */
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.choice {
  border: 2px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  background: #fff;
  text-align: center;
  transition: border-color .15s, background .15s;
}
.choice:hover { border-color: var(--brand); background: var(--brand-light); }
.choice .ico { font-size: 30px; line-height: 1; margin-bottom: 8px; }
.choice h3 { margin: 0 0 6px; font-size: 15.5px; }
.choice p { margin: 0; font-size: 13px; color: var(--gray-600); }

/* --------------------------- Danh sách chứng thư ------------------------ */
.cert-item {
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 10px;
  cursor: pointer;
  background: #fff;
}
.cert-item:hover { border-color: var(--brand); background: var(--brand-light); }
.cert-item.active { border-color: var(--brand); background: var(--brand-light); }
.cert-item .cn { font-weight: 700; }
.cert-item .meta { font-size: 12.5px; color: var(--gray-600); margin-top: 3px; }

/* ==========================================================================
   TOAST — thông báo nổi
   ========================================================================== */
.toast-wrap {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
  max-width: min(380px, calc(100vw - 32px));
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 11px;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-left: 4px solid var(--gray-400);
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: 0 8px 28px rgba(16, 24, 40, .14);
  font-size: 14px;
  line-height: 1.45;
  opacity: 0;
  transform: translateX(24px) scale(.97);
  transition: opacity .22s ease, transform .22s cubic-bezier(.22, 1, .36, 1);
}
.toast.in { opacity: 1; transform: none; }
.toast.out { opacity: 0; transform: translateX(24px) scale(.97); }

.toast-ico {
  flex: none;
  width: 20px; height: 20px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  margin-top: 1px;
}
.toast-msg { flex: 1 1 auto; word-break: break-word; }
.toast-x {
  flex: none;
  border: 0;
  background: none;
  font-size: 20px;
  line-height: 1;
  color: var(--gray-400);
  cursor: pointer;
  padding: 0 2px;
  font-family: inherit;
}
.toast-x:hover { color: var(--gray-800); }

.toast-success { border-left-color: var(--green); }
.toast-success .toast-ico { background: var(--green); }
.toast-error   { border-left-color: var(--red); }
.toast-error   .toast-ico { background: var(--red); }
.toast-warn    { border-left-color: var(--amber); }
.toast-warn    .toast-ico { background: var(--amber); }
.toast-info    { border-left-color: var(--brand); }
.toast-info    .toast-ico { background: var(--brand); }

/* ==========================================================================
   DIALOG — thay alert() / confirm()
   ========================================================================== */
.dlg-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, .5);
  backdrop-filter: blur(2px);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 9998;
  opacity: 0;
  transition: opacity .18s ease;
  overflow-y: auto;
}
.dlg-overlay.in { opacity: 1; }

.dlg-box {
  background: #fff;
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 24px 60px rgba(16, 24, 40, .32);
  transform: translateY(10px) scale(.98);
  transition: transform .2s cubic-bezier(.22, 1, .36, 1);
  max-height: 90vh;
  overflow-y: auto;
}
.dlg-box.wide { max-width: 660px; }
.dlg-overlay.in .dlg-box { transform: none; }

.dlg-icon {
  width: 46px; height: 46px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 22px;
  font-weight: 700;
  margin: 0 auto 14px;
}
.dlg-icon-info  { background: var(--brand-light); color: var(--brand-dark); }
.dlg-icon-warn  { background: #fff7e6; color: var(--amber); }
.dlg-icon-error { background: #fdeaea; color: var(--red); }
.dlg-icon-success { background: var(--green-light); color: var(--green); }

.dlg-title {
  margin: 0 0 8px;
  font-size: 17px;
  text-align: center;
}
.dlg-box.wide .dlg-title { text-align: left; }

.dlg-body {
  font-size: 14.5px;
  color: var(--gray-600);
  text-align: center;
  margin-bottom: 20px;
  white-space: pre-line;
}
.dlg-box.wide .dlg-body { text-align: left; white-space: normal; color: var(--gray-800); }

.dlg-actions { display: flex; gap: 10px; }
.dlg-actions .btn { flex: 1 1 0; }
.dlg-actions .btn.block { flex: 1 1 100%; }

/* Bảng thông tin trong dialog */
.dlg-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.dlg-table th {
  width: 150px;
  text-align: left;
  font-weight: 600;
  color: var(--gray-600);
  background: none;
  text-transform: none;
  letter-spacing: 0;
  padding: 7px 10px 7px 0;
  vertical-align: top;
  white-space: normal;
}
.dlg-table td { padding: 7px 0; word-break: break-word; }

.dlg-log {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--gray-100);
  border-radius: 8px;
  padding: 4px 10px;
  background: var(--gray-50);
}
.dlg-log-item {
  padding: 8px 0;
  border-bottom: 1px solid var(--gray-100);
  font-size: 13px;
}
.dlg-log-item:last-child { border-bottom: 0; }
.dlg-log-item .when { color: var(--gray-600); font-size: 12px; }

/* ==========================================================================
   TOOLTIP — dùng thuộc tính data-tip="..."
   ========================================================================== */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 9px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: var(--gray-800);
  color: #fff;
  font-size: 12.5px;
  font-weight: 400;
  line-height: 1.4;
  letter-spacing: 0;
  text-transform: none;
  padding: 7px 10px;
  border-radius: 7px;
  white-space: pre-line;
  width: max-content;
  max-width: 240px;
  opacity: 0;
  visibility: hidden;
  transition: opacity .15s ease, transform .15s ease;
  z-index: 9000;
  pointer-events: none;
  box-shadow: 0 6px 18px rgba(16, 24, 40, .22);
}
[data-tip]::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 3px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  border: 6px solid transparent;
  border-top-color: var(--gray-800);
  opacity: 0;
  visibility: hidden;
  transition: opacity .15s ease, transform .15s ease;
  z-index: 9000;
  pointer-events: none;
}
[data-tip]:hover::after, [data-tip]:hover::before,
[data-tip].tip-open::after, [data-tip].tip-open::before {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}
[data-tip=""]::after, [data-tip=""]::before { display: none; }

/* Dấu hỏi tròn nhỏ để gắn tooltip */
.tip-mark {
  display: inline-grid;
  place-items: center;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--gray-200);
  color: var(--gray-600);
  font-size: 11px;
  font-weight: 700;
  cursor: help;
  margin-left: 5px;
  vertical-align: middle;
}
.tip-mark:hover { background: var(--brand); color: #fff; }

/* ---------------------------- Details / Summary -------------------------- */
details {
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  background: var(--gray-50);
  padding: 12px 14px;
}
details > summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  color: var(--brand-dark);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before {
  content: '▸';
  font-size: 13px;
  transition: transform .15s;
}
details[open] > summary::before { transform: rotate(90deg); }

/* ------------------------------ Misc ------------------------------------ */
.copy-row { display: flex; gap: 8px; }
.copy-row input { font-size: 13px; }
.center { text-align: center; }
.muted { color: var(--gray-600); }
.big-check { font-size: 54px; color: var(--green); line-height: 1; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--gray-600); }
.kv dd { margin: 0; word-break: break-word; }
.spin {
  width: 16px; height: 16px;
  border: 2px solid rgba(255, 255, 255, .4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: sp .7s linear infinite;
}
@keyframes sp { to { transform: rotate(360deg); } }

.steps { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.step {
  flex: 1 1 0;
  min-width: 120px;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--gray-100);
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-600);
}
.step.active { background: var(--brand); color: #fff; }
.step.done { background: var(--green-light); color: var(--green); }

/* ============================ RESPONSIVE ================================= */
@media (max-width: 780px) {
  .grid-2 { grid-template-columns: 1fr; }
  .choice-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { margin-top: 8px; font-size: 12.5px; }
  .container { padding: 14px 12px 44px; }
  .card { padding: 16px; border-radius: 8px; }
  .pdf-stage { padding: 8px; max-height: 62vh; }
  .btn { width: 100%; }
  .btn.small, .btn-row .btn { width: auto; }
  .topbar .inner { padding: 10px 12px; }
  table { font-size: 13px; }
  th, td { padding: 9px 8px; }
}

@media (max-width: 480px) {
  body { font-size: 14.5px; }
  .logo { font-size: 15px; }
  .steps { gap: 6px; }
  .step { min-width: 0; padding: 7px 8px; font-size: 11.5px; text-align: center; }
  #drawCanvas { height: 180px; }
  .btn-row { flex-direction: column; }
  .btn-row .btn { width: 100%; }
}

/* Máy in */
@media print {
  .topbar, .btn, .pdf-toolbar, .action-bar { display: none !important; }
}

/* ==========================================================================
   TRANG KÝ — giao diện tối giản cho người không rành máy tính
   ========================================================================== */

/* ------- Trạng thái công cụ ký số ------- */
.tool-state {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14.5px;
}
.dot {
  width: 11px; height: 11px;
  border-radius: 50%;
  flex: none;
}
.dot-gray   { background: var(--gray-400); animation: pulse 1.2s infinite; }
.dot-green  { background: var(--green); }
.dot-orange { background: var(--amber); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

.install-head { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.install-steps {
  margin: 0;
  padding-left: 22px;
  font-size: 14px;
  line-height: 1.9;
}
.install-steps li::marker { font-weight: 700; color: var(--brand); }

/* ------- Ô chữ ký kéo được ------- */
.sig-box.draggable {
  cursor: grab;
  box-shadow: 0 0 0 3px rgba(15, 111, 214, .12);
  transition: box-shadow .15s;
}
.sig-box.draggable:active,
.sig-box.dragging { cursor: grabbing; box-shadow: 0 0 0 6px rgba(15, 111, 214, .2); }
.sig-box.flash { animation: flash 0.7s ease; }
@keyframes flash {
  0%, 100% { background: rgba(15, 111, 214, .12); }
  50% { background: rgba(22, 163, 74, .35); }
}
.sig-box .handle { width: 22px; height: 22px; right: -11px; bottom: -11px; }

/* ------- Thanh hành động ------- */
.action-bar {
  position: sticky;
  bottom: 0;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: 0 -4px 18px rgba(16, 24, 40, .08);
  padding: 14px 18px;
  margin-bottom: 18px;
  z-index: 20;
}
.agree {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-weight: 500;
  font-size: 14px;
  margin-bottom: 12px;
  cursor: pointer;
}
.agree input {
  width: 20px; height: 20px;
  margin: 0;
  flex: none;
  accent-color: var(--brand);
  cursor: pointer;
}
.action-btns { display: flex; gap: 10px; }
.action-btns .btn { flex: 1 1 0; }

.btn.big {
  padding: 14px 20px;
  font-size: 16px;
  min-height: 52px;
  border-radius: 10px;
}

/* ------- Modal ------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, .55);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 100;
  overflow-y: auto;
}
.modal-box {
  background: #fff;
  border-radius: 14px;
  padding: 22px;
  width: 100%;
  max-width: 520px;
  box-shadow: 0 20px 60px rgba(16, 24, 40, .3);
  max-height: 92vh;
  overflow-y: auto;
}
.modal-box h3 { margin: 0 0 4px; font-size: 17px; }

.spin-big {
  width: 42px; height: 42px;
  border: 4px solid var(--gray-100);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: sp .8s linear infinite;
  margin: 0 auto;
}

/* ------- Responsive trang ký ------- */
@media (max-width: 780px) {
  .action-btns { flex-direction: column; }
  .action-btns .btn { width: 100%; }
  .action-bar { padding: 12px 14px; border-radius: 10px 10px 0 0; margin-bottom: 0; }
  .sign-page .container { padding-bottom: 20px; }
  .modal-box { padding: 18px; border-radius: 12px; }
  .install-steps { font-size: 13.5px; padding-left: 20px; }
  /* Ngón tay cần vùng bắt lớn hơn */
  .sig-box .handle { width: 28px; height: 28px; right: -14px; bottom: -14px; }

  /* Toast xuống đáy màn hình cho dễ với tay */
  .toast-wrap {
    top: auto;
    bottom: 12px;
    left: 12px;
    right: 12px;
    max-width: none;
  }
  .toast { transform: translateY(24px) scale(.97); }
  .toast.out { transform: translateY(24px) scale(.97); }

  .dlg-box { padding: 20px; border-radius: 12px; }
  .dlg-actions { flex-direction: column-reverse; }
  .dlg-actions .btn { width: 100%; }
  .dlg-table th { width: 42%; }

  [data-tip]::after { max-width: 200px; font-size: 12px; }
}
