/* ========================================================================== 
   TradeSuite Golden CSS
   --------------------------------------------------------------------------
   Suite-wide visual foundation shared by every TS module.

   Load this file before a module stylesheet:
     <link rel="stylesheet" href="/css/golden.css">
     <link rel="stylesheet" href="/css/cv.css">

   Module styles may add module-specific layouts and components, but must not
   override the universal status-pill geometry, core component values, fixed
   viewport-anchor behavior, or shared spacing tokens.
   ========================================================================== */

@font-face {
  font-family: "TradeSuite Board";
  src: url("/css/vendor/DejaVuSans.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: block;
}

@font-face {
  font-family: "TradeSuite Board";
  src: url("/css/vendor/DejaVuSans-Bold.ttf") format("truetype");
  font-style: normal;
  font-weight: 700;
  font-display: block;
}

:root {
  /* The locked board is rendered with DejaVu Sans; the local copy keeps browser renders comparable offline. */
  --ts-font-sans: "TradeSuite Board", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --ts-font-weight-regular: 400;
  --ts-font-weight-medium: 500;
  --ts-font-weight-semibold: 600;
  --ts-font-weight-bold: 700;

  /* Colour foundation */
  --ts-colour-ink: #151515;
  --ts-colour-ink-muted: #5f6368;
  --ts-colour-line: #252525;
  --ts-colour-line-soft: #d6d6d6;
  --ts-colour-page: #f7f7f5;
  --ts-colour-surface: #ffffff;
  --ts-colour-surface-subtle: #f1f1ef;
  --ts-colour-brand: #f4bc18;
  --ts-colour-brand-contrast: #151515;

  /* Bold universal status colours: never muted. */
  --ts-status-active-bg: #10843d;
  --ts-status-active-fg: #ffffff;
  --ts-status-due-bg: #f3b400;
  --ts-status-due-fg: #151515;
  --ts-status-expired-bg: #d92d20;
  --ts-status-expired-fg: #ffffff;

  /* Shared geometry */
  --ts-radius-sm: 0.5rem;
  --ts-radius-md: 0.75rem;
  --ts-radius-lg: 1rem;
  --ts-radius-round: 999rem;
  --ts-border-width: 1px;
  --ts-border: var(--ts-border-width) solid var(--ts-colour-line);
  --ts-border-soft: var(--ts-border-width) solid var(--ts-colour-line-soft);

  /* Shared spacing scale */
  --ts-space-1: 0.25rem;
  --ts-space-2: 0.5rem;
  --ts-space-3: 0.75rem;
  --ts-space-4: 1rem;
  --ts-space-5: 1.25rem;
  --ts-space-6: 1.5rem;
  --ts-space-8: 2rem;

  /* Visual separation uses borders and background contrast only. */

  /* Universal status marker geometry: do not override in module CSS. */
  --ts-status-width: 81px; /* 212 board px */
  --ts-status-height: 18px; /* 47 board px */
  --ts-status-radius: 4px; /* 11 board px */
  --ts-status-font-size: 7px; /* 19 board px */
  --ts-status-font-weight: var(--ts-font-weight-bold);
  --ts-status-border: 1px solid #000000;

  /* Fluid phone layout: 430px iPhone 16 Plus is the maximum envelope. */
  --ts-layout-max-width: 430px;
  --ts-page-edge-padding: 16px;
  /* Fixed edge insets preserve the same border relationship on every phone. */
  --ts-header-edge-start: 24px;
  --ts-header-edge-end: 30px;
  
  /* Base heights without safe area. Reduced to pull the header bottom edge up. */
  --ts-header-base-height: clamp(80px, 22vw, 95px);
  /* Reduced detail-header height to remove excess room above the content */
  --ts-detail-header-base-height: clamp(45px, 12vw, 55px);
  --ts-header-safe-top: env(safe-area-inset-top, 0px);
  
  /* Total header heights dynamically absorb the safe area without adding fixed padding */
  --ts-header-height: calc(var(--ts-header-base-height) + var(--ts-header-safe-top));
  --ts-detail-header-height: calc(var(--ts-detail-header-base-height) + var(--ts-header-safe-top));
  
  --ts-header-content-height: clamp(56px, 15.6vw, 67px);
  --ts-header-bottom-clearance: clamp(12px, 3.3vw, 14px);
  --ts-header-status-stack-height: var(--ts-header-content-height);
  --ts-status-gap: calc((var(--ts-header-content-height) - (3 * var(--ts-status-height))) / 2);
  
  /* Navigation: Reduced inner padding further to minimize empty space below nav */
  --ts-nav-padding: 8px;
  --ts-nav-functional-height: 32px;
  --ts-add-button-size: 56px;
  --ts-add-button-overlap: 24px;
  
  --ts-nav-total-height: calc(
    var(--ts-nav-padding) + var(--ts-nav-functional-height) + var(--ts-nav-padding) + env(safe-area-inset-bottom, 0px)
  );
  --ts-content-bottom-clearance: calc(
    var(--ts-nav-total-height) + var(--ts-add-button-overlap) + var(--ts-space-6)
  );

  /* Shared document dimensions. */
  --ts-credit-card-ratio: 1.586 / 1;
  --ts-content-max-width: var(--ts-layout-max-width);
}

/* --------------------------------------------------------------------------
   Baseline
   -------------------------------------------------------------------------- */

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

html {
  background: var(--ts-colour-page);
  color: var(--ts-colour-ink);
  font-family: var(--ts-font-sans);
  font-size: 16px;
  line-height: 1.4;
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

html[data-ts-text-size="small"] { font-size: 14px; }
html[data-ts-text-size="medium"] { font-size: 16px; }
html[data-ts-text-size="large"] { font-size: 20px; }

body {
  min-width: 20rem;
  min-height: 100dvh;
  margin: 0;
  background: var(--ts-colour-page);
  color: inherit;
  font: inherit;
}

button,
input,
select,
textarea {
  color: inherit;
  font: inherit;
}

button,
[role="button"] {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 0.2rem solid rgb(21 21 21 / 24%);
  outline-offset: 0.125rem;
}

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

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

/* --------------------------------------------------------------------------
   App shell and fixed viewport anchors
   -------------------------------------------------------------------------- */

.ts-app-shell {
  width: min(100%, var(--ts-layout-max-width));
  min-height: 100dvh;
  margin-inline: auto;
  background: var(--ts-colour-page);
}

/*
  The primary header is fixed and separated by its border.
*/
.ts-header {
  position: fixed;
  z-index: 40;
  top: 0;
  left: 50%;
  width: min(100%, var(--ts-layout-max-width));
  height: var(--ts-header-height);
  transform: translateX(-50%);
  /* Fluid edge insets preserve the locked board relationship up to 430px. */
  padding: var(--ts-header-safe-top) var(--ts-header-edge-end) var(--ts-header-bottom-clearance) var(--ts-header-edge-start);
  background: var(--ts-colour-brand);
  border-bottom: var(--ts-border);
}

.ts-header__inner,
.ts-content-width {
  width: 100%;
  margin-inline: auto;
}

.ts-header__inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--ts-space-4);
  align-items: center;
}

