:root {
  --bg: #050505;
  --bg-soft: #0d0d0d;
  --panel: rgba(18, 18, 18, .88);
  --panel-strong: rgba(24, 24, 24, .94);
  --card: rgba(255, 255, 255, .045);
  --card-hover: rgba(255, 255, 255, .075);
  --line: rgba(255, 255, 255, .12);
  --line-soft: rgba(255, 255, 255, .075);
  --gold: #d4af37;
  --gold-light: #f2d36b;
  --gold-soft: rgba(212, 175, 55, .15);
  --silver: #e8edf0;
  --text: #f7f4ed;
  --muted: #a9a39a;
  --muted-2: #77716a;
  --danger: #ff6767;
  --success: #35d48a;
  --shadow: 0 24px 80px rgba(0, 0, 0, .42);
  --shadow-soft: 0 16px 44px rgba(0, 0, 0, .25);
  --radius: 24px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --sidebar: 310px;
}

* { box-sizing: border-box; }
html { min-height: 100%; scroll-behavior: smooth; }
body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  font-family: Inter, Arial, Helvetica, sans-serif;
  background:
    radial-gradient(circle at 18% -10%, rgba(212,175,55,.20), transparent 26%),
    radial-gradient(circle at 100% 5%, rgba(232,237,240,.08), transparent 26%),
    linear-gradient(135deg, #030303 0%, #0d0d0d 48%, #050505 100%);
  overflow-x: hidden;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,.75), transparent 78%);
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
img { max-width: 100%; display: block; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  z-index: 5;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 26px;
  padding: 26px;
  border-right: 1px solid var(--line);
  background: rgba(5, 5, 5, .88);
  backdrop-filter: blur(18px);
  box-shadow: 18px 0 60px rgba(0,0,0,.22);
}
.brand-block {
  display: grid;
  gap: 16px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line-soft);
}
.brand-logo-wrap {
  width: 100%;
  min-height: 108px;
  display: grid;
  place-items: center;
  padding: 14px;
  border: 1px solid rgba(212,175,55,.22);
  border-radius: 22px;
  background:
    radial-gradient(circle at 50% 0%, rgba(212,175,55,.15), transparent 55%),
    linear-gradient(160deg, rgba(255,255,255,.055), rgba(255,255,255,.02));
}
.brand-logo { width: 235px; max-height: 95px; object-fit: contain; }
.brand-fallback {
  display: none;
  width: 78px;
  height: 78px;
  place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(212,175,55,.55);
  color: var(--gold-light);
  font-weight: 900;
  letter-spacing: -.08em;
  background: linear-gradient(145deg, rgba(212,175,55,.24), rgba(255,255,255,.05));
}
.eyebrow {
  margin: 0 0 7px;
  color: var(--gold-light);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .18em;
  text-transform: uppercase;
}
h1, h2, h3, h4, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 23px; letter-spacing: -.02em; }
h2 { margin-bottom: 0; max-width: 960px; font-size: clamp(29px, 4vw, 50px); line-height: .98; letter-spacing: -.055em; }
h3 { margin-bottom: 0; font-size: 22px; letter-spacing: -.025em; }
h4 { margin-bottom: 10px; font-size: 16px; }

.nav { display: grid; gap: 10px; }
.nav-link {
  position: relative;
  width: 100%;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 14px 16px 14px 18px;
  border: 1px solid transparent;
  border-radius: 16px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
  text-align: left;
  transition: transform .16s ease, background .16s ease, border-color .16s ease, color .16s ease;
}
.nav-link::before {
  content: "";
  width: 8px;
  height: 8px;
  margin-right: 12px;
  border-radius: 50%;
  background: var(--muted-2);
  box-shadow: none;
}
.nav-link:hover,
.nav-link.active {
  color: var(--text);
  border-color: rgba(212,175,55,.38);
  background: linear-gradient(90deg, rgba(212,175,55,.18), rgba(255,255,255,.035));
  transform: translateX(2px);
}
.nav-link.active::before { background: var(--gold-light); box-shadow: 0 0 18px rgba(242,211,107,.65); }

