/* ================================================================
   Routact — Production Design System
   ================================================================ */

:root {
  /* Brand / Primary */
  --primary:          #0d9488;
  --primary-dark:     #0f766e;
  --primary-light:    #f0fdfa;
  --primary-border:   #5eead4;

  /* Sidebar */
  --sidebar-bg:       #0f172a;
  --sidebar-hover:    rgba(255,255,255,0.06);
  --sidebar-active:   rgba(13,148,136,0.20);
  --sidebar-text:     #94a3b8;
  --sidebar-text-hi:  #f8fafc;
  --sidebar-width:    252px;

  /* Surfaces */
  --page-bg:          #f1f5f9;
  --surface:          #ffffff;
  --surface-2:        #f8fafc;
  --border:           #e2e8f0;
  --border-strong:    #cbd5e1;
  --border-2:         #f1f5f9;

  /* Text */
  --text:             #0f172a;
  --text-2:           #334155;
  --text-muted:       #64748b;
  --text-xs:          #94a3b8;

  /* Semantic colours */
  --success:          #16a34a;
  --success-bg:       #dcfce7;
  --warning:          #ca8a04;
  --warning-bg:       #fef9c3;
  --danger:           #dc2626;
  --danger-bg:        #fee2e2;
  --info:             #2563eb;
  --info-bg:          #dbeafe;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0,0,0,.05);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow:    0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
  --shadow-md: 0 10px 15px rgba(0,0,0,.08), 0 4px 6px rgba(0,0,0,.05);

  /* Radii */
  --r-sm:  4px;
  --r:     8px;
  --r-lg: 12px;
}

/* ─── Base ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { min-height: 100%; }

body {
  margin: 0;
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Inter', sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--page-bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary-dark); text-decoration: none; }
a:hover { color: var(--primary); }

/* ─── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 200;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
  transition: transform 0.28s cubic-bezier(.4,0,.2,1);
}
.sidebar::-webkit-scrollbar { display: none; }

.app-main {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--page-bg);
}

/* ─── Brand ──────────────────────────────────────────────────── */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px 14px;
  color: #fff;
  text-decoration: none;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}
.sidebar-brand:hover { color: #fff; }

.brand-icon {
  width: 36px; height: 36px;
  background: transparent url("../img/routact-mark.svg") center / contain no-repeat;
  border-radius: 0;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  color: transparent;
  font-size: 0;
}
.brand-icon svg { display: none; }

.sidebar-company {
  margin: 0 12px 10px;
  padding: 6px 10px;
  background: rgba(255,255,255,0.06);
  border-radius: var(--r);
  color: var(--sidebar-text);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: uppercase;
  flex-shrink: 0;
}

/* ─── Sidebar Nav ────────────────────────────────────────────── */
.sidebar-nav {
  flex: 1;
  padding: 6px 10px;
}

.nav-section-label {
  padding: 14px 10px 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: rgba(148,163,184,0.55);
  white-space: nowrap;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.14s, color 0.14s;
  white-space: nowrap;
  cursor: pointer;
}
.nav-link:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text-hi);
  text-decoration: none;
}
.nav-link.active,
.nav-link.active:hover {
  background: var(--sidebar-active);
  color: #fff;
}
.nav-link svg {
  width: 16px; height: 16px;
  flex-shrink: 0;
  opacity: 0.7;
}
.nav-link.active svg,
.nav-link:hover svg { opacity: 1; }

/* ─── Sidebar Footer ─────────────────────────────────────────── */
.sidebar-footer {
  flex-shrink: 0;
  padding: 10px 12px;
  border-top: 1px solid rgba(255,255,255,0.06);
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--sidebar-text-hi);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-role {
  font-size: 11px;
  color: var(--sidebar-text);
}

.btn-icon-logout,
.btn-icon-sidebar {
  width: 30px; height: 30px;
  display: grid;
  place-items: center;
  border: none;
  background: transparent;
  color: var(--sidebar-text);
  border-radius: var(--r);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.14s, color 0.14s;
  text-decoration: none;
}
.btn-icon-logout:hover,
.btn-icon-sidebar:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
}
.btn-icon-logout svg,
.btn-icon-sidebar svg { width: 15px; height: 15px; }

/* ─── Sidebar Overlay (mobile) ───────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 199;
}

/* ─── Top Bar ────────────────────────────────────────────────── */
.app-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}

.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--r);
  cursor: pointer;
  color: var(--text-muted);
  flex-shrink: 0;
}
.sidebar-toggle:hover { background: var(--surface-2); color: var(--text); }
.sidebar-toggle svg { width: 17px; height: 17px; }

.topbar-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  flex: 1;
}

/* ─── Content ────────────────────────────────────────────────── */
.app-content {
  flex: 1;
  padding: 24px;
}

/* ─── Toast notifications ────────────────────────────────────── */
.toast-stack {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 380px;
  pointer-events: none;
}

.toast-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-2);
  pointer-events: all;
  animation: toast-in 0.22s ease;
}
.toast-success { border-left: 3px solid var(--success); }
.toast-error   { border-left: 3px solid var(--danger);  }

.toast-close {
  margin-left: auto;
  background: none; border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 2px;
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
}
.toast-close:hover { color: var(--text); }

/* Site Dialogs */
body.dialog-open {
  overflow: hidden;
}

.doc-dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: start center;
  padding: 72px 16px 24px;
  background: rgba(15, 23, 42, .58);
  backdrop-filter: blur(2px);
}

.doc-dialog-backdrop[hidden] { display: none !important; }

.doc-dialog {
  position: relative;
  width: min(460px, 100%);
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 14px;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(15, 23, 42, .24), var(--shadow-md);
  animation: dialog-in .16s ease-out;
}

.doc-dialog-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--info-bg);
  color: var(--info);
  font-weight: 900;
  font-size: 20px;
}

.doc-dialog.is-danger .doc-dialog-icon {
  background: var(--danger-bg);
  color: var(--danger);
}

.doc-dialog.is-warning .doc-dialog-icon {
  background: var(--warning-bg);
  color: var(--warning);
}

.doc-dialog-content { min-width: 0; padding-right: 18px; }

.doc-dialog-kicker {
  margin-bottom: 2px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.doc-dialog h2 {
  margin: 0 0 6px;
  font-size: 18px;
  line-height: 1.25;
  font-weight: 800;
  color: var(--text);
}

.doc-dialog p {
  margin: 0;
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.55;
}

.doc-dialog-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
}

.doc-dialog-close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.doc-dialog-close:hover { color: var(--text); }

@keyframes dialog-in {
  from { opacity: 0; transform: translateY(-10px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(24px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ─── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xs);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px 12px;
  border-bottom: 1px solid var(--border-2);
}
.card-header h2,
.card-header h3 {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.card-body { padding: 16px 20px; }
.card-subtitle {
  margin: 3px 0 0;
  color: var(--text-muted);
  font-size: 12px;
}

/* ─── Stat Grid ──────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px 18px 14px;
  box-shadow: var(--shadow-xs);
}

.stat-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 30px;
  font-weight: 800;
  line-height: 1;
  color: var(--text);
}

.stat-card.s-draft     .stat-value { color: #b45309; }
.stat-card.s-review    .stat-value { color: #1d4ed8; }
.stat-card.s-effective .stat-value { color: #15803d; }
.stat-card.s-primary   .stat-value { color: var(--primary); }
.stat-card.s-due       .stat-value { color: #b45309; }
.stat-card.s-overdue   .stat-value { color: var(--danger); }

.stat-card-link {
  display: block;
  text-decoration: none;
  transition: box-shadow 0.14s, transform 0.14s;
}
.stat-card-link:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.stat-cta {
  margin-top: 8px;
  font-size: 12px;
  font-weight: 700;
}

/* ─── Page Header ────────────────────────────────────────────── */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
}
.page-head h1 {
  font-size: 25px;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--text);
  margin: 0 0 4px;
}
.page-head p {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0;
}
.page-head-main { min-width: 0; }

/* Document-number chip used in headers and lists */
.doc-number-chip {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--primary-light);
  border: 1px solid var(--primary-border);
  color: var(--primary-dark);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}
