/* Clause45 — base styles, following Corporate Identity Guidelines C45-CI-001 v1.0.
   Montserrat is self-hosted (no external fonts or CDNs: POPIA, and works on slow site connections). */

@font-face {
  font-family: "Montserrat";
  src: url("fonts/montserrat-latin-var.woff2") format("woff2");
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Corporate palette (section 3) */
  --green: #1B7F3A;          /* Primary Green — brand, navigation, positive states */
  --green-dark: #146530;     /* hover/pressed shade of Primary Green */
  --green-tint: #E6F2EA;
  --orange: #F26522;         /* Construction Orange — attention, priority actions only */
  --orange-tint: #FDEDE4;
  --charcoal: #1F2933;       /* text, headings */
  --sa-red: #E03C31;         /* errors, overdue, serious risk only */
  --sa-red-tint: #FCE9E8;
  --sa-blue: #0055A4;
  --sa-blue-tint: #E5EEF7;
  --sa-yellow: #F2B705;
  --light-grey: #F2F4F5;     /* workspace background */
  --white: #FFFFFF;

  /* Derived UI tones */
  --ink-soft: #4B5563;
  --muted: #6B7280;
  --line: #DDE2E5;
  --field-border: #C4CBD1;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(31, 41, 51, .05), 0 4px 16px rgba(31, 41, 51, .05);
  --font: "Montserrat", Aptos, Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 400 15px/1.6 var(--font); color: var(--charcoal); background: var(--light-grey); }
a { color: var(--green); font-weight: 500; }
a:hover { color: var(--green-dark); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; color: var(--charcoal); }
h1 { font-size: 1.65rem; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; font-weight: 600; margin-top: 1.6em; }
h3 { font-size: .98rem; font-weight: 600; }
code { font-family: var(--mono); font-size: .88em; background: var(--green-tint); padding: .1em .35em; border-radius: 4px; }
code.key { display: block; padding: .6em .8em; word-break: break-all; user-select: all; }
small { color: var(--muted); font-size: .82rem; }
.muted { color: var(--muted); }
.center { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Brand bar: a slim strip of the logo's supporting accents, green-led */
.brand-bar {
  height: 4px;
  background: linear-gradient(90deg, var(--green) 0 70%, var(--sa-yellow) 70% 80%, var(--orange) 80% 90%, var(--sa-blue) 90% 100%);
}

/* Logo — always the supplied master artwork, never retyped (section 2.2) */
.logo-link { display: inline-block; line-height: 0; }
.logo { height: 48px; width: auto; }               /* = ~158px wide, above the 120px minimum */
.logo--hero { height: auto; width: 100%; max-width: 340px; }

/* Logged-out pages */
.plain-main { max-width: 640px; margin: 0 auto; padding: 48px 16px; display: flex; flex-direction: column; align-items: center; }
.plain-main .logo-link { margin: 8px 0 32px; }
.plain-foot { margin-top: 2rem; text-align: center; }
.tagline { margin: 0; font-weight: 600; color: var(--green); font-size: .95rem; }
.descriptor { margin: .25rem 0 0; font-size: .78rem; color: var(--muted); letter-spacing: .04em; }

/* Top bar: white workspace, charcoal text, green highlight (section 7.1) */
.topbar {
  display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap;
  background: var(--white); padding: 10px 24px; border-bottom: 1px solid var(--line);
}
.org-switch select {
  background: var(--white); color: var(--charcoal); border: 1px solid var(--field-border);
  padding: .4rem .6rem; border-radius: 6px; font: inherit; font-size: .88rem; font-weight: 500; max-width: 280px;
}
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: .9rem; }
.topbar-name { font-size: .88rem; font-weight: 500; color: var(--ink-soft); }

.main { max-width: 1120px; margin: 0 auto; padding: 32px 24px 64px; }

/* Cards */
.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px; width: 100%; }
.card--auth { max-width: 420px; }
.card--wide { max-width: 640px; }

