/* ════════════════════════════════════════════════════════════════════════
   Forms Engine — application stylesheet
   Light theme. --accent is overridden at runtime from /api/config branding.
   ════════════════════════════════════════════════════════════════════════ */

:root {
  --bg:            #f4f5f7;
  --bg-secondary:  #eceef1;
  --bg-card:       #ffffff;
  --text-primary:  #1a1f2b;
  --text-secondary:#5b6472;
  --text-muted:    #9aa3b2;
  --border:        #e3e6ea;
  --accent:        #2563eb;
  --accent-dark:   #1d4ed8;
  --danger:        #dc2626;
  --success:       #16a34a;
  --warning:       #d97706;
  --radius:        10px;
  --radius-sm:     6px;
  --shadow:        0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg:     0 12px 32px rgba(16, 24, 40, .18);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

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

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; cursor: pointer;
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: var(--bg-secondary);
  color: var(--text-primary); transition: background .12s, opacity .12s;
  white-space: nowrap;
}
.btn:hover  { opacity: .92; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary   { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); opacity: 1; }
.btn-secondary { background: var(--bg-card); border-color: var(--border); }
.btn-ghost     { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-secondary); opacity: 1; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-sm   { padding: 6px 11px; font-size: 13px; }
.btn-block{ width: 100%; }

/* ── Forms ─────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; font-weight: 600; font-size: 13px;
  margin-bottom: 6px; color: var(--text-secondary);
}
.form-control {
  width: 100%; font: inherit; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-card); color: var(--text-primary);
}
.form-control:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
select.form-control { appearance: none; background-image:
  url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path fill='%239aa3b2' d='M0 0l5 6 5-6z'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 30px; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 5px; }
.form-row { display: flex; gap: 14px; }
.form-row .form-group { flex: 1; }

/* ── Alerts ────────────────────────────────────────────────────────────── */
.alert {
  padding: 10px 13px; border-radius: var(--radius-sm);
  font-size: 13px; margin-bottom: 14px;
}
.alert-error   { background: #fdeaea; color: var(--danger); }
.alert-success { background: #e7f6ec; color: var(--success); }
.alert-warning { background: #fdf1e0; color: var(--warning); }

/* ── Login screen ──────────────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px;
  background: linear-gradient(160deg, #eef1f6 0%, #e3e8f0 100%);
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 380px; background: var(--bg-card);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 34px 30px;
}
.login-brand { text-align: center; margin-bottom: 22px; }
.login-logo  { max-height: 52px; margin-bottom: 12px; }
.login-brand h1 { font-size: 22px; }
.login-sub   { color: var(--text-muted); font-size: 13px; margin-top: 3px; }
.login-footnote { color: var(--text-muted); font-size: 12px; }
.login-divider {
  display: flex; align-items: center; text-align: center;
  color: var(--text-muted); font-size: 12px; margin: 16px 0;
}
.login-divider::before, .login-divider::after {
  content: ""; flex: 1; border-top: 1px solid var(--border);
}
.login-divider span { padding: 0 12px; }
.btn-google {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; font: inherit; font-weight: 600; cursor: pointer;
  padding: 10px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: #fff; color: #3c4043;
}
.btn-google:hover { background: #f7f8fa; }

/* ── App layout ────────────────────────────────────────────────────────── */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px; flex-shrink: 0; background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 700; font-size: 16px;
  padding: 18px 18px; border-bottom: 1px solid var(--border);
}
.nav-logo { max-height: 28px; }
.nav { flex: 1; padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--text-secondary); font-weight: 600; font-size: 14px;
}
.nav-item:hover { background: var(--bg-secondary); }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-icon { font-size: 15px; width: 18px; text-align: center; }
.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; margin-bottom: 10px;
  cursor: pointer; border-radius: var(--radius-sm); padding: 4px; }
.user-chip:hover { background: var(--bg-secondary); }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent) center/cover no-repeat; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}
.user-meta { overflow: hidden; }
.user-name { font-weight: 600; font-size: 13px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 12px; color: var(--text-muted); }

.main { flex: 1; padding: 26px 32px; overflow-x: hidden; min-width: 0; }
.page { display: none; }
.page.active { display: block; animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ── Page header / placeholder ─────────────────────────────────────────── */
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 22px;
}
.page-title { font-size: 21px; }
.page-subtitle { color: var(--text-muted); font-size: 13px; margin-top: 3px; }
.page-placeholder {
  text-align: center; padding: 90px 20px; color: var(--text-muted);
}
.page-placeholder .ph-icon { font-size: 44px; margin-bottom: 12px; }
.page-placeholder h2 { color: var(--text-secondary); font-size: 19px; }
.page-placeholder p { margin-top: 6px; font-size: 14px; }

