/* ==========================================================================
   RuleCheck — Design System
   Legal tech aesthetic: system-ui, conservative, no startup elements
   ========================================================================== */

/* --------------------------------------------------------------------------
   Custom properties
   -------------------------------------------------------------------------- */
:root {
  /* Brand palette */
  --c-navy:        #003366;
  --c-navy-dark:   #002244;
  --c-navy-light:  #e6edf5;

  /* Semantic colours */
  --c-success:     #1a6b36;
  --c-success-bg:  #eaf6ee;
  --c-warning:     #7a5200;
  --c-warning-bg:  #fdf6e3;
  --c-danger:      #8b1a1a;
  --c-danger-bg:   #fdecea;

  /* Neutrals */
  --c-ink:         #1c2b3a;
  --c-ink-muted:   #4a5568;
  --c-border:      #ccd5e0;
  --c-surface:     #ffffff;
  --c-bg:          #f5f7fa;

  /* Typography — system stack, no web fonts */
  --font-ui:   system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

  /* Spacing scale */
  --sp-xs:  0.25rem;
  --sp-sm:  0.5rem;
  --sp-md:  1rem;
  --sp-lg:  1.5rem;
  --sp-xl:  2rem;
  --sp-2xl: 3rem;

  /* Radii — minimal, functional */
  --radius-sm: 2px;
  --radius-md: 3px;
  --radius-lg: 4px;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-ui);
  background: var(--c-bg);
  color: var(--c-ink);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main { flex: 1; }

img, svg { display: block; max-width: 100%; }

/* --------------------------------------------------------------------------
   Accessibility utilities
   -------------------------------------------------------------------------- */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--sp-md);
  background: var(--c-navy);
  color: #fff;
  padding: var(--sp-sm) var(--sp-md);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  z-index: 999;
}
.skip-link:focus { top: var(--sp-sm); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --------------------------------------------------------------------------
   Layout container
   -------------------------------------------------------------------------- */
.container {
  width: min(960px, 100% - 2 * var(--sp-lg));
  margin-inline: auto;
}

/* --------------------------------------------------------------------------
   Header & navigation
   -------------------------------------------------------------------------- */
header {
  background: var(--c-navy);
  border-bottom: 3px solid var(--c-navy-dark);
  padding: var(--sp-sm) 0;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-lg);
  min-height: 3rem;
}

/* Brand */
.brand {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  text-decoration: none;
  color: #fff;
}

.brand-name {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.2;
  color: #fff;
}

.brand-sub {
  font-weight: 400;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.9em;
}

/* Nav */
nav[aria-label="Primary navigation"] ul.nav-links {
  display: flex;
  list-style: none;
  gap: var(--sp-xs);
}

.nav-links a {
  display: block;
  padding: 0.3rem var(--sp-sm);
  color: rgba(255, 255, 255, 0.82);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  border-bottom: 2px solid transparent;
}

.nav-links a:hover,
.nav-links a:focus-visible {
  color: #fff;
  border-bottom-color: rgba(255, 255, 255, 0.6);
}

/* --------------------------------------------------------------------------
   Main content spacing
   -------------------------------------------------------------------------- */
main .container {
  padding-top: var(--sp-xl);
  padding-bottom: var(--sp-2xl);
}

/* --------------------------------------------------------------------------
   Flash messages
   -------------------------------------------------------------------------- */
.flash-messages {
  margin-bottom: var(--sp-lg);
}

.flash {
  padding: var(--sp-sm) var(--sp-md);
  border-left: 3px solid transparent;
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: var(--sp-xs);
}

.flash.error,
.flash.danger,
.flash.message {
  background: var(--c-danger-bg);
  border-left-color: var(--c-danger);
  color: var(--c-danger);
}

.flash.success {
  background: var(--c-success-bg);
  border-left-color: var(--c-success);
  color: var(--c-success);
}

.flash.info {
  background: var(--c-navy-light);
  border-left-color: var(--c-navy);
  color: var(--c-navy);
}

/* --------------------------------------------------------------------------
   Cards
   -------------------------------------------------------------------------- */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: var(--sp-xl);
  margin-bottom: var(--sp-lg);
}

/* --------------------------------------------------------------------------
   Intro block (landing page — replaces hero)
   -------------------------------------------------------------------------- */
.intro-block {
  margin-bottom: var(--sp-xl);
  padding-bottom: var(--sp-xl);
  border-bottom: 1px solid var(--c-border);
}

.intro-block h1 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--c-navy);
  margin-bottom: var(--sp-sm);
}