a.doc-number-link {
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
a.doc-number-link:hover {
  background: var(--primary-border);
  border-color: var(--primary-dark);
  color: var(--primary-dark);
  text-decoration: none;
}

/* ─── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--r);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.14s, border-color 0.14s, box-shadow 0.14s;
  text-decoration: none !important;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(180deg, var(--primary) 0%, var(--primary-dark) 100%);
  border-color: var(--primary-dark);
  color: #fff !important;
  box-shadow: 0 1px 2px rgba(13,148,136,0.35), inset 0 1px 0 rgba(255,255,255,0.15);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); box-shadow: 0 2px 6px rgba(13,148,136,0.4); }
.btn-primary:active { box-shadow: inset 0 1px 2px rgba(0,0,0,0.2); }

.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text-2) !important;
}
.btn-secondary:hover,
.btn-secondary:focus,
.btn-secondary:focus-visible,
.btn-secondary:active,
.btn-secondary.active,
.btn-secondary.show,
.show > .btn-secondary.dropdown-toggle,
.btn-check:focus + .btn-secondary,
.btn-check:checked + .btn-secondary,
.btn-check:active + .btn-secondary {
  background: var(--surface-2) !important;
  border-color: var(--border-strong) !important;
  color: var(--text) !important;
  box-shadow: 0 0 0 3px rgba(13, 148, 136, .14) !important;
}

.btn-secondary:active,
.btn-secondary.active,
.btn-check:checked + .btn-secondary {
  transform: translateY(1px);
}

.btn-secondary:disabled,
.btn-secondary.disabled {
  background: var(--surface) !important;
  border-color: var(--border) !important;
  color: var(--text-muted) !important;
  box-shadow: none !important;
  opacity: .65;
}

.btn-outline-primary {
  background: transparent;
  border-color: var(--primary);
  color: var(--primary) !important;
}
.btn-outline-primary:hover { background: var(--primary-light); }

.btn-danger {
  background: var(--danger-bg);
  border-color: transparent;
  color: var(--danger) !important;
}
.btn-danger:hover { background: #fecaca; }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted) !important;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text) !important; }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-xs { padding: 2px 8px;  font-size: 11px; }

.btn svg { width: 15px; height: 15px; }
.btn-sm svg { width: 13px; height: 13px; }

.action-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.inline-form { display: inline; }

/* ─── Tables ─────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  padding: 9px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  background: var(--surface-2);
  white-space: nowrap;
}
.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-2);
  color: var(--text-2);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: var(--surface-2); }

.col-primary { font-weight: 600; color: var(--text) !important; }
.col-mono {
  font-family: Consolas, 'Courier New', monospace;
  font-size: 12px;
  color: var(--primary-dark) !important;
  font-weight: 600;
}
.col-muted { color: var(--text-muted) !important; font-size: 12px; }

/* ─── Status Badges (new system) ─────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.badge-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
}

.badge-draft     { background: #fef9c3; color: #a16207; }
.badge-draft     .badge-dot { background: #ca8a04; }
.badge-inreview  { background: #dbeafe; color: #1d4ed8; }
.badge-inreview  .badge-dot { background: #3b82f6; }
.badge-effective { background: #dcfce7; color: #15803d; }
.badge-effective .badge-dot { background: #22c55e; }
.badge-rejected  { background: #fee2e2; color: #b91c1c; }
.badge-rejected  .badge-dot { background: #ef4444; }
.badge-obsolete  { background: #f1f5f9; color: #64748b; }
.badge-obsolete  .badge-dot { background: #94a3b8; }
.badge-pending   { background: #fef9c3; color: #a16207; }
.badge-approved  { background: #dcfce7; color: #15803d; }
.badge-active    { background: #dcfce7; color: #14532d; }
.badge-active    .badge-dot { background: #16a34a; }
.badge-expired   { background: #fff7ed; color: #9a3412; }
.badge-expired   .badge-dot { background: #f97316; }
.badge-revoked   { background: #fee2e2; color: #991b1b; }
.badge-revoked   .badge-dot { background: #dc2626; }
.badge-neutral   { background: #e2e8f0; color: #334155; }
.badge-neutral   .badge-dot { background: #64748b; }
.badge-success   { background: #dcfce7; color: #166534; }
.badge-success   .badge-dot { background: #16a34a; }
.badge-muted     { background: #f1f5f9; color: #64748b; }
.badge-muted     .badge-dot { background: #94a3b8; }
.badge-due       { background: #fef9c3; color: #854d0e; }
.badge-due       .badge-dot { background: #ca8a04; }
.badge-overdue   { background: #fee2e2; color: #991b1b; }
.badge-overdue   .badge-dot { background: #dc2626; }

/* Legacy status-badge classes (keep for existing Detail view) */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.status-draft     { background: #fef9c3; color: #a16207; }
.status-inreview  { background: #dbeafe; color: #1d4ed8; }
.status-effective { background: #dcfce7; color: #15803d; }
.status-rejected,
.status-obsolete  { background: #fee2e2; color: #b91c1c; }

/* ─── Forms ──────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 5px;
}

.form-control {
  display: block;
  width: 100%;
  padding: 8px 11px;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  transition: border-color 0.14s, box-shadow 0.14s;
  outline: none;
  line-height: 1.5;
}
.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13,148,136,0.12);
}
textarea.form-control { resize: vertical; }

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

.form-select[multiple] {
  background-image: none;
  padding-right: 11px;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.form-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}

.text-danger { color: var(--danger) !important; font-size: 11px; }

/* ─── Filter Bar ─────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.search-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 6px 11px;
  min-width: 220px;
  flex: 0 1 260px;
}
.search-input-wrap input {
  border: none;
  outline: none;
  font-size: 13px;
  color: var(--text);
  background: transparent;
  flex: 1;
  min-width: 0;
}
.search-input-wrap input::placeholder { color: var(--text-muted); }
.search-input-wrap svg { width: 14px; height: 14px; color: var(--text-muted); flex-shrink: 0; }

.filter-tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 3px;
}
.filter-tab {
  padding: 4px 12px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: transparent;
  transition: background 0.12s, color 0.12s, box-shadow 0.12s;
  white-space: nowrap;
}
.filter-tab:hover { color: var(--text); }
.filter-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xs);
}

/* ─── Auth Pages ─────────────────────────────────────────────── */
.auth-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  background: var(--page-bg);
}

.auth-brand {
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 64px 56px;
}

.auth-brand-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 48px;
}
.auth-brand-logo .brand-icon { width: 44px; height: 44px; }

.auth-tagline {
  font-size: 28px;
  font-weight: 800;
  color: #fff;
  line-height: 1.25;
  margin-bottom: 14px;
}

.auth-sub {
  font-size: 14px;
  color: var(--sidebar-text);
  line-height: 1.65;
  max-width: 340px;
}

.auth-features {
  list-style: none;
  padding: 0;
  margin: 28px 0 0;
  display: grid;
  gap: 12px;
}

.auth-features li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  color: var(--sidebar-text);
  font-size: 13px;
  line-height: 1.5;
}

.auth-features li svg {
  width: 16px; height: 16px;
  color: var(--primary);
  flex-shrink: 0;
  margin-top: 1px;
}

.auth-form-panel {
  display: grid;
  place-items: center;
  padding: 40px;
  background: var(--surface);
}

.auth-form-inner {
  width: 100%;
  max-width: 380px;
}

.auth-form-inner h1 {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  margin: 0 0 4px;
}

.auth-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 26px;
}

.auth-form-stack { display: grid; gap: 14px; }

.auth-inline-link {
  min-height: 18px;
  margin-top: -6px;
  text-align: right;
  font-size: 12px;
}
.auth-inline-link a {
  font-weight: 600;
}
.auth-inline-link a[hidden] {
  display: none !important;
}

.auth-info {
  padding: 10px 12px;
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: var(--page-bg);
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
  margin-bottom: 16px;
}
.auth-info-warning {
  border-color: #fde68a;
  background: #fffbeb;
  color: #92400e;
}

.auth-footer {
  margin-top: 20px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}
.auth-footer a { font-weight: 600; }

/* ─── Document Sheet ─────────────────────────────────────────── */
.document-sheet {
  position: relative;
  overflow: hidden;
  min-height: 400px;
  padding: 2rem 2.5rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}

.document-content {
  position: relative;
  z-index: 2;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: Consolas, 'Courier New', monospace;
  line-height: 1.65;
  font-size: 13px;
}

.watermark-text {
  position: absolute;
  top: 50%; left: 50%;
  z-index: 1;
  width: 120%;
  transform: translate(-50%, -50%) rotate(-28deg);
  text-align: center;
  font-size: 4rem;
  font-weight: 800;
  pointer-events: none;
  user-select: none;
}

/* Repeating (tiled) controlled-copy watermark */
.watermark-tile {
  position: absolute;
  inset: 0;
  z-index: 1;
  background-repeat: repeat;
  background-position: center top;
  pointer-events: none;
  user-select: none;
}

/* ─── Detail Layout ──────────────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: minmax(0,1fr) 372px;
  gap: 20px;
  align-items: start;
}
.detail-grid main,
.detail-grid aside { display: grid; gap: 16px; }

/* ─── Compact List ───────────────────────────────────────────── */
.compact-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.compact-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border-2);
  font-size: 13px;
  color: var(--text-2);
}
.compact-list li:last-child { border-bottom: 0; }
.compact-list small { color: var(--text-muted); font-size: 11px; }

/* ─── Approval Actions ───────────────────────────────────────── */
.approval-actions { display: grid; gap: 6px; }
.approval-actions form {
  display: grid;
  grid-template-columns: minmax(110px,1fr) minmax(120px,1fr) auto;
  gap: 6px;
}

/* ─── Hash Fragment ──────────────────────────────────────────── */
.hash-fragment {
  color: var(--warning);
  font-family: Consolas, monospace;
  font-size: 0.85rem;
}

/* ─── Side Panel ─────────────────────────────────────────────── */
.side-panel { padding-top: 0.5rem; }

/* ─── Share Result ───────────────────────────────────────────── */
.share-result {
  max-width: 780px;
  display: grid;
  gap: 0.75rem;
}

.share-result-card {
  background: var(--success-bg);
  border: 1px solid #bbf7d0;
  border-radius: var(--r-lg);
  padding: 20px;
}

.token-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 10px 14px;
  font-family: Consolas, monospace;
  font-size: 13px;
  color: var(--primary-dark);
  word-break: break-all;
}

/* ─── Activity Feed ──────────────────────────────────────────── */
.review-worklist-card {
  margin-bottom: 20px;
}

.review-worklist-table td {
  vertical-align: top;
}

.review-row-overdue td {
  background: #fff7f7;
}

.review-notice-stack {
  display: grid;
  gap: 2px;
  color: var(--text-muted);
  font-size: 12px;
}

.review-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.activity-feed { padding: 2px 0; }

.activity-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border-2);
}
.activity-item:last-child { border-bottom: 0; }

.activity-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--primary);
  flex-shrink: 0;
  margin-top: 5px;
}

.activity-text { flex: 1; min-width: 0; font-size: 13px; color: var(--text-2); line-height: 1.4; }
.activity-time { font-size: 11px; color: var(--text-muted); white-space: nowrap; }

.activity-line { display: block; }
.activity-actor { font-weight: 700; color: var(--text); }
.activity-action { color: var(--text-2); }
.activity-actor::after { content: " · "; color: var(--text-muted); font-weight: 400; }
.activity-doc {
  display: inline-block;
  margin-top: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--primary-light);
  border: 1px solid var(--primary-border);
  color: var(--primary-dark);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
}

