@import url('../assets/brand.css');

/* Finopoli first-party consent layer — component styles (CR-001/ADR-008).
 * WCAG 2.1 AA: >=44px touch targets, AA contrast on the waitlist palette,
 * visible focus, honours prefers-reduced-motion. The three banner choices
 * are DELIBERATELY styled identically (DPDP equal-weight controls) — do
 * not "improve" Accept all into a filled primary button. The preference
 * centre's three choices are laid out on an equal-width grid for the same
 * reason: no consent choice may read as the recommended one.
 *
 * Layout contract for the preference centre: every category card is a
 * two-column grid — a fixed control column (--fc-control) and the text
 * column. The checkboxes and the essential lock therefore share one left
 * edge, and every heading, description and cookie table hangs off one
 * text edge, whatever the category name's length or the display language.
 * Do not move a control back into the heading row; that is what made the
 * checkbox column stagger with the label width. */

.fc-banner, .fc-modal, .fc-centre {
  --fc-bg: var(--fin-surface);
  --fc-text: var(--fin-text);
  --fc-muted: var(--fin-muted);
  --fc-border: var(--fin-line);
  --fc-accent: var(--fin-button);
  --fc-accent-text: var(--fin-text);
  --fc-accent-soft: #196a58;
  --fc-focus: var(--fin-orange);
  --fc-control: 44px; /* control column = one 44px touch target wide */
  --fc-gutter: 12px;
  font-family: var(--fin-font);
  font-size: 1rem; /* rem, not px, so a raised browser font size is honoured */
  line-height: 1.5;
  color: var(--fc-text);
  color-scheme: dark;
  overflow-wrap: anywhere;
}
.fc-banner, .fc-banner *, .fc-modal, .fc-modal *, .fc-centre, .fc-centre * { box-sizing: border-box; }

.fc-banner {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 2147483000;
  background: var(--fc-bg);
  border-top: 1px solid #52627e;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.24);
  padding: 20px 24px max(20px, env(safe-area-inset-bottom));
  max-height: 100vh;
  max-height: 100dvh;
  overflow-y: auto;
}
.fc-banner-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 20px 32px;
  align-items: center;
}
.fc-banner-text { flex: 1 1 320px; margin: 0; }
.fc-banner-text { color: var(--fin-body); }
.fc-banner-text a { color: var(--fin-link); text-underline-offset: .2em; }
.fc-banner-text a:focus-visible { outline: 3px solid var(--fc-focus); outline-offset: 3px; }
.fc-buttons { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: 1fr; gap: 10px; flex: 1 1 520px; }

/* Equal-weight controls: identical size, border, colour and weight. */
.fc-btn {
  min-height: 48px;
  min-width: 44px;
  padding: 10px 18px;
  background: var(--fc-accent);
  color: var(--fc-accent-text);
  border: 1px solid #3baa8b;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
}
.fc-btn:hover, .fc-icon-btn:hover { background: var(--fc-accent-soft); }
.fc-btn:focus-visible, .fc-icon-btn:focus-visible, .fc-check:focus-visible,
.fc-table-wrap:focus-visible {
  outline: 3px solid var(--fc-focus);
  outline-offset: 2px;
}

/* The preference centre's three choices: one grid track each, so they are
   exactly the same width at every viewport and wrap in step rather than
   leaving a ragged last row. */
.fc-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  grid-auto-rows: 1fr;
  gap: 12px;
}

.fc-modal {
  position: fixed;
  inset: 0;
  z-index: 2147483001;
  background: rgba(3, 7, 25, 0.8);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
/* Header / scrolling body / footer, so the consent choices stay on screen
   however long the cookie declaration grows. */
.fc-dialog {
  background: var(--fc-bg);
  color: var(--fc-text);
  border: 1px solid #52627e;
  border-radius: 24px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .35);
  max-width: 760px;
  width: 100%;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.fc-dialog:focus { outline: none; }
.fc-dialog-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 24px 28px 20px;
  border-bottom: 1px solid var(--fc-border);
}
.fc-dialog-head h2 { margin: 0; flex: 1; font-size: 1.5em; line-height: 1.3; font-weight: 600; color: white; }
.fc-dialog-body {
  padding: 24px 28px;
  overflow-y: auto;
  overscroll-behavior: contain;
  min-height: 0;
}
.fc-dialog-head, .fc-dialog-foot { flex-shrink: 0; }
.fc-dialog-foot { padding: 20px 28px; border-top: 1px solid var(--fc-border); }
.fc-centre h2 { margin-top: 0; font-size: 1.4em; }

.fc-icon-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  margin: -10px -10px 0 0; /* optical alignment; keeps the 44px target */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 0;
  border-radius: 6px;
  color: var(--fc-muted);
  cursor: pointer;
}
.fc-icon-btn:hover { color: var(--fc-text); }
.fc-icon-btn svg { width: 20px; height: 20px; }

.fc-intro { margin: 0 0 24px; color: var(--fc-muted); }
.fc-centre > .fc-intro { padding: 20px 24px; border-left: 3px solid var(--fin-teal); background: rgba(29,158,117,.08); border-radius: 0 12px 12px 0; }
.fc-centre > .fc-actions { margin-top: 24px; }

