/* Sutton Attorneys Document Portal — Matching rmsutton.co.za Design System */
:root {
  --primary-bg: #020c1b;
  --secondary-bg: #0a192f;
  --card-bg: #0d1f3a;
  --gold: #c5a059;
  --gold-hover: #d8b572;
  --gold-muted: rgba(197, 160, 89, 0.32);
  --gold-soft: rgba(197, 160, 89, 0.12);
  --text-primary: #ccd6f6;
  --text-secondary: #a8b2d1;
  --text-muted: #8892b0;
  --white: #ffffff;
  --success: #34d399;
  --success-bg: rgba(52, 211, 153, 0.14);
  --warning: #fbbf24;
  --warning-bg: rgba(251, 191, 36, 0.14);
  --info: #60a5fa;
  --info-bg: rgba(96, 165, 250, 0.14);
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.14);
  --radius: 10px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--primary-bg);
  color: var(--text-primary);
  font-family: 'Inter', "Segoe UI", Arial, sans-serif;
  line-height: 1.6;
  min-height: 100vh;
}

h1, h2, h3, h4 {
  font-family: 'Playfair Display', "Times New Roman", serif;
  color: var(--gold);
  margin: 0 0 0.75rem 0;
  line-height: 1.25;
}

a { color: var(--gold); text-decoration: none; transition: color 0.2s ease; }
a:hover { color: var(--gold-hover); }

/* Header */
.portal-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(2, 12, 27, 0.96);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--gold-muted);
  padding: 0.75rem 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--gold-muted);
  object-fit: cover;
}

.brand-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--white);
  letter-spacing: 1.4px;
  display: block;
}