/* ─── Empty State ────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state p { font-size: 13px; margin: 0; }

/* ─── Settings layout ────────────────────────────────────────── */
.settings-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px,1fr));
  gap: 1rem;
}

.settings-wide {
  grid-column: 1 / -1;
}

.settings-collapse-panel {
  padding: 0;
  overflow: hidden;
}

.settings-collapse-summary {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
  padding: 16px 96px 16px 20px;
  cursor: pointer;
  user-select: none;
  list-style: none;
}

.settings-collapse-summary::-webkit-details-marker {
  display: none;
}

.settings-collapse-summary::before {
  content: "+";
  position: absolute;
  right: 58px;
  top: 50%;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border: 1px solid var(--primary-border);
  border-radius: 999px;
  background: #effefe;
  color: var(--primary);
  font-size: 14px;
  font-weight: 900;
  line-height: 1;
  transform: translateY(-50%);
}

.settings-collapse-summary::after {
  content: "Show";
  position: absolute;
  right: 20px;
  top: 50%;
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
  transform: translateY(-50%);
}

.settings-collapse-panel[open] .settings-collapse-summary::before {
  content: "-";
}

.settings-collapse-panel[open] .settings-collapse-summary::after {
  content: "Hide";
}

.settings-collapse-summary span {
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 900;
}

.settings-collapse-summary small {
  display: block;
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

.settings-collapse-body {
  display: grid;
  gap: 14px;
  padding: 0 20px 20px;
  border-top: 1px solid var(--border);
}

.settings-collapse-body > .grid-toolbar:first-child {
  margin-top: 0;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  padding: 0 2px;
}

.opacity-control {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.opacity-control-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.opacity-control-head label {
  margin: 0;
}

.opacity-control output {
  min-width: 52px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.watermark-opacity-slider {
  width: 100%;
  height: 18px;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
}

.watermark-opacity-slider::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--primary) 0 var(--opacity-fill, 0%), #d8e1ea var(--opacity-fill, 0%) 100%);
}

.watermark-opacity-slider::-webkit-slider-thumb {
  width: 16px;
  height: 16px;
  margin-top: -4px;
  border: 2px solid #fff;
  border-radius: 999px;
  background: var(--primary);
  box-shadow: 0 1px 4px rgba(15, 23, 42, .24);
  appearance: none;
  -webkit-appearance: none;
}

.watermark-opacity-slider::-moz-range-track {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--primary) 0 var(--opacity-fill, 0%), #d8e1ea var(--opacity-fill, 0%) 100%);
}

.watermark-opacity-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 2px solid #fff;
  border-radius: 999px;
  background: var(--primary);
  box-shadow: 0 1px 4px rgba(15, 23, 42, .24);
}

.watermark-opacity-slider:focus-visible {
  outline: 2px solid rgba(20, 184, 166, .35);
  outline-offset: 4px;
}

.opacity-scale {
  display: flex;
  justify-content: space-between;
  color: var(--text-muted);
  font-size: 11px;
}

/* Tenant administration */
.tenant-admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, .65fr);
  gap: 18px;
  align-items: start;
}

.tenant-subscription-form {
  display: grid;
  gap: 16px;
  padding: 18px 20px;
}

.billing-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 12px;
  padding: 18px 20px;
}

.billing-summary-grid div {
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  padding: 12px;
}

.billing-summary-grid span,
.billing-summary-grid small {
  display: block;
  color: var(--text-muted);
  font-size: 11px;
}

.billing-summary-grid strong {
  display: block;
  margin-top: 4px;
  color: var(--text);
  font-size: 14px;
  overflow-wrap: anywhere;
}

.billing-cancel-form {
  display: flex;
  justify-content: flex-end;
  padding: 0 20px 20px;
}

.tenant-usage-card .card-header {
  border-bottom: 0;
}

.usage-metric-list {
  display: grid;
  gap: 16px;
  padding: 4px 20px 18px;
}

.usage-meter {
  display: grid;
  gap: 7px;
}

.usage-meter-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--text-muted);
  font-size: 12px;
}

.usage-meter-head strong {
  color: var(--text);
  font-weight: 700;
}

.usage-meter.is-over-limit .usage-meter-head span,
.usage-meter.is-over-limit .usage-meter-head strong {
  color: #b42318;
}

.usage-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--border-2);
  overflow: hidden;
}

.usage-bar span {
  display: block;
  height: 100%;
  min-width: 3px;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), #2563eb);
}

.usage-meter.is-over-limit .usage-bar span {
  background: linear-gradient(90deg, #ef4444, #b42318);
}

.tenant-usage-facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 0 20px 20px;
}

.tenant-usage-facts div {
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 11px;
  background: var(--surface-2);
}

.tenant-usage-facts span,
.tenant-usage-facts small {
  display: block;
  color: var(--text-muted);
  font-size: 11px;
}

.tenant-usage-facts strong {
  display: block;
  margin: 2px 0;
  font-size: 22px;
  line-height: 1.1;
  color: var(--text);
}

.tenant-plan-section {
  margin-top: 18px;
}

.section-title-row {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.section-title-row h2 {
  margin: 2px 0 0;
  font-size: 22px;
}

.billing-env {
  color: var(--text-muted);
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  background: var(--surface);
}

.paypal-sandbox-note {
  margin: 0 0 18px;
  padding: 12px 14px;
  border: 1px solid #fde68a;
  border-radius: 8px;
  background: #fffbeb;
  color: #92400e;
  font-size: 13px;
  line-height: 1.45;
}

.tenant-plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.plan-card {
  display: grid;
  gap: 14px;
  align-content: start;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 16px;
}

.plan-card.is-current {
  border-color: rgba(0, 150, 136, .45);
  box-shadow: 0 0 0 1px rgba(0, 150, 136, .08), var(--shadow);
}

.plan-card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.plan-card h3 {
  margin: 0;
  font-size: 18px;
}

.plan-card p {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.45;
}

.plan-price {
  display: flex;
  align-items: baseline;
  gap: 7px;
  min-height: 36px;
  flex-wrap: wrap;
}

.plan-price strong {
  font-size: 32px;
  line-height: 1;
  color: var(--text);
}

.plan-price strong:not(:first-child)::before,
.plan-price strong:first-child:not(:only-child)::before {
  content: "$";
  font-size: 15px;
  vertical-align: super;
}

.plan-price span {
  color: var(--text-muted);
  font-size: 12px;
}

.plan-price small {
  flex-basis: 100%;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.35;
}

.plan-limit-list {
  display: grid;
  gap: 8px;
  margin: 0;
}

.plan-limit-list div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 7px;
}

.plan-limit-list dt {
  color: var(--text-muted);
  font-size: 12px;
}

.plan-limit-list dd {
  margin: 0;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  text-align: right;
}

.billing-period-control,
.extra-seat-control {
  display: grid;
  gap: 7px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  padding: 10px;
}

.billing-period-control label,
.extra-seat-control label {
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.billing-period-control select,
.extra-seat-control input {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--text);
  background: var(--surface);
  padding: 6px 9px;
}

.billing-period-control small,
.extra-seat-control small,
.billing-help-text {
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.45;
}

.plan-price-estimate {
  color: var(--primary);
  font-size: 12px;
}

.plan-feature-list {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.plan-feature-list li {
  position: relative;
  padding-left: 16px;
  color: var(--text-muted);
  font-size: 12px;
}

.plan-feature-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 7px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
}

.plan-action {
  min-height: 48px;
}

.paypal-button-slot {
  min-height: 44px;
}

.plan-error {
  min-height: 16px;
  margin-top: 6px;
  color: #b42318;
  font-size: 12px;
}

.btn-danger-soft {
  color: #b42318;
  background: #fee4e2;
  border-color: #fecaca;
}

.btn-muted {
  color: var(--text-muted);
  background: var(--surface-2);
  border-color: var(--border);
}

@media (max-width: 1200px) {
  .tenant-plan-grid {
    grid-template-columns: repeat(2, minmax(240px, 1fr));
  }
}

@media (max-width: 900px) {
  .tenant-admin-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .tenant-plan-grid,
  .billing-summary-grid,
  .tenant-usage-facts {
    grid-template-columns: 1fr;
  }

  .section-title-row {
    align-items: flex-start;
    flex-direction: column;
  }
}

.batch-share-card {
  margin-bottom: 18px;
}

.batch-share-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 18px;
}

.batch-share-grid section {
  display: grid;
  gap: 10px;
}

.batch-share-grid h3 {
  font-size: 13px;
  font-weight: 800;
  margin: 0;
}

/* ─── Document Form ──────────────────────────────────────────── */
.document-form { display: grid; gap: 0.75rem; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(200px,1fr));
  gap: 0.85rem;
}
.editor-shell {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  overflow: hidden;
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.editor-shell .document-editor {
  border: 0;
  border-radius: 0;
}

.document-editor {
  min-height: 280px;
  font-family: Consolas, 'Courier New', monospace;
}

.editor-status {
  min-height: 28px;
  padding: 6px 10px;
  color: var(--text-muted);
  font-size: 12px;
  border-top: 1px solid var(--border-2);
}

.document-workspace-head {
  align-items: center;
  margin-bottom: 18px;
}

.page-eyebrow {
  display: block;
  margin-bottom: 4px;
  color: var(--primary-dark);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Detail header: chip + status badge row (not an uppercase kicker) */
.document-detail-head .page-eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  text-transform: none;
  letter-spacing: 0;
}

.document-builder-form {
  display: grid;
  gap: 16px;
  width: 100%;
}

.form-grid-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.document-builder-card {
  overflow: hidden;
  border-radius: var(--r);
}

.document-profile-grid {
  display: grid;
  grid-template-columns: minmax(160px, 220px) minmax(260px, 1fr) repeat(3, minmax(150px, 210px));
  gap: 14px;
  align-items: start;
}

.document-builder-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border-2);
  background: var(--surface-2);
}