.fc-cat {
  display: grid;
  grid-template-columns: var(--fc-control) minmax(0, 1fr);
  column-gap: var(--fc-gutter);
  row-gap: 8px;
  align-items: start;
  border: 1px solid var(--fc-border);
  background: var(--fin-panel);
  border-radius: 16px;
  padding: 20px;
  margin: 0 0 16px;
}
.fc-cat:last-child { margin-bottom: 0; }
.fc-cat > * { grid-column: 2; }
.fc-cat > .fc-cat-control { grid-column: 1; grid-row: 1; }

/* The control column: the checkbox itself is 24px, the label around it is
   the 44px target, and both stay flush with the column's left edge. */
.fc-cat-control {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 44px;
  margin: 0;
}
label.fc-cat-control { cursor: pointer; }
.fc-check {
  width: 24px;
  height: 24px;
  margin: 0;
  accent-color: var(--fc-accent);
  cursor: pointer;
}
.fc-lock { width: 22px; height: 22px; color: var(--fc-muted); }

.fc-cat-head {
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  min-height: 44px; /* all three category rows share one row height */
}
.fc-cat-head h3 { margin: 0; font-size: 1.125em; font-weight: 600; flex: 1 1 160px; color: white; }
.fc-cat-head h3 label { cursor: pointer; }
.fc-cat p { color: var(--fc-muted); margin: 0; }
.fc-always-on {
  font-weight: 600;
  font-size: 0.85em;
  color: var(--fc-muted);
  border: 1px solid var(--fc-border);
  border-radius: 999px;
  padding: 3px 10px;
  white-space: nowrap;
}
.fc-cat:has(.fc-check:checked) { border-color: #3baa8b; }
.fc-cat:focus-within { border-color: var(--fc-focus); }
.fc-check { accent-color: var(--fin-button); }

/* The declaration scrolls inside its own card rather than widening the
   dialog on narrow screens; tabindex keeps that scroll keyboard-reachable. */
.fc-table-wrap { overflow-x: auto; }
.fc-table {
  width: 100%;
  min-width: 420px;
  border-collapse: collapse;
  font-size: 0.9em;
}
.fc-table caption { text-align: left; color: var(--fc-muted); padding-bottom: 4px; }
.fc-table th, .fc-table td {
  border: 0;
  border-bottom: 1px solid var(--fc-border);
  padding: 8px 16px 8px 0;
  text-align: left;
  vertical-align: top;
}
.fc-table th {
  color: var(--fc-muted);
  font-weight: 600;
  white-space: nowrap;
  border-bottom-width: 2px;
}
.fc-table td:last-child, .fc-table th:last-child { padding-right: 0; }
.fc-table td:last-child { min-width: 200px; }
.fc-table tbody tr:last-child td { border-bottom: 0; }
.fc-none { color: var(--fc-muted); font-style: italic; margin: 0; }

/* Below the width where four columns still fit, each cookie becomes a
   stack of labelled values rather than a table the visitor has to scroll
   sideways. consent.js spells out the table roles so the semantics survive
   `display: block`, and the headings stay in the accessibility tree. */
@media (max-width: 560px) {
  .fc-banner { padding: 16px 20px max(16px, env(safe-area-inset-bottom)); }
  .fc-buttons { flex-basis: 100%; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .fc-banner-inner { gap: 12px; }
  .fc-banner .fc-btn { padding-inline: 6px; font-size: .875rem; }
  .fc-btn { padding-inline: 12px; }
  .fc-modal { padding: 10px; }
  .fc-dialog { border-radius: 20px; max-height: calc(100dvh - 20px); }
  .fc-dialog-head { padding: 20px 18px 16px; }
  .fc-dialog-head h2 { font-size: clamp(1.125rem, 5.5vw, 1.5rem); }
  .fc-dialog-body { padding: 18px; }
  .fc-dialog-foot { padding: 16px 18px; }
  .fc-actions { grid-template-columns: 1fr; gap: 8px; }
  .fc-cat { padding: 14px; --fc-gutter: 4px; }
  .fc-cat > p, .fc-cat > .fc-table-wrap { grid-column: 1 / -1; }
  .fc-centre > .fc-intro { padding: 16px 18px; }
  .fc-table { min-width: 0; }
  .fc-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .fc-table tr { display: block; }
  .fc-table tbody tr + tr {
    border-top: 1px solid var(--fc-border);
    margin-top: 12px;
    padding-top: 12px;
  }
  .fc-table td, .fc-table tbody tr:last-child td {
    display: block;
    border: 0;
    padding: 0 0 8px;
    min-width: 0;
  }
  .fc-table tr td:last-child { padding-bottom: 0; }
  .fc-table td::before {
    content: attr(data-label);
    display: block;
    color: var(--fc-muted);
    font-weight: 600;
  }
}

/* At short viewport heights or large zoom, allow the complete dialog to
 * scroll so a pinned header/footer cannot squeeze its content to zero. */
@media (max-height: 600px) {
  .fc-dialog { overflow-y: auto; overscroll-behavior: contain; }
  .fc-dialog-body { overflow-y: visible; flex-shrink: 0; }
}

@media (prefers-reduced-motion: no-preference) {
  .fc-banner { animation: fc-rise 200ms ease-out; }
  @keyframes fc-rise { from { transform: translateY(100%); } to { transform: none; } }
}
