:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e4e7ec;
  --text: #1d2433;
  --muted: #667085;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #dc2626;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.1), 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 20px 40px rgba(16, 24, 40, 0.18);
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

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

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card .sub { color: var(--muted); margin: 0 0 24px; }
.hint {
  margin-top: 18px;
  font-size: 12px;
  color: var(--muted);
  background: #f9fafb;
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

/* ---------- Form controls ---------- */
label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
.field { margin-bottom: 16px; }
input, textarea, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}
textarea { resize: vertical; min-height: 64px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.btn:hover { background: var(--primary-hover); }
.btn.full { width: 100%; justify-content: center; }
.btn.secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: #f9fafb; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #b91c1c; }
.btn.sm { padding: 6px 10px; font-size: 13px; }

.error {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 16px;
  font-size: 13px;
}

/* ---------- App shell ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.topbar .right { display: flex; align-items: center; gap: 14px; }
.role-chip {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: #eef2ff;
  color: var(--primary);
  text-transform: capitalize;
}

.container { max-width: 1080px; margin: 28px auto; padding: 0 28px; }

.banner-warn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #9a3412;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 18px;
  font-size: 14px;
}
.page-head {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px;
}
.page-head h2 { margin: 0; font-size: 20px; }
.muted { color: var(--muted); }

/* ---------- Table ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 12px 18px;
  background: #fafafa;
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 14px 18px; border-bottom: 1px solid var(--border); }
tbody tr { cursor: pointer; transition: background 0.12s ease; }
tbody tr:hover { background: #f9fafb; }
tbody tr:last-child td { border-bottom: none; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- Status badge ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  text-transform: capitalize;
}
.badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.none      { background: #f2f4f7; color: #667085; }
.badge.draft     { background: #f2f4f7; color: #667085; }
.badge.sent      { background: #eff6ff; color: #2563eb; }
.badge.viewed    { background: #f5f3ff; color: #7c3aed; }
.badge.signed    { background: #ecfeff; color: #0891b2; }
.badge.completed { background: #ecfdf3; color: #16a34a; }
.badge.declined  { background: #fef2f2; color: #dc2626; }
.badge.expired   { background: #fff7ed; color: #ea580c; }
.badge.revoked   { background: #fef2f2; color: #b91c1c; }

/* ---------- Drawer ---------- */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 40;
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: 440px;
  max-width: 92vw;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 50;
  display: flex;
  flex-direction: column;
}
.drawer-open .drawer-overlay { opacity: 1; pointer-events: auto; }
.drawer-open .drawer { transform: translateX(0); }
.drawer-head {
  padding: 20px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}
.drawer-head h3 { margin: 0 0 2px; font-size: 18px; }
.drawer-body { padding: 22px; overflow-y: auto; flex: 1; }
.drawer-close {
  background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1;
}

.detail-grid { display: grid; grid-template-columns: 1fr; gap: 10px; margin-bottom: 22px; }
.detail-row { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.detail-row .k { color: var(--muted); }
.detail-row .v { font-weight: 600; text-align: right; word-break: break-word; }

.section-title {
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); margin: 22px 0 12px;
}

.doc-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.doc-item .meta { min-width: 0; }
.doc-item .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-item .date { font-size: 12px; color: var(--muted); }

.divider { height: 1px; background: var(--border); margin: 22px 0; }

.flex { display: flex; gap: 8px; align-items: center; }
.flex.end { justify-content: flex-end; }
.spacer { flex: 1; }
.htmx-indicator { opacity: 0; transition: opacity 0.2s; }
.htmx-request .htmx-indicator { opacity: 1; }
.htmx-request.htmx-indicator { opacity: 1; }

/* ---------- Toasts ---------- */
#toast-container {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 360px;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--muted);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  color: #fff;
  font-size: 12px;
  flex-shrink: 0;
}
.toast.success { border-left-color: #16a34a; }
.toast.success .toast-icon { background: #16a34a; }
.toast.error { border-left-color: var(--danger); }
.toast.error .toast-icon { background: var(--danger); }
.toast.info { border-left-color: var(--primary); }
.toast.info .toast-icon { background: var(--primary); }
