/* ============================================================================
   TÜV SÜD Middle East — Inspection QR System
   Design system: brand tokens, light/dark themes, components, print rules.
   Primary navy #003087 · Accent blue #009bde · Inter (body) · Barlow (display)
   ============================================================================ */

/* ── Tokens ────────────────────────────────────────────────────────────────*/
:root {
  --navy: #003087;
  --navy-700: #00245f;
  --navy-300: #6a86c0;
  --accent: #009bde;
  --accent-600: #0086c2;
  --accent-100: #e3f4fc;

  --bg: #eef2f9;
  --surface: #ffffff;
  --surface-2: #f6f8fc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --text: #0f1b33;
  --text-muted: #5b6b86;
  --text-faint: #8595ad;

  --ok: #15803d;        --ok-bg: #e7f6ec;   --ok-bd: #b6e2c4;
  --warn: #b45309;      --warn-bg: #fdf2e1; --warn-bd: #f3d8a6;
  --bad: #c81e1e;       --bad-bg: #fbeaea;  --bad-bd: #f1c2c2;
  --neutral: #475569;   --neutral-bg: #eef2f7; --neutral-bd: #d7dfea;

  --logo-fg: var(--navy);
  --ring: rgba(0, 155, 222, .35);
  --shadow-sm: 0 1px 2px rgba(15, 27, 51, .06);
  --shadow: 0 1px 2px rgba(15, 27, 51, .06), 0 10px 30px rgba(15, 27, 51, .07);
  --shadow-lg: 0 18px 50px rgba(15, 27, 51, .14);

  --radius: 14px;
  --radius-sm: 9px;
  --maxw: 1120px;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Barlow", var(--font-body);
}

[data-theme="dark"] {
  --navy: #2f6fd0;
  --navy-700: #21508f;
  --navy-300: #8fb0e6;
  --accent: #22b6f3;
  --accent-600: #0e9bd6;
  --accent-100: #0e2236;

  --bg: #080d18;
  --surface: #111a2c;
  --surface-2: #0d1524;
  --border: #243246;
  --border-strong: #33445f;

  --text: #e9eefc;
  --text-muted: #9fb0cc;
  --text-faint: #6f819e;

  --ok: #46d07f;        --ok-bg: #10241a;   --ok-bd: #1f5436;
  --warn: #f0b357;      --warn-bg: #281d0d;  --warn-bd: #5a4318;
  --bad: #f47171;       --bad-bg: #2a1313;   --bad-bd: #5e2626;
  --neutral: #9fb0cc;   --neutral-bg: #16202f; --neutral-bd: #2b3850;

  --logo-fg: #eaf1ff;
  --ring: rgba(34, 182, 243, .4);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 34px rgba(0, 0, 0, .45);
  --shadow-lg: 0 22px 60px rgba(0, 0, 0, .55);
}

/* ── Base ──────────────────────────────────────────────────────────────────*/
*, *::before, *::after { box-sizing: border-box; }
/* The `hidden` attribute must always win, even over components that set display
   (e.g. .field{display:flex}, .edit-grid{display:grid}). */
[hidden] { display: none !important; }
.tuv-logo { display: block; object-fit: contain; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { font-family: var(--font-display); color: var(--text); line-height: 1.2; margin: 0 0 .4em; letter-spacing: -.01em; }
h1 { font-size: clamp(1.5rem, 1.1rem + 1.6vw, 2rem); font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 700; }
a { color: var(--accent-600); text-decoration: none; }
a:hover { text-decoration: underline; }
p { margin: 0 0 1rem; }
img { max-width: 100%; display: block; }
:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; border-radius: 6px; }

.container { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }
.page { padding: 28px 0 64px; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; letter-spacing: .03em; }
.stack > * + * { margin-top: 14px; }
.hidden { display: none !important; }

/* ── Top bar ───────────────────────────────────────────────────────────────*/
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between;
  gap: 16px; max-width: var(--maxw); margin: 0 auto; padding: 12px 20px; }
.brand { display: inline-flex; align-items: center; gap: 12px; color: var(--logo-fg); }
.brand:hover { text-decoration: none; }
.brand .tuv-logo { display: block; color: var(--logo-fg); }
.brand-sub {
  font-family: var(--font-display); font-weight: 600; font-size: .72rem;
  letter-spacing: .14em; text-transform: uppercase; color: var(--text-muted);
  padding-left: 12px; border-left: 1px solid var(--border-strong);
}
.topnav { display: flex; align-items: center; gap: 8px; }
.nav-link { color: var(--text-muted); font-weight: 600; font-size: .92rem;
  padding: 8px 12px; border-radius: 8px; }
