/* ================================================================
   DocControl SaaS — 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-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: 34px; height: 34px;
  background: var(--primary);
  border-radius: var(--r);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.brand-icon svg { width: 18px; height: 18px; color: #fff; }

.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); }

@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;
}

/* ─── 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 { background: var(--surface-2); }

.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-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: 40px; height: 40px; }

.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;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  padding: 0 2px;
}

/* 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-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);
}

.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;
}

.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-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;
}

.extra-seat-control {
  display: grid;
  gap: 7px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  padding: 10px;
}

.extra-seat-control label {
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.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;
}

.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;
}

.share-toolbar-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 180px auto;
  gap: 12px;
  align-items: end;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-2);
  background: var(--surface-2);
}

.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;
}

.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;
}

.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,
  .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 { 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: 32px; height: 32px;
  display: grid; place-items: center;
  background: var(--primary);
  border-radius: 8px;
}
.ext-logo svg { width: 18px; height: 18px; }
.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; }

/* 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; }
}
