:root {
  --bg: #0c1014;
  --card-bg: #141b23;
  --card-bg-2: #19222c;
  --card-bg-hover: #1c2632;
  --white: #f0ebe1;
  --muted: #9a9490;
  --muted-2: #6a6660;
  --line: rgba(240, 235, 225, .09);
  --line-strong: rgba(240, 235, 225, .18);
  --accent: #e8c48a;
  --accent-soft: rgba(232, 196, 138, .14);
  --danger: #e88a8a;
}

* { box-sizing: border-box; }
html, body { overflow-x: hidden; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--white);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }

.site {
  position: relative;
  min-height: 100svh;
  isolation: isolate;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.auth-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin: 0 0 18px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 12px;
}
.auth-tab {
  flex: 1;
  padding: 10px 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: rgba(255,255,255,.55);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: .18s;
}
.auth-tab:hover { color: #fff; }
.auth-tab.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.auth-pane { display: none; }
.auth-pane.is-active { display: block; }

/* ===== Состояния сертификатов ===== */
.cert-loading,
.cert-empty {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border-radius: 10px;
  background: rgba(255,255,255,.03);
  border: 1px dashed rgba(255,255,255,.12);
  color: rgba(255,255,255,.7);
  font-size: 14px;
  line-height: 1.5;
}

.cert-loading[hidden],
.cert-empty[hidden],
#signatureForm[hidden] {
  display: none !important;
}