.status-card {
  margin-top: auto;
  display: flex;
  gap: 12px;
  padding: 16px;
  border: 1px solid rgba(53,212,138,.28);
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(53,212,138,.10), rgba(255,255,255,.025));
}
.status-card strong { display: block; font-size: 14px; }
.status-card p { margin: 6px 0 0; color: var(--muted); font-size: 12.5px; line-height: 1.45; }
.status-dot { flex: 0 0 auto; width: 10px; height: 10px; margin-top: 5px; border-radius: 50%; background: var(--success); box-shadow: 0 0 18px var(--success); }

.main {
  position: relative;
  z-index: 1;
  min-width: 0;
  padding: 34px;
}
.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 26px;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(255,255,255,.065), rgba(255,255,255,.025)),
    radial-gradient(circle at 100% 0%, rgba(212,175,55,.12), transparent 32%);
  box-shadow: var(--shadow-soft);
}
.top-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }
.grid { display: grid; gap: 22px; }
.two-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.panel {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(160deg, rgba(255,255,255,.062), rgba(255,255,255,.025));
  box-shadow: var(--shadow-soft);
}
.panel + .panel { margin-top: 22px; }
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}
.counter {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  padding: 6px 11px;
  border: 1px solid rgba(212,175,55,.28);
  border-radius: 999px;
  color: var(--gold-light);
  background: rgba(212,175,55,.09);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.dropzone {
  position: relative;
  min-height: 230px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 9px;
  padding: 28px;
  border: 1px dashed rgba(212,175,55,.60);
  border-radius: 20px;
  color: var(--text);
  background:
    radial-gradient(circle at 50% 0%, rgba(212,175,55,.08), transparent 42%),
    rgba(0,0,0,.24);
  text-align: center;
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
}
.dropzone.compact { min-height: 155px; }
.dropzone.dragover { transform: translateY(-2px); border-color: var(--gold-light); background: rgba(212,175,55,.12); }
.dropzone input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.dropzone strong { font-size: 18px; letter-spacing: -.02em; }
.dropzone small { color: var(--muted); line-height: 1.35; }
.drop-icon {
  width: 58px;
  height: 58px;
  display: inline-grid;
  place-items: center;
  border-radius: 16px;
  color: #111;
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  box-shadow: 0 18px 35px rgba(212,175,55,.18);
  font-weight: 950;
  letter-spacing: -.06em;
}

.file-list, .result-list, .template-cards { display: grid; gap: 10px; margin-top: 14px; }
.empty { color: var(--muted); }
.file-row, .result-row, .template-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 15px;
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  background: rgba(0,0,0,.22);
}
.file-row:hover, .result-row:hover, .template-card:hover { background: var(--card-hover); border-color: rgba(212,175,55,.22); }
.file-row small, .result-row small, .template-card small { color: var(--muted); }
.list-toolbar { display: flex; justify-content: flex-end; margin-top: 10px; }