.html-editor {
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.8);
}

.html-editor-toolbar {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  padding: 8px;
  border-bottom: 1px solid var(--border);
  background: #f7f9fc;
}

.editor-tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid #d8e0ea;
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  user-select: none;
}

.editor-tool:hover {
  background: var(--primary-light);
  border-color: var(--primary-border);
  color: var(--primary-dark);
}

.editor-file-tool {
  margin: 0;
}

.editor-divider {
  width: 1px;
  height: 22px;
  margin: 0 3px;
  background: var(--border);
}

.html-editor-canvas {
  min-height: 430px;
  padding: 28px 34px;
  outline: none;
  background: #fff;
  color: var(--text);
  line-height: 1.65;
}

.html-editor-canvas:focus {
  box-shadow: inset 0 0 0 3px rgba(13,148,136,0.08);
}

.html-editor-input {
  display: none;
}

.document-rich-content {
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Inter', sans-serif;
  white-space: normal;
  word-break: normal;
  font-size: 14px;
  color: var(--text);
}

.document-rich-content h1,
.document-rich-content h2,
.document-rich-content h3,
.document-rich-content h4,
.document-rich-content h5,
.document-rich-content h6,
.html-editor-canvas h1,
.html-editor-canvas h2,
.html-editor-canvas h3,
.html-editor-canvas h4,
.html-editor-canvas h5,
.html-editor-canvas h6 {
  margin: 0 0 10px;
  color: var(--text);
  line-height: 1.25;
}

.document-rich-content h1,
.html-editor-canvas h1 { font-size: 24px; }
.document-rich-content h2,
.html-editor-canvas h2 { font-size: 19px; }
.document-rich-content h3,
.html-editor-canvas h3 { font-size: 16px; }
.document-rich-content h4,
.html-editor-canvas h4 { font-size: 15px; }
.document-rich-content h5,
.html-editor-canvas h5,
.document-rich-content h6,
.html-editor-canvas h6 { font-size: 14px; }

.document-rich-content p,
.html-editor-canvas p {
  margin: 0 0 12px;
}

.document-rich-content ul,
.document-rich-content ol,
.html-editor-canvas ul,
.html-editor-canvas ol {
  margin: 0 0 14px 22px;
  padding: 0;
}

.document-rich-content table,
.html-editor-canvas table {
  width: 100%;
  margin: 14px 0;
  border-collapse: collapse;
  font-size: 13px;
}

.document-rich-content th,
.document-rich-content td,
.html-editor-canvas th,
.html-editor-canvas td {
  padding: 9px 10px;
  border: 1px solid var(--border);
  vertical-align: top;
}

.document-rich-content th,
.html-editor-canvas th {
  background: var(--surface-2);
  font-weight: 800;
}

.document-rich-content blockquote,
.html-editor-canvas blockquote {
  margin: 14px 0;
  padding: 10px 14px;
  border-left: 3px solid var(--primary);
  background: var(--primary-light);
}

.document-rich-content pre,
.document-html-editor .dx-htmleditor-content pre {
  margin: 14px 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: #0f172a;
  color: #f8fafc;
  overflow: auto;
  white-space: pre-wrap;
}

.document-rich-content code,
.document-html-editor .dx-htmleditor-content code {
  font-family: Consolas, 'Courier New', monospace;
  font-size: .92em;
}

.document-rich-content .ql-align-center { text-align: center; }
.document-rich-content .ql-align-right { text-align: right; }
.document-rich-content .ql-align-justify { text-align: justify; }
.document-rich-content .ql-size-small { font-size: .85em; }
.document-rich-content .ql-size-large { font-size: 1.25em; }
.document-rich-content .ql-size-huge { font-size: 1.55em; }
.document-rich-content .ql-font-serif { font-family: Georgia, 'Times New Roman', serif; }
.document-rich-content .ql-font-monospace { font-family: Consolas, 'Courier New', monospace; }
.document-rich-content .ql-direction-rtl { direction: rtl; text-align: inherit; }
.document-rich-content .ql-indent-1 { padding-left: 2.25rem; }
.document-rich-content .ql-indent-2 { padding-left: 4.5rem; }
.document-rich-content .ql-indent-3 { padding-left: 6.75rem; }
.document-rich-content .ql-indent-4 { padding-left: 9rem; }
.document-rich-content .ql-indent-5 { padding-left: 11.25rem; }
.document-rich-content .ql-indent-6 { padding-left: 13.5rem; }
.document-rich-content .ql-indent-7 { padding-left: 15.75rem; }
.document-rich-content .ql-indent-8 { padding-left: 18rem; }

.version-compare-card {
  overflow: hidden;
}

.diff-table td {
  vertical-align: top;
  font-family: Consolas, 'Courier New', monospace;
  white-space: pre-wrap;
}

.diff-table td:first-child,
.diff-table td:nth-child(2),
.diff-table td:nth-child(4) {
  font-family: 'Segoe UI', sans-serif;
}

.diff-added td {
  background: #ecfdf5;
}

.diff-removed td {
  background: #fff1f2;
}

.diff-modified td {
  background: #fffbeb;
}

.diff-badge {
  background: var(--surface-2);
  color: var(--text-2);
}

.diff-added .diff-badge {
  background: var(--success-bg);
  color: var(--success);
}

.diff-removed .diff-badge {
  background: var(--danger-bg);
  color: var(--danger);
}

.diff-modified .diff-badge {
  background: var(--warning-bg);
  color: #854d0e;
}

.diff-side-table {
  table-layout: fixed;
}

.diff-side-table th:nth-child(3),
.diff-side-table th:nth-child(5),
.diff-side-table td:nth-child(3),
.diff-side-table td:nth-child(5) {
  width: 38%;
}

.diff-side-cell {
  line-height: 1.55;
  word-break: break-word;
}

.email-sent {
  background: var(--success-bg);
  border-color: #bbf7d0;
}

.email-not-sent {
  background: var(--warning-bg);
  border-color: #fde68a;
}

/* ─── Summary grid (document detail) ────────────────────────── */
.document-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.document-summary div {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 0.85rem;
}
.document-summary strong { display: block; font-size: 1.1rem; }
.document-summary span { color: var(--text-muted); font-size: 0.86rem; }

/* Document control tabbed workflow */
.document-detail-head {
  margin-bottom: 14px;
}

.document-summary-compact {
  gap: 10px;
}

.document-summary-compact div {
  border-radius: var(--r);
  padding: 12px 14px;
}

.document-summary-compact strong {
  font-size: 14px;
  margin-top: 3px;
}

.rx-card-tabs {
  overflow: hidden;
  border-radius: var(--r);
}

.rx-card-tabs > .card-header {
  background: var(--surface);
}

.rx-doc-tabs {
  width: 100%;
  gap: 0;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
}

.rx-doc-tabs .nav-item {
  margin-bottom: -1px;
}

.rx-doc-tabs .nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  transition: color 0.14s, border-color 0.14s, background 0.14s;
}

.rx-doc-tabs .nav-link:hover {
  background: var(--surface-2);
  color: var(--text);
}

.rx-doc-tabs .nav-link.active {
  background: var(--surface);
  border-color: var(--border) var(--border) var(--surface);
  color: var(--primary-dark);
}

.rx-doc-tab-content {
  padding: 18px;
}

.document-tab-stack {
  display: grid;
  gap: 18px;
  width: 100%;
}

.document-reader-panel {
  min-width: 0;
}

/* Full-width edit draft panel (editor is the primary view) */
.document-edit-full {
  width: 100%;
}

.document-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border-2);
}

.editor-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 16px 0 8px;
}

.editor-summary-label {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  margin-top: 16px;
}

.form-hint-inline {
  font-weight: 500;
  font-size: 12px;
  color: var(--text-muted);
}

/* Collapsible rendered preview under the editor */
.document-preview-details {
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  overflow: hidden;
}

.document-preview-details > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  font-weight: 700;
  color: var(--text);
  background: var(--surface-2);
  user-select: none;
}

.document-preview-details > summary::-webkit-details-marker {
  display: none;
}

.document-preview-details > summary::before {
  content: "▸";
  color: var(--text-muted);
  font-size: 12px;
}

.document-preview-details[open] > summary::before {
  content: "▾";
}

.document-preview-hint {
  font-weight: 500;
  font-size: 12px;
  color: var(--text-muted);
}

.document-preview-details .document-sheet-reader {
  border: 0;
  border-radius: 0;
  min-height: 0;
}

.section-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-title-row h2,
.grid-toolbar h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
}

.section-title-row p,
.grid-toolbar p {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 12px;
}

.document-sheet-reader {
  min-height: 560px;
}

.document-edit-panel {
  padding: 16px;
}

.workflow-layout {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.workflow-layout > .grid-panel:only-child {
  grid-column: 1 / -1;
}

.workflow-submit-panel {
  padding: 16px;
}

.grid-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}

.grid-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.control-grid {
  border-collapse: separate;
  border-spacing: 0;
}

.control-grid th {
  padding: 10px 12px;
  background: #f7f9fc;
  border-bottom: 1px solid #d8e0ea;
  color: #475569;
}

.control-grid td {
  padding: 10px 12px;
  border-bottom: 1px solid #edf2f7;
}

.control-grid tbody tr:hover td {
  background: #f8fbfd;
}

.grid-empty {
  padding: 28px 14px !important;
  text-align: center;
  color: var(--text-muted) !important;
  background: var(--surface) !important;
}

.grid-secondary-text {
  display: grid;
  gap: 2px;
  color: var(--text-muted);
  font-size: 12px;
}