.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(232,196,138,.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.cert-empty {
  display: block;
  padding: 18px;
}
.cert-empty-title {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  margin-bottom: 6px;
}
.cert-empty-text {
  font-size: 13px;
  line-height: 1.5;
  color: rgba(255,255,255,.65);
}
.cert-empty-text a { color: var(--accent); }

.btn-ghost {
  display: inline-block;
  margin-top: 10px;
  padding: 6px 12px;
  border: 1px solid rgba(232,196,138,.4);
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.btn-ghost:hover { background: rgba(232,196,138,.1); }

.signature-hint {
  margin: 12px 0 0;
  font-size: 12px;
  color: rgba(255,255,255,.45);
  text-align: center;
}

.btn-login:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.site::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -3;
  pointer-events: none;
  background:
    radial-gradient(ellipse 60% 50% at 55% 40%, rgba(80, 120, 160, .1), transparent 60%),
    radial-gradient(ellipse 45% 40% at 90% 12%, rgba(110, 90, 180, .07), transparent 60%),
    radial-gradient(ellipse 45% 40% at 15% 85%, rgba(180, 140, 80, .04), transparent 60%);
}

.stars {
  position: fixed; z-index: -2; inset: 0;
  opacity: .45; pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 8% 14%, #fff 45%, transparent 100%),
    radial-gradient(1px 1px at 18% 72%, #fff 45%, transparent 100%),
    radial-gradient(1px 1px at 27% 31%, #fff 45%, transparent 100%),
    radial-gradient(1px 1px at 37% 82%, #fff 45%, transparent 100%),
    radial-gradient(1px 1px at 48% 17%, #fff 45%, transparent 100%),
    radial-gradient(1px 1px at 57% 69%, #fff 45%, transparent 100%),
    radial-gradient(1px 1px at 67% 25%, #fff 45%, transparent 100%),
    radial-gradient(1px 1px at 78% 77%, #fff 45%, transparent 100%),
    radial-gradient(1px 1px at 89% 35%, #fff 45%, transparent 100%),
    radial-gradient(1px 1px at 95% 87%, #fff 45%, transparent 100%);
  background-size: 510px 420px;
}

.header {
  position: relative; z-index: 3;
  height: 64px;
  border-bottom: 1px solid var(--line);
  background: rgba(12, 16, 20, .7);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.header-inner {
  width: min(1500px, calc(100% - 72px));
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  margin: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: max-content;
}
.brand-mark {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 15px;
  font-weight: 700;
}
.brand-name {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -.01em;
  color: var(--white);
  white-space: nowrap;
}

.header-link {
  color: var(--muted);
  font-size: 14px;
  transition: color .2s;
}
.header-link:hover { color: var(--white); }

.main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  position: relative;
  z-index: 2;
}

.login-wrap {
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.login-head { text-align: center; }
.login-head h1 {
  margin: 0 0 12px;
  font-size: 40px;
  font-weight: 600;
  letter-spacing: -.04em;
  line-height: 1;
  color: var(--white);
}
.login-head h1 em {
  font-style: normal;
  color: var(--accent);
}
.login-head p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}

.login-card {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 40px 36px 36px;
  box-shadow: 0 1px 0 rgba(240, 235, 225, .04), 0 24px 60px rgba(0, 0, 0, .35);
  position: relative;
  overflow: hidden;
}
.login-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: .55;
}

.error-msg {
  display: none;
  padding: 12px 16px;
  border-radius: 8px;
  background: rgba(232, 138, 138, .1);
  color: var(--danger);
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 24px;
}
.error-msg.show { display: block; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 28px;
}
.field label {
  color: var(--muted-2);
  font-size: 11px;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.field input {
  width: 100%;
  padding: 10px 0 12px;
  border: 0;
  border-bottom: 1px solid var(--line-strong);
  border-radius: 0;
  background: transparent;
  color: var(--white);
  font: inherit;
  font-size: 17px;
  letter-spacing: -.01em;
  outline: none;
  transition: border-color .25s;
}
.field input::placeholder {
  color: var(--muted-2);
  font-size: 16px;
}
.field input:focus {
  border-bottom-color: var(--accent);
}

.field-password { position: relative; }
.field-password input { padding-right: 40px; }

.toggle-pass {
  position: absolute;
  right: 0;
  bottom: 10px;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: 0;
  background: transparent;
  color: var(--muted-2);
  border-radius: 6px;
  transition: color .2s;
}
.toggle-pass:hover { color: var(--white); }
.toggle-pass svg { width: 18px; height: 18px; }

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 30px;
  flex-wrap: wrap;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.checkbox input {
  appearance: none;
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
  position: relative;
  transition: border-color .2s, background-color .2s;
}
.checkbox input:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.checkbox input:checked::after {
  content: "";
  position: absolute;
  left: 5px; top: 1px;
  width: 5px; height: 10px;
  border: solid #0c1014;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.link-accent {
  color: var(--accent);
  font-size: 13px;
  transition: opacity .2s;
}
.link-accent:hover { opacity: .8; }

.btn-login {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 17px 24px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #0c1014;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  transition: transform .2s, box-shadow .25s, background-color .2s;
}
.btn-login:hover {
  transform: translateY(-1px);
  background: #eed4a3;
  box-shadow: 0 12px 28px rgba(232, 196, 138, .28);
}
.btn-login:disabled {
  opacity: .7;
  cursor: not-allowed;
  transform: none;
}
.btn-login svg { width: 16px; height: 16px; }

.register-block {
  padding: 24px 28px;
  border-radius: 14px;
  background: var(--card-bg-2);
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}
.register-block .txt {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.register-block strong {
  color: var(--white);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: -.01em;
}
.register-block span {
  color: var(--muted-2);
  font-size: 13px;
  line-height: 1.5;
}
.register-block .arrow-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 8px;
  background: rgba(232, 196, 138, .1);
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color .2s, color .2s;
}
.register-block .arrow-link:hover {
  background: var(--accent);
  color: #0c1014;
}

.login-hint {
  text-align: center;
  color: var(--muted-2);
  font-size: 13px;
  line-height: 1.6;
}
.login-hint a {
  color: var(--muted);
  transition: color .2s;
}
.login-hint a:hover { color: var(--white); }

.footer {
  position: relative; z-index: 2;
  border-top: 1px solid var(--line);
  padding: 22px 0;
  color: var(--muted-2);
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.footer-inner {
  width: min(1500px, calc(100% - 72px));
  margin: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translate(-50%, 20px);
  padding: 14px 24px;
  border-radius: 10px;
  background: var(--card-bg-hover);
  color: var(--white);
  font-size: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
  opacity: 0;
  visibility: hidden;
  transition: opacity .3s, transform .3s, visibility .3s;
  z-index: 100;
}
.toast.show {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}

/* ===== Триггер выбора сертификата ===== */
.cert-trigger {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: rgba(255,255,255,.03);
  color: var(--white);
  font: inherit;
  cursor: pointer;
  text-align: left;
  transition: .18s;
}
.cert-trigger:hover {
  border-color: rgba(232,196,138,.4);
  background: rgba(232,196,138,.05);
}
.cert-trigger.is-selected {
  border-color: rgba(232,196,138,.5);
}
.cert-trigger-icon {
  flex: none;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
}
.cert-trigger-icon svg { width: 20px; height: 20px; }
.cert-trigger-text {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 2px;
}
.cert-trigger-title {
  font-size: 14px; font-weight: 600;
  color: var(--white);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cert-trigger-sub {
  font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cert-trigger-chevron {
  flex: none; width: 16px; height: 16px;
  color: var(--muted);
}

/* ===== Модалка сертификатов ===== */
body.cert-modal-open { overflow: hidden; }

.cert-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.cert-modal[hidden] { display: none !important; }

.cert-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 9, 12, .7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: certModalFade .2s ease;
}
@keyframes certModalFade {
  from { opacity: 0; } to { opacity: 1; }
}

.cert-modal-dialog {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: min(80vh, 720px);
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  background: var(--card-bg);
  border: 1px solid var(--line-strong);
  box-shadow: 0 30px 80px rgba(0,0,0,.55);
  animation: certModalIn .22s cubic-bezier(.2,.8,.2,1);
  overflow: hidden;
}
@keyframes certModalIn {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

.cert-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px 16px;
  border-bottom: 1px solid var(--line);
}
.cert-modal-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -.01em;
  color: var(--white);
}
.cert-modal-sub {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted-2);
  letter-spacing: .04em;
  text-transform: uppercase;
}
.cert-modal-close {
  flex: none;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  transition: .18s;
}
.cert-modal-close:hover {
  color: var(--white);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.cert-modal-close svg { width: 16px; height: 16px; }

.cert-modal-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cert-modal-item {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  width: 100%;
  padding: 14px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: rgba(255,255,255,.02);
  color: var(--white);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: .15s;
}
.cert-modal-item:hover {
  background: rgba(232,196,138,.06);
  border-color: rgba(232,196,138,.25);
}
.cert-modal-item:focus-visible {
  outline: none;
  border-color: var(--accent);
  background: rgba(232,196,138,.08);
}
.cert-modal-item.is-active {
  background: var(--accent-soft);
  border-color: rgba(232,196,138,.45);
}

.cert-modal-item-icon {
  flex: none;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
}
.cert-modal-item-icon svg { width: 20px; height: 20px; }

.cert-modal-item-body {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 4px;
}
.cert-modal-item-org {
  font-size: 14px; font-weight: 600;
  color: var(--white);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cert-modal-item-fio {
  font-size: 13px; color: rgba(240,235,225,.8);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cert-modal-item-meta {
  display: flex; flex-wrap: wrap; gap: 10px;
  font-size: 11px; color: var(--muted-2);
}
.cert-modal-item-meta span { position: relative; }
.cert-modal-item-meta span + span::before {
  content: '·';
  position: absolute;
  left: -7px;
  color: rgba(240,235,225,.25);
}

.cert-modal-item-check {
  flex: none;
  width: 22px; height: 22px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: transparent;
  color: var(--accent);
  opacity: 0;
  transition: opacity .15s;
}
.cert-modal-item-check svg { width: 16px; height: 16px; }
.cert-modal-item.is-active .cert-modal-item-check { opacity: 1; }

@media (max-width: 900px) {
  .header-inner, .footer-inner { width: calc(100% - 48px); }
}

@media (max-width: 650px) {
  .header { height: 56px; }
  .header-inner, .footer-inner { width: calc(100% - 36px); }
  .main { padding: 40px 18px; }

  .login-head h1 { font-size: 32px; }
  .login-head p { font-size: 14px; }

  .login-card { padding: 30px 22px 26px; border-radius: 12px; }
  .field input { font-size: 16px; }

  .register-block { padding: 20px 22px; }
  .register-block .arrow-link { width: 100%; justify-content: center; }

  .footer-inner { flex-direction: column; align-items: flex-start; gap: 8px; }

  .cert-modal { padding: 12px; }
  .cert-modal-dialog { max-height: 90vh; border-radius: 14px; }
  .cert-modal-head { padding: 18px 18px 14px; }
  .cert-modal-title { font-size: 16px; }
}

@media (max-width: 400px) {
  .brand-name { font-size: 13px; }
  .header-link { font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}