.intro-block p {
  color: var(--c-ink-muted);
  font-size: 0.95rem;
  max-width: 68ch;
  margin-bottom: var(--sp-md);
}

.intro-block ul {
  list-style: none;
  padding: 0;
  margin-bottom: var(--sp-md);
  display: flex;
  flex-direction: column;
  gap: var(--sp-xs);
}

.intro-block ul li {
  font-size: 0.9rem;
  color: var(--c-ink);
  padding-left: 1.2rem;
  position: relative;
}

.intro-block ul li::before {
  content: "\2014";
  position: absolute;
  left: 0;
  color: var(--c-navy);
  font-weight: 700;
}

.security-note {
  display: block;
  font-size: 0.82rem;
  color: var(--c-ink-muted);
  border-left: 3px solid var(--c-border);
  padding-left: var(--sp-sm);
  margin-top: var(--sp-md);
}

/* --------------------------------------------------------------------------
   Typography
   -------------------------------------------------------------------------- */
h1 {
  font-size: clamp(1.2rem, 3vw, 1.6rem);
  font-weight: 700;
  color: var(--c-navy);
  line-height: 1.3;
  margin-bottom: var(--sp-lg);
}

h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--c-ink);
  border-bottom: 1px solid var(--c-border);
  padding-bottom: var(--sp-xs);
  margin-bottom: var(--sp-md);
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  flex-wrap: wrap;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.82rem;
}

p { margin-bottom: var(--sp-md); }
p:last-child { margin-bottom: 0; }

.text-small { font-size: 0.875rem; color: var(--c-ink-muted); }
.mono       { font-family: var(--font-mono); font-size: 0.85em; }

.section-count {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--c-ink-muted);
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  padding: 0.1em var(--sp-sm);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  text-transform: none;
  letter-spacing: 0;
}

/* --------------------------------------------------------------------------
   Section header (flex heading + action)
   -------------------------------------------------------------------------- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-md);
  margin-bottom: var(--sp-lg);
}

.section-header h1 { margin-bottom: 0; }

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */
.upload-form { display: flex; flex-direction: column; gap: var(--sp-lg); }

fieldset.form-section {
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  padding: var(--sp-lg);
}

fieldset.form-section legend {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--c-navy);
  padding: 0 var(--sp-sm);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--sp-md);
}

label {
  display: flex;
  flex-direction: column;
  gap: var(--sp-xs);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--c-ink);
}

.checkbox-label {
  flex-direction: row;
  align-items: flex-start;
  gap: var(--sp-sm);
  font-weight: 400;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  margin-top: 0.2em;
  flex-shrink: 0;
  width: 1rem;
  height: 1rem;
  accent-color: var(--c-navy);
  cursor: pointer;
}

input[type="text"],
input[type="file"],
select {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  padding: var(--sp-sm) var(--sp-md);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  background: var(--c-surface);
  color: var(--c-ink);
  width: 100%;
}

input[type="text"]:focus,
input[type="file"]:focus,
select:focus {
  outline: none;
  border-color: var(--c-navy);
  box-shadow: 0 0 0 3px rgba(0, 51, 102, 0.12);
}

input[type="text"]:focus-visible,
input[type="file"]:focus-visible,
select:focus-visible,
a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--c-navy);
  outline-offset: 2px;
}

.field-hint {
  font-size: 0.8rem;
  color: var(--c-ink-muted);
  line-height: 1.4;
  display: block;
}

code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: 0.1em 0.3em;
}

.retention-option { border-top: 1px solid var(--c-border); padding-top: var(--sp-md); }

.form-actions { display: flex; gap: var(--sp-md); align-items: center; }

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-xs);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1;
  padding: var(--sp-sm) var(--sp-lg);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.btn-primary {
  background: var(--c-navy);
  color: #fff;
  border-color: var(--c-navy);
}
.btn-primary:hover, .btn-primary:focus-visible {
  background: var(--c-navy-dark);
  border-color: var(--c-navy-dark);
}

.btn-secondary {
  background: var(--c-surface);
  color: var(--c-navy);
  border-color: var(--c-navy);
}
.btn-secondary:hover, .btn-secondary:focus-visible {
  background: var(--c-navy-light);
}

.btn-ghost {
  background: transparent;
  color: var(--c-ink-muted);
  border-color: var(--c-border);
}
.btn-ghost:hover, .btn-ghost:focus-visible {
  background: var(--c-bg);
  color: var(--c-ink);
  border-color: var(--c-ink-muted);
}

.btn-sm {
  font-size: 0.8rem;
  padding: 0.3rem var(--sp-md);
}

