/* ═══════════════════════════════════════════════════════════════════════════
   PAPYRUS — Dark Editorial Design System
   BG: #0E0E0F | Text: #F0EDE8 | Accent: #C8933A | Cards: #1A1A1C
   Fonts: DM Serif Display (headings) · IBM Plex Mono (meta) · Inter (body)
═══════════════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display:ital@0;1&family=IBM+Plex+Mono:wght@400;500&family=Inter:wght@300;400;500;600&display=swap');

/* ── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Design tokens ─────────────────────────────────────────────────────── */
:root {
  --bg:          #0E0E0F;
  --surface:     #1A1A1C;
  --surface2:    #242426;
  --surface3:    #2E2E31;
  --border:      #2A2A2D;
  --border-soft: #222224;

  --text:        #F0EDE8;
  --text-muted:  #8A8785;
  --text-dim:    #4A4A4D;

  --accent:      #C8933A;
  --accent-dim:  rgba(200, 147, 58, 0.15);
  --accent-glow: rgba(200, 147, 58, 0.08);

  --green:       #3DAA6E;
  --green-dim:   rgba(61, 170, 110, 0.15);
  --blue:        #4A8FD4;
  --blue-dim:    rgba(74, 143, 212, 0.15);
  --amber:       #D4893A;
  --amber-dim:   rgba(212, 137, 58, 0.15);
  --red:         #C44B4B;
  --red-dim:     rgba(196, 75, 75, 0.15);
  --gray-dim:    rgba(138, 135, 133, 0.15);

  --font-serif:  'DM Serif Display', Georgia, serif;
  --font-mono:   'IBM Plex Mono', 'Courier New', monospace;
  --font-sans:   'Inter', system-ui, sans-serif;

  --radius:      6px;
  --radius-lg:   10px;
  --radius-xl:   16px;

  --nav-width:   220px;
  --topbar-h:    56px;

  --shadow:      0 2px 8px rgba(0,0,0,0.4);
  --shadow-lg:   0 8px 32px rgba(0,0,0,0.5);
}

/* ── Base ──────────────────────────────────────────────────────────────── */
html { font-size: 15px; -webkit-font-smoothing: antialiased; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-weight: 400;
  line-height: 1.6;
  min-height: 100vh;
}

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

h1, h2, h3 {
  font-family: var(--font-serif);
  font-weight: 400;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.15rem; }

p { color: var(--text-muted); }

hr { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

/* ── Layout shell ──────────────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: var(--nav-width) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  min-height: 100vh;
}

/* ── Topbar ────────────────────────────────────────────────────────────── */
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topbar-h);
}

.topbar-wordmark {
  font-family: var(--font-serif);
  font-size: 1.3rem;
  color: var(--text);
  letter-spacing: 0.04em;
}

.topbar-wordmark span { color: var(--accent); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.topbar-user {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ── Sidebar nav ───────────────────────────────────────────────────────── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.5rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  overflow-y: auto;
}

.nav-section {
  padding: 0.75rem 1.25rem 0.25rem;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 1.25rem;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 400;
  border-left: 2px solid transparent;
  transition: all 0.15s ease;
}

.nav-link:hover {
  color: var(--text);
  background: var(--surface2);
}

.nav-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-glow);
}

.nav-link svg { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.7; }
.nav-link.active svg { opacity: 1; }

.nav-spacer { flex: 1; }

.nav-bottom {
  padding: 1rem 1.25rem 0;
  border-top: 1px solid var(--border);
}

/* ── Main content area ─────────────────────────────────────────────────── */
.main {
  background: var(--bg);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.page {
  padding: 2rem 2.5rem;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
}

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

.page-title { font-size: 1.75rem; color: var(--text); }
.page-subtitle { font-size: 0.875rem; color: var(--text-muted); margin-top: 0.25rem; }

/* ── Cards ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}

.card-sm { padding: 1rem 1.25rem; }
.card-lg { padding: 2rem; }

.card-title {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  margin-bottom: 1rem;
  color: var(--text);
}

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

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
}

.stat-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.stat-value {
  font-family: var(--font-serif);
  font-size: 2rem;
  color: var(--text);
  line-height: 1;
}

.stat-delta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.stat-delta.up { color: var(--green); }
.stat-delta.down { color: var(--red); }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
  white-space: nowrap;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
}
.btn-primary:hover { background: #D9A045; color: var(--bg); }

.btn-secondary {
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-secondary:hover { color: var(--text); background: var(--surface3); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { color: var(--text); background: var(--surface2); }

.btn-danger {
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid rgba(196,75,75,0.25);
}
.btn-danger:hover { background: var(--red); color: #fff; }

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }
.btn-icon { padding: 0.5rem; }
.btn svg { width: 15px; height: 15px; }

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

.form-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.form-control {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 0.9rem;
  color: var(--text);
  font-size: 0.9rem;
  font-family: var(--font-sans);
  transition: border-color 0.15s ease;
  -webkit-appearance: none;
}

.form-control:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface3);
}

.form-control::placeholder { color: var(--text-dim); }

textarea.form-control {
  resize: vertical;
  min-height: 120px;
  line-height: 1.6;
}

select.form-control { cursor: pointer; }

.form-hint {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 0.35rem;
}

.form-error {
  font-size: 0.78rem;
  color: var(--red);
  margin-top: 0.35rem;
}

/* ── Tables ────────────────────────────────────────────────────────────── */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 0.85rem 1.25rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-weight: 500;
}

