/* ==========================================================================
   Zedenz Referral Management System - site stylesheet (no CSS framework).
   Colours and spacing are defined once as custom properties (variables)
   below, so the look can be changed in one place.
   ========================================================================== */

:root {
  --colour-brand: #0f766e;        /* teal: header, links, buttons */
  --colour-brand-dark: #115e59;   /* hover / active states */
  --colour-brand-light: #e6f4f1;  /* tinted backgrounds */
  --colour-accent: #b45309;       /* amber: focus ring, highlights */
  --colour-text: #1f2937;         /* body text (contrast > 12:1 on white) */
  --colour-muted: #4b5563;        /* secondary text (contrast > 7:1) */
  --colour-border: #d1d5db;
  --colour-bg: #f7faf9;           /* page background */
  --colour-surface: #ffffff;      /* cards, tables, forms */

  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --radius: 8px;
  --shadow: 0 1px 3px rgb(0 0 0 / 0.08), 0 4px 12px rgb(0 0 0 / 0.04);
  --space: 1rem;
  --max-width: 72rem;
}

/* ---- Base ---------------------------------------------------------------- */

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;               /* keeps the footer at the bottom */
  flex-direction: column;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--colour-text);
  background: var(--colour-bg);
}

h1,
h2,
h3 {
  line-height: 1.25;
  color: var(--colour-brand-dark);
}

h1 {
  font-size: clamp(1.6rem, 1.2rem + 1.5vw, 2.2rem);
  margin: 0 0 var(--space);
}

a {
  color: var(--colour-brand);
}

a:hover {
  color: var(--colour-brand-dark);
}

/* Visible keyboard focus on every interactive element. */
:focus-visible {
  outline: 3px solid var(--colour-accent);
  outline-offset: 2px;
}

img {
  max-width: 100%;
  height: auto;
}

/* Centred, width-limited content column used by header, main and footer. */
.container {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  /* Left/right only. A `padding` shorthand here would also zero the top and
     bottom padding of everything using .container (e.g. <main>), because a
     class selector beats a plain element selector like `main`. */
  padding-inline: calc(var(--space) * 1.5);
}

/* Hidden until focused, so keyboard users can jump past the menu. */
.skip-link {
  position: absolute;
  left: var(--space);
  top: -3rem;
  padding: 0.5rem 1rem;
  background: var(--colour-surface);
  color: var(--colour-brand-dark);
  border-radius: var(--radius);
  z-index: 10;
}

.skip-link:focus {
  top: var(--space);
}

/* ---- Header -------------------------------------------------------------- */

.site-header {
  background: var(--colour-brand);
  color: #ffffff;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space);
  padding-top: 0.9rem;
  padding-bottom: 0.9rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: #ffffff;
  text-decoration: none;
}

.brand:hover {
  color: #ffffff;
}

.brand-logo {
  flex-shrink: 0;
  border-radius: 10px;
  box-shadow: 0 0 0 2px rgb(255 255 255 / 0.6);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-name {
  font-size: 1.3rem;
  font-weight: 700;
}

.brand-system {
  font-size: 0.85rem;
  opacity: 0.9;
}

/* ---- Main menu ----------------------------------------------------------- */

.main-nav {
  background: var(--colour-brand-dark);
}

.main-nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin: 0 auto;
  list-style: none;
}

.main-nav a {
  display: block;
  padding: 0.7rem 1rem;
  color: #ffffff;
  text-decoration: none;
  font-weight: 600;
  border-bottom: 3px solid transparent;
}

.main-nav a:hover {
  background: rgb(255 255 255 / 0.1);
  color: #ffffff;
}

.main-nav a[aria-current="page"] {
  border-bottom-color: #ffffff;
}

/* ---- Main content -------------------------------------------------------- */

main {
  flex: 1;                     /* fills the space so the footer sits at the bottom */
  padding-top: calc(var(--space) * 2);
  padding-bottom: calc(var(--space) * 3);
}