/* ── Cards ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  font-weight: 700;
}
.card-body { padding: 18px; }

/* ── Table ─────────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left; padding: 11px 16px; color: var(--text-muted);
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--border); background: var(--bg-secondary);
}
.data-table td {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #fafbfc; }
.muted { color: var(--text-muted); }
.text-right { text-align: right; }

/* ── Badges / pills ────────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 700;
}
.badge-accent  { background: rgba(37, 99, 235, .12); color: var(--accent); }
.badge-success { background: #e7f6ec; color: var(--success); }
.badge-muted   { background: var(--bg-secondary); color: var(--text-muted); }
.badge-warning { background: #fdf1e0; color: var(--warning); }
.badge-danger  { background: #fdeaea; color: var(--danger); }

/* ── Modal ─────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .5);
  display: flex; align-items: center; justify-content: center;
  padding: 24px; z-index: 100; animation: fade .12s ease;
}
.modal {
  background: var(--bg-card); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); width: 100%;
  max-height: 90vh; display: flex; flex-direction: column;
  animation: pop .14s ease;
}
@keyframes pop { from { transform: scale(.97); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-sm { max-width: 380px; }
.modal-md { max-width: 520px; }
.modal-lg { max-width: 760px; }
.modal-xl { max-width: 1040px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; }
.modal-close {
  border: none; background: none; cursor: pointer;
  font-size: 22px; line-height: 1; color: var(--text-muted);
}
.modal-close:hover { color: var(--text-primary); }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 9px;
  padding: 14px 20px; border-top: 1px solid var(--border);
}

/* ── Toast ─────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 22px; right: 22px; z-index: 200;
  display: flex; flex-direction: column; gap: 9px;
}
.toast {
  background: var(--text-primary); color: #fff;
  padding: 11px 16px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); font-size: 13px; font-weight: 500;
  max-width: 340px; animation: toast-in .2s ease;
}
.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }
.toast-info    { background: var(--text-primary); }
@keyframes toast-in {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* ── Form Builder ──────────────────────────────────────────────────────── */
.fb-layout { display: flex; gap: 18px; align-items: flex-start; }
.fb-rail {
  width: 248px; flex-shrink: 0; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.fb-rail-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border); font-weight: 700;
}
.fb-form-list { max-height: 70vh; overflow-y: auto; }
.fb-form-item {
  padding: 11px 14px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.fb-form-item:hover { background: var(--bg-secondary); }
.fb-form-item.active { background: rgba(37, 99, 235, .1); border-left: 3px solid var(--accent); }
.fb-form-item .fi-name { font-weight: 600; }
.fb-form-item .fi-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.fb-main { flex: 1; min-width: 0; }
.fb-section { margin-bottom: 18px; }
.fb-section-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--text-muted); margin-bottom: 9px;
}

.fb-field-row {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--bg-card);
}
.fb-field-row:last-child { border-bottom: none; }
.fb-field-row .drag-handle { cursor: grab; color: var(--text-muted); font-size: 15px; }
.fb-field-row.dragging { opacity: .4; }
.fb-field-row.drop-target { border-top: 2px solid var(--accent); }
.fb-field-main { flex: 1; min-width: 0; }
.fb-field-main .ff-label { font-weight: 600; }
.fb-field-main .ff-key { font-size: 12px; color: var(--text-muted); font-family: ui-monospace, monospace; }

/* drag-drop PDF uploader */
.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 36px 20px; text-align: center; color: var(--text-muted);
  cursor: pointer; transition: border-color .12s, background .12s;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent); background: rgba(37, 99, 235, .05);
}
.dropzone .dz-icon { font-size: 32px; margin-bottom: 8px; }

/* PDF placement stage */
.pdf-toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 12px;
}
.pdf-stage {
  position: relative; display: inline-block; line-height: 0;
  box-shadow: var(--shadow-lg); border-radius: 4px; overflow: hidden;
}
.pdf-stage canvas { display: block; }
.pdf-overlay { position: absolute; inset: 0; }
.field-box {
  position: absolute; box-sizing: border-box;
  background: rgba(37, 99, 235, .14); border: 1.5px solid var(--accent);
  border-radius: 3px; font-size: 11px; line-height: 1.4;
  color: var(--accent-dark); padding: 1px 4px; cursor: move;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  user-select: none;
}
.field-box.sig { background: rgba(22, 163, 74, .14); border-color: var(--success); color: #14532d; }
.field-box:hover { box-shadow: 0 0 0 2px rgba(37, 99, 235, .25); }
.unplaced-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 10px; margin: 0 6px 6px 0; cursor: pointer;
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: 999px; font-size: 12px; font-weight: 600;
}
.unplaced-chip:hover { border-color: var(--accent); color: var(--accent); }

/* ── Document library ──────────────────────────────────────────────────── */
.doc-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.doc-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; display: flex; flex-direction: column; min-height: 150px;
}
.doc-card .doc-icon { font-size: 26px; margin-bottom: 6px; }
.doc-card .doc-title { font-weight: 700; margin-bottom: 6px; }

/* ── Signature pad ─────────────────────────────────────────────────────── */
.sig-pad {
  width: 100%; max-width: 440px; height: 150px; display: block;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: #fff; cursor: crosshair; touch-action: none;
}

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: static;
    flex-direction: row; flex-wrap: wrap; align-items: center;
  }
  .sidebar-brand { border-bottom: none; }
  .nav { flex-direction: row; flex-wrap: wrap; flex: 1 1 100%; }
  .sidebar-footer { border-top: none; }
  .main { padding: 18px; }
  .form-row { flex-direction: column; gap: 0; }
}