.grid-secondary-text strong {
  color: var(--text-2);
}

.grid-actions-stacked {
  display: grid;
  gap: 8px;
  min-width: 420px;
}

.approval-action-form {
  display: grid;
  grid-template-columns: minmax(100px, 140px) minmax(140px, 1fr) auto;
  gap: 6px;
}

.approval-single-action {
  min-width: min(720px, 100%);
}

.approval-decision-form {
  display: grid;
  grid-template-columns: minmax(118px, 0.36fr) minmax(220px, 1fr) minmax(170px, 0.72fr) auto;
  gap: 8px;
  align-items: center;
}

.approval-decision-form .btn {
  white-space: nowrap;
}

.share-toolbar-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 180px minmax(220px, .8fr) auto;
  gap: 12px;
  align-items: end;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-2);
  background: var(--surface-2);
}

.share-option-check {
  align-self: center;
  margin: 0;
}

.share-option-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 10px 18px;
  margin: 14px 0;
}

.smtp-test-row {
  margin-top: 12px;
  align-items: end;
}

.smtp-test-action {
  display: flex;
  align-items: end;
  justify-content: flex-start;
}

.template-token-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-content: start;
  padding-top: 20px;
}

.template-token-list span {
  width: 100%;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.template-token-list code {
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--text-2);
}

.template-editor {
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
}

.email-log-panel {
  margin-top: 18px;
}

.locked-state {
  margin: 14px 16px;
  padding: 10px 12px;
  border: 1px solid #fde68a;
  border-radius: var(--r);
  background: var(--warning-bg);
  color: #854d0e;
  font-size: 13px;
}

.selected-count {
  flex-shrink: 0;
  padding: 4px 9px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

.document-workspace-head .action-bar {
  flex: 1 1 auto;
  justify-content: flex-end;
}

.document-head-copy {
  flex: 0 0 auto;
  min-width: 260px;
}

.document-head-search {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  flex: 1 1 520px;
  max-width: 780px;
  min-width: 360px;
}

.document-head-search .form-control {
  min-height: 36px;
  background: #fff;
}

.search-match-cell {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.search-match-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.search-match-tag {
  padding: 2px 7px;
  border: 1px solid rgba(20, 184, 166, .45);
  border-radius: 999px;
  background: rgba(20, 184, 166, .1);
  color: var(--primary-dark);
  font-size: 11px;
  font-weight: 800;
}

.search-match-snippet {
  color: var(--text);
  font-size: 12px;
  line-height: 1.45;
  white-space: normal;
}

@media (max-width: 1200px) {
  .document-workspace-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .document-workspace-head .action-bar,
  .document-head-search {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .document-head-search {
    grid-template-columns: 1fr;
    min-width: 0;
  }
}

.documents-grid-card {
  overflow: hidden;
}

.dx-grid-host {
  width: 100%;
}

.dx-grid-host .dx-datagrid {
  background: transparent;
  color: var(--text);
  font-family: inherit;
}

.dx-grid-host .dx-datagrid-headers,
.dx-grid-host .dx-toolbar,
.dx-grid-host .dx-datagrid-filter-row,
.dx-grid-host .dx-datagrid-pager {
  background: var(--surface-2);
}

.dx-grid-host .dx-datagrid-headers .dx-datagrid-table .dx-row > td {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.dx-grid-host .dx-row.dx-data-row > td {
  vertical-align: middle;
  color: var(--text);
}

.dx-grid-host .dx-datagrid-search-panel {
  width: min(340px, 100%);
}

.dx-grid-host .dx-master-detail-cell {
  background: #fbfdff;
}

.dx-grid-host .role-text {
  font-weight: 700;
  color: var(--text);
}

.dx-grid-host .role-select-host .dx-texteditor {
  min-height: 30px;
}

.dx-grid-host .role-select-host .dx-texteditor-input {
  min-height: 28px;
  padding-top: 4px;
  padding-bottom: 4px;
  font-weight: 700;
}

.access-detail-grid {
  padding: 10px 0 12px;
}

.access-detail-grid .access-status-badge {
  min-width: 78px;
  justify-content: center;
  font-weight: 800;
  letter-spacing: 0;
}

.access-permission-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 112px;
  margin: 0;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}

.access-permission-switch input {
  appearance: none;
  width: 32px;
  height: 18px;
  margin: 0;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: #e2e8f0;
  position: relative;
  transition: background .16s ease, border-color .16s ease;
}

.access-permission-switch input::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .2);
  transition: transform .16s ease;
}

.access-permission-switch input:checked {
  border-color: var(--primary);
  background: var(--primary);
}

.access-permission-switch input:checked::before {
  transform: translateX(14px);
}

.access-permission-switch input:disabled {
  cursor: not-allowed;
  opacity: .55;
}

.dx-editor-shell {
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
  background: var(--surface);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.65);
  position: relative;
}

.document-html-editor.dx-htmleditor {
  border: 0;
  font-family: inherit;
}

.document-html-editor .dx-htmleditor-content {
  color: var(--text);
  font-size: 14px;
  line-height: 1.62;
}

.document-html-editor .dx-htmleditor-content h1,
.document-html-editor .dx-htmleditor-content h2,
.document-html-editor .dx-htmleditor-content h3 {
  color: var(--text);
  margin: 1.1rem 0 .55rem;
  font-weight: 800;
}

.document-html-editor .dx-htmleditor-content table {
  width: 100%;
  border-collapse: collapse;
}

.document-html-editor .dx-htmleditor-content th,
.document-html-editor .dx-htmleditor-content td {
  border: 1px solid var(--border);
  padding: 8px 10px;
}

.dx-editor-shell.dx-editor-ready .dx-editor-hidden {
  display: none;
}

.dx-editor-fallback {
  display: none;
  width: 100%;
  min-height: 360px;
  border: 0;
  padding: 14px;
  color: var(--text);
  background: var(--surface);
  font-family: Consolas, 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.55;
  resize: vertical;
}

.dx-editor-loading {
  padding: 9px 12px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--surface-2);
  font-size: 12px;
}

.dx-editor-shell.dx-editor-ready .dx-editor-loading {
  display: none;
}

.dx-editor-shell.dx-editor-failed .dx-editor-loading {
  color: #991b1b;
  background: #fef2f2;
}

.dx-editor-shell.dx-editor-failed .dx-editor-fallback {
  display: block;
}

.dx-editor-shell.dx-editor-failed .dx-editor-loading::after {
  content: " Using HTML fallback.";
}

.batch-share-message {
  display: none;
  margin-bottom: 12px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 13px;
}

.batch-share-message.active {
  display: block;
}

.rx-modal .modal-content {
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-md);
}

.rx-modal .modal-header,
.rx-modal .modal-footer {
  border-color: var(--border);
}

.rx-modal .modal-body {
  display: grid;
  gap: 12px;
}

.modal-eyebrow {
  display: block;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.rx-modal .modal-title {
  margin: 2px 0 0;
  font-size: 16px;
  font-weight: 800;
}

.compare-modal .modal-dialog {
  max-width: min(1480px, calc(100vw - 32px));
}

.import-diff-modal .modal-dialog {
  max-width: min(1480px, calc(100vw - 32px));
}

.compare-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.compare-summary div {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
}

.compare-summary span {
  display: block;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.compare-summary strong {
  display: block;
  margin-top: 3px;
}

.doc-compare-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.doc-compare-panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
}

.doc-compare-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.doc-compare-heading span {
  display: block;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.doc-compare-heading strong {
  display: block;
  margin-top: 2px;
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
}

.doc-compare-content {
  height: min(66vh, 680px);
  min-height: 430px;
  overflow: auto;
  padding: 24px;
  background: #fff;
  color: var(--text);
}

.doc-compare-content img {
  max-width: 100%;
  height: auto;
}

.html-diff-del,
.html-diff-ins {
  border-left: 3px solid transparent !important;
  margin-left: -3px;
  padding-left: 12px !important;
}

.html-diff-del {
  background-color: rgba(220, 38, 38, 0.09) !important;
  border-left-color: #dc2626 !important;
}

.html-diff-ins {
  background-color: rgba(5, 150, 105, 0.11) !important;
  border-left-color: #059669 !important;
}

.doc-compare-content tr.html-diff-del > th,
.doc-compare-content tr.html-diff-del > td {
  background-color: rgba(220, 38, 38, 0.09) !important;
}

.doc-compare-content tr.html-diff-ins > th,
.doc-compare-content tr.html-diff-ins > td {
  background-color: rgba(5, 150, 105, 0.11) !important;
}

.doc-compare-content tr.html-diff-del > th:first-child,
.doc-compare-content tr.html-diff-del > td:first-child,
.doc-compare-content th.html-diff-del,
.doc-compare-content td.html-diff-del {
  border-left: 3px solid #dc2626 !important;
}

.doc-compare-content tr.html-diff-ins > th:first-child,
.doc-compare-content tr.html-diff-ins > td:first-child,
.doc-compare-content th.html-diff-ins,
.doc-compare-content td.html-diff-ins {
  border-left: 3px solid #059669 !important;
}

.doc-compare-content td > .html-diff-del,
.doc-compare-content th > .html-diff-del,
.doc-compare-content td > .html-diff-ins,
.doc-compare-content th > .html-diff-ins,
.doc-compare-content td > .html-diff-line,
.doc-compare-content th > .html-diff-line {
  display: block;
  margin: 0 -6px 8px;
  padding: 4px 6px 4px 10px !important;
}

.doc-compare-content td > .html-diff-line,
.doc-compare-content th > .html-diff-line {
  border-left: 3px solid transparent;
}

.html-word-del,
.html-word-ins {
  border-radius: 3px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  padding: 1px 2px;
}

.html-word-del {
  background-color: rgba(220, 38, 38, 0.14);
  color: #7f1d1d;
}

.html-word-ins {
  background-color: rgba(5, 150, 105, 0.15);
  color: #064e3b;
}

.html-diff-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 18px;
  margin: 0 0 12px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  font-size: 12px;
}

.html-diff-legend[hidden] {
  display: none;
}

.html-diff-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-2);
}