.ts-header__copy {
  display: flex;
  height: var(--ts-header-status-stack-height);
  flex-direction: column;
  justify-content: space-between;
}

.ts-header__title {
  margin: 0;
  color: var(--ts-colour-brand-contrast);
  font-size: clamp(30px, 11.2vw, 48px);
  font-weight: var(--ts-font-weight-bold);
  /* The locked Pillow render has no artificial tracking. */
  letter-spacing: normal;
  line-height: 1;
  /* Pixel-bounded board comparison: production glyph band aligns at -4 CSS px. */
  transform: translateY(-4px);
}

.ts-header__identity {
  margin: 0;
  color: var(--ts-colour-brand-contrast);
  font-size: clamp(13px, 4vw, 17px);
  font-weight: var(--ts-font-weight-regular);
  line-height: 1;
  /* Pixel-bounded board comparison: production glyph band aligns at +3 CSS px. */
  transform: translateY(3px);
}

/* All main-screen content fills the viewport width inside a single shared edge inset. */
.ts-main,
.ts-detail-main {
  width: min(100%, var(--ts-layout-max-width));
  margin-inline: auto;
}

.ts-main > .ts-content-width,
.ts-detail-main > .ts-content-width {
  width: 100%;
  max-width: none;
}

.ts-main {
  min-height: 100dvh;
  padding:
    calc(var(--ts-header-height) + var(--ts-space-5))
    var(--ts-space-4)
    var(--ts-content-bottom-clearance);
}