.nav-link:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav-link.is-active { color: var(--navy); background: var(--accent-100); }
[data-theme="dark"] .nav-link.is-active { color: var(--accent); }
.user-chip { font-size: .82rem; color: var(--text-muted); padding: 6px 10px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.theme-toggle { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; font-size: 1rem;
  display: inline-flex; align-items: center; justify-content: center; transition: .15s; }
.theme-toggle:hover { background: var(--surface-2); border-color: var(--border-strong); }

/* ── Buttons ───────────────────────────────────────────────────────────────*/
.btn {
  --b: var(--navy);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font-body); font-weight: 600; font-size: .94rem;
  padding: 10px 18px; border-radius: 10px; border: 1px solid transparent;
  cursor: pointer; transition: transform .04s, background .15s, box-shadow .15s; white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--navy); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--navy-700); text-decoration: none; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-600); text-decoration: none; }
.btn-outline { background: transparent; color: var(--navy); border-color: var(--border-strong); }
[data-theme="dark"] .btn-outline { color: var(--text); }
.btn-outline:hover { background: var(--surface-2); text-decoration: none; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.btn-sm { padding: 7px 12px; font-size: .85rem; border-radius: 8px; }
.btn-lg { padding: 13px 22px; font-size: 1rem; }
.btn-block { width: 100%; }
.btn-danger { background: transparent; color: var(--bad); border: 1px solid transparent; }
.btn-danger:hover { background: var(--bad-bg); color: var(--bad); text-decoration: none; }

/* Inspector affordance shown on the public page when signed in */
.admin-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; background: var(--accent-100); border: 1px solid var(--accent);
  color: var(--accent-600); padding: 10px 14px; border-radius: 10px; margin-bottom: 16px;
  font-size: .9rem; font-weight: 600; }
.col-actions { text-align: right; white-space: nowrap; }

/* ── Cards ─────────────────────────────────────────────────────────────────*/
.card { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 22px; }
.card-head { display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 18px 22px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h2 { margin: 0; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .sub { color: var(--text-muted); margin: 2px 0 0; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; }

/* ── Table ─────────────────────────────────────────────────────────────────*/
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table.table { width: 100%; border-collapse: collapse; font-size: .92rem; min-width: 720px; }
.table thead th { text-align: left; font-size: .72rem; text-transform: uppercase;
  letter-spacing: .08em; color: var(--text-muted); font-weight: 700;
  padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.table tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr { cursor: pointer; transition: background .12s; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.cell-id { font-family: var(--font-display); font-weight: 700; letter-spacing: .06em; color: var(--navy); }
[data-theme="dark"] .cell-id { color: var(--accent); }

/* ── Chips / badges ────────────────────────────────────────────────────────*/
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: .76rem; font-weight: 700;
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--neutral-bd);
  background: var(--neutral-bg); color: var(--neutral); white-space: nowrap; }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.valid    { color: var(--ok);   background: var(--ok-bg);   border-color: var(--ok-bd); }
.chip.soon     { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-bd); }
.chip.expired  { color: var(--bad);  background: var(--bad-bg);  border-color: var(--bad-bd); }
.chip.permanent{ color: var(--accent-600); background: var(--accent-100); border-color: transparent; }
.chip.draft    { color: var(--neutral); }
.chip.published{ color: var(--ok); background: var(--ok-bg); border-color: var(--ok-bd); }
.chip.no-dot::before { display: none; }

/* ── Banner (public status) ────────────────────────────────────────────────*/
.banner { display: flex; align-items: center; gap: 14px; padding: 16px 20px;
  border-radius: var(--radius); border: 1px solid var(--neutral-bd); background: var(--neutral-bg);
  color: var(--neutral); font-weight: 600; }
.banner .dot { width: 14px; height: 14px; border-radius: 50%; background: currentColor; flex: none;
  box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 22%, transparent); }
.banner .banner-title { font-family: var(--font-display); font-size: 1.05rem; }
.banner .banner-sub { font-weight: 500; opacity: .85; font-size: .88rem; }
.banner.valid    { color: var(--ok);   background: var(--ok-bg);   border-color: var(--ok-bd); }
.banner.soon     { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-bd); }
.banner.expired  { color: var(--bad);  background: var(--bad-bg);  border-color: var(--bad-bd); }
.banner.permanent{ color: var(--accent-600); background: var(--accent-100); border-color: transparent; }