.html-diff-legend-note {
  margin-left: auto;
  color: var(--text-muted);
  font-style: italic;
}

.html-diff-legend-swatch {
  display: inline-block;
  width: 14px;
  height: 12px;
  border-left: 3px solid transparent;
  border-radius: 2px;
}

.html-diff-legend-swatch.is-del {
  background: rgba(220, 38, 38, 0.14);
  border-color: #dc2626;
}

.html-diff-legend-swatch.is-ins {
  background: rgba(5, 150, 105, 0.16);
  border-color: #059669;
}

.badge-pending .badge-dot { background: #ca8a04; }
.badge-approved .badge-dot { background: #22c55e; }

/* ─── External View ──────────────────────────────────────────── */
.external-body { background: #eef3f0; }
.external-shell { max-width: 1060px; margin: 0 auto; padding: 1.25rem; }
.external-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.external-header h1 { font-size: 1.5rem; margin: 0; }
.external-header p,
.external-header span { color: var(--text-muted); margin: 0.2rem 0 0; }
.external-auth { margin: 2rem auto; }
.external-sheet { min-height: calc(100vh - 140px); }

/* ─── Auth Shell (legacy external view) ─────────────────────── */
.auth-shell {
  min-height: calc(100vh - 160px);
  display: grid;
  place-items: center;
}
.auth-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  width: min(100%, 430px);
  padding: 2rem;
}
.auth-panel h1, .auth-panel h2 { font-size: 1.2rem; margin: 0 0 1rem; }
.auth-switch { margin-top: 1rem; text-align: center; }
.auth-check { margin: 0.2rem 0 0.8rem; }
.stack-form { display: grid; gap: 0.55rem; }

/* ─── Form panels (legacy detail view) ──────────────────────── */
.form-panel, .table-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xs);
}
.form-panel { padding: 1.25rem; }
.table-panel { padding: 0.4rem 1rem 1rem; }
.form-panel h2, .table-panel h2 { font-size: 1.1rem; margin: 0 0 0.85rem; }
.wide-form { max-width: 980px; }
.compact-form { max-width: 620px; }
.page-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.page-heading h1 { font-size: 1.6rem; margin: 0; }
.page-heading p { color: var(--text-muted); margin: 0.2rem 0 0; }
.action-row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.table { margin-bottom: 0; }
.table th { color: var(--text-muted); font-size: 0.78rem; text-transform: uppercase; }
.table-title { font-weight: 700; }
.metric-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px,1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.metric-row div {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 0.85rem;
}
.metric-row strong { display: block; font-size: 1.2rem; }
.metric-row span { color: var(--text-muted); font-size: 0.86rem; }
.mono { font-family: Consolas, 'Courier New', monospace; }

/* ─── Responsive ─────────────────────────────────────────────── */
@media (max-width: 960px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.active { display: block; }
  .app-main { margin-left: 0; }
  .sidebar-toggle { display: flex; }

  .auth-page { grid-template-columns: 1fr; }
  .auth-brand { display: none; }

  .detail-grid,
  .settings-layout,
  .batch-share-grid,
  .form-grid-4,
  .workflow-layout,
  .share-toolbar-form,
  .share-option-grid,
  .compare-summary,
  .doc-compare-grid,
  .document-profile-grid { grid-template-columns: 1fr; }

  .workflow-layout > .grid-panel:only-child {
    grid-column: auto;
  }
}

@media (max-width: 640px) {
  .app-content { padding: 16px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .document-sheet { padding: 1.2rem; }
  .watermark-text { font-size: 2.2rem; }
  .field-row,
  .form-grid { grid-template-columns: 1fr; }
  .approval-actions form { grid-template-columns: 1fr; }
  .approval-action-form,
  .approval-decision-form { grid-template-columns: 1fr; }
  .grid-actions-stacked { min-width: 0; }
  .rx-doc-tabs { overflow-x: auto; flex-wrap: nowrap; }
  .grid-toolbar { align-items: flex-start; flex-direction: column; }
  .html-editor-canvas { min-height: 320px; padding: 20px; }
  .doc-compare-content { height: auto; max-height: 70vh; min-height: 280px; padding: 18px; }
  .document-builder-actions { justify-content: stretch; }
  .document-builder-actions .btn { width: 100%; justify-content: center; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .search-input-wrap { flex: 1; }
}

/* ============================================================
   Retired widget integration
   ============================================================ */
/* Grid blends into the card surface */
/* Document grid cell helpers */
/* Badges sit comfortably inside grid cells */
/* Retired rich editor frame */
/* Validation summary box (only shows when there are errors) */
.validation-summary-valid { display: none; }
.validation-summary.validation-summary-errors {
  margin-bottom: 14px;
  background: var(--danger-bg);
  border: 1px solid #fca5a5;
  border-radius: var(--r);
  padding: 12px 16px;
}
.validation-summary.validation-summary-errors ul { margin: 0; padding-left: 18px; }

/* Approval queue row actions */
.queue-actions { display: flex; gap: 6px; justify-content: flex-end; }
/* Version diff text cell — wrap long lines */
.diff-table .diff-text { white-space: pre-wrap; word-break: break-word; }

/* Inline word-level diff highlighting */
.diff-text ins {
  background: #dcfce7;
  color: #166534;
  text-decoration: none;
  padding: 0 2px;
  border-radius: 3px;
}
.diff-text del {
  background: #fee2e2;
  color: #991b1b;
  text-decoration: line-through;
  padding: 0 2px;
  border-radius: 3px;
}
.diff-legend {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--text-muted);
}
.diff-legend ins { background:#dcfce7; color:#166534; text-decoration:none; padding:0 6px; border-radius:3px; }
.diff-legend del { background:#fee2e2; color:#991b1b; padding:0 6px; border-radius:3px; }
.diff-legend-note { margin-left: auto; }

/* ============================================================
   External recipient portal
   ============================================================ */
.ext-body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: #eef2f7;
  color: var(--text);
}
.ext-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 22px;
  background: linear-gradient(120deg, #0f172a 0%, #134e4a 100%);
  color: #fff;
}
.ext-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  text-decoration: none;
  font-size: 16px;
  font-weight: 800;
}
.ext-brand small { font-weight: 500; opacity: .75; font-size: 11px; display: block; }
.ext-logo {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  background: transparent url("../img/routact-mark.svg") center / contain no-repeat;
  border-radius: 0;
}
.ext-logo svg { display: none; }
.ext-topbar-right { display: flex; align-items: center; gap: 12px; }
.ext-user-chip {
  font-size: 12.5px;
  background: rgba(255,255,255,.12);
  padding: 5px 12px;
  border-radius: 999px;
}
.ext-main { flex: 1; width: min(1040px, 94vw); margin: 26px auto; }
.ext-footer { text-align: center; color: var(--text-muted); font-size: 12px; padding: 18px; }

.ext-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  padding: 22px 24px;
  margin-bottom: 18px;
}
.ext-login-card { width: min(460px, 94vw); margin: 6vh auto; }
.ext-eyebrow {
  display: block;
  color: var(--primary-dark);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.ext-card h1 { font-size: 22px; font-weight: 800; margin: 0 0 6px; letter-spacing: -.01em; }
.ext-muted { color: var(--text-muted); font-size: 13.5px; }
.ext-form { display: grid; gap: 4px; margin-top: 14px; }
.ext-fineprint { margin-top: 16px; font-size: 12px; color: var(--text-muted); }

.ext-page-head { margin-bottom: 16px; }
.ext-page-head h1 { font-size: 25px; font-weight: 800; margin: 2px 0 4px; letter-spacing: -.02em; }

.ext-company-card { padding: 0; overflow: hidden; }
.ext-company-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-2);
  background: var(--surface-2);
}
.ext-company-head h2 { font-size: 16px; font-weight: 800; margin: 0; }
.ext-company-card.is-locked .ext-company-head { background: #fff7ed; }
.ext-lock-badge {
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em;
  padding: 4px 10px; border-radius: 999px;
  background: #fee2e2; color: #b91c1c;
}
.ext-lock-badge.is-on { background: var(--success-bg); color: #166534; }
.ext-company-card .data-table { margin: 0; }
.ext-company-card .data-table th { padding-left: 20px; }
.ext-company-card .data-table td { padding-left: 20px; }
.ext-company-card > p { padding: 14px 20px 0; margin: 0; }
.ext-unlock-form {
  display: flex; gap: 10px; align-items: center;
  padding: 14px 20px 20px;
  max-width: 420px;
}
.ext-unlock-form .form-control { font-family: ui-monospace, Consolas, monospace; letter-spacing: 2px; }

.ext-package-access-card {
  width: min(900px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 0.9fr);
  gap: 0;
  padding: 0;
  overflow: hidden;
  margin: 26px auto 18px;
}

.ext-package-access-info {
  min-height: 230px;
  display: grid;
  align-content: center;
  padding: 30px 32px;
  background: var(--surface);
  border-right: 1px solid var(--border-2);
}

.ext-package-access-info h1 {
  font-size: 29px;
  line-height: 1.12;
  margin-bottom: 8px;
}

.ext-package-facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 22px;
}

.ext-package-facts span {
  min-height: 58px;
  display: grid;
  align-content: center;
  gap: 3px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.ext-package-facts strong {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.2;
  text-overflow: ellipsis;
  text-transform: none;
  letter-spacing: 0;
  white-space: nowrap;
}

.ext-package-access-panel {
  display: grid;
  align-content: center;
  gap: 14px;
  padding: 30px 32px;
  background: #f8fbfc;
}

.ext-package-access-panel h2 {
  margin: 0;
  color: var(--text);
  font-size: 17px;
  font-weight: 800;
}

.ext-package-unlock-form {
  display: grid;
  gap: 13px;
  max-width: none;
  padding: 0;
}

.ext-package-unlock-form .form-control {
  width: 100%;
  height: 48px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1.2px;
  padding: 10px 14px;
}

.ext-package-unlock-form label {
  display: grid;
  gap: 6px;
  margin: 0;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.ext-package-unlock-form input[name="Email"] {
  min-width: 0;
}

.ext-package-unlock-form input[name="AccessCode"] {
  min-width: 0;
}

.ext-package-unlock-form .btn {
  width: 100%;
  min-height: 48px;
  padding-inline: 18px;
  white-space: nowrap;
}

/* Document viewer */
.ext-doc-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 12px 16px;
  margin-bottom: 16px;
  position: sticky; top: 10px; z-index: 20;
  box-shadow: var(--shadow-sm);
}
.ext-doc-meta { display: flex; align-items: center; gap: 14px; min-width: 0; }
.ext-doc-title { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
.ext-doc-title strong { font-size: 14px; }
.ext-pager { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.ext-page-indicator { font-size: 12.5px; color: var(--text-muted); min-width: 92px; text-align: center; }

.ext-doc-viewer { display: flex; flex-direction: column; align-items: center; }
.ext-doc-source { position: absolute; left: -99999px; top: 0; visibility: hidden; }
.ext-doc-pages { width: 100%; display: flex; justify-content: center; }
.ext-page {
  position: relative;
  width: min(820px, 96%);
  min-height: 1040px;
  padding: 56px 64px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
  background-image: var(--ext-wm);
  background-repeat: repeat;
  background-position: center top;
  -webkit-user-select: none;
  user-select: none;
}
.ext-page > * { position: relative; }

@media (max-width: 720px) {
  .ext-doc-toolbar { flex-direction: column; align-items: stretch; }
  .ext-page { padding: 28px 22px; min-height: auto; }
}

@media (max-width: 860px) {
  .ext-package-access-card {
    grid-template-columns: 1fr;
    width: min(560px, 100%);
  }

  .ext-package-access-info {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border-2);
  }

  .ext-package-facts {
    grid-template-columns: 1fr;
  }
}

@media print {
  body.print-without-watermark .watermark-tile {
    display: none !important;
  }

  body.print-without-watermark .document-sheet {
    background-image: none !important;
  }

  body.printing-document {
    background: #fff !important;
  }

  body.printing-document .sidebar,
  body.printing-document .sidebar-overlay,
  body.printing-document .app-topbar,
  body.printing-document .page-head,
  body.printing-document .document-summary,
  body.printing-document .card-header,
  body.printing-document .document-edit-panel,
  body.printing-document .section-title-row,
  body.printing-document .tab-pane:not(#document-pane),
  body.printing-document #documentDetailTabs {
    display: none !important;
  }

  body.printing-document .app-main,
  body.printing-document .app-content {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    min-height: auto !important;
    background: #fff !important;
  }

  body.printing-document .rx-card-tabs,
  body.printing-document .rx-doc-tab-content,
  body.printing-document .document-tab-stack,
  body.printing-document .document-reader-panel {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: #fff !important;
  }

  body.printing-document #document-pane,
  body.printing-document #docViewPanel {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
  }

  body.printing-document .document-sheet {
    width: 100% !important;
    min-height: auto !important;
    margin: 0 !important;
    padding: 24px 32px !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }

  body.printing-document .document-content {
    color: #000 !important;
  }
}

/* Activity Page */
.activity-page-card .card-body {
  display: grid;
  gap: 16px;
}

.activity-filter-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1.5fr) minmax(160px, 1fr) minmax(150px, 1fr) minmax(135px, .75fr) minmax(135px, .75fr) minmax(90px, .45fr) auto;
  gap: 10px;
  align-items: end;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface-2);
}