/* Detail and inspection screens have no bottom navigation. */
.ts-main--detail {
  padding-bottom: var(--ts-space-8);
}

/* --------------------------------------------------------------------------
   Surfaces, controls, and content grid
   -------------------------------------------------------------------------- */

.ts-surface,
.ts-card,
.ts-search-input,
.ts-filter-button,
.ts-ocr-panel,
.ts-document-face {
  background: var(--ts-colour-surface);
  border: var(--ts-border);
  border-radius: var(--ts-radius-lg);
}

.ts-content-stack {
  display: grid;
  gap: var(--ts-space-4);
}

.ts-search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--ts-space-3);
  align-items: stretch;
}

.ts-search-input {
  display: flex;
  min-width: 0;
  min-height: 3.5rem;
  align-items: center;
  gap: var(--ts-space-3);
  padding-inline: var(--ts-space-4);
}

.ts-search-input input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 1rem;
}

.ts-search-input input::placeholder {
  color: var(--ts-colour-ink-muted);
  opacity: 1;
}

.ts-filter-button {
  display: inline-grid;
  min-width: 3.5rem;
  min-height: 3.5rem;
  place-items: center;
  padding: var(--ts-space-3);
  color: var(--ts-colour-ink);
  cursor: pointer;
}

.ts-filter-menu {
  display: grid;
  gap: var(--ts-space-2);
  margin: var(--ts-space-2) 0 0;
  padding: var(--ts-space-3);
  background: var(--ts-colour-surface);
  border: var(--ts-border);
  border-radius: var(--ts-radius-md);
}

/* The permitted filter states are Active, Due Soon, and Expired only. */
.ts-filter-option {
  display: flex;
  min-height: 2.75rem;
  align-items: center;
  justify-content: flex-start;
  padding-inline: var(--ts-space-3);
  border: 0;
  border-radius: var(--ts-radius-sm);
  background: transparent;
  color: var(--ts-colour-ink);
  cursor: pointer;
  font-weight: var(--ts-font-weight-semibold);
  text-align: left;
}

.ts-filter-option[aria-pressed="true"] {
  background: var(--ts-colour-surface-subtle);
}

/* --------------------------------------------------------------------------
   Universal status markers
   -------------------------------------------------------------------------- */

.ts-status {
  display: inline-grid;
  width: var(--ts-status-width);
  min-width: var(--ts-status-width);
  height: var(--ts-status-height);
  min-height: var(--ts-status-height);
  place-items: center;
  padding: 0 var(--ts-space-2);
  overflow: hidden;
  border: var(--ts-status-border);
  border-radius: var(--ts-status-radius);
  font-size: var(--ts-status-font-size);
  font-weight: var(--ts-status-font-weight);
  line-height: 1;
  text-align: center;
  white-space: nowrap;
}

.ts-status--active {
  background: var(--ts-status-active-bg);
  color: var(--ts-status-active-fg);
}

.ts-status--due {
  background: var(--ts-status-due-bg);
  color: var(--ts-status-due-fg);
}

.ts-status--expired {
  background: var(--ts-status-expired-bg);
  color: var(--ts-status-expired-fg);
}

.ts-status-stack {
  display: flex;
  height: var(--ts-header-status-stack-height);
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-end;
}

.ts-status-stack__row {
  display: grid;
  grid-template-columns: 1.5rem var(--ts-status-width);
  /* Board count right edge sits 15px before each pill after scale conversion. */
  gap: 15px;
  align-items: center;
}

.ts-status-stack__count {
  font-size: 10px; /* 25 board px */
  font-weight: var(--ts-font-weight-bold);
  line-height: 1;
  text-align: right;
}

@media (max-width: 359px) {
  /* Preserve the universal pill while releasing space for the Home title. */
  .ts-header__title {
    font-size: 28px;
  }

  .ts-header__identity {
    font-size: 13px;
  }

  .ts-status-stack__row {
    grid-template-columns: var(--ts-status-width);
    gap: 0;
  }

  .ts-status-stack__count {
    display: none;
  }

  .ts-back-header {
    grid-template-columns: 52px minmax(0, 1fr) var(--ts-status-width);
    gap: 8px;
  }

  .ts-back-header__button {
    width: 52px;
  }
}