/* Home page: text beside the image, stacked on small screens. */
.hero {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  align-items: center;
  gap: calc(var(--space) * 2.5);
  padding: calc(var(--space) * 2);
  background: var(--colour-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.lead {
  font-size: 1.15rem;
  color: var(--colour-muted);
}

.hero-image {
  width: 100%;
  justify-self: center;
}

/* ---- Log Out (a form button styled as a header link) -------------------- */

.logout-form {
  display: flex;
  align-items: center;
  gap: var(--space);
  margin: 0;
}

.signed-in-as {
  font-size: 0.9rem;
  opacity: 0.9;
}

.link-button {
  padding: 0.4rem 0.9rem;
  font: inherit;
  font-weight: 600;
  color: #ffffff;
  background: transparent;
  border: 2px solid rgb(255 255 255 / 0.8);
  border-radius: var(--radius);
  cursor: pointer;
}

.link-button:hover {
  background: #ffffff;
  color: var(--colour-brand-dark);
}

/* ---- Cards, forms and buttons -------------------------------------------- */

.card {
  padding: calc(var(--space) * 2);
  background: var(--colour-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login-card {
  max-width: 26rem;
  margin: calc(var(--space) * 2) auto;
}

.muted {
  color: var(--colour-muted);
}

.form-field {
  margin-bottom: var(--space);
}

.form-field label {
  display: block;
  margin-bottom: 0.3rem;
  font-weight: 600;
}

.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  font: inherit;
  color: var(--colour-text);
  background: var(--colour-surface);
  border: 1px solid var(--colour-border);
  border-radius: var(--radius);
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  border-color: var(--colour-brand);
}

/* Django renders field errors as <ul class="errorlist">. */
.errorlist,
.form-errors {
  margin: 0.4rem 0 0;
  padding: 0.6rem 0.8rem;
  list-style: none;
  color: #991b1b;
  background: #fef2f2;
  border-left: 4px solid #b91c1c;
  border-radius: 4px;
}

.form-errors {
  margin-bottom: var(--space);
}

.form-errors p {
  margin: 0;
}

.button {
  display: inline-block;
  padding: 0.6rem 1.3rem;
  font: inherit;
  font-weight: 600;
  color: #ffffff;
  text-decoration: none;
  background: var(--colour-brand);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}

.button:hover {
  color: #ffffff;
  background: var(--colour-brand-dark);
}

.button-secondary {
  color: var(--colour-brand-dark);
  background: var(--colour-surface);
  border: 2px solid var(--colour-brand);
}

.button-secondary:hover {
  color: var(--colour-brand-dark);
  background: var(--colour-brand-light);
}

.button-danger {
  background: #b91c1c;
}

.button-danger:hover {
  background: #991b1b;
}

.actions,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.form-actions {
  margin-top: calc(var(--space) * 1.5);
}

.form-card {
  max-width: 40rem;
}

.optional,
.help-text {
  font-weight: 400;
  font-size: 0.9rem;
  color: var(--colour-muted);
}

.help-text {
  margin: 0.3rem 0 0;
}

.has-error input,
.has-error select,
.has-error textarea {
  border-color: #b91c1c;
}

/* ---- List and detail pages ----------------------------------------------- */

.page-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space);
  margin-bottom: calc(var(--space) * 1.5);
}

.page-heading h1 {
  margin: 0;
}

.breadcrumb {
  margin: 0 0 var(--space);
}

.empty {
  padding: calc(var(--space) * 1.5);
  color: var(--colour-muted);
  background: var(--colour-surface);
  border: 1px dashed var(--colour-border);
  border-radius: var(--radius);
}

/* Wide tables scroll sideways on phones instead of breaking the layout. */
.table-wrap {
  overflow-x: auto;
  background: var(--colour-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

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

.data-table th,
.data-table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--colour-border);
}

.data-table th {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--colour-muted);
  background: var(--colour-brand-light);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr:hover {
  background: var(--colour-bg);
}

.card h2 {
  margin-top: 0;
  font-size: 1.2rem;
}

.card + .card {
  margin-top: calc(var(--space) * 1.5);
}

/* Label / value pairs on detail pages, two columns on wide screens. */
.details {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.6rem 1.5rem;
  margin: 0;
}

.details dt {
  font-weight: 600;
  color: var(--colour-muted);
}

.details dd {
  margin: 0;
  white-space: pre-line;        /* keeps line breaks in addresses and notes */
  overflow-wrap: anywhere;
}

/* ---- Messages ("Client added", errors) ------------------------------------ */

.messages {
  margin: 0 0 calc(var(--space) * 1.5);
  padding: 0;
  list-style: none;
}

.message {
  padding: 0.8rem 1rem;
  border-left: 4px solid var(--colour-brand);
  border-radius: 4px;
  background: var(--colour-brand-light);
}

.message + .message {
  margin-top: 0.5rem;
}

.message-error {
  color: #991b1b;
  background: #fef2f2;
  border-left-color: #b91c1c;
}

/* ---- Footer -------------------------------------------------------------- */

.site-footer {
  background: var(--colour-brand-dark);
  color: #ffffff;
  text-align: center;
}

.site-footer p {
  margin: 0 auto;
  padding: var(--space) calc(var(--space) * 1.5);
}

/* ---- Small screens ------------------------------------------------------- */

@media (max-width: 48rem) {
  .hero {
    grid-template-columns: 1fr;
    padding: calc(var(--space) * 1.25);
  }

  .brand-system {
    display: none;             /* keep the header compact on phones */
  }

  .signed-in-as {
    display: none;
  }

  .details {
    grid-template-columns: 1fr;   /* label above value on phones */
    gap: 0.15rem;
  }

  .details dd {
    margin-bottom: 0.6rem;
  }
}
