/* ==========================================================================
   Made by Tristan Brands : UI foundations
   Shared by the client portal and the admin.

   Structure before decoration. Typography, spacing and 1px rules do the work.
   The product should still look deliberate in black, white and grey.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Typeface

   Archivo is used when it is present on the system or supplied as a local
   file. No third-party font is fetched at runtime.

   To ship Archivo with the portal, drop the woff2 files into
   public/assets/fonts/ and uncomment the @font-face rules below.
   -------------------------------------------------------------------------- */

/*
@font-face {
  font-family: "Archivo";
  src: url("../fonts/archivo-regular.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Archivo";
  src: url("../fonts/archivo-semibold.woff2") format("woff2");
  font-weight: 600; font-style: normal; font-display: swap;
}
*/

:root {
  /* UI shell palette : neutral. Client colour never themes the shell. */
  --ui-bg: #ffffff;
  --ui-surface: #f7f7f5;
  --ui-surface-strong: #efefec;

  --ui-text: #171717;
  --ui-text-muted: #666661;

  /* --ui-rule is decorative: dividers and grouping boundaries.
     --ui-rule-strong draws control edges : input and button borders : so it
     meets the 3:1 non-text contrast requirement against both the page
     background and the surface tint. */
  --ui-rule: #deded9;
  --ui-rule-strong: #8f8f89;

  --ui-accent: #3730b7;
  --ui-accent-soft: #eeecff;

  --ui-success: #197a4a;
  --ui-warning: #8a5b13;
  --ui-danger: #b42318;

  /* Type scale */
  --size-12: 0.75rem;
  --size-14: 0.875rem;
  --size-16: 1rem;
  --size-20: 1.25rem;
  --size-28: 1.75rem;
  --size-40: 2.5rem;

  /* Spacing : 8px rhythm */
  --space-4: 4px;
  --space-8: 8px;
  --space-12: 12px;
  --space-16: 16px;
  --space-24: 24px;
  --space-32: 32px;
  --space-48: 48px;
  --space-64: 64px;
  --space-96: 96px;

  /* Corners */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  /* Motion */
  --motion-instant: 100ms;
  --motion-fast: 160ms;
  --motion-ui: 220ms;
  --motion-layout: 360ms;

  --ease-enter: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-move: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-exit: cubic-bezier(0.4, 0, 1, 1);

  --font-ui: "Archivo", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* --------------------------------------------------------------------------
   Reset
   -------------------------------------------------------------------------- */

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--ui-bg);
  color: var(--ui-text);
  font-family: var(--font-ui);
  font-size: var(--size-16);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.2; letter-spacing: -0.011em; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; }
img, svg { max-width: 100%; }
img { height: auto; }

a { color: inherit; }

/* --------------------------------------------------------------------------
   Focus : visible and consistent. Never removed without a replacement.
   -------------------------------------------------------------------------- */

:focus-visible {
  outline: 3px solid var(--ui-accent);
  outline-offset: 2px;
  border-radius: 2px;
}

.skip-link {
  position: absolute;
  left: var(--space-8);
  top: -100px;
  z-index: 100;
  padding: var(--space-12) var(--space-16);
  background: var(--ui-text);
  color: #fff;
  text-decoration: none;
  border-radius: var(--radius-md);
  transition: top var(--motion-fast) var(--ease-enter);
}
.skip-link:focus { top: var(--space-8); }

/* --------------------------------------------------------------------------
   Layout helpers
   -------------------------------------------------------------------------- */

.page { max-width: 1440px; margin: 0 auto; padding: 0 var(--space-32); }
.measure { max-width: 42vwch; }
.measure-narrow { max-width: 36vw; }

.stack > * + * { margin-top: var(--space-16); }
.stack-8 > * + * { margin-top: var(--space-8); }
.stack-24 > * + * { margin-top: var(--space-24); }
.stack-32 > * + * { margin-top: var(--space-32); }

.rule { border: 0; border-top: 1px solid var(--ui-rule); margin: 0; }
.rule-strong { border-top-color: var(--ui-rule-strong); }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap; border: 0;
}

/* --------------------------------------------------------------------------
   Spacing utilities

   A small fixed set on the 8px rhythm. These exist so no template needs an
   inline style attribute, which the Content Security Policy forbids.
   -------------------------------------------------------------------------- */