/* --------------------------------------------------------------------------
   Generic record cards: icon + strict three-line content layout
   -------------------------------------------------------------------------- */

.ts-record-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--ts-space-4);
  align-items: start;
  /* Reduced top/bottom padding to tighten the space above/below the icon and text */
  padding: var(--ts-space-3) var(--ts-space-4);
  background: var(--ts-colour-surface);
  border: var(--ts-border);
  border-radius: var(--ts-radius-lg);
}

.ts-record-card__icon {
  display: grid;
  width: 4.5rem;
  height: 4.5rem;
  place-items: center;
  overflow: hidden;
  background: var(--ts-colour-surface-subtle);
  border: var(--ts-border);
  border-radius: var(--ts-radius-md);
}

.ts-record-card__content {
  display: grid;
  min-width: 0;
  gap: var(--ts-space-2);
}

/* Line 1: left-aligned title. */
.ts-record-card__title {
  margin: 0;
  color: var(--ts-colour-ink);
  font-size: 1.125rem;
  font-weight: var(--ts-font-weight-bold);
  line-height: 1.2;
  text-align: left;
}

/* Line 2: left-aligned expiry date. */
.ts-record-card__expiry {
  margin: 0;
  color: var(--ts-colour-ink-muted);
  font-size: 0.9375rem;
  font-weight: var(--ts-font-weight-medium);
  text-align: left;
}

/* Line 3: universal status marker, right-aligned. */
.ts-record-card__status-row {
  display: flex;
  justify-content: flex-end;
  min-height: var(--ts-status-height);
}

/* --------------------------------------------------------------------------
   Fixed bottom navigation: only the central Add action uses brand colour
   -------------------------------------------------------------------------- */

.ts-bottom-nav {
  position: fixed;
  z-index: 40;
  bottom: 0;
  left: 50%;
  width: min(100%, var(--ts-layout-max-width));
  min-height: var(--ts-nav-total-height);
  transform: translateX(-50%);
  padding: var(--ts-nav-padding) var(--ts-space-4) calc(var(--ts-nav-padding) + env(safe-area-inset-bottom, 0px));
  background: var(--ts-colour-surface);
  border-top: var(--ts-border-width) solid var(--ts-colour-ink); /* Black divider matching header */
}

.ts-bottom-nav__inner {
  display: grid;
  width: 100%;
  min-height: var(--ts-nav-functional-height);
  grid-template-columns: 1fr auto 1fr;
  gap: var(--ts-space-4);
  align-items: center;
  margin-inline: auto;
}

.ts-nav-action {
  display: grid;
  width: 3.25rem;
  height: 3.25rem;
  place-items: center;
  justify-self: start;
  border: 2px solid var(--ts-colour-ink);
  border-radius: 0.625rem;
  background: var(--ts-colour-surface);
  color: var(--ts-colour-ink);
  cursor: pointer;
}

.ts-nav-action svg {
  width: 2rem;
  height: 2rem;
}

/* A solid ink active control remains recognizable in bright outdoor light. */
.ts-nav-action[aria-current="page"] {
  background: var(--ts-colour-ink);
  color: var(--ts-colour-surface);
}

.ts-nav-action--right {
  justify-self: end;
}

.ts-add-button {
  display: grid;
  width: var(--ts-add-button-size);
  height: var(--ts-add-button-size);
  place-items: center;
  align-self: start;
  margin-top: calc(var(--ts-add-button-overlap) * -1);
  border: var(--ts-border);
  border-radius: 50%;
  background: var(--ts-colour-brand);
  color: var(--ts-colour-brand-contrast);
  cursor: pointer;
  font-size: 2rem;
  font-weight: var(--ts-font-weight-regular);
  line-height: 1;
}

/* --------------------------------------------------------------------------
   Detail screens and document faces
   -------------------------------------------------------------------------- */