/* --------------------------------------------------------------------------
   Status badges
   -------------------------------------------------------------------------- */
.status-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.25em 0.6em;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge-ready {
  background: var(--c-success-bg);
  color: var(--c-success);
  border-color: #b2ddc0;
}

.badge-review {
  background: var(--c-warning-bg);
  color: var(--c-warning);
  border-color: #e8d5a0;
}

.badge-not-ready {
  background: var(--c-danger-bg);
  color: var(--c-danger);
  border-color: #f0b8b8;
}

/* --------------------------------------------------------------------------
   Score display
   -------------------------------------------------------------------------- */
.readiness-score {
  font-size: 3rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.score-denom {
  font-size: 1.1rem;
  font-weight: 400;
  opacity: 0.5;
  margin-left: 0.1em;
}

.readiness-score.score-high { color: var(--c-success); }
.readiness-score.score-mid  { color: var(--c-warning); }
.readiness-score.score-low  { color: var(--c-danger); }

/* Compact score pill for tables */
.score-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  min-width: 2.5rem;
  padding: 0.2em 0.5em;
  border-radius: var(--radius-sm);
  font-variant-numeric: tabular-nums;
}

.score-pill.score-high { background: var(--c-success-bg); color: var(--c-success); }
.score-pill.score-mid  { background: var(--c-warning-bg); color: var(--c-warning); }
.score-pill.score-low  { background: var(--c-danger-bg);  color: var(--c-danger); }

/* --------------------------------------------------------------------------
   Result header layout
   -------------------------------------------------------------------------- */
.result-header { padding-bottom: var(--sp-lg); }

.result-meta {
  display: flex;
  gap: var(--sp-xl);
  align-items: flex-start;
  margin-bottom: var(--sp-lg);
}

.result-score-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-sm);
  flex-shrink: 0;
  min-width: 7rem;
  text-align: center;
  padding-right: var(--sp-xl);
  border-right: 1px solid var(--c-border);
}

.result-detail { flex: 1; min-width: 0; }
.result-detail h1 { font-size: clamp(1.1rem, 3vw, 1.5rem); margin-bottom: var(--sp-md); text-transform: none; letter-spacing: 0; }

.result-actions {
  display: flex;
  gap: var(--sp-sm);
  flex-wrap: wrap;
  border-top: 1px solid var(--c-border);
  padding-top: var(--sp-lg);
}

/* Run metadata definition list */
.run-dl {
  display: flex;
  flex-direction: column;
  gap: var(--sp-xs);
}

.run-dl-row {
  display: flex;
  gap: var(--sp-md);
  font-size: 0.875rem;
}

.run-dl-row dt {
  font-weight: 600;
  color: var(--c-ink-muted);
  min-width: 5.5rem;
  flex-shrink: 0;
}

.run-dl-row dd { color: var(--c-ink); }

/* --------------------------------------------------------------------------
   Forum compliance note
   -------------------------------------------------------------------------- */
.forum-note {
  background: var(--c-navy-light);
  border-left: 3px solid var(--c-navy);
  border-radius: var(--radius-md);
  padding: var(--sp-sm) var(--sp-md);
  font-size: 0.85rem;
  color: var(--c-ink);
  margin-bottom: var(--sp-md);
}

.forum-note strong {
  color: var(--c-navy);
}

/* --------------------------------------------------------------------------
   Checklist
   -------------------------------------------------------------------------- */
.checklist {
  display: flex;
  flex-direction: column;
  gap: 1px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.checklist-item {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  padding: 0.6rem var(--sp-md);
  background: var(--c-surface);
  border-left: 3px solid transparent;
}

.checklist-item + .checklist-item {
  border-top: 1px solid var(--c-border);
}

.checklist-item.pass {
  border-left-color: var(--c-success);
}

.checklist-item.fail {
  background: var(--c-danger-bg);
  border-left-color: var(--c-danger);
}

.checklist-item.warning {
  background: var(--c-warning-bg);
  border-left-color: var(--c-warning);
}

.checklist-icon {
  font-size: 0.85rem;
  font-weight: 800;
  width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
  font-family: var(--font-ui);
}

.checklist-item.pass    .checklist-icon { color: var(--c-success); }
.checklist-item.fail    .checklist-icon { color: var(--c-danger); }
.checklist-item.warning .checklist-icon { color: var(--c-warning); }

.checklist-label {
  font-size: 0.875rem;
  color: var(--c-ink);
  flex: 1;
}

.checklist-severity {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--c-ink-muted);
  white-space: nowrap;
}

.checklist-item.fail    .checklist-severity { color: var(--c-danger); }
.checklist-item.warning .checklist-severity { color: var(--c-warning); }

