:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  --line: #e6e9f0;
  --brand: #4f46e5;
  --brand-dark: #4338ca;
  --brand-soft: #eef2ff;
  --danger: #e11d48;
  --danger-soft: #fff1f3;
  --ok: #059669;
  --ok-soft: #ecfdf5;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.05);
  --shadow-md: 0 4px 14px rgba(15,23,42,.08);
  --shadow-lg: 0 18px 50px rgba(15,23,42,.18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s, box-shadow .15s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); color: #fff; box-shadow: var(--shadow-sm); }
.btn.primary:hover { background: var(--brand-dark); }
.btn.primary:disabled { background: #c7cbe8; cursor: not-allowed; box-shadow: none; }
.btn.ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: #f8fafc; border-color: #d3d9e6; }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.danger:hover { background: #ffe4e9; }
.btn.ok { background: var(--ok-soft); color: var(--ok); }
.btn.small { padding: 8px 13px; font-size: 13px; }
.btn.block { display: block; width: 100%; margin-top: 8px; padding: 13px; }

/* ---------- Loading ---------- */
.screen {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.spinner {
  width: 42px; height: 42px;
  border: 4px solid var(--line); border-top-color: var(--brand);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Landing ---------- */
.landing {
  max-width: 940px; width: 100%;
  display: grid; grid-template-columns: 1.1fr .9fr; gap: 48px;
  align-items: center;
  padding: 40px 8px;
}
.landing-logo {
  width: 66px; height: 66px; border-radius: 16px;
  box-shadow: 0 10px 30px rgba(79,70,229,.32); margin-bottom: 20px;
}
.landing-title { font-size: 40px; font-weight: 800; letter-spacing: -.02em; }
.landing-tag { font-size: 19px; font-weight: 600; color: var(--ink); margin-top: 10px; }
.landing-sub { color: var(--muted); margin-top: 12px; font-size: 15px; max-width: 460px; }
.landing-note { color: var(--faint); font-size: 13px; margin-top: 16px; }
.btn-google {
  display: inline-flex; align-items: center; gap: 10px;
  background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 13px 22px;
  font-size: 15px; font-weight: 600; color: var(--ink);
  cursor: pointer; box-shadow: var(--shadow-sm); margin-top: 26px;
  transition: transform .1s, box-shadow .15s;
}
.btn-google:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }

.landing-features { display: flex; flex-direction: column; gap: 14px; }
.feat {
  display: flex; gap: 14px; align-items: flex-start;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm);
}
.feat-ic {
  font-size: 20px; width: 42px; height: 42px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--brand-soft); border-radius: 11px;
}
.feat b { display: block; font-size: 14.5px; }
.feat span { display: block; color: var(--muted); font-size: 13px; margin-top: 3px; }

@media (max-width: 820px) {
  .landing { grid-template-columns: 1fr; gap: 30px; text-align: left; }
  .landing-title { font-size: 34px; }
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: rgba(255,255,255,.85); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 12px 22px; position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 800; font-size: 17px; display: flex; align-items: center; gap: 9px; letter-spacing: -.01em; }
.brand-logo { width: 28px; height: 28px; border-radius: 8px; }
.user-box { display: flex; align-items: center; gap: 12px; }
.user-name { font-size: 13.5px; color: var(--muted); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.wrap { max-width: 1000px; margin: 0 auto; padding: 30px 22px 70px; }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.section-head h2 { font-size: 23px; font-weight: 800; letter-spacing: -.01em; }
.section-head .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }

