/* Shared design tokens. Page hooks and custom.css can override individual components. */
@font-face {
  font-family: "Montserrat";
  src: url("../fonts/montserrat/Montserrat-Variable.ttf") format("truetype");
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --brand-blue: #011947;
  --brand-red: #d6001a;
  --bg: #f4f7fa;
  --ink: #203440;
  --muted: #637887;
  --accent: var(--brand-blue);
  --accent-dark: var(--brand-red);
  --surface: #ffffff;
  --border: #d8e3eb;
  --danger: var(--brand-red);
  --radius: 8px;
  --topbar-height: 55px;
  --font-family: "Montserrat", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --catalogue-font-scale: 1.2;
  --catalogue-row-odd: #ffffff;
  --catalogue-row-even: #edf4f8;
  --catalogue-row-hover: #fcecef;
}

/* App shell: no unqualified body, heading, form or table styles. */
.app-shell, .app-shell * { box-sizing: border-box; }
.app-shell {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--font-family);
  font-size: 14px;
  line-height: 1.5;
}
.app-main {
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  min-height: calc(100vh - 125px);
  padding: 0 36px 48px;
}
.app-footer {
  max-width: 1368px;
  margin: 0 auto;
  padding: 22px 0;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
}

/* Shared primitives. Prefer the page-specific hook for local overrides. */
.ui-link { color: inherit; text-decoration: none; }
.ui-link:hover { color: var(--brand-red); }
.ui-button, .button {
  font: inherit;
  cursor: pointer;
  border: 0;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--radius);
  padding: 11px 17px;
  line-height: 1.3;
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}
.ui-button:disabled { opacity: .45; cursor: default; }
.ui-button:focus-visible, .ui-link:focus-visible, .ui-input:focus-visible,
.ui-select:focus-visible, .tooltip-wrap:focus-visible {
  outline: 2px solid var(--brand-blue);
  outline-offset: 3px;
}
.ui-input, .ui-select {
  font: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--surface);
  color: var(--ink);
  width: 100%;
  min-width: 0;
}
.ui-select {
  appearance: none;
  min-height: 46px;
  padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='m1 1 5 5 5-5' fill='none' stroke='%23011947' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
.ui-input:focus, .ui-select:focus { border-color: var(--brand-blue); }
.ui-checkbox { width: 16px; height: 16px; accent-color: var(--brand-blue); padding: 0; }
.ui-label { display: flex; flex-direction: column; gap: 8px; font-weight: 500; }
.ui-title { font-size: 32px; font-weight: 700; letter-spacing: -.8px; margin: 8px 0 0; line-height: 1.2; }
.ui-subtitle { font-size: 18px; font-weight: 650; letter-spacing: -.3px; margin: 0; }
.ui-text { line-height: 1.6; }
.ui-form { margin: 0; }
.muted, .help { color: var(--muted); }
.help { font-size: 12px; line-height: 1.7; }
.eyebrow { font-size: 10px; text-transform: uppercase; letter-spacing: 1.8px; color: var(--brand-blue); margin: 0; }
.primary { background: var(--brand-blue); color: #fff; font-weight: 650; }
.primary:hover { background: var(--brand-red); color: #fff; }
.secondary { background: var(--surface); color: var(--brand-blue); border: 1px solid var(--border); }
.secondary:hover { color: #fff; background: var(--brand-red); border-color: var(--brand-red); }
.quiet-link, .quiet-button { color: var(--muted); font-size: 13px; }
.quiet-button { background: none; padding: 0; }
.quiet-button:hover { color: var(--brand-red); }
.icon-button { background: transparent; color: var(--brand-blue); padding: 8px; font-size: 24px; }
.icon-button:hover { background: var(--brand-red); color: #fff; }
.stack { display: flex; flex-direction: column; gap: 19px; }
:where(.stack) .ui-text { margin: 0; }
.page-heading { display: flex; align-items: center; justify-content: space-between; padding: 32px 0 24px; gap: 20px; }
.form-error { color: var(--danger); background: #fff0f2; border-radius: var(--radius); padding: 12px; font-size: 13px; }
.notice { background: #e6f1f7; color: var(--brand-blue); padding: 12px; border-radius: var(--radius); }

/* Top bar and account controls. */
.app-topbar { background: var(--brand-blue); color: #fff; border-bottom: 3px solid var(--brand-red); }
.app-topbar-inner { max-width: 1440px; margin: 0 auto; padding: 7px 36px; min-height: var(--topbar-height); display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.app-brand { font-weight: 800; font-size: 26px; line-height: 1.2; letter-spacing: -1px; color: #fff; padding: 2px 8px; margin-left: -8px; border-radius: 6px; }
.app-brand:hover { color: #fff; background: var(--brand-red); }
.app-brand-dot { color: var(--brand-red); }
.app-brand:hover .app-brand-dot { color: #fff; }
.app-account { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.app-account-name { font-weight: 500; }
.app-account-link, .app-logout-button, .app-settings-link { color: #fff; border-radius: 6px; padding: 6px 8px; }
.app-settings-link { display: inline-flex; align-items: center; justify-content: center; line-height: 1; }
.app-account-link:hover, .app-logout-button:hover, .app-settings-link:hover { color: #fff; background: var(--brand-red); }
.app-account-link:focus-visible, .app-logout-button:focus-visible, .app-settings-link:focus-visible, .app-brand:focus-visible { outline-color: #fff; }

/* Login and password pages. */
.login-panel { max-width: 390px; margin: 0 auto; padding: 72px 0; }
.login-title { font-size: 30px; margin-top: 12px; }
:where(.login-panel) > .stack { margin-top: 32px; }
:where(.login-panel) > .help { margin-top: 24px; }
.narrow-panel { max-width: 440px; margin: 0 auto; padding: 48px 0; }
.password-title { margin: 24px 0 32px; }

/* Tables: shared structure; catalogue density and sizes are independent. */
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow-x: auto; }
.ui-table { width: 100%; border-collapse: collapse; text-align: left; }
.ui-th { font-size: 12px; color: #fff; font-weight: 650; background: var(--brand-blue); white-space: nowrap; padding: 12px 16px; border-bottom: 2px solid var(--brand-red); }
.ui-cell { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
:where(.ui-row:last-child) .ui-cell { border-bottom: 0; }
.number { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.catalogue-table { font-size: calc(14px * var(--catalogue-font-scale)); }
:where(.catalogue-table) .ui-th { font-size: calc(11px * var(--catalogue-font-scale)); }
.catalogue-cell { font-size: calc(14px * var(--catalogue-font-scale)); padding: 7px 16px; line-height: 1.4; }
.catalogue-row:nth-child(odd) { background: var(--catalogue-row-odd); }
.catalogue-row:nth-child(even) { background: var(--catalogue-row-even); }
.catalogue-row:hover { background: var(--catalogue-row-hover); }
.catalogue-photo-header { width: 96px; }
.product-photo, .photo-placeholder { width: 48px; height: 48px; border-radius: 6px; object-fit: contain; background: #e8eff4; }
.photo-placeholder { display: flex; align-items: center; justify-content: center; text-align: center; font-size: calc(9px * var(--catalogue-font-scale)); line-height: 1.15; color: var(--muted); padding: 4px; overflow-wrap: anywhere; }
.catalogue-photo-placeholder { width: 64px; height: 40px; overflow-wrap: normal; }
.product-name { font-weight: 500; min-width: 180px; }
.identifier-button { background: none; color: var(--brand-blue); font-size: calc(12px * var(--catalogue-font-scale)); padding: 5px 0; text-align: left; justify-content: flex-start; max-width: 260px; overflow-wrap: anywhere; }
.identifier-button:hover { color: var(--brand-red); text-decoration: underline; }
.count { color: var(--muted); white-space: nowrap; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.search-label { width: 460px; }
.pagination { display: flex; justify-content: flex-end; align-items: center; gap: 18px; margin-top: 18px; }
:where(.pagination) .ui-button { padding: 8px 12px; font-size: 12px; }
.empty-state { text-align: center; padding: 60px 20px; }
:where(.empty-state) .ui-text { color: var(--muted); margin-bottom: 22px; }

/* Immediate, keyboard-accessible tooltips. */
.tooltip-wrap { position: relative; cursor: help; display: inline-flex; align-items: center; gap: 6px; }
.info-mark { font-size: 9px; border: 1px solid currentColor; border-radius: 50%; width: 13px; height: 13px; text-align: center; }
.tooltip { position: fixed; width: 220px; white-space: normal; background: var(--brand-blue); color: #fff; padding: 10px 12px; border-radius: 7px; font-size: 12px; font-weight: 500; line-height: 1.5; z-index: 40; visibility: hidden; opacity: 0; pointer-events: none; box-shadow: 0 5px 18px #102b4033; }
.tooltip-wrap:hover .tooltip, .tooltip-wrap:focus .tooltip { visibility: visible; opacity: 1; }

/* Dialogs and identifier tags. */
.ui-dialog { border: 1px solid var(--border); border-top: 4px solid var(--brand-blue); border-radius: 12px; padding: 26px; width: min(560px, calc(100% - 32px)); max-height: 90vh; overflow: auto; color: var(--ink); background: var(--surface); box-shadow: 0 20px 80px #102b4033; font-family: var(--font-family); }
.ui-dialog::backdrop { background: #112b4266; }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
:where(.dialog-heading) .ui-subtitle { font-size: 20px; }
:where(.dialog-heading) .icon-button { padding: 0 6px; }
.field-label { font-size: 11px; color: var(--muted); margin: 0 0 8px; }
.tags { display: flex; flex-wrap: wrap; gap: 7px; min-height: 24px; }
.tag { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 6px; background: #e4f0f7; color: var(--brand-blue); font-size: 12px; overflow-wrap: anywhere; max-width: 100%; white-space: pre-wrap; }
.readonly { background: #edf1f4; color: var(--muted); }
:where(.tag) .ui-button { padding: 0 3px; background: transparent; font-size: 17px; line-height: 1; color: var(--brand-blue); }
:where(.tag) .ui-button:hover { color: #fff; background: var(--brand-red); }
.actions { display: flex; justify-content: flex-end; gap: 10px; }

/* Administration. */
.tabs { display: flex; border-bottom: 1px solid var(--border); gap: 24px; margin-bottom: 24px; }
:where(.tabs) .ui-button { background: none; border-radius: 0; padding: 13px 0; color: var(--muted); border-bottom: 3px solid transparent; }
:where(.tabs) .ui-button[aria-selected="true"] { color: var(--brand-blue); border-color: var(--brand-blue); }
:where(.tabs) .ui-button:hover { color: var(--brand-red); border-color: var(--brand-red); }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin: 22px 0; }
.connection-list { display: grid; gap: 12px; margin-top: 24px; }
.connection-card { display: flex; justify-content: space-between; align-items: center; gap: 24px; background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--brand-blue); border-radius: var(--radius); padding: 20px; }
:where(.connection-card) .ui-text { margin: 5px 0 0; font-size: 12px; color: var(--muted); }
.connection-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
:where(.connection-actions) .ui-button { font-size: 12px; padding: 9px 12px; }
.future-note { display: flex; flex-direction: column; gap: 9px; margin-top: 28px; padding: 20px; border: 1px dashed var(--border); border-radius: var(--radius); font-size: 12px; }
.check-label { display: flex; align-items: center; flex-direction: row; font-size: 12px; gap: 8px; }
.user-email { display: block; font-size: 12px; color: var(--muted); margin-top: 6px; }
.settings-user-row:nth-child(even) { background: var(--catalogue-row-even); }
.settings-user-row:hover { background: var(--catalogue-row-hover); }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); padding: 13px 20px; background: var(--brand-blue); color: #fff; border-radius: 10px; box-shadow: 0 4px 24px #102b4033; z-index: 60; max-width: 90vw; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.app-shell [hidden] { display: none; }

@media (max-width: 760px) {
  .app-topbar-inner { flex-wrap: wrap; padding: 7px 16px; gap: 12px; }
  .app-main { padding: 0 16px 32px; }
  .app-footer { margin: 0 16px; }
  .app-account { gap: 6px; flex-wrap: wrap; }
  .app-account-name { display: none; }
  .app-account-link, .app-logout-button { padding: 6px; font-size: 11px; }
  .ui-title { font-size: 28px; }
  .page-heading { padding: 26px 0 22px; }
  .toolbar { align-items: flex-start; flex-direction: column; }
  .search-label { width: 100%; }
  .catalogue-table { min-width: 780px; }
  .catalogue-cell { padding: 7px 12px; }
  .connection-card { align-items: flex-start; flex-direction: column; }
  .connection-actions { justify-content: flex-start; }
  .login-panel { padding-top: 48px; }
  :where(.section-heading) .primary { font-size: 12px; }
  .pagination { justify-content: space-between; }
}
@media (prefers-reduced-motion: reduce) {
  .ui-button, .button { transition: none; }
}