.activity-filter-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.activity-log-list {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  background: var(--surface);
}

.activity-log-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-2);
}

.activity-log-row:last-child { border-bottom: 0; }
.activity-log-row:hover { background: var(--surface-2); }

.activity-log-marker {
  display: flex;
  justify-content: center;
  padding-top: 5px;
}

.activity-log-main {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.activity-log-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
}

.activity-event,
.activity-entity {
  display: inline-flex;
  align-items: center;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
}

.activity-event {
  background: var(--info-bg);
  color: #1d4ed8;
}

.activity-entity {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.activity-log-summary {
  color: var(--text-2);
  font-size: 13px;
}

.activity-log-doc .activity-doc { text-decoration: none; }

.activity-log-time {
  min-width: 112px;
  text-align: right;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.35;
}

.activity-log-time strong {
  display: block;
  color: var(--text-2);
}

.activity-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text-muted);
  font-size: 13px;
}

.activity-empty {
  border: 1px dashed var(--border);
  border-radius: var(--r-lg);
}

@media (max-width: 1180px) {
  .activity-filter-grid {
    grid-template-columns: repeat(3, minmax(160px, 1fr));
  }
}

@media (max-width: 760px) {
  .doc-dialog-backdrop {
    place-items: end center;
    padding: 16px;
  }

  .doc-dialog {
    grid-template-columns: 1fr;
  }

  .doc-dialog-icon {
    width: 36px;
    height: 36px;
  }

  .activity-filter-grid,
  .activity-log-row {
    grid-template-columns: 1fr;
  }

  .activity-pager {
    flex-direction: column;
    align-items: stretch;
  }

  .activity-log-time {
    text-align: left;
  }
}

/* ============================================================
   Platform Admin
   ============================================================ */
.platform-body {
  background: var(--page-bg);
}

.platform-sidebar .brand-icon {
  font-size: 0;
  font-weight: 900;
  letter-spacing: 0;
}

.nav-glyph {
  width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  background: rgba(255,255,255,.08);
  color: currentColor;
  font-size: 10px;
  font-weight: 800;
  flex: 0 0 16px;
}

.platform-auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #e8eef3;
}

.platform-auth-card {
  width: min(430px, 100%);
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.platform-auth-head {
  margin-bottom: 18px;
}

.platform-auth-head h1 {
  margin: 0 0 4px;
  font-size: 24px;
  font-weight: 800;
}

.platform-auth-head p {
  margin: 0;
  color: var(--text-muted);
}

.platform-totp-input {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: 4px;
}

.totp-setup-panel {
  display: grid;
  grid-template-columns: 144px 1fr;
  gap: 16px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
}

.totp-qr {
  width: 144px;
  height: 144px;
  border-radius: var(--r-sm);
  background: #fff;
  border: 1px solid var(--border);
}

.totp-secret {
  display: block;
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  white-space: normal;
  overflow-wrap: anywhere;
}

.user-authenticator-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
}

.user-authenticator-date {
  font-size: 11px;
}

.user-actions-cell {
  display: inline-flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  min-height: 30px;
}

.platform-auth-submit {
  justify-content: center;
  padding: 10px;
}

.platform-stat-grid {
  grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
}

.platform-money {
  font-size: 24px;
}

.metric-pill {
  align-self: flex-start;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.4rem 0.7rem;
}

.metric-pill.success {
  background: #dcfce7;
  color: #14532d;
}

.metric-pill.warning {
  background: #fef3c7;
  color: #92400e;
}

.platform-dashboard-grid,
.platform-detail-grid,
.platform-log-grid,
.platform-monitor-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.platform-log-grid,
.platform-monitor-grid {
  align-items: start;
}

.platform-table-wrap {
  overflow-x: auto;
}

.platform-table {
  min-width: 760px;
}

.platform-table td small,
.platform-table th small {
  display: block;
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
}

.platform-row-warning {
  background: #fff7ed;
}

.platform-search-form {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 10px;
  align-items: center;
}

.platform-definition-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 18px;
  margin: 0;
}

.platform-definition-grid div {
  min-width: 0;
}

