/* ── Clauselab Design System ── */
:root {
  --bg-base: #FAFAFC;
  --bg-surface: #FFFFFF;
  --bg-muted: #F1F5F9;
  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-tertiary: #94A3B8;
  --accent-primary: #2563EB;
  --accent-light: #EFF6FF;
  --border-color: #E2E8F0;
  --border-strong: #CBD5E1;

  --success: #10B981;
  --success-light: #D1FAE5;
  --warning: #F59E0B;
  --warning-light: #FEF3C7;
  --danger: #EF4444;
  --danger-light: #FEE2E2;
  --info: #0EA5C8;
  --info-light: #E0F7FA;

  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-display: 'Outfit', 'Inter', sans-serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, monospace;

  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.06), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);

  --transition: all 0.2s ease;
}

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

html { scroll-behavior: smooth; }

body {
  background-color: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 2rem;
}

.container-wide { max-width: 1400px; margin: 0 auto; padding: 0 2rem; }

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

button { font-family: inherit; cursor: pointer; }

/* ── Typography ── */
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 700; line-height: 1.2; color: var(--text-primary); }
h1 { font-size: clamp(2.25rem, 4vw, 3.5rem); }
h2 { font-size: clamp(1.75rem, 3vw, 2.5rem); }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.125rem; }
p { color: var(--text-secondary); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-full);
  font-weight: 500;
  font-size: 0.9rem;
  text-decoration: none;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  white-space: nowrap;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn-primary { background: var(--text-primary); color: white; }