.signature-preview {
  min-height: 82px;
  display: grid;
  place-items: center;
  margin: 14px 0 18px;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  background: rgba(255,255,255,.035);
  overflow: hidden;
}
.signature-preview img { max-width: 270px; max-height: 74px; object-fit: contain; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid.single { grid-template-columns: 1fr; }
label { display: grid; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 800; }
input, select, textarea {
  width: 100%;
  min-height: 46px;
  padding: 12px 13px;
  border: 1px solid var(--line-soft);
  border-radius: 13px;
  outline: none;
  color: var(--text);
  background: rgba(0,0,0,.50);
  transition: border-color .14s ease, box-shadow .14s ease, background .14s ease;
}
input::placeholder { color: rgba(247,244,237,.38); }
input:focus, select:focus, textarea:focus { border-color: rgba(242,211,107,.78); box-shadow: 0 0 0 4px rgba(212,175,55,.12); background: rgba(0,0,0,.70); }
select { appearance: auto; }
textarea {
  min-height: 460px;
  resize: vertical;
  font-family: Consolas, Monaco, monospace;
  font-size: 13px;
  line-height: 1.45;
}

.btn {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border: 1px solid transparent;
  border-radius: 14px;
  color: var(--text);
  background: rgba(255,255,255,.06);
  font-weight: 900;
  text-decoration: none;
  transition: transform .15s ease, background .15s ease, border-color .15s ease, opacity .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-primary { color: #111; background: linear-gradient(135deg, var(--gold), var(--gold-light)); box-shadow: 0 16px 36px rgba(212,175,55,.17); }
.btn-secondary { color: var(--gold-light); border-color: rgba(212,175,55,.35); background: rgba(212,175,55,.10); }
.btn-ghost { color: var(--muted); border-color: var(--line-soft); background: transparent; }
.btn.small { min-height: 34px; padding: 8px 11px; border-radius: 11px; font-size: 12px; }
.btn.big { min-height: 56px; padding: 16px 26px; font-size: 18px; }
.file-button { position: relative; overflow: hidden; }
.file-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.button-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

.action-panel {
  margin-top: 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  border-color: rgba(212,175,55,.28);
  background:
    linear-gradient(135deg, rgba(212,175,55,.11), rgba(255,255,255,.025)),
    rgba(18,18,18,.88);
}
.action-panel .muted { max-width: 760px; margin: 10px 0 0; color: var(--muted); line-height: 1.55; }
.action-stack { display: grid; justify-items: end; gap: 10px; }
.progress-text { color: var(--muted); font-size: 13px; }
.results-panel { margin-top: 22px; }

.calibration-grid { align-items: start; }
.coord-box { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 16px; }
.hint-box {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid rgba(212,175,55,.22);
  border-radius: 16px;
  background: rgba(212,175,55,.075);
}
.hint-box p { margin: 8px 0 0; color: var(--muted); line-height: 1.52; }
.preview-panel { overflow: hidden; }
.pdf-preview-wrap {
  position: relative;
  min-height: 540px;
  display: grid;
  place-items: start center;
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--line-soft);
  border-radius: 18px;
  background: #242424;
}
#pdfCanvas { max-width: 100%; height: auto; background: #fff; box-shadow: 0 22px 48px rgba(0,0,0,.38); }
.preview-placeholder { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; color: var(--muted); text-align: center; }
.marker { position: absolute; pointer-events: none; border: 2px solid var(--gold-light); background: rgba(212,175,55,.14); box-shadow: 0 0 0 9999px rgba(0,0,0,.025); }
.marker.date { width: 110px !important; height: 18px !important; }
.hidden { display: none !important; }

.doc-panel p { color: var(--muted); line-height: 1.58; }
.doc-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-top: 20px; }
.doc-card { min-height: 160px; padding: 18px; border: 1px solid var(--line-soft); border-radius: 18px; background: rgba(0,0,0,.20); }
.doc-card.warning { border-color: rgba(255,103,103,.35); background: rgba(255,103,103,.06); }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 50; max-width: 460px; padding: 14px 16px; border: 1px solid rgba(212,175,55,.36); border-radius: 16px; background: rgba(12,12,12,.95); box-shadow: var(--shadow); color: var(--text); }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .brand-block { grid-template-columns: 170px 1fr; align-items: center; }
  .brand-logo-wrap { min-height: 82px; }
  .brand-logo { width: 150px; max-height: 62px; }
  .nav { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .status-card { margin-top: 0; }
  .two-cols { grid-template-columns: 1fr; }
  .doc-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .main, .sidebar { padding: 18px; }
  .brand-block { grid-template-columns: 1fr; }
  .topbar, .action-panel { flex-direction: column; align-items: stretch; }
  .top-actions, .action-stack { width: 100%; justify-items: stretch; }
  .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid, .coord-box, .doc-grid { grid-template-columns: 1fr; }
  .btn { width: 100%; }
  .panel { padding: 18px; border-radius: 20px; }
  .dropzone { min-height: 185px; }
  h2 { font-size: 31px; }
}
@media print {
  body { background: white; color: black; }
  .sidebar, .top-actions, .nav, .btn { display: none !important; }
  .app-shell { display: block; }
  .panel { box-shadow: none; border-color: #ddd; }
}