/* ── Forms ─────────────────────────────────────────────────────────────────*/
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: .82rem; font-weight: 600; color: var(--text-muted); }
.field .req { color: var(--bad); }
.input, .select, textarea.input {
  font-family: var(--font-body); font-size: .95rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 10px; padding: 11px 13px; width: 100%; transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: var(--text-faint); }
.input:focus, .select:focus, textarea.input:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring);
}
.select { appearance: none; background-image:
  url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235b6b86' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 38px; }
.field-hint { font-size: .78rem; color: var(--text-faint); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }

.form-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  padding-top: 8px; border-top: 1px solid var(--border); margin-top: 8px; }
.save-state { font-size: .85rem; color: var(--text-muted); margin-left: auto; }
.save-state.ok { color: var(--ok); }
.save-state.err { color: var(--bad); }

/* ── Inline notices ────────────────────────────────────────────────────────*/
.notice { padding: 12px 16px; border-radius: 10px; font-size: .9rem; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-muted); }
.notice.error { color: var(--bad); background: var(--bad-bg); border-color: var(--bad-bd); }
.notice.warn  { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-bd); }
.notice.info  { color: var(--accent-600); background: var(--accent-100); border-color: transparent; }

/* ── Empty state ───────────────────────────────────────────────────────────*/
.empty { text-align: center; padding: 56px 24px; color: var(--text-muted); }
.empty .empty-ico { font-size: 2.4rem; opacity: .5; margin-bottom: 8px; }

/* ── Edit layout (form + sticky preview) ───────────────────────────────────*/
.edit-grid { display: grid; grid-template-columns: 1fr 340px; gap: 24px; align-items: start; }
.preview-col { position: sticky; top: 86px; }
@media (max-width: 900px) { .edit-grid { grid-template-columns: 1fr; } .preview-col { position: static; } }

