:root {
  --bg: #f1f1f1;
  --card: #ffffff;
  --text: #1f1f1f;
  --text-soft: #595959;
  --muted: #8c8c8c;
  --primary: #1677ff;
  --primary-hover: #4096ff;
  --primary-active: #0958d9;
  --primary-soft: #e6f4ff;
  --accent: #22d3ee;
  --border: #d9d9d9;
  --border-soft: #f0f0f0;
  --error: #ff4d4f;
  --error-bg: #fff2f0;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.12);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

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

button { font-family: inherit; }

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

.layout {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 32px;
  background: transparent;
}

.brand-logo {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}
.dmed-img { display: block; }
.dmed-img--brand {
  height: 56px;
  width: auto;
}

/* ─── Language dropdown ──────────────────────────────── */

.lang-dropdown { position: relative; }
.lang-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: #fff;
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.lang-trigger:hover { border-color: var(--primary); }
.lang-trigger .flag { font-size: 16px; line-height: 1; }
.lang-trigger .chev {
  width: 0; height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--muted);
  margin-left: 2px;
}

.lang-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 160px;
  background: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 4px;
  z-index: 10;
}
.lang-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 8px 12px;
  font-size: 14px;
  text-align: left;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
}
.lang-menu button:hover:not(:disabled) { background: var(--primary-soft); }
.lang-menu button:disabled {
  color: var(--muted);
  cursor: not-allowed;
}
.lang-menu button[aria-current="true"] { color: var(--primary); font-weight: 600; }

/* ─── Centered content (auth page) ───────────────────── */

.center {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 24px 16px 64px;
}

.auth-heading {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  margin: 0 0 32px;
  color: var(--text);
}

.auth-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 100%;
  max-width: 400px;
}

.input {
  width: 100%;
  padding: 11px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
  text-align: center;
}
.input::placeholder { color: var(--muted); letter-spacing: 0.5px; }
.input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(22, 119, 255, 0.12);
}
.input.error { border-color: var(--error); }

.btn {
  border: 0;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  padding: 11px 28px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
  min-width: 160px;
  font-family: inherit;
}
.btn:hover:not(:disabled) { background: var(--primary-hover); }
.btn:active:not(:disabled) { background: var(--primary-active); transform: translateY(1px); }
.btn:disabled {
  background: #e5e7eb;
  color: #9ca3af;
  cursor: not-allowed;
}
.btn.secondary {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--border);
}
.btn.secondary:hover:not(:disabled) {
  background: var(--primary-soft);
  border-color: var(--primary);
}

.alert {
  background: var(--error-bg);
  border: 1px solid #ffccc7;
  color: var(--error);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  text-align: center;
  width: 100%;
}

/* ─── PIN inputs ─────────────────────────────────────── */

.pin-row {
  display: flex;
  justify-content: center;
  gap: 12px;
}
.pin-row input {
  width: 56px;
  height: 64px;
  text-align: center;
  font-size: 24px;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.pin-row input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(22, 119, 255, 0.12);
}
.pin-row.error input { border-color: var(--error); }

/* ─── Help illustration ──────────────────────────────── */

.help-illustration {
  margin-top: 32px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  width: 100%;
  max-width: 480px;
}
.help-illustration .help-svg {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
}
.help-illustration .help-text {
  font-size: 13px;
  color: var(--text-soft);
  line-height: 1.5;
  text-align: center;
  max-width: 360px;
}

/* ─── Document view ──────────────────────────────────── */

.doc-shell {
  background: var(--bg);
  padding: 16px 0 64px;
  display: flex;
  justify-content: center;
}

/* Floating print button — bottom-right, Ant-default style */
.print-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #fff;
  color: rgba(0, 0, 0, 0.88);
  border: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  z-index: 10;
}
.print-fab:hover {
  color: var(--primary);
  border-color: var(--primary);
}
.print-fab:active {
  color: var(--primary-active);
  border-color: var(--primary-active);
}

#doc-content {
  margin: 0 auto;
  min-height: 841pt;
  width: 595pt;
  background: #fffffe;
  padding: 40px;
  font-size: 10.5pt;
  line-height: 12.5pt;
  user-select: none;
  box-shadow: var(--shadow);
}

#doc-content .doc-header { width: 100%; }
#doc-content .doc-header td { vertical-align: middle; text-align: center; padding: 0 6px; }
#doc-content .doc-header p { margin: 0; font-size: 12px; line-height: 1.2; }
#doc-content .doc-header .ministry { font-weight: 600; }
#doc-content .doc-header .emblem-cell { width: 33.333%; }
#doc-content .emblem-img {
  display: block;
  margin: 0 auto;
  width: 64px;
  height: 64px;
  object-fit: contain;
}
#doc-content .doc-title { margin-top: 18pt; text-align: center; }
#doc-content .doc-title h1 {
  margin: 0;
  font-size: 13.5pt;
  font-weight: 600;
  line-height: 16pt;
}
#doc-content .doc-title p {
  margin: 0;
  font-size: 13.5pt;
  font-weight: 600;
  line-height: 16pt;
}
#doc-content .institution {
  margin: 18pt 0 0;
  text-align: center;
  line-height: 1;
}
#doc-content .institution-sub {
  text-align: center;
  font-size: 9pt;
}
#doc-content .body {
  margin-top: 18pt;
  border-collapse: collapse;
  width: 100%;
}
#doc-content .body td {
  border: 1px solid;
  padding: 6pt;
  vertical-align: top;
}
#doc-content .body td.no { width: 5%; text-align: left; }
#doc-content .body .label { font-weight: 600; }
#doc-content .body .group-title { font-weight: 600; margin-bottom: 4px; }

#doc-content .footer {
  margin-top: 20pt;
  font-size: 9pt;
}
#doc-content .footer table { width: 100%; border-spacing: 0; border-collapse: collapse; }
#doc-content .footer td { padding: 0; vertical-align: middle; }

#doc-content .footer-logo img,
#doc-content .footer-logo svg { display: block; height: 22px; width: auto; }
#doc-content .footer-logo { margin-bottom: 8pt; }
.dmed-img--footer { height: 22px; width: auto; }
#doc-content .footer-uuid { margin-top: 12pt; }
#doc-content .footer-text {
  font-size: 9pt;
  line-height: 1.4;
}
#doc-content .pin-code {
  font-size: 26pt;
  font-weight: 600;
  text-align: right;
  padding-right: 8pt;
  white-space: nowrap;
}
#doc-content .qr-code-box svg {
  display: block;
  width: 98pt;
  height: 98pt;
}
#doc-content .uuid-line { margin: 0; line-height: 1; }
#doc-content .uuid-line + .uuid-line { margin-top: 4px; }
#doc-content .uuid-line .label { font-weight: 700; }

@media print {
  .page-header, .print-fab { display: none !important; }
  body, .layout, .doc-shell {
    background: #fff !important;
    padding: 0 !important;
  }
  #doc-content {
    box-shadow: none !important;
    width: auto !important;
    margin: 0 !important;
  }
}

/* ─── Loader ─────────────────────────────────────────── */

.loader {
  text-align: center;
  color: var(--muted);
  padding: 64px 24px;
  font-size: 14px;
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-soft);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