.mt-0  { margin-top: 0; }
.mt-4  { margin-top: var(--space-4); }
.mt-8  { margin-top: var(--space-8); }
.mt-12 { margin-top: var(--space-12); }
.mt-16 { margin-top: var(--space-16); }
.mt-24 { margin-top: var(--space-24); }
.mt-32 { margin-top: var(--space-32); }
.mt-48 { margin-top: var(--space-48); }
.mt-64 { margin-top: var(--space-64); }

.mb-8  { margin-bottom: var(--space-8); }
.mb-16 { margin-bottom: var(--space-16); }
.mb-24 { margin-bottom: var(--space-24); }
.mb-32 { margin-bottom: var(--space-32); }

.pt-16 { padding-top: var(--space-16); }

.block { display: block; }
.w-sm  { max-width: 200px; }

/* A fieldset that carries no visual box of its own. */
.fieldset-plain { border: 0; padding: 0; margin: 0; }
.fieldset-plain.mt-24 { margin: var(--space-24) 0 0; }

/* --------------------------------------------------------------------------
   Type roles
   -------------------------------------------------------------------------- */

.t-meta { font-size: var(--size-12); color: var(--ui-text-muted); }
.t-secondary { font-size: var(--size-14); color: var(--ui-text-muted); }
.t-body { font-size: var(--size-16); }
.t-subsection { font-size: var(--size-20); font-weight: 600; }
.t-section { font-size: var(--size-28); font-weight: 600; }
.t-page { font-size: var(--size-40); font-weight: 600; letter-spacing: -0.02em; }
.t-mono { font-family: var(--font-mono); font-size: var(--size-14); font-variant-numeric: tabular-nums; }

.t-label {
  font-size: var(--size-12);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ui-text-muted);
}

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

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-8);
  min-height: 44px;
  padding: 0 var(--space-16);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font: inherit;
  font-size: var(--size-14);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  background: var(--ui-bg);
  color: var(--ui-text);
  transition:
    background-color var(--motion-fast) var(--ease-move),
    border-color var(--motion-fast) var(--ease-move),
    color var(--motion-fast) var(--ease-move);
}

.btn-primary { background: var(--ui-text); color: #fff; border-color: var(--ui-text); }
.btn-secondary { background: var(--ui-bg); border-color: var(--ui-rule-strong); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--ui-text-muted); }
.btn-danger { background: var(--ui-bg); border-color: var(--ui-danger); color: var(--ui-danger); }
.btn-danger-strong { background: var(--ui-danger); border-color: var(--ui-danger); color: #fff; }

@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover { background: #000; }
  .btn-secondary:hover { background: var(--ui-surface); }
  .btn-quiet:hover { background: var(--ui-surface); color: var(--ui-text); }
  .btn-danger:hover { background: #fdf3f2; }
  .btn-danger-strong:hover { background: #9c1e14; }
}

.btn:active { transform: none; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

.btn-sm { min-height: 36px; font-size: var(--size-14); padding: 0 var(--space-12); }
.btn-block { width: 100%; }

.btn-icon {
  min-width: 44px;
  min-height: 44px;
  padding: 0;
}

.btn-row { display: flex; flex-wrap: wrap; gap: var(--space-8); align-items: center; }

/* --------------------------------------------------------------------------
   Forms : inputs look like inputs.
   -------------------------------------------------------------------------- */

.field { display: block; }
.field + .field { margin-top: var(--space-24); }

.field > label,
.field-label {
  display: block;
  font-size: var(--size-14);
  font-weight: 600;
  margin-bottom: var(--space-8);
}

.field-help {
  margin-top: var(--space-8);
  font-size: var(--size-14);
  color: var(--ui-text-muted);
}

.field-error {
  margin-top: var(--space-8);
  font-size: var(--size-14);
  color: var(--ui-danger);
}

.input, .textarea, .select {
  width: 100%;
  min-height: 44px;
  padding: var(--space-8) var(--space-12);
  border: 1px solid var(--ui-rule-strong);
  border-radius: var(--radius-md);
  background: var(--ui-bg);
  color: var(--ui-text);
  font: inherit;
  font-size: var(--size-16);
  transition: border-color var(--motion-fast) var(--ease-move);
}

.textarea { min-height: 96px; resize: vertical; line-height: 1.55; padding-top: var(--space-12); }

.input:hover, .textarea:hover, .select:hover { border-color: var(--ui-text-muted); }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--ui-danger); }

.input-mono { font-family: var(--font-mono); }

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-12);
  min-height: 44px;
  padding: var(--space-8) 0;
}
.checkbox-row input[type="checkbox"] { width: 20px; height: 20px; margin: 2px 0 0; flex: none; accent-color: var(--ui-accent); }
.checkbox-row label { font-size: var(--size-16); font-weight: 400; }