.brand-sub {
  font-size: 0.72rem;
  color: var(--gold);
  letter-spacing: 1px;
  text-transform: uppercase;
  display: block;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.header-nav a {
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
}

.header-nav a:hover, .header-nav a.active {
  color: var(--gold);
}

/* Layout */
.portal-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.portal-main-narrow {
  max-width: 720px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.75rem;
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: 0.92rem;
  margin: 0;
}

/* Cards */
.card {
  background: var(--secondary-bg);
  border: 1px solid var(--gold-muted);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.card-title {
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--secondary-bg);
  border: 1px solid rgba(197, 160, 89, 0.22);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.stat-card:hover, .stat-card.active {
  border-color: var(--gold);
  transform: translateY(-2px);
}

.stat-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
}

.stat-value {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 2rem;
  font-weight: 700;
  color: var(--white);
  margin-top: 0.2rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.65rem 1.2rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  text-decoration: none;
  font-family: inherit;
}

.btn-gold {
  background: var(--gold);
  color: var(--primary-bg);
}

.btn-gold:hover {
  background: var(--gold-hover);
  color: var(--primary-bg);
}

.btn-outline {
  background: transparent;
  border-color: var(--gold-muted);
  color: var(--gold);
}

.btn-outline:hover {
  border-color: var(--gold);
  background: var(--gold-soft);
  color: var(--white);
}

.btn-danger {
  background: var(--danger-bg);
  border-color: rgba(248, 113, 113, 0.4);
  color: var(--danger);
}

.btn-danger:hover {
  background: rgba(248, 113, 113, 0.25);
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Forms */
.form-group {
  margin-bottom: 1.15rem;
}

.form-label {
  display: block;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

.form-control {
  width: 100%;
  background: var(--primary-bg);
  border: 1px solid rgba(197, 160, 89, 0.3);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem;
  color: var(--white);
  font-size: 0.92rem;
  font-family: inherit;
}

.form-control:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(197, 160, 89, 0.18);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  background: rgba(2, 12, 27, 0.6);
  border: 1px solid rgba(197, 160, 89, 0.22);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  margin-bottom: 0.85rem;
  cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
  accent-color: var(--gold);
  width: 18px;
  height: 18px;
  margin-top: 2px;
  flex-shrink: 0;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.22rem 0.65rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-draft { background: rgba(148, 163, 184, 0.16); color: #cbd5e1; }
.badge-sent { background: var(--info-bg); color: var(--info); }
.badge-awaiting_countersign { background: var(--warning-bg); color: var(--warning); }
.badge-completed { background: var(--success-bg); color: var(--success); }
.badge-voided { background: var(--danger-bg); color: var(--danger); }

/* Tables */
.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.data-table th {
  text-align: left;
  padding: 0.8rem 0.9rem;
  border-bottom: 1px solid var(--gold-muted);
  color: var(--gold);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.data-table td {
  padding: 0.85rem 0.9rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  vertical-align: middle;
}

.data-table tr:hover td {
  background: rgba(197, 160, 89, 0.04);
}

/* Alerts */
.alert {
  padding: 0.9rem 1.1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
}

.alert-error { background: var(--danger-bg); border: 1px solid rgba(248, 113, 113, 0.4); color: #fecaca; }
.alert-info { background: var(--info-bg); border: 1px solid rgba(96, 165, 250, 0.35); color: #dbeafe; }
.alert-success { background: var(--success-bg); border: 1px solid rgba(52, 211, 153, 0.4); color: #d1fae5; }
.alert-warning { background: var(--warning-bg); border: 1px solid rgba(251, 191, 36, 0.4); color: #fef3c7; }

/* PDF Builder & Signer Workspace */
.workspace-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1.5rem;
  align-items: start;
}

.workspace-sidebar {
  position: sticky;
  top: 86px;
  background: var(--secondary-bg);
  border: 1px solid var(--gold-muted);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.pdf-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.pdf-page-wrap {
  position: relative;
  background: #ffffff;
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.55);
  border-radius: 4px;
  overflow: hidden;
  user-select: none;
  max-width: 100%;
}

.pdf-page-wrap canvas {
  display: block;
  width: 100%;
  height: auto;
}

.pdf-overlay {
  position: absolute;
  inset: 0;
  cursor: crosshair;
}

.field-box {
  position: absolute;
  border: 2px solid var(--gold);
  background: rgba(197, 160, 89, 0.18);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.74rem;
  font-weight: 700;
  color: #020c1b;
  cursor: move;
  overflow: visible;
  transition: box-shadow 0.15s ease;
}

.field-box.role-attorney {
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.18);
}

.field-box.selected {
  box-shadow: 0 0 0 3px rgba(197, 160, 89, 0.55);
  z-index: 20;
}

.field-box .field-tag {
  background: rgba(255, 255, 255, 0.92);
  padding: 1px 6px;
  border-radius: 3px;
  pointer-events: none;
  white-space: nowrap;
  max-width: 95%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.field-box .field-del {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: #ef4444;
  color: #fff;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.field-box .field-resize {
  position: absolute;
  right: -5px;
  bottom: -5px;
  width: 12px;
  height: 12px;
  background: var(--gold);
  border: 1px solid #020c1b;
  border-radius: 2px;
  cursor: nwse-resize;
}

/* Signer Field Interactive Overlay */
.sign-field {
  position: absolute;
  border: 2px dashed var(--gold);
  background: rgba(197, 160, 89, 0.22);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 700;
  color: #020c1b;
  transition: all 0.15s ease;
  padding: 2px;
}

.sign-field:hover {
  background: rgba(197, 160, 89, 0.34);
  box-shadow: 0 0 0 3px rgba(197, 160, 89, 0.45);
}

.sign-field.filled {
  border-style: solid;
  border-color: rgba(16, 185, 129, 0.8);
  background: rgba(255, 255, 255, 0.85);
}

.sign-field img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  pointer-events: none;
}

/* Signature Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 12, 27, 0.84);
  backdrop-filter: blur(4px);
  z-index: 500;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop.open {
  display: flex;
}

.modal-card {
  width: 100%;
  max-width: 520px;
  background: var(--secondary-bg);
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.sig-canvas-wrap {
  background: #ffffff;
  border: 2px solid var(--gold-muted);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin: 0.75rem 0;
  touch-action: none;
}

.sig-canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 180px;
  cursor: crosshair;
}

.tab-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.tab-btn {
  flex: 1;
  padding: 0.5rem;
  background: var(--primary-bg);
  border: 1px solid var(--gold-muted);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
}

.tab-btn.active {
  background: var(--gold);
  color: var(--primary-bg);
  border-color: var(--gold);
}

/* Signer Sticky Bottom Action Bar */
.sign-footer-bar {
  position: sticky;
  bottom: 0;
  z-index: 90;
  background: rgba(2, 12, 27, 0.97);
  border-top: 1px solid var(--gold-muted);
  padding: 1rem 1.5rem;
  margin-top: 2rem;
}

.sign-footer-inner {
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

/* Tool Palette Buttons */
.tool-btn {
  width: 100%;
  text-align: left;
  padding: 0.6rem 0.85rem;
  margin-bottom: 0.5rem;
  background: var(--primary-bg);
  border: 1px solid rgba(197, 160, 89, 0.25);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tool-btn.active, .tool-btn:hover {
  border-color: var(--gold);
  background: var(--gold-soft);
  color: var(--white);
}

.otp-input {
  text-align: center;
  font-family: monospace;
  font-size: 1.75rem;
  letter-spacing: 0.5rem;
  font-weight: 700;
}

/* Responsive */
@media (max-width: 900px) {
  .workspace-layout {
    grid-template-columns: 1fr;
  }
  .workspace-sidebar {
    position: static;
  }
  .form-row {
    grid-template-columns: 1fr;
  }
  .portal-header {
    padding: 0.75rem 1rem;
  }
}