tbody tr {
  border-bottom: 1px solid var(--border-soft);
  transition: background 0.1s ease;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }

tbody td {
  padding: 1rem 1.25rem;
  font-size: 0.875rem;
  color: var(--text);
  vertical-align: middle;
}

.td-muted { color: var(--text-muted); }

/* ── Status badges ─────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
}

.badge::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.badge-draft    { background: var(--gray-dim);  color: var(--text-muted); }
.badge-sent     { background: var(--blue-dim);   color: var(--blue); }
.badge-partial  { background: var(--amber-dim);  color: var(--amber); }
.badge-complete { background: var(--green-dim);  color: var(--green); }
.badge-voided   { background: var(--red-dim);    color: var(--red); }
.badge-overdue  { background: var(--red-dim);    color: var(--red); }

/* ── Modals ────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(3px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 560px;
  padding: 2rem;
  box-shadow: var(--shadow-lg);
  transform: translateY(12px);
  transition: transform 0.2s ease;
}

.modal-backdrop.open .modal { transform: translateY(0); }

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.modal-title {
  font-family: var(--font-serif);
  font-size: 1.3rem;
  color: var(--text);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
  font-size: 1.25rem;
}

.modal-close:hover { color: var(--text); }

.modal-footer {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

/* ── Empty states ──────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.3;
}

.empty-title {
  font-family: var(--font-serif);
  font-size: 1.3rem;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.empty-desc {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 1.5rem;
}

/* ── Alerts / toasts ───────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: calc(var(--topbar-h) + 1rem);
  right: 1.5rem;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  color: var(--text);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 260px;
  animation: slideIn 0.2s ease;
}

.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.info    { border-left: 3px solid var(--blue); }

@keyframes slideIn {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Search / filter bar ───────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
}

.search-wrap svg {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  width: 15px;
  height: 15px;
}

.search-wrap .form-control { padding-left: 2.25rem; }

/* ── Tabs ──────────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

.tab {
  padding: 0.65rem 1.25rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.15s ease;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: var(--font-sans);
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Progress / timeline ───────────────────────────────────────────────── */
.progress-bar {
  height: 4px;
  background: var(--surface2);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.timeline-item {
  display: flex;
  gap: 1rem;
  padding-bottom: 1.25rem;
  position: relative;
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: 6px;
  top: 20px;
  bottom: 0;
  width: 1px;
  background: var(--border);
}

.timeline-item:last-child::before { display: none; }

.timeline-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--surface3);
  border: 2px solid var(--border);
  flex-shrink: 0;
  margin-top: 4px;
}

.timeline-dot.done { background: var(--green); border-color: var(--green); }
.timeline-dot.active { background: var(--accent); border-color: var(--accent); }

.timeline-body { flex: 1; }
.timeline-label { font-size: 0.875rem; color: var(--text); }
.timeline-time { font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-muted); margin-top: 0.2rem; }

/* ── Signing page overrides ────────────────────────────────────────────── */
.signing-page {
  background: #fff;
  color: #111;
  min-height: 100vh;
  font-family: var(--font-sans);
}

.signing-page .signing-wordmark {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  letter-spacing: 0.04em;
  color: #111;
}

.signing-page .signing-wordmark span { color: #C8933A; }

/* ── Skeleton loaders ──────────────────────────────────────────────────── */
.skeleton {
  background: var(--surface2);
  border-radius: var(--radius);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ── Dividers & spacing utils ──────────────────────────────────────────── */
.flex   { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1  { gap: 0.5rem; }
.gap-2  { gap: 1rem; }
.gap-3  { gap: 1.5rem; }
.mt-1   { margin-top: 0.5rem; }
.mt-2   { margin-top: 1rem; }
.mt-3   { margin-top: 1.5rem; }
.mb-1   { margin-bottom: 0.5rem; }
.mb-2   { margin-bottom: 1rem; }
.mb-3   { margin-bottom: 1.5rem; }

.text-mono  { font-family: var(--font-mono); font-size: 0.8rem; }
.text-muted { color: var(--text-muted); }
.text-dim   { color: var(--text-dim); }
.text-sm    { font-size: 0.8rem; }
.text-xs    { font-size: 0.72rem; }
.text-accent { color: var(--accent); }
.text-green  { color: var(--green); }
.text-red    { color: var(--red); }

.w-full { width: 100%; }

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
  }

  .sidebar { display: none; }
  .page { padding: 1.25rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── Shared layout partial ─────────────────────────────────────────────── */
/* Included via JS include or server-side include in each view */

/* ── Scrollbar styling ─────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