.field-grid {
  display: grid;
  gap: var(--space-16);
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

/* --------------------------------------------------------------------------
   Status : text first, colour second.
   -------------------------------------------------------------------------- */

.status {
  display: inline-flex;
  align-items: center;
  gap: var(--space-8);
  font-size: var(--size-12);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ui-text-muted);
}
.status::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.status-live { color: var(--ui-success); }
.status-draft { color: var(--ui-text-muted); }
.status-expired { color: var(--ui-warning); }
.status-revoked { color: var(--ui-danger); }
.status-archived { color: var(--ui-text-muted); }

/* --------------------------------------------------------------------------
   Notices
   -------------------------------------------------------------------------- */

.notice {
  padding: var(--space-12) var(--space-16);
  border: 1px solid var(--ui-rule);
  border-left-width: 3px;
  border-radius: var(--radius-sm);
  background: var(--ui-surface);
  font-size: var(--size-14);
}
.notice-success { border-left-color: var(--ui-success); }
.notice-error { border-left-color: var(--ui-danger); }
.notice-warning { border-left-color: var(--ui-warning); }
.notice-info { border-left-color: var(--ui-accent); }
.notice + .notice { margin-top: var(--space-8); }
.notice ul { padding-left: var(--space-16); }
.notice li + li { margin-top: var(--space-4); }

/* --------------------------------------------------------------------------
   Copyable values
   -------------------------------------------------------------------------- */

.copy {
  display: inline-flex;
  align-items: center;
  gap: var(--space-8);
  min-height: 44px;
  padding: 0 var(--space-8);
  margin-left: calc(var(--space-8) * -1);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  font: inherit;
  font-family: var(--font-mono);
  font-size: var(--size-14);
  font-variant-numeric: tabular-nums;
  color: var(--ui-text);
  cursor: pointer;
  text-align: left;
  transition: background-color var(--motion-instant) var(--ease-move),
              border-color var(--motion-instant) var(--ease-move);
}
@media (hover: hover) and (pointer: fine) {
  .copy:hover { background: var(--ui-surface); border-color: var(--ui-rule); }
}
.copy[data-copied="true"] { color: var(--ui-success); }
.copy-hint {
  font-family: var(--font-ui);
  font-size: var(--size-12);
  color: var(--ui-text-muted);
  opacity: 0;
  transition: opacity var(--motion-fast) var(--ease-move);
}
@media (hover: hover) and (pointer: fine) {
  .copy:hover .copy-hint { opacity: 1; }
}
.copy:focus-visible .copy-hint { opacity: 1; }
.copy[data-copied="true"] .copy-hint { opacity: 1; color: var(--ui-success); }

/* --------------------------------------------------------------------------
   Modal : opacity plus a small transform. No dramatic zoom.
   -------------------------------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-24);
}
.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(23, 23, 23, 0.4);
  animation: modal-fade var(--motion-ui) var(--ease-enter);
}

.modal-panel {
  position: relative;
  width: 100%;
  max-width: 720px;
  max-height: calc(100dvh - var(--space-48));
  overflow: auto;
  background: var(--ui-bg);
  border: 1px solid var(--ui-rule);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px rgba(23, 23, 23, 0.12);
  animation: modal-enter var(--motion-ui) var(--ease-enter);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-16);
  padding: var(--space-24) var(--space-24) var(--space-16);
  border-bottom: 1px solid var(--ui-rule);
}
.modal-body { padding: var(--space-24); }
.modal-footer {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-8);
  justify-content: flex-end;
  padding: var(--space-16) var(--space-24) var(--space-24);
  border-top: 1px solid var(--ui-rule);
}

@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-enter {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* --------------------------------------------------------------------------
   Live region for copy/save confirmations
   -------------------------------------------------------------------------- */

.live-region {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Empty states : very simple, no illustration.
   -------------------------------------------------------------------------- */

.empty {
  padding: var(--space-32) 0;
  border-top: 1px solid var(--ui-rule);
}
.empty p + p { margin-top: var(--space-8); }
.empty .btn-row { margin-top: var(--space-16); }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 900px) {
  .page { padding: 0 var(--space-24); }
}

@media (max-width: 600px) {
  :root { --size-40: 2rem; }
  .page { padding: 0 var(--space-16); }
  .modal { padding: 0; align-items: flex-end; }
  .modal-panel { max-width: none; border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 92dvh; }
  @keyframes modal-enter {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: none; }
  }
}

@media print {
  .no-print { display: none !important; }
}