/* Forms */
.form { display: grid; gap: 1rem; margin-top: 1rem; }
.form label { display: grid; gap: .3rem; font-weight: 500; font-size: .9rem; }
.form small { font-weight: 400; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=date], select, textarea {
  width: 100%; font: inherit; font-weight: 400; color: var(--charcoal);
  padding: .65rem .75rem; border: 1px solid var(--field-border); border-radius: 6px; background: var(--white);
}
input:focus, select:focus, textarea:focus, .btn:focus-visible {
  outline: 3px solid rgba(27, 127, 58, .25); outline-offset: 1px; border-color: var(--green);
}

/* Buttons — green is the standard action; orange is reserved for priority actions */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; padding: .65rem 1.1rem; border-radius: 6px;
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
}
.btn--primary { background: var(--green); color: var(--white); }
.btn--primary:hover { background: var(--green-dark); color: var(--white); }
.btn--priority { background: var(--orange); color: var(--white); }
.btn--priority:hover { background: #d9541a; color: var(--white); }
.btn--ghost { background: transparent; border-color: var(--line); color: var(--charcoal); }
.btn--ghost:hover { border-color: var(--field-border); background: var(--light-grey); }
.btn--small { padding: .35rem .75rem; font-size: .82rem; }
.btn--block { width: 100%; }

/* Alerts */
.alert { border-radius: 6px; padding: .75rem 1rem; margin: 0 0 1rem; border-left: 4px solid; width: 100%; }
.alert p { margin: .3em 0; }
.alert--success { background: var(--green-tint);   border-color: var(--green); }
.alert--error   { background: var(--sa-red-tint);  border-color: var(--sa-red); }
.alert--info    { background: var(--sa-blue-tint); border-color: var(--sa-blue); }
.plain-main > .alert { max-width: 420px; }

/* Install checklist */
.checklist { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.checklist li { display: flex; gap: .7rem; align-items: flex-start; padding: .55rem .75rem; border-radius: 6px; }
.checklist .ok   { background: var(--green-tint); }
.checklist .fail { background: var(--sa-red-tint); }
.check-icon { font-weight: 700; width: 1.2em; }
.checklist .ok .check-icon { color: var(--green); }
.checklist .fail .check-icon { color: var(--sa-red); }

/* Dashboard */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.eyebrow { margin: 0 0 .25rem; font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--green); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.stat { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; display: grid; gap: .2rem; border-top: 4px solid var(--green); }
.stat--warn { border-top-color: var(--orange); background: linear-gradient(var(--orange-tint), var(--white) 60%); }
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--ink-soft); font-size: .88rem; font-weight: 500; }
.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.module { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; }
.module h3 span { color: var(--green); }
.module p { margin: 0 0 .8rem; color: var(--ink-soft); font-size: .9rem; }
.tag { display: inline-block; font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; background: var(--light-grey); color: var(--ink-soft); padding: .2rem .5rem; border-radius: 4px; border: 1px solid var(--line); }