/* --------------------------------------------------------------------------
   Citations table
   -------------------------------------------------------------------------- */
.citation-summary { margin-bottom: var(--sp-md); }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--c-ink-muted);
  background: var(--c-bg);
  padding: var(--sp-sm) var(--sp-md);
  text-align: left;
  border-bottom: 2px solid var(--c-border);
}

tbody td {
  padding: var(--sp-sm) var(--sp-md);
  border-bottom: 1px solid var(--c-border);
  vertical-align: top;
}

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

.citation-text { font-size: 0.875rem; }

.citation-status {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.2em 0.6em;
  border-radius: var(--radius-sm);
}

.citation-verified    { background: var(--c-success-bg); color: var(--c-success); }
.citation-needs-review { background: var(--c-warning-bg); color: var(--c-warning); }

/* --------------------------------------------------------------------------
   Disclosure blockquote
   -------------------------------------------------------------------------- */
.disclosure-box {
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--c-ink);
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-left: 3px solid var(--c-navy);
  border-radius: var(--radius-md);
  padding: var(--sp-md) var(--sp-lg);
  margin: 0;
  white-space: pre-wrap;
}

/* --------------------------------------------------------------------------
   Purge tag (runs table)
   -------------------------------------------------------------------------- */
.purge-tag {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--c-ink-muted);
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: 0.1em 0.4em;
  margin-left: var(--sp-xs);
  vertical-align: middle;
}

/* --------------------------------------------------------------------------
   Empty state
   -------------------------------------------------------------------------- */
.empty-state {
  text-align: center;
  padding: var(--sp-2xl) var(--sp-xl);
  border: 1px dashed var(--c-border);
  border-radius: var(--radius-lg);
}

.empty-icon {
  font-size: 2rem;
  margin-bottom: var(--sp-md);
  opacity: 0.35;
}

.empty-state p { color: var(--c-ink-muted); margin-bottom: var(--sp-lg); }

/* --------------------------------------------------------------------------
   Error page
   -------------------------------------------------------------------------- */
.error-page { text-align: center; padding: var(--sp-2xl) var(--sp-xl); }

.error-code {
  font-size: 5rem;
  font-weight: 800;
  color: var(--c-border);
  line-height: 1;
  margin-bottom: var(--sp-md);
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */
footer {
  background: var(--c-surface);
  border-top: 1px solid var(--c-border);
  padding: var(--sp-md) 0;
  margin-top: auto;
  font-size: 0.8rem;
  color: var(--c-ink-muted);
  text-align: center;
  line-height: 1.6;
}

footer p { margin-bottom: var(--sp-xs); }
footer p:last-child { margin-bottom: 0; }

.footer-disclaimer {
  font-size: 0.75rem;
  opacity: 0.75;
}

/* --------------------------------------------------------------------------
   Spacing utilities
   -------------------------------------------------------------------------- */
.mt-xs  { margin-top: var(--sp-xs); }
.mt-sm  { margin-top: var(--sp-sm); }
.mt-md  { margin-top: var(--sp-md); }
.mt-lg  { margin-top: var(--sp-lg); }
.mb-md  { margin-bottom: var(--sp-md); }
.mb-lg  { margin-bottom: var(--sp-lg); }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
  .header-inner { flex-direction: column; align-items: flex-start; gap: var(--sp-xs); }

  .result-meta  { flex-direction: column; }

  .result-score-block {
    flex-direction: row;
    align-items: center;
    min-width: unset;
    padding-right: 0;
    border-right: none;
    border-bottom: 1px solid var(--c-border);
    padding-bottom: var(--sp-sm);
    width: 100%;
    justify-content: flex-start;
  }

  .section-header { flex-direction: column; align-items: flex-start; }

  thead { display: none; }
  tbody tr {
    display: block;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-md);
    margin-bottom: var(--sp-sm);
  }
  tbody td {
    display: flex;
    justify-content: space-between;
    gap: var(--sp-sm);
    border-bottom: 1px solid var(--c-border);
    padding: var(--sp-sm) var(--sp-md);
  }
  tbody td:last-child { border-bottom: none; }
  tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--c-ink-muted);
    white-space: nowrap;
  }
}

/* --------------------------------------------------------------------------
   Print
   -------------------------------------------------------------------------- */
@media print {
  header, footer, .btn, .result-actions, .form-actions, .skip-link { display: none !important; }
  body { background: white; }
  .card { border: 1px solid #ccc; break-inside: avoid; }
}

/* --------------------------------------------------------------------------
   Reduced motion
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