.btn-primary:hover { background: #1E293B; }
.btn-accent { background: var(--accent-primary); color: white; }
.btn-accent:hover { background: #1D4ED8; }
.btn-secondary { background: var(--bg-surface); color: var(--text-primary); border: 1px solid var(--border-color); }
.btn-secondary:hover { border-color: var(--border-strong); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #DC2626; }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-muted); color: var(--text-primary); }
.btn-sm { padding: 0.45rem 0.9rem; font-size: 0.8125rem; }
.btn-lg { padding: 1rem 2rem; font-size: 1rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ── Cards ── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}
.card-lg { padding: 2rem; }
.card-hover { transition: var(--transition); }
.card-hover:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

/* ── Forms ── */
.field { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 1rem; }
.field label { font-size: 0.8125rem; font-weight: 600; color: var(--text-primary); }
.field .hint { font-size: 0.75rem; color: var(--text-tertiary); }
.input, .select, .textarea {
  width: 100%;
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  transition: var(--transition);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgb(37 99 235 / 0.12);
}
.textarea { min-height: 120px; resize: vertical; font-family: var(--font-mono); line-height: 1.5; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-success { background: var(--success-light); color: #065F46; }
.badge-warning { background: var(--warning-light); color: #92400E; }
.badge-danger { background: var(--danger-light); color: #991B1B; }
.badge-info { background: var(--info-light); color: #0E7490; }
.badge-neutral { background: var(--bg-muted); color: var(--text-secondary); }
.badge-accent { background: var(--accent-light); color: var(--accent-primary); }

/* ── Tags / chips ── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  background: var(--bg-muted);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

/* ── Page layout ── */
.page { padding: 7rem 0 5rem; }
.page-header { margin-bottom: 2.5rem; }
.page-eyebrow { font-size: 0.8125rem; font-weight: 600; color: var(--accent-primary); margin-bottom: 0.5rem; display: block; text-transform: uppercase; letter-spacing: 0.06em; }
.page-title { font-family: var(--font-display); font-size: clamp(2rem, 4vw, 2.75rem); font-weight: 700; margin-bottom: 0.75rem; }
.page-lead { font-size: 1.05rem; color: var(--text-secondary); max-width: 65ch; }
.page-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-top: 2rem; flex-wrap: wrap; }

/* ── Hero (for landing) ── */
.hero { padding: 9rem 0 5rem; }
.hero-eyebrow {
  display: inline-flex; align-items: center; gap: 0.5rem;
  font-size: 0.8125rem; font-weight: 600; color: var(--accent-primary);
  background: var(--accent-light); padding: 0.5rem 1rem;
  border-radius: var(--radius-full); margin-bottom: 1.5rem;
}
.hero-eyebrow::before { content: ''; width: 6px; height: 6px; background: var(--accent-primary); border-radius: 50%; }
.hero-title { font-family: var(--font-display); font-size: clamp(2.5rem, 5.5vw, 4.5rem); font-weight: 700; line-height: 1.05; letter-spacing: -0.02em; margin-bottom: 1.25rem; }
.hero-lead { font-size: 1.125rem; color: var(--text-secondary); max-width: 62ch; margin-bottom: 2rem; }
.hero-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }

/* ── Stats row ── */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  padding: 1.75rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-top: 3rem;
}
.stat-num { display: block; font-family: var(--font-display); font-size: 2rem; font-weight: 700; line-height: 1; }
.stat-lbl { font-size: 0.75rem; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 0.35rem; display: block; }
@media (max-width: 700px) { .stats { grid-template-columns: repeat(2, 1fr); padding: 1.25rem; gap: 1rem; } .stat-num { font-size: 1.5rem; } }

/* ── Feature grid (landing) ── */
.feature-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem; }
@media (max-width: 900px) { .feature-grid { grid-template-columns: 1fr; } }
.feature-card { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 1.75rem; transition: var(--transition); }
.feature-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: var(--border-strong); }
.feature-icon { width: 44px; height: 44px; border-radius: 10px; background: var(--accent-light); color: var(--accent-primary); display: flex; align-items: center; justify-content: center; margin-bottom: 1rem; }
.feature-title { font-family: var(--font-display); font-size: 1.125rem; font-weight: 700; margin-bottom: 0.5rem; }
.feature-desc { font-size: 0.9rem; color: var(--text-secondary); }

/* ── Section ── */
.section { padding: 4rem 0; }
.section-title-row { display: flex; justify-content: space-between; align-items: end; margin-bottom: 2rem; gap: 1rem; flex-wrap: wrap; }
.section-title { font-family: var(--font-display); font-size: 1.75rem; font-weight: 700; }
.section-sub { font-size: 0.95rem; color: var(--text-secondary); margin-top: 0.35rem; }

/* ── Sidebar layout (for tools) ── */
.tool-layout { display: grid; grid-template-columns: 240px 1fr; gap: 2rem; align-items: start; }
.tool-sidebar { position: sticky; top: 6rem; background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 1rem; }
.tool-sidebar-title { font-size: 0.7rem; font-weight: 700; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.06em; padding: 0.5rem 0.75rem; }
.tool-sidebar a { display: flex; align-items: center; gap: 0.6rem; padding: 0.55rem 0.75rem; border-radius: var(--radius-sm); font-size: 0.875rem; font-weight: 500; color: var(--text-secondary); text-decoration: none; transition: var(--transition); }
.tool-sidebar a:hover { background: var(--bg-muted); color: var(--text-primary); }
.tool-sidebar a.active { background: var(--accent-light); color: var(--accent-primary); }
.tool-main { min-width: 0; }
@media (max-width: 900px) { .tool-layout { grid-template-columns: 1fr; } .tool-sidebar { position: static; } }

/* ── Tables ── */
.table-wrap { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-md); overflow: hidden; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th { background: var(--bg-muted); color: var(--text-secondary); font-weight: 600; text-align: left; padding: 0.85rem 1rem; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--border-color); }
.table td { padding: 0.85rem 1rem; border-bottom: 1px solid var(--border-color); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--bg-muted); }
.table .cell-title { font-weight: 600; color: var(--text-primary); }
.table .cell-meta { font-size: 0.75rem; color: var(--text-tertiary); margin-top: 0.15rem; }
.table-empty { padding: 3rem 1rem; text-align: center; color: var(--text-tertiary); }
@media (max-width: 700px) {
  .table-wrap { overflow-x: auto; }
  .table { min-width: 600px; }
}

/* ── Modal ── */
.modal-backdrop { position: fixed; inset: 0; background: rgb(15 23 42 / 0.4); backdrop-filter: blur(4px); z-index: 9500; display: none; align-items: center; justify-content: center; padding: 1rem; }
.modal-backdrop.open { display: flex; }
.modal { background: var(--bg-surface); border-radius: var(--radius-md); width: 100%; max-width: 640px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.modal-lg { max-width: 880px; }
.modal-header { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.modal-title { font-family: var(--font-display); font-size: 1.25rem; font-weight: 700; }
.modal-close { background: none; border: none; padding: 0.25rem; cursor: pointer; color: var(--text-secondary); border-radius: var(--radius-sm); }
.modal-close:hover { background: var(--bg-muted); color: var(--text-primary); }
.modal-body { padding: 1.5rem; }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border-color); display: flex; justify-content: flex-end; gap: 0.5rem; }

/* ── Toast ── */
.toast-wrap { position: fixed; bottom: 90px; right: 1.5rem; z-index: 9999; display: flex; flex-direction: column; gap: 0.5rem; max-width: 360px; }
@media (min-width: 901px) { .toast-wrap { bottom: 1.5rem; } }
.toast { background: var(--text-primary); color: white; padding: 0.85rem 1.15rem; border-radius: var(--radius-sm); font-size: 0.875rem; box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 0.5rem; animation: slideIn 0.25s ease-out; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes slideIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ── Utility ── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.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; } .mt-4 { margin-top: 2rem; }
.mb-1 { margin-bottom: 0.5rem; } .mb-2 { margin-bottom: 1rem; } .mb-3 { margin-bottom: 1.5rem; } .mb-4 { margin-bottom: 2rem; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-muted { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.text-center { text-align: center; }
.w-full { width: 100%; }
.mono { font-family: var(--font-mono); font-size: 0.85em; }
.hidden { display: none !important; }

/* ── Footer ── */
footer { padding: 3rem 0; border-top: 1px solid var(--border-color); background: var(--bg-surface); margin-top: 5rem; }
@media (max-width: 900px) { footer { margin-bottom: 64px; } }
.footer-inner { display: flex; justify-content: space-between; align-items: flex-start; gap: 2rem; flex-wrap: wrap; }
.footer-brand { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1rem; }
.footer-brand-mark { width: 32px; height: 32px; }
.footer-brand-name { font-family: var(--font-display); font-weight: 700; font-size: 1.1rem; }
.footer-about { max-width: 340px; font-size: 0.875rem; color: var(--text-secondary); }
.footer-col-title { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-tertiary); margin-bottom: 0.75rem; }
.footer-links { display: flex; flex-direction: column; gap: 0.5rem; list-style: none; }
.footer-links a { font-size: 0.875rem; color: var(--text-secondary); }
.footer-links a:hover { color: var(--accent-primary); }
.footer-bottom { margin-top: 2rem; padding-top: 2rem; border-top: 1px solid var(--border-color); display: flex; justify-content: space-between; flex-wrap: wrap; gap: 1rem; font-size: 0.8125rem; color: var(--text-tertiary); }

/* ── Legal pages ── */
.legal-body { max-width: 780px; margin: 0 auto; }
.legal-body h2 { font-family: var(--font-display); font-size: 1.5rem; margin-top: 2.5rem; margin-bottom: 1rem; }
.legal-body h3 { font-size: 1.1rem; margin-top: 2rem; margin-bottom: 0.75rem; }
.legal-body p, .legal-body li { color: var(--text-secondary); margin-bottom: 1rem; line-height: 1.7; }
.legal-body ul, .legal-body ol { padding-left: 1.5rem; margin-bottom: 1rem; }
.legal-body li { margin-bottom: 0.5rem; }
.legal-body strong { color: var(--text-primary); font-weight: 600; }
.legal-meta { padding: 1rem 1.25rem; background: var(--bg-muted); border-radius: var(--radius-sm); font-size: 0.875rem; color: var(--text-secondary); margin-bottom: 2rem; }

/* ── Dashboard widgets ── */
.widget-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
@media (max-width: 900px) { .widget-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 500px) { .widget-grid { grid-template-columns: 1fr; } }
.widget { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 1.25rem; }
.widget-label { font-size: 0.75rem; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.5rem; }
.widget-value { font-family: var(--font-display); font-size: 2rem; font-weight: 700; line-height: 1; }
.widget-change { font-size: 0.75rem; color: var(--text-tertiary); margin-top: 0.5rem; }

/* ── Clause list ── */
.clause-list { display: grid; grid-template-columns: 280px 1fr; gap: 1.5rem; align-items: start; }
@media (max-width: 900px) { .clause-list { grid-template-columns: 1fr; } }
.clause-sidebar { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 1rem; }
.clause-cat { display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 0.75rem; border-radius: var(--radius-sm); font-size: 0.875rem; color: var(--text-secondary); cursor: pointer; transition: var(--transition); }
.clause-cat:hover { background: var(--bg-muted); color: var(--text-primary); }
.clause-cat.active { background: var(--accent-light); color: var(--accent-primary); font-weight: 600; }
.clause-cat-count { font-size: 0.7rem; background: var(--bg-muted); padding: 0.1rem 0.45rem; border-radius: var(--radius-full); }
.clause-cat.active .clause-cat-count { background: white; }
.clause-cards { display: flex; flex-direction: column; gap: 1rem; }
.clause-card { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 1.25rem; }
.clause-card-head { display: flex; justify-content: space-between; align-items: start; gap: 1rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.clause-title { font-weight: 600; font-size: 1rem; color: var(--text-primary); }
.clause-body { font-family: var(--font-mono); font-size: 0.8125rem; line-height: 1.65; color: var(--text-secondary); background: var(--bg-base); border: 1px solid var(--border-color); border-radius: var(--radius-sm); padding: 1rem; max-height: 240px; overflow-y: auto; white-space: pre-wrap; }
.clause-actions { display: flex; gap: 0.5rem; margin-top: 0.75rem; flex-wrap: wrap; }

/* ── Drafter ── */
.drafter-grid { display: grid; grid-template-columns: 360px 1fr; gap: 1.5rem; align-items: start; }
@media (max-width: 1000px) { .drafter-grid { grid-template-columns: 1fr; } }
.drafter-preview { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 2.5rem; min-height: 500px; }
.drafter-preview h1 { font-family: var(--font-display); font-size: 1.5rem; text-align: center; margin-bottom: 2rem; }
.drafter-preview h2 { font-size: 1rem; font-family: var(--font-sans); font-weight: 700; margin-top: 1.5rem; margin-bottom: 0.75rem; text-transform: uppercase; letter-spacing: 0.02em; }
.drafter-preview p { color: var(--text-primary); font-size: 0.95rem; line-height: 1.7; margin-bottom: 1rem; }

/* ── AI Review ── */
.review-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 1000px) { .review-grid { grid-template-columns: 1fr; } }
.review-output { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 1.5rem; min-height: 400px; font-size: 0.9rem; line-height: 1.7; white-space: pre-wrap; overflow-y: auto; max-height: 70vh; }
.review-output h3 { font-family: var(--font-display); font-size: 1.1rem; margin: 1rem 0 0.5rem; }
.review-output ul { padding-left: 1.25rem; margin: 0.5rem 0; }
.review-output li { margin-bottom: 0.35rem; color: var(--text-secondary); }
.review-output strong { color: var(--text-primary); }
.review-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 1rem; }

/* ── Banner (notice on top) ── */
.notice { background: var(--warning-light); border: 1px solid #FCD34D; color: #78350F; padding: 0.9rem 1.25rem; border-radius: var(--radius-sm); font-size: 0.875rem; margin-bottom: 1.5rem; }
.notice-info { background: var(--info-light); border-color: #67E8F9; color: #0C4A6E; }
.notice strong { font-weight: 700; }

/* ── Empty states ── */
.empty { text-align: center; padding: 4rem 1rem; }
.empty-icon { font-size: 2.5rem; margin-bottom: 1rem; opacity: 0.6; }
.empty-title { font-family: var(--font-display); font-size: 1.25rem; margin-bottom: 0.5rem; }
.empty-desc { color: var(--text-secondary); margin-bottom: 1.5rem; max-width: 400px; margin-left: auto; margin-right: auto; }

/* ── Filter bar ── */
.filter-bar { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1.5rem; align-items: center; }
.filter-bar .input, .filter-bar .select { max-width: 240px; }
.filter-bar .search { flex: 1; min-width: 220px; max-width: 360px; }

/* ── Print styles (for drafter export) ── */
@media print {
  nav, .btab-bar, footer, .no-print, .tool-sidebar { display: none !important; }
  .page, .tool-layout, .drafter-grid { padding: 0 !important; grid-template-columns: 1fr !important; }
  .drafter-preview { border: none; box-shadow: none; padding: 0; }
}

/* ── Animations ── */
.fade-up { opacity: 0; transform: translateY(16px); transition: opacity 0.5s ease, transform 0.5s ease; }
.fade-up.visible { opacity: 1; transform: translateY(0); }