/* ── Sticker (preview + print) ─────────────────────────────────────────────*/
.sticker {
  background: #fff; color: var(--navy);
  border: 1.5px solid #d4dce9; border-radius: 12px;
  padding: 14px 14px 12px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.sticker-head { display: flex; align-items: center; justify-content: space-between; width: 100%;
  gap: 8px; padding-bottom: 8px; border-bottom: 1px solid #e6ebf3; }
.sticker-head .tuv-logo { color: #003087; }
.sticker-dept { font-family: var(--font-display); font-weight: 700; font-size: .56rem;
  text-transform: uppercase; letter-spacing: .06em; color: #5b6b86; text-align: right; line-height: 1.25; }
.sticker-qr { width: 70%; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; padding: 4px 0; }
.sticker-qr img, .sticker-qr svg { width: 100%; height: 100%; }
.sticker-id { font-family: var(--font-display); font-weight: 800; font-size: 1.05rem;
  letter-spacing: .14em; color: #003087; }
.sticker-cap { font-size: .62rem; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: #5b6b86; }
.sticker-band { height: 5px; width: 100%; border-radius: 3px;
  background: linear-gradient(90deg, #003087 0 60%, #009bde 60% 100%); }

/* ── Public certificate ────────────────────────────────────────────────────*/
.cert-wrap { max-width: 720px; margin: 0 auto; }
.certificate { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.cert-top { padding: 24px 26px; border-bottom: 3px solid var(--accent);
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.cert-top .tuv-logo { color: var(--logo-fg); }
.cert-kicker { font-family: var(--font-display); font-weight: 700; text-transform: uppercase;
  letter-spacing: .12em; font-size: .72rem; color: var(--text-muted); }
.cert-body { padding: 26px; }
.cert-title { font-family: var(--font-display); font-size: 1.4rem; font-weight: 700; margin: 0 0 4px; }
.dl { display: grid; grid-template-columns: 1fr 1fr; gap: 0; margin-top: 18px;
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.dl > div { padding: 14px 18px; border-bottom: 1px solid var(--border); }
.dl > div:nth-child(odd) { border-right: 1px solid var(--border); }
.dl dt { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); font-weight: 700; margin-bottom: 3px; }
.dl dd { margin: 0; font-size: 1rem; font-weight: 500; color: var(--text); word-break: break-word; }
@media (max-width: 560px) {
  .dl { grid-template-columns: 1fr; }
  .dl > div:nth-child(odd) { border-right: 0; }
}
.cert-foot { padding: 16px 26px; border-top: 1px solid var(--border); color: var(--text-faint);
  font-size: .8rem; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* Centered single-panel pages (login, pending, 404) */
.center-screen { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.panel { width: 100%; max-width: 420px; }
.panel-wide { max-width: 560px; }
.brand-stack { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 22px; color: var(--logo-fg); text-align: center; }
.brand-stack .dept { font-family: var(--font-display); font-weight: 600; font-size: .74rem;
  letter-spacing: .14em; text-transform: uppercase; color: var(--text-muted); }

/* ── Print sheet ───────────────────────────────────────────────────────────*/
.print-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.print-sheet { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.print-sheet .sticker { box-shadow: var(--shadow-sm); }
@media (max-width: 720px) { .print-sheet { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 460px) { .print-sheet { grid-template-columns: 1fr; } }

@media print {
  @page { size: A4; margin: 12mm; }
  html, body { background: #fff !important; }
  .no-print { display: none !important; }
  .page, .container { padding: 0 !important; margin: 0 !important; max-width: none !important; }
  .print-sheet { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6mm; }
  .sticker { box-shadow: none !important; border-color: #c2ccdb !important; break-inside: avoid; }
  .print-item { break-inside: avoid; }
  .print-item.deselected { display: none !important; }
  .sel-row { display: none !important; }
  .sticker-head .tuv-logo, .sticker-id { color: #003087 !important; }
}

/* ── Footer ────────────────────────────────────────────────────────────────*/
.site-foot { text-align: center; color: var(--text-faint); font-size: .8rem; padding: 28px 0; }

/* ── Tabs (dashboard) ───────────────────────────────────────────────────────*/
.tabs { display: flex; gap: 2px; padding: 6px 10px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tab { appearance: none; border: 0; background: transparent; font: inherit; font-weight: 600; font-size: .9rem;
  color: var(--text-muted); cursor: pointer; padding: 11px 14px; border-bottom: 2px solid transparent;
  margin-bottom: -1px; border-radius: 8px 8px 0 0; }
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.is-active { color: var(--navy); border-bottom-color: var(--accent); }
[data-theme="dark"] .tab.is-active { color: var(--accent); }
.tab-count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 2px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-muted); font-size: .72rem; line-height: 18px; }
.tab.is-active .tab-count { background: var(--accent-100); color: var(--accent-600); }

/* ── Bulk-create control ────────────────────────────────────────────────────*/
.bulk-create { display: inline-flex; align-items: stretch; gap: 8px; }
.input-num { width: 76px; text-align: center; padding-left: 6px; padding-right: 6px; }

/* ── Toast ──────────────────────────────────────────────────────────────────*/
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(8px); z-index: 60;
  background: var(--navy); color: #fff; padding: 11px 20px; border-radius: 999px; box-shadow: var(--shadow-lg);
  font-size: .9rem; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Print selection ────────────────────────────────────────────────────────*/
.print-item { display: flex; flex-direction: column; gap: 8px; }
.sel-row { display: inline-flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 700;
  font-size: .8rem; letter-spacing: .04em; color: var(--text-muted); cursor: pointer; user-select: none; }
.sel-row input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.print-item.deselected .sticker { opacity: .3; filter: grayscale(0.5); }

/* ── Mobile ─────────────────────────────────────────────────────────────────*/
@media (max-width: 640px) {
  .topbar-inner { flex-wrap: wrap; padding: 10px 16px; gap: 8px 10px; }
  .brand-sub { display: none; }
  .user-chip { display: none; }
  .topnav { gap: 4px; }
  .nav-link { padding: 7px 9px; font-size: .88rem; }
  .page { padding: 18px 0 56px; }
  .page-head { gap: 12px; }
  .toolbar { width: 100%; }
  .bulk-create { flex: 1; }
  .bulk-create .btn { flex: 1; }

  /* Records table → stacked cards */
  table.table { min-width: 0; }
  .table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tbody tr { padding: 12px 14px; border-bottom: 1px solid var(--border); }
  .table tbody td { padding: 5px 0; border: 0; display: flex; justify-content: space-between; align-items: center;
    gap: 14px; text-align: right; }
  .table tbody td::before { content: attr(data-label); color: var(--text-muted); font-size: .7rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: .05em; text-align: left; }
  .table tbody td.col-actions { justify-content: flex-end; padding-top: 8px; }
  .table tbody td.col-actions::before { display: none; }
  .cell-id { font-size: 1.05rem; }
}
@media (max-width: 380px) {
  .nav-link { padding: 6px 7px; font-size: .82rem; }
}