/* ---------- Admin scope tabs ---------- */
.admin-tabs {
  display: inline-flex; background: #eef1f6; border: 1px solid var(--line);
  border-radius: 11px; padding: 3px; margin-bottom: 18px;
}
.seg {
  border: none; background: transparent; padding: 8px 16px; border-radius: 8px;
  font-size: 13.5px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.seg.active { background: #fff; color: var(--brand-dark); box-shadow: var(--shadow-sm); }

/* ---------- Document grid ---------- */
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.doc-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow-sm); transition: box-shadow .15s, transform .1s;
  display: flex; flex-direction: column; gap: 14px;
}
.doc-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.doc-card-top { display: flex; gap: 13px; align-items: flex-start; }
.doc-ic {
  font-size: 20px; width: 44px; height: 44px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--brand-soft); border-radius: 11px;
}
.doc-card-title { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-card-meta { color: var(--faint); font-size: 12.5px; margin-top: 3px; }
.doc-fields { display: flex; flex-direction: column; gap: 8px; }
.mini-label { font-size: 11px; font-weight: 700; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 3px; }
.copy-row { display: flex; gap: 8px; }
.copy-row .input { flex: 1; min-width: 0; }
.doc-card-actions { display: flex; gap: 8px; margin-top: 2px; }
.doc-card-actions .btn { flex: 1; }

/* ---------- Inputs ---------- */
.input {
  width: 100%; border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 13px; font-size: 14px; font-family: inherit; color: var(--ink);
  background: #fff; transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79,70,229,.14); }
.input[readonly] { background: #f8fafc; color: var(--muted); }
.field-label { display: block; font-size: 13px; font-weight: 600; margin: 16px 0 7px; }
.field-label .req { color: var(--faint); font-weight: 500; font-size: 12px; }
.field-hint { color: var(--muted); font-size: 12.5px; margin-top: 8px; }
.pw-row { display: flex; gap: 8px; }
.pw-row .input { flex: 1; }

/* ---------- Email chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 8px; }
.chips:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  background: var(--brand-soft); color: var(--brand-dark);
  border-radius: 8px; padding: 5px 9px; font-size: 12.5px; font-weight: 600;
}
.chip > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { border: none; background: transparent; color: var(--brand-dark); cursor: pointer; font-size: 11px; padding: 0; line-height: 1; opacity: .65; }
.chip button:hover { opacity: 1; }
.chips.readonly .chip { background: #f1f5f9; color: var(--muted); }
.chip.more { background: #e2e8f0; color: var(--muted); }
.chip.none { background: transparent; color: var(--faint); font-weight: 500; padding-left: 0; }
.mini-chips { margin-bottom: 0; }
.mini-chips .chip { font-size: 11.5px; padding: 3px 8px; background: #f1f5f9; color: var(--muted); }

/* ---------- Empty state ---------- */
.empty-card {
  text-align: center; background: var(--card); border: 1px dashed #d3d9e6;
  border-radius: var(--radius); padding: 54px 24px;
}
.empty-ic { font-size: 40px; margin-bottom: 12px; }
.empty-card h3 { font-size: 18px; }
.empty-card p { color: var(--muted); font-size: 14px; margin: 8px auto 20px; max-width: 360px; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(15,23,42,.5); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-card {
  background: var(--card); border-radius: 20px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 460px; padding: 28px; position: relative;
  max-height: 92vh; overflow-y: auto;
}
.modal-x {
  position: absolute; top: 16px; right: 16px; border: none; background: #f1f5f9;
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer; color: var(--muted); font-size: 13px;
}
.modal-x:hover { background: #e2e8f0; }
.modal-title { font-size: 19px; font-weight: 800; margin-bottom: 16px; }

.dropzone {
  border: 2px dashed #cbd3e1; border-radius: var(--radius); padding: 30px 20px;
  text-align: center; cursor: pointer; transition: border-color .15s, background .15s; color: var(--muted); font-size: 14px;
}
.dropzone.drag { border-color: var(--brand); background: var(--brand-soft); }
.dropzone.filled { border-style: solid; border-color: var(--brand); background: var(--brand-soft); color: var(--ink); }
.dz-icon { font-size: 32px; margin-bottom: 8px; }

.up-status { text-align: center; font-weight: 600; margin: 18px 0 14px; }
.bar { background: var(--line); border-radius: 99px; height: 10px; overflow: hidden; }
.bar-fill { background: var(--brand); height: 100%; width: 0%; border-radius: 99px; transition: width .2s; }

.done-ic { font-size: 40px; text-align: center; }
.done-sub { text-align: center; color: var(--muted); font-size: 14px; margin: 6px 0 4px; }

/* ---------- Password gate ---------- */
.gate-card {
  background: var(--card); border-radius: 20px; box-shadow: var(--shadow-md);
  width: 100%; max-width: 400px; padding: 36px 30px; text-align: center;
}
.gate-logo { width: 54px; height: 54px; border-radius: 13px; box-shadow: 0 8px 22px rgba(79,70,229,.28); }
.gate-lock { font-size: 30px; margin: 14px 0 6px; }
.gate-card h2 { font-size: 21px; font-weight: 800; }
.gate-sub { color: var(--muted); font-size: 14px; margin: 8px 0 20px; }
.gate-card .input { margin-bottom: 10px; text-align: left; }
.gate-error { color: var(--danger); font-size: 13px; font-weight: 600; margin-top: 12px; }
.gate-home { display: inline-block; margin-top: 18px; color: var(--faint); font-size: 13px; text-decoration: none; }
.gate-home:hover { color: var(--muted); text-decoration: underline; }

/* ---------- Viewer ---------- */
#viewer {
  position: fixed; inset: 0; background: #1e293b; z-index: 50;
  display: flex; flex-direction: column;
  user-select: none; -webkit-user-select: none;
}
.viewer-bar {
  display: flex; align-items: center; gap: 12px;
  background: #0f172a; color: #e2e8f0; padding: 10px 14px;
}
.viewer-bar .btn.ghost { background: transparent; color: #e2e8f0; border-color: #334155; }
.viewer-bar .btn.ghost:hover { background: #1e293b; }
#viewer-title { flex: 1; min-width: 0; font-weight: 700; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-nav { display: flex; align-items: center; gap: 8px; }
.navbtn {
  background: #1e293b; border: 1px solid #334155; color: #e2e8f0;
  width: 36px; height: 36px; border-radius: 9px; font-size: 18px; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .12s;
}
.navbtn:hover:not(:disabled) { background: #334155; }
.navbtn:disabled { opacity: .35; cursor: default; }
.pageinfo { font-size: 13px; color: #cbd5e1; min-width: 58px; text-align: center; white-space: nowrap; }

.viewer-stage {
  flex: 1; overflow: hidden; position: relative;
  display: flex; align-items: center; justify-content: center;
  padding: 14px; touch-action: pan-y;
}
.viewer-stage.fit-width { overflow-y: auto; align-items: flex-start; }
.page-img {
  max-width: 100%; max-height: 100%; object-fit: contain;
  border-radius: 6px; box-shadow: 0 6px 22px rgba(0,0,0,.4);
  display: block; pointer-events: none;
}
.viewer-stage.fit-width .page-img { max-height: none; width: 100%; }
.stage-msg { color: #94a3b8; font-size: 14px; text-align: center; }

@media (max-width: 520px) {
  #viewer-title { display: none; }
}

@media print {
  body * { display: none !important; }
  body::after { content: "This document cannot be printed."; display: block !important; font-size: 20px; padding: 40px; }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #0f172a; color: #fff; border-radius: var(--radius-sm);
  padding: 12px 20px; font-size: 14px; z-index: 100; box-shadow: var(--shadow-lg);
  max-width: 90vw; text-align: center;
}
.toast.err { background: var(--danger); }

.docx-work { position: fixed; left: -12000px; top: 0; width: 900px; background: #fff; }

/* ---------- Consent + legal ---------- */
.consent {
  display: flex; align-items: flex-start; gap: 9px; text-align: left;
  font-size: 13px; color: var(--muted); max-width: 340px; margin: 22px 0 4px;
}
.gate-card .consent { margin-left: auto; margin-right: auto; }
.consent input { margin-top: 2px; flex: none; width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }
.consent a { color: var(--brand); text-decoration: none; }
.consent a:hover { text-decoration: underline; }
.btn-google:disabled { opacity: .5; cursor: not-allowed; }
.btn-google:disabled:hover { transform: none; box-shadow: var(--shadow-sm); }

.landing-legal { margin-top: 14px; font-size: 12.5px; color: var(--faint); }
.landing-legal a { color: var(--muted); text-decoration: none; }
.landing-legal a:hover { color: var(--brand); text-decoration: underline; }

.site-footer {
  border-top: 1px solid var(--line); background: var(--card);
  padding: 18px 22px; text-align: center;
  font-size: 12.5px; color: var(--faint);
  display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; align-items: center;
}
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--brand); text-decoration: underline; }
.site-footer .dot { opacity: .5; }

.legal-meta { font-size: 12px; color: var(--faint) !important; margin-bottom: 12px !important; }
.legal-body { max-height: 56vh; overflow-y: auto; font-size: 13.5px; color: var(--ink); line-height: 1.55; margin-bottom: 10px; }
.legal-body h4 { font-size: 14px; margin: 15px 0 5px; }
.legal-body p { margin-bottom: 8px; color: var(--muted); }
.legal-body ul { margin: 0 0 8px 18px; color: var(--muted); }
.legal-body li { margin-bottom: 4px; }
.legal-contact { font-weight: 600; color: var(--ink) !important; margin-top: 12px; }

@media (max-width: 560px) {
  .topbar { padding: 10px 14px; }
  .user-name { display: none; }
  .wrap { padding: 20px 14px 56px; }
  .section-head { flex-direction: column; align-items: stretch; }
  .doc-grid { grid-template-columns: 1fr; }
}