/* Status labels (section 7.1) — use these classes everywhere for consistency */
.status { display: inline-block; font-size: .75rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; }
.status--compliant      { background: var(--green-tint);   color: #0f5a27; }
.status--non-compliant  { background: var(--sa-red-tint);  color: #a3241b; }
.status--pending        { background: var(--sa-blue-tint); color: #00427f; }
.status--under-review   { background: #FEF6DA;             color: #7a5a00; }
.status--expired        { background: var(--sa-red-tint);  color: #a3241b; }
.status--na             { background: var(--light-grey);   color: var(--muted); }

.error-code { font-size: 3rem; font-weight: 700; color: var(--orange); margin: 0; line-height: 1; }

/* Main navigation */
.mainnav { display: flex; gap: .25rem; margin-left: .75rem; }
.mainnav a { color: var(--ink-soft); text-decoration: none; font-weight: 500; font-size: .92rem; padding: .45rem .8rem; border-radius: 6px; }
.mainnav a:hover { background: var(--light-grey); color: var(--charcoal); }
.mainnav a.active { color: var(--green); background: var(--green-tint); font-weight: 600; }

/* Page furniture */
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: .5rem; }
.crumbs a { font-weight: 500; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.page-head h1 .status { vertical-align: middle; margin-left: .35rem; }
section + section, .card + section, section + .card { margin-top: 1.75rem; }
.banner { display: flex; gap: 1rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  padding: .7rem 1rem; border-bottom: 1px solid var(--line); background: #FAFBFB; white-space: nowrap; }
.table td { padding: .75rem 1rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table a { text-decoration: none; }
.table a:hover { text-decoration: underline; }
.row-muted td { background: #FCFCFD; }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions form { display: inline-flex; gap: .35rem; flex-wrap: wrap; justify-content: flex-end; }

/* Detail cards */
.dl-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem 1.5rem; margin: 0; }
.dl-grid dt { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.dl-grid dd { margin: .15rem 0 0; font-weight: 500; overflow-wrap: anywhere; }
.callout { border-left: 4px solid var(--green); }
.callout--attention { border-left-color: var(--orange); }
.callout h2 { margin-top: 0; }
.invite-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .75rem; }
.invite-list li { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .75rem 0; border-top: 1px solid var(--line); }
.invite-list li:first-child { border-top: 0; padding-top: 0; }

/* Empty states */
.empty { background: var(--white); border: 1px dashed var(--field-border); border-radius: var(--radius); padding: 2.5rem 1.5rem; text-align: center; }
.empty h2 { margin-top: 0; }
.empty p { color: var(--ink-soft); max-width: 46ch; margin: 0 auto 1rem; }
.empty--small { padding: 1.5rem; }

/* Page forms */
.form--page { max-width: 760px; }
.form-section { font-size: 1rem; margin: .75rem 0 0; padding-top: .75rem; border-top: 1px solid var(--line); }
.form-section:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
.form-help { margin: -.5rem 0 0; font-size: .88rem; }
.form-actions { display: flex; gap: .5rem; margin-top: .5rem; }
.form-row--3 { grid-template-columns: 1fr 1fr 1.3fr; }
.inline-form { margin-top: 1rem; max-width: none; }
.inline-form h3 { margin: 0; }
.field-error { color: var(--sa-red); font-size: .82rem; font-weight: 500; }
.module--ready { border-color: #B9DBC4; }
.module-link { font-weight: 600; font-size: .9rem; text-decoration: none; }

@media (max-width: 640px) {
  .topbar { padding: 10px 16px; gap: .75rem; }
  .logo { height: 40px; }
  .org-switch { order: 3; width: 100%; }
  .org-switch select { max-width: none; width: 100%; }
  .topbar-name { display: none; }
  .main { padding: 24px 16px 48px; }
  .card { padding: 20px; }
  .form-row { grid-template-columns: 1fr; }
  h1 { font-size: 1.4rem; }
  .page-head { gap: .25rem; }
  .page-head > p { margin: 0; }
  .mainnav { order: 4; width: 100%; margin-left: 0; overflow-x: auto; }
  .form-row--3 { grid-template-columns: 1fr; }
  .row-actions { text-align: left; }
  .row-actions form { justify-content: flex-start; }

  /* Tables become stacked cards on phones */
  .table-wrap { background: transparent; border: 0; overflow: visible; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: .75rem; padding: .35rem 0; }
  .table td { border: 0; padding: .4rem 1rem; text-align: left; }
  .table td.num { text-align: left; }
  .table td[data-label]:not([data-label=""])::before {
    content: attr(data-label); display: block; font-size: .7rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: .05em; color: var(--muted); margin-bottom: .1rem;
  }
  .table td:empty { display: none; }
}
