/* ================================================================
   VGRA CONTRATOS — Redesigned UI
   Tally-inspired single-scroll, VGRA branded dark theme
   ================================================================ */
:root {
  --bg: #0C0E11;
  --bg-card: #13161B;
  --bg-input: #181C22;
  --bg-hover: #1E2330;
  --border: #252B38;
  --border-focus: #C8A962;
  --text: #E5E3DE;
  --text-2: #9BA3B0;
  --text-3: #5E6678;
  --gold: #C8A962;
  --gold-soft: rgba(200,169,98,.12);
  --green: #34D399;
  --green-soft: rgba(52,211,153,.10);
  --red: #F87171;
  --red-soft: rgba(248,113,113,.10);
  --blue: #60A5FA;
  --blue-soft: rgba(96,165,250,.10);
  --yellow: #FBBF24;
  --yellow-soft: rgba(251,191,36,.10);
  --font: 'DM Sans', system-ui, sans-serif;
  --font-display: 'Instrument Serif', Georgia, serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius: 8px;
  --radius-lg: 14px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-font-smoothing: antialiased; scroll-behavior: smooth; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.55; min-height: 100vh; }
::selection { background: var(--gold); color: var(--bg); }
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ============ LOGIN ============ */
.login-overlay {
  position: fixed; inset: 0; z-index: 999;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.login-overlay.hidden { display: none; }
.login-card { text-align: center; width: 380px; max-width: 90vw; }
.login-brand { display: flex; align-items: center; gap: 14px; justify-content: center; margin-bottom: 36px; }
.login-brand h1 { font-family: var(--font); font-size: 1.5rem; font-weight: 600; text-align: left; line-height: 1.2; }
.login-brand h1 span { color: var(--gold); }
.login-brand p { font-size: .8rem; color: var(--text-3); text-align: left; margin-top: 2px; }
.brand-mark {
  width: 48px; height: 48px; border-radius: 12px;
  background: var(--gold); color: var(--bg);
  font-family: var(--font-display); font-size: 1.6rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-weight: 400;
}
.brand-mark.sm { width: 32px; height: 32px; font-size: 1.1rem; border-radius: 8px; }
.login-field {
  display: flex; gap: 0; border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; background: var(--bg-input);
  transition: border-color .15s;
}
.login-field:focus-within { border-color: var(--gold); }
.login-field input {
  flex: 1; border: none; background: transparent; padding: 14px 16px;
  color: var(--text); font-family: var(--font); font-size: .95rem; outline: none;
}
.login-field input::placeholder { color: var(--text-3); }
.login-field button {
  width: 52px; background: var(--gold); border: none; color: var(--bg);
  font-size: 1.2rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.login-field button:hover { background: #D4B56E; }
.login-field button.loading .btn-label { display: none; }
.login-field button.loading .spinner { display: block; }
.login-field button .spinner { display: none; width: 16px; height: 16px; border: 2px solid transparent; border-top-color: var(--bg); border-radius: 50%; animation: spin .6s linear infinite; }
.login-error { display: block; margin-top: 10px; font-size: .82rem; color: var(--red); min-height: 20px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ TOPBAR ============ */
.topbar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 24px; background: rgba(12,14,17,.85);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-title { font-weight: 600; font-size: .9rem; }
.topbar-title span { color: var(--gold); }
.topbar-right { display: flex; gap: 4px; }
.link-btn {
  background: none; border: none; color: var(--text-2); font-family: var(--font);
  font-size: .8rem; padding: 6px 12px; border-radius: var(--radius); cursor: pointer;
  transition: all .15s;
}
.link-btn:hover { color: var(--text); background: var(--bg-hover); }
.link-btn.warn { color: var(--red); }
.link-btn.warn:hover { background: var(--red-soft); }

.hidden { display: none !important; }

/* ============ CONTRACTS WRAPPER ============ */
.contracts-wrap {
  display: flex; gap: 0; min-height: calc(100vh - 53px);
}
.contracts-wrap.single { }
.contracts-wrap.dual .contract-col { width: 50%; }
.contracts-wrap.dual .contract-col:first-child { border-right: 1px solid var(--border); }

.contract-col {
  width: 100%; overflow-y: auto; height: calc(100vh - 53px);
  padding: 0;
}

/* ============ FORM SCROLL CONTENT ============ */
.form-scroll { max-width: 680px; margin: 0 auto; padding: 32px 28px 120px; }

/* Section header - Tally style */
.section-head {
  margin-bottom: 20px; padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.section-head h2 {
  font-family: var(--font-display); font-size: 1.8rem; font-weight: 400;
  color: var(--text); margin-bottom: 4px; line-height: 1.2;
}
.section-head p { color: var(--text-3); font-size: .85rem; }

.section-label {
  font-size: .72rem; font-weight: 600; color: var(--gold);
  text-transform: uppercase; letter-spacing: .07em;
  margin-top: 32px; margin-bottom: 14px;
  display: flex; align-items: center; gap: 8px;
}
.section-label::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* Area selector */
.area-selector { margin-bottom: 28px; }
.area-selector label { display: block; font-size: .82rem; color: var(--text-2); margin-bottom: 8px; font-weight: 500; }
.area-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.area-pill {
  padding: 10px 18px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-card); color: var(--text-2); font-size: .88rem;
  cursor: pointer; transition: all .2s; font-family: var(--font);
}
.area-pill:hover { border-color: var(--text-3); color: var(--text); }
.area-pill.active { border-color: var(--gold); background: var(--gold-soft); color: var(--gold); }

/* Second contract toggle */
.second-toggle {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 0; margin-top: 8px;
}
.second-toggle span { font-size: .85rem; color: var(--text-2); }

/* ============ FORM FIELDS ============ */
.field { margin-bottom: 18px; }
.field.hidden-field { display: none; }
.field label {
  display: block; font-size: .82rem; font-weight: 500;
  color: var(--text-2); margin-bottom: 6px;
}
.field label .req { color: var(--red); margin-left: 2px; }

.field input[type="text"],
.field input[type="email"],
.field input[type="tel"],
.field input[type="date"],
.field input[type="number"],
.field select,
.field textarea {
  width: 100%; background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 11px 14px;
  color: var(--text); font-family: var(--font); font-size: .9rem;
  transition: border-color .15s, box-shadow .15s; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft);
}
.field input::placeholder, .field textarea::placeholder { color: var(--text-3); }
.field select { cursor: pointer; }
.field select option { background: var(--bg-card); }
.field textarea { resize: vertical; min-height: 60px; }

/* Toggle */
.toggle-field { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; }
.toggle-field .t-label { font-size: .88rem; color: var(--text-2); }
.toggle-field .t-label .req { color: var(--red); margin-left: 2px; }
.sw { position: relative; width: 40px; height: 22px; flex-shrink: 0; }
.sw input { opacity: 0; width: 0; height: 0; }
.sw .track {
  position: absolute; inset: 0; background: var(--border); border-radius: 11px;
  cursor: pointer; transition: .2s;
}
.sw .track::before {
  content: ''; position: absolute; width: 16px; height: 16px;
  left: 3px; top: 3px; background: var(--text); border-radius: 50%;
  transition: .2s;
}
.sw input:checked + .track { background: var(--gold); }
.sw input:checked + .track::before { transform: translateX(18px); }

/* WPP field */
.wpp-row { display: flex; gap: 8px; align-items: center; }
.wpp-row input { flex: 1; }
.wpp-row .country-prefix {
  background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 11px 10px; color: var(--text-3); font-size: .85rem; white-space: nowrap;
  display: flex; align-items: center; gap: 4px; min-width: 70px; justify-content: center;
}
.wpp-row .country-prefix select {
  background: transparent; border: none; color: var(--text-3); font-family: var(--font);
  font-size: .85rem; cursor: pointer; outline: none; padding: 0;
  width: auto; -webkit-appearance: none; appearance: none;
}
.wpp-badge {
  font-size: .72rem; font-weight: 600; padding: 4px 8px;
  border-radius: 4px; white-space: nowrap;
}
.wpp-badge.checking { background: var(--yellow-soft); color: var(--yellow); }
.wpp-badge.ok { background: var(--green-soft); color: var(--green); }
.wpp-badge.fail { background: var(--red-soft); color: var(--red); }
.wpp-badge.warn { background: var(--yellow-soft); color: var(--yellow); }

/* ============ DUMP + CHECKLIST SIDE-BY-SIDE ============ */
.dump-section {
  display: grid; grid-template-columns: 1fr 320px; gap: 20px;
  margin-top: 8px;
}
@media (max-width: 900px) {
  .dump-section { grid-template-columns: 1fr; }
}

.dump-box { }
.dump-box textarea {
  width: 100%; min-height: 280px; background: var(--bg-input);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; color: var(--text); font-family: var(--font);
  font-size: .9rem; line-height: 1.6; resize: vertical;
  transition: border-color .15s; outline: none;
}
.dump-box textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.dump-box textarea::placeholder { color: var(--text-3); }

.dump-actions {
  display: flex; gap: 8px; margin-top: 10px; align-items: center;
}

/* ============ CHECKLIST (password-criteria style) ============ */
.checklist-panel {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px;
  position: sticky; top: 73px; max-height: calc(100vh - 100px);
  overflow-y: auto;
}
.checklist-panel .chk-title {
  font-size: .78rem; font-weight: 600; color: var(--text-2);
  margin-bottom: 12px; display: flex; align-items: center; gap: 6px;
}
.checklist-panel .chk-counter {
  margin-left: auto; font-family: var(--font-mono);
  font-size: .72rem; color: var(--text-3);
}
.chk-group { margin-bottom: 14px; }
.chk-group-label {
  font-size: .7rem; font-weight: 600; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .04em;
  margin-bottom: 6px;
}
.chk-item {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 0; font-size: .8rem; color: var(--text-3);
  transition: color .3s;
}
.chk-item .dot {
  width: 6px; height: 6px; border-radius: 50%;
  flex-shrink: 0; transition: all .3s;
  background: var(--border);
}
.chk-item.found { color: var(--green); }
.chk-item.found .dot { background: var(--green); box-shadow: 0 0 6px var(--green-soft); }
.chk-item.missing-req { color: var(--red); }
.chk-item.missing-req .dot { background: var(--red); }
.chk-item.low-conf { color: var(--yellow); }
.chk-item.low-conf .dot { background: var(--yellow); }
.chk-item .chk-val {
  margin-left: auto; font-family: var(--font-mono); font-size: .68rem;
  color: var(--text-3); max-width: 120px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============ DOCUMENTS GRID ============ */
.docs-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; }
@media (max-width: 600px) { .docs-grid { grid-template-columns: 1fr; } }
.doc-item {
  display: flex; align-items: center; gap: 8px; padding: 6px 0;
}
.doc-item input[type="checkbox"] {
  appearance: none; width: 16px; height: 16px; border: 1.5px solid var(--border);
  border-radius: 4px; cursor: pointer; flex-shrink: 0; transition: all .15s;
  position: relative;
}
.doc-item input[type="checkbox"]:checked { background: var(--gold); border-color: var(--gold); }
.doc-item input[type="checkbox"]:checked::after {
  content: '✓'; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  font-size: .6rem; color: var(--bg); font-weight: 700;
}
.doc-item label { font-size: .82rem; color: var(--text-2); cursor: pointer; }
.doc-item.ai-rec { background: var(--blue-soft); border-radius: var(--radius); padding: 6px 8px; margin: -2px -8px; }

/* ============ RECOMMENDATIONS ============ */
.recs-box {
  background: var(--blue-soft); border: 1px solid rgba(96,165,250,.2);
  border-radius: var(--radius); padding: 14px 16px; margin-top: 16px;
  display: none;
}
.recs-box.visible { display: block; }
.recs-box .recs-title {
  font-size: .82rem; font-weight: 600; color: var(--blue); margin-bottom: 8px;
}
.rec-line { font-size: .8rem; color: var(--text-2); padding: 4px 0; line-height: 1.4; }
.rec-line::before { content: '→ '; color: var(--blue); }

/* ============ SUMMARY ============ */
.ai-summary {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin-top: 12px; font-size: .82rem; color: var(--text-2);
  line-height: 1.5; max-height: 160px; overflow-y: auto;
}
.ai-summary .sum-label { font-size: .7rem; font-weight: 600; color: var(--gold); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }

/* ============ AI STATUS ============ */
.ai-status {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: .82rem; color: var(--gold); padding: 8px 0;
}
.ai-status .dots span {
  display: inline-block; width: 5px; height: 5px; background: var(--gold);
  border-radius: 50%; margin: 0 1px; animation: pulse 1.2s infinite;
}
.ai-status .dots span:nth-child(2) { animation-delay: .2s; }
.ai-status .dots span:nth-child(3) { animation-delay: .4s; }
@keyframes pulse { 0%,80%,100% { opacity:.3; transform:scale(.8); } 40% { opacity:1; transform:scale(1.2); } }

/* ============ SUBMIT BAR (sticky bottom) ============ */
.submit-bar {
  position: sticky; bottom: 0; left: 0; right: 0;
  background: rgba(12,14,17,.9); backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 12px 28px; max-width: 680px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
}
.submit-status { display: flex; align-items: center; gap: 8px; font-size: .82rem; color: var(--text-3); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.status-dot.ok { background: var(--green); }
.status-dot.pending { background: var(--yellow); }
.status-dot.err { background: var(--red); }

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border: none; border-radius: var(--radius);
  font-family: var(--font); font-size: .85rem; font-weight: 600;
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.btn:disabled { opacity: .35; cursor: not-allowed; }
.btn-gold { background: var(--gold); color: var(--bg); }
.btn-gold:hover:not(:disabled) { background: #D4B56E; }
.btn-outline { background: transparent; color: var(--text-2); border: 1px solid var(--border); }
.btn-outline:hover:not(:disabled) { border-color: var(--text-3); color: var(--text); }
.btn-blue { background: var(--blue); color: #fff; }
.btn-blue:hover:not(:disabled) { filter: brightness(1.1); }
.btn-green { background: var(--green); color: var(--bg); }
.btn-green:hover:not(:disabled) { filter: brightness(1.1); }
.btn-red { background: var(--red); color: #fff; }
.btn-sm { padding: 7px 14px; font-size: .8rem; }
.btn.loading { pointer-events: none; opacity: .6; }
.btn.loading .btn-label { display: none; }
.btn.loading .spinner { display: block; }
.btn .spinner { display: none; width: 14px; height: 14px; border: 2px solid transparent; border-top-color: currentColor; border-radius: 50%; animation: spin .6s linear infinite; }

/* ============ MODAL ============ */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 1000; backdrop-filter: blur(4px); }
.modal-overlay.hidden { display: none; }
.modal-box { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); width: 90%; max-width: 520px; max-height: 80vh; overflow-y: auto; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: .95rem; font-weight: 600; }
.modal-head button { background: none; border: none; color: var(--text-3); font-size: 1.2rem; cursor: pointer; }
.modal-body { padding: 18px; }
.modal-footer { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

/* ============ TOAST ============ */
.toast-container { position: fixed; top: 14px; right: 14px; z-index: 2000; display: flex; flex-direction: column; gap: 6px; }
.toast {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; font-size: .82rem; color: var(--text);
  display: flex; align-items: center; gap: 8px;
  animation: toastIn .25s ease-out; max-width: 360px;
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.warning { border-left: 3px solid var(--yellow); }
.toast.info { border-left: 3px solid var(--blue); }
.toast.removing { animation: toastOut .15s forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(20px); } }

/* ============ HISTORY ============ */
.history-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; cursor: pointer; transition: border-color .15s; margin-bottom: 8px;
}
.history-card:hover { border-color: var(--text-3); }
.history-card .hc-top { display: flex; justify-content: space-between; margin-bottom: 4px; }
.history-card .hc-name { font-weight: 600; font-size: .88rem; }
.history-card .hc-date { font-size: .75rem; color: var(--text-3); font-family: var(--font-mono); }
.history-card .hc-meta { font-size: .8rem; color: var(--text-3); }

/* ============ RESPONSIVE ============ */
@media (max-width: 900px) {
  .contracts-wrap.dual { flex-direction: column; }
  .contracts-wrap.dual .contract-col { width: 100%; height: auto; min-height: 50vh; border-right: none !important; border-bottom: 1px solid var(--border); }
  .form-scroll { padding: 24px 16px 100px; }
}