.platform-definition-grid dt {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.platform-definition-grid dd {
  margin: 2px 0 0;
  color: var(--text);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.platform-usage-facts {
  margin-top: 14px;
}

.platform-support-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.platform-action-form {
  display: grid;
  gap: 8px;
  align-content: start;
}

.platform-sso-card {
  margin-bottom: 18px;
}

.platform-sso-grid {
  display: grid;
  grid-template-columns: minmax(280px, .8fr) minmax(420px, 1.2fr);
  gap: 18px;
  align-items: start;
}

.platform-section-label {
  color: var(--primary-dark);
  font-size: 10.5px;
  font-weight: 900;
  letter-spacing: .08em;
  line-height: 1.2;
  margin-bottom: 10px;
  text-transform: uppercase;
}

.platform-sso-reference .platform-definition-grid {
  grid-template-columns: 1fr;
}

.platform-sso-reference .mono,
.platform-sso-form .mono {
  white-space: pre-wrap;
  word-break: break-word;
}

.platform-sso-form {
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.platform-sso-entitlement-form {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

.company-sso-panel {
  display: grid;
  gap: 14px;
}

.company-sso-reference {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

.platform-sso-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

.alert-success {
  background: #dcfce7;
  border-color: #86efac;
  color: #166534;
}

.platform-note-list {
  display: grid;
  gap: 10px;
}

.platform-note {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
}

.platform-note p {
  margin: 0 0 6px;
  color: var(--text-2);
}

.platform-note small {
  color: var(--text-muted);
}

.platform-alert-list {
  display: grid;
  gap: 8px;
}

.platform-alert-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--text);
  text-decoration: none;
}

.platform-alert-row:hover {
  background: var(--surface-2);
  color: var(--text);
}

.platform-alert-row strong,
.platform-alert-row span {
  display: block;
}

.platform-alert-row span,
.platform-alert-row small {
  color: var(--text-muted);
}

@media (max-width: 1180px) {
  .platform-dashboard-grid,
  .platform-detail-grid,
  .platform-sso-grid,
  .platform-log-grid,
  .platform-monitor-grid,
  .platform-support-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .platform-search-form,
  .platform-definition-grid {
    grid-template-columns: 1fr;
  }
}

.doc-file-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 100%;
  padding: 4px 10px;
  border-radius: 999px;
  background: #f7fbfd;
  border: 1px solid #c3dce8;
  color: var(--primary-dark);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
  white-space: nowrap;
  text-decoration: none;
  transition: background .15s, border-color .15s, box-shadow .15s, color .15s;
}

/* Routact does not bundle Font Awesome, so the `fas fa-file-*` glyphs never
   render. Draw the icon from a self-contained SVG instead — works on every
   page that uses .doc-file-link without any view changes. */
.doc-file-link i {
  flex: 0 0 auto;
  width: 14px;
  height: 15px;
  display: inline-block;
  font-size: 0;
  background: url("/img/icon-file-doc.svg") no-repeat center / contain;
}

.doc-file-link.is-pdf i {
  background-image: url("/img/icon-file-pdf.svg");
}

a.doc-file-link:hover,
a.doc-file-link:focus {
  background: #eef8fb;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(16, 111, 132, .12);
  color: var(--primary-dark);
  text-decoration: none;
}

.two-col-grid {
  display: grid;
  grid-template-columns: minmax(360px, 0.8fr) minmax(0, 1.2fr);
  gap: 18px;
  align-items: start;
}

.form-check-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
}

.form-check-row label,
label.form-check-row {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.form-check-line {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
}

.form-check-line input {
  margin-top: 3px;
  accent-color: var(--primary);
}

.package-index-head {
  align-items: center;
}

.package-index-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.package-index-metric {
  min-height: 72px;
  display: grid;
  align-content: center;
  gap: 5px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.package-index-metric span {
  color: var(--text-muted);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: .06em;
  line-height: 1.2;
  text-transform: uppercase;
}

.package-index-metric strong {
  color: var(--text);
  font-size: 24px;
  font-weight: 850;
  line-height: 1;
}

.package-index-metric.is-success strong { color: var(--success); }
.package-index-metric.is-danger strong { color: var(--danger); }

.package-register-card,
.package-create-card {
  overflow: hidden;
  margin-bottom: 18px;
}

.package-register-header,
.package-create-header {
  background: var(--surface-2);
}

.package-register-table {
  margin-bottom: 0;
}

.package-register-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.package-register-search {
  flex: 0 1 420px;
  min-width: 260px;
}

.package-register-search .form-control {
  min-height: 36px;
  background: #fff;
}

.package-register-count {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.package-register-table th,
.package-register-table td {
  padding-top: 13px;
  padding-bottom: 13px;
  vertical-align: middle;
}

.package-name-cell {
  max-width: 520px;
}

.package-name-cell .col-muted {
  margin-top: 2px;
}

.package-empty-state {
  margin: 0;
  border: 0;
  border-radius: 0;
}

.package-register-no-results {
  margin: 0;
  border: 0;
  border-top: 1px solid var(--border);
  border-radius: 0;
}

.package-create-form {
  padding: 18px 20px 20px;
}

.package-create-grid {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr);
  gap: 18px 20px;
  align-items: start;
}

.package-form-section {
  display: grid;
  gap: 12px;
  min-width: 0;
  padding-top: 2px;
}

.package-section-label {
  color: var(--primary-dark);
  font-size: 10.5px;
  font-weight: 900;
  letter-spacing: .08em;
  line-height: 1.2;
  text-transform: uppercase;
}

.package-option-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.package-option-row label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  margin: 0;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 750;
}

.package-option-row input[type="checkbox"],
.package-doc-row input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--primary);
}

.package-recipient-box {
  min-height: 138px;
}

.package-create-documents {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border-2);
}

.package-doc-picker-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.package-doc-search {
  flex: 0 1 360px;
  min-width: 260px;
}

.package-doc-search .form-control {
  min-height: 36px;
  background: #fff;
}

.package-doc-picker {
  display: grid;
  gap: 8px;
}

.package-doc-list {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
  padding-right: 4px;
}

.package-doc-list-modern {
  max-height: 440px;
}

.package-doc-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, auto);
  gap: 12px;
  align-items: center;
  padding: 10px 11px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  transition: border-color .14s, background .14s, box-shadow .14s;
}

.package-doc-row:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.package-doc-main {
  display: grid;
  grid-template-columns: auto minmax(120px, auto) minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.package-doc-select {
  display: grid;
  grid-template-columns: auto minmax(120px, auto) minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  margin: 0;
}

.package-doc-select-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  margin: 0;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.package-doc-title {
  min-width: 0;
}

.package-doc-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.package-sign-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  margin: 0;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.package-doc-row small {
  display: block;
  color: var(--text-muted);
  margin-top: 2px;
}

.package-doc-no-results {
  margin: 10px 0 0;
}

.package-create-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border-2);
}

.package-create-footer span {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

.package-detail-head {
  margin-bottom: 18px;
}

.page-head-note {
  max-width: 880px;
  margin-top: 6px;
}

.package-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.package-metric {
  min-height: 86px;
  display: grid;
  align-content: center;
  gap: 7px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.package-metric span {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .06em;
  line-height: 1.2;
  text-transform: uppercase;
}

.package-metric strong {
  color: var(--text);
  font-size: 22px;
  font-weight: 800;
  line-height: 1.1;
}

.package-metric.is-success strong {
  color: var(--success);
}

.package-metric.is-danger strong {
  color: var(--danger);
}

.package-card {
  overflow: hidden;
  margin-bottom: 16px;
}

.package-card .card-header {
  background: var(--surface-2);
}

.package-card .data-table {
  margin-bottom: 0;
}

.package-card .data-table th,
.package-card .data-table td {
  padding-top: 13px;
  padding-bottom: 13px;
  vertical-align: middle;
}

.package-section-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.package-section-summary::-webkit-details-marker {
  display: none;
}

.package-section-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 900;
}

.package-section-toggle::before {
  content: "+";
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 1px solid var(--primary-border);
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: 13px;
  line-height: 1;
}

.package-section-card[open] .package-section-toggle::before {
  content: "-";
}

.package-section-card[open] .package-section-toggle {
  font-size: 0;
}

.package-section-card[open] .package-section-toggle::after {
  content: "Hide";
  font-size: 12px;
}

.signature-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.signed-download-options {
  display: grid;
  gap: 10px;
}

.signed-download-option {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  transition: background .15s, border-color .15s, box-shadow .15s;
}

.signed-download-option:hover,
.signed-download-option:focus-visible {
  background: var(--primary-light);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, .14);
  outline: 0;
}

.signed-download-option .option-title,
.signed-download-option .option-text {
  display: block;
}

.signed-download-option .option-title {
  font-size: 14px;
  font-weight: 900;
}

.signed-download-option .option-text {
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.45;
}

.package-output-form,
.package-output-state {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.package-output-form label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--text);
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
}

.package-output-form input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--primary);
}

.package-output-form .form-control-sm {
  width: min(260px, 100%);
  height: 30px;
  font-size: 12px;
}

.package-output-state .metric-pill:not(.success) {
  background: var(--surface-2);
  color: var(--text-muted);
}

.package-sign-card,
.signature-certificate {
  margin-top: 18px;
}

.signature-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.signature-head h2 {
  margin: 0;
  color: var(--text);
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 0;
}

.signature-form {
  max-width: 860px;
}

.signature-pad {
  display: block;
  width: 100%;
  max-width: 620px;
  height: 170px;
  margin-bottom: 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  background:
    linear-gradient(to bottom, transparent calc(100% - 35px), rgba(15, 23, 42, .12) calc(100% - 34px), transparent calc(100% - 33px)),
    #fff;
  touch-action: none;
}

.signature-image {
  display: block;
  max-width: 320px;
  max-height: 120px;
  margin: 4px 0 16px;
  border-bottom: 1px solid var(--border);
}

.signature-script {
  margin: 4px 0 16px;
  color: var(--text);
  font-family: "Segoe Script", "Brush Script MT", cursive;
  font-size: 30px;
  line-height: 1.35;
}

.signature-grid {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 8px 16px;
  margin: 0;
}

.signature-grid dt {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.signature-grid dd {
  min-width: 0;
  margin: 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  word-break: break-word;
}

.hash-value {
  font-family: Consolas, "Courier New", monospace;
  font-size: 11px !important;
}

.ext-terms-box {
  max-height: 52vh;
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
}

@media (max-width: 980px) {
  .two-col-grid {
    grid-template-columns: 1fr;
  }

  .package-index-metrics,
  .package-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .package-create-grid {
    grid-template-columns: 1fr;
  }

  .package-doc-picker-head {
    align-items: stretch;
    flex-direction: column;
  }

  .package-doc-search {
    flex-basis: auto;
    min-width: 0;
    width: 100%;
  }

  .package-register-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .package-register-search {
    flex-basis: auto;
    min-width: 0;
    width: 100%;
  }
}

@media (max-width: 560px) {
  .package-index-head {
    align-items: flex-start;
  }

  .package-index-metrics,
  .package-summary-grid {
    grid-template-columns: 1fr;
  }

  .package-create-form {
    padding: 16px;
  }

  .package-doc-row,
  .package-doc-main,
  .package-doc-select {
    grid-template-columns: 1fr;
  }

  .package-doc-controls {
    justify-content: stretch;
  }

  .package-sign-option {
    width: 100%;
    justify-content: center;
    border-radius: var(--r);
  }

  .package-create-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .package-create-footer .btn {
    justify-content: center;
    width: 100%;
  }
}