.ts-back-header {
  position: fixed;
  z-index: 40;
  top: 0;
  left: 50%;
  display: grid;
  width: min(100%, var(--ts-layout-max-width));
  height: var(--ts-detail-header-height);
  transform: translateX(-50%);
  /* Board: Back control 148px wide, title begins at x=238, pill right edge x=1042. */
  grid-template-columns: 57px minmax(0, 1fr) var(--ts-status-width);
  gap: 11px;
  align-items: end;
  padding: var(--ts-header-safe-top) var(--ts-header-edge-end) var(--ts-header-bottom-clearance) var(--ts-header-edge-start);
  background: var(--ts-colour-brand);
  border-bottom: var(--ts-border);
}

.ts-back-header__button {
  display: flex;
  width: 57px;
  height: 25px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: var(--ts-border);
  border-radius: 4px;
  background: var(--ts-colour-surface);
  color: var(--ts-colour-brand-contrast);
  cursor: pointer;
  font-size: 10px; /* 25 board px */
  font-weight: var(--ts-font-weight-bold);
  line-height: 1;
}

.ts-back-header__title {
  display: flex;
  height: 25px;
  align-items: center;
  overflow: hidden;
  margin: 0;
  color: var(--ts-colour-brand-contrast);
  font-size: clamp(11px, 3vw, 13px);
  font-weight: var(--ts-font-weight-bold);
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ts-back-header__status {
  justify-self: end;
}

.ts-detail-main {
  min-height: 100dvh;
  padding: calc(var(--ts-detail-header-height) + var(--ts-space-5)) var(--ts-space-4)
    var(--ts-space-8);
}

.ts-ocr-panel {
  overflow: hidden;
}

.ts-ocr-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.ts-ocr-field {
  min-height: 5.75rem;
  padding: var(--ts-space-4);
  border-right: var(--ts-border-soft);
  border-bottom: var(--ts-border-soft);
}

.ts-ocr-field:nth-child(2n) {
  border-right: 0;
}

.ts-ocr-field:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.ts-ocr-field__label {
  display: block;
  color: var(--ts-colour-ink-muted);
  font-size: 0.8125rem;
  font-weight: var(--ts-font-weight-medium);
}

.ts-ocr-field__value {
  display: block;
  margin-top: var(--ts-space-1);
  color: var(--ts-colour-ink);
  font-weight: var(--ts-font-weight-bold);
  overflow-wrap: anywhere;
}

.ts-document-label {
  display: block;
  margin: var(--ts-space-5) 0 var(--ts-space-2);
  color: var(--ts-colour-ink-muted);
  font-size: 0.875rem;
  font-weight: var(--ts-font-weight-semibold);
}

/* No outer wrapper or padding: the document itself matches the OCR width. */
.ts-document-face {
  display: block;
  width: 100%;
  aspect-ratio: var(--ts-credit-card-ratio);
  object-fit: cover;
  cursor: zoom-in;
}

/* --------------------------------------------------------------------------
   Card inspection: only the document transforms; header remains fixed
   -------------------------------------------------------------------------- */

.ts-inspection-stage {
  position: fixed;
  z-index: 10;
  top: var(--ts-detail-header-height);
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: var(--ts-space-3);
  background: var(--ts-colour-surface);
}

/*
  The inspecting module sets --ts-inspection-document-height with a
  ResizeObserver. It must calculate the largest 90-degree-rotated document
  that fits below the fixed header while retaining 1.586:1 proportions.
*/
.ts-inspection-document {
  width: auto;
  height: var(--ts-inspection-document-height, calc(100vw - var(--ts-space-3) - var(--ts-space-3)));
  max-width: none;
  max-height: none;
  border: var(--ts-border);
  border-radius: var(--ts-radius-lg);
  object-fit: contain;
  transform: rotate(90deg);
  transform-origin: center;
}

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

@media (max-width: 23rem) {
  :root {
    --ts-space-4: 0.875rem;
  }

  .ts-header__inner {
    gap: var(--ts-space-3);
  }

  .ts-record-card {
    gap: var(--ts-space-3);
  }

  .ts-record-card__icon {
    width: 4rem;
    height: 4rem;
  }
}

@media (min-width: 48rem) {
  .ts-main,
  .ts-detail-main {
    padding-inline: var(--ts-space-6);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
