/* ---------- MRPscan theme (from mrpscan-design-mockup: cream / red, Playfair + Inter) ---------- */
:root {
  color-scheme: light;
  --page: #fbf7f0;          /* mockup --bg */
  --surface: #ffffff;       /* --panel */
  --surface-2: #f4ecdc;     /* --bg-alt */
  --ink: #15120d;           /* --text */
  --ink-2: #6b6150;
  --muted: #857a63;         /* --text-dim */
  --grid: #efe5d0;
  --axis: #ddd0b0;          /* --metallic-2 */
  --border: #e9ddc4;
  --accent: #d9291f;        /* brand red (--gold in the mockup) */
  --accent-light: #e85a4f;
  --accent-deep: #a81f17;
  --accent-soft: rgba(217, 41, 31, 0.25); /* --glow */
  --metal-gold: #b8860b; --metal-gold-bg: #fbf3dd; --metal-gold-border: #ecd9a0;
  --diamond: #2f6fb0; --diamond-bg: #eaf3fb; --diamond-border: #bcdcf4;
  --labour: #2f7d5c; --labour-bg: #eaf5ef; --labour-border: #c3e3d3;
  --wastage: #8a5a7a; --wastage-bg: #f8eef5; --wastage-border: #e7d1e0;
  --metallic-1: #f5efe0; --metallic-2: #ddd0b0; --metallic-3: #c2b28c;
  /* chart / identity colours, all from the mockup's material palette */
  --series-1: #d9291f; --series-2: #b8860b; --series-3: #2f7d5c; --series-4: #2f6fb0;
  --series-5: #8a5a7a; --series-6: #a81f17; --series-7: #c2703d; --series-8: #6b6150;
  --good: #1a8a4a; --good-text: #1a7a42; --warning: #b8860b; --serious: #e85a4f; --critical: #a81f17;
  --shadow: 0 10px 22px -16px rgba(60, 20, 15, 0.35);
  --shadow-raised: 0 14px 28px -14px rgba(21, 18, 13, 0.28);
  --radius: 16px;
  --serif: 'Playfair Display', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  font-size: 15px; line-height: 1.45; color: var(--ink); background: var(--page);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h1 { font-family: var(--serif); font-size: 26px; font-weight: 700; }
h2 { font-family: var(--serif); font-size: 18px; font-weight: 700; }
h3 { font-size: 13px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.muted { color: var(--muted); } .ink2 { color: var(--ink-2); }
.mono { font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.hidden { display: none !important; }

.app { min-height: 100dvh; display: flex; flex-direction: column; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: auto 1fr auto; gap: 16px; align-items: center;
  padding: 12px 20px; background: color-mix(in srgb, var(--page) 92%, transparent); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-light), var(--accent-deep)); color: #fff;
  font-family: var(--serif); font-weight: 800; font-size: 17px;
  box-shadow: 0 10px 22px -10px var(--accent-soft);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-title { font-family: var(--serif); font-weight: 700; font-size: 18px; }
.brand-sub { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.search { position: relative; max-width: 520px; width: 100%; margin: 0 auto; }
.search-icon { position: absolute; left: 14px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.search input {
  width: 100%; height: 46px; padding: 0 16px 0 42px; border-radius: 14px; border: 1.5px solid var(--border);
  background: #fff; color: var(--ink); font-size: 15px; font-family: inherit; outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.search input::placeholder { color: #b8ac8f; }
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

/* ---------- view ---------- */
.view { width: 100%; max-width: 1120px; margin: 0 auto; padding: 22px 20px 48px; flex: 1; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.page-head .sub { color: var(--muted); font-size: 13px; font-weight: 500; margin-top: 2px; }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.card { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head .sub { font-size: 12px; color: var(--muted); font-weight: 600; }
.section-title { margin: 26px 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; }

/* stat tiles (mockup rate-card look) */
.hero { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 24px; }
.hero-figure { font-size: 52px; font-weight: 800; line-height: 1; letter-spacing: -0.02em; }
.hero-label { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.hero-meta { display: flex; flex-wrap: wrap; gap: 8px 18px; font-size: 13px; color: var(--ink-2); padding-bottom: 6px; }
.hero-meta b { color: var(--ink); font-weight: 700; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.tile .label { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.tile .value { font-size: 24px; font-weight: 800; margin-top: 4px; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.tile .delta { font-size: 12px; color: var(--ink-2); margin-top: 3px; font-weight: 500; }
.tile.compact .value { font-size: 18px; }
/* first tile of each group: the mockup's red trial-tile gradient */
.tiles .tile:first-child {
  position: relative; overflow: hidden; border: 1px solid rgba(255, 255, 255, 0.14); color: rgba(255, 255, 255, 0.96);
  background: linear-gradient(150deg, #e0897c 0%, #c25f4e 55%, #a8483a 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), 0 10px 22px -14px rgba(60, 20, 15, 0.55);
}
.tiles .tile:first-child::before { content: ''; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(120deg, rgba(255,255,255,0.16) 0%, rgba(255,255,255,0.03) 35%, rgba(255,255,255,0) 60%); }
.tiles .tile:first-child > * { position: relative; }
.tiles .tile:first-child .label, .tiles .tile:first-child .delta { color: rgba(255, 255, 255, 0.85); }

/* chips (licence badges) */
.chip { font-family: var(--sans); display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--border); white-space: nowrap; letter-spacing: 0.01em; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; }
.chip.good { background: var(--labour-bg); border-color: var(--labour-border); color: var(--labour); }
.chip.good .dot { background: var(--labour); }
.chip.warning { background: var(--metal-gold-bg); border-color: var(--metal-gold-border); color: #8a6508; }
.chip.warning .dot { background: var(--metal-gold); }
.chip.serious { background: #fdecea; border-color: #f4c6c1; color: var(--accent-deep); }
.chip.serious .dot { background: var(--accent-light); }
.chip.critical { background: #fdecea; border-color: #f4c6c1; color: var(--accent-deep); }
.chip.critical .dot { background: var(--accent); }

/* user list */
.user-list { display: flex; flex-direction: column; gap: 12px; }
.user-card { display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center; padding: 14px 16px; background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); transition: transform 0.12s ease, border-color 0.2s ease, box-shadow 0.2s ease; }
.user-card:hover { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); transform: translateY(-1px); }
.user-card:active { transform: scale(0.99); }
.avatar { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-family: var(--serif); font-weight: 800; font-size: 17px; color: #fff; background: var(--series-1); box-shadow: inset 0 1px 0 rgba(255,255,255,0.25); }
.user-main { min-width: 0; }
.user-name { font-weight: 800; font-size: 16px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.user-sub { font-size: 12px; color: var(--muted); font-weight: 600; display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 2px; }
.user-stats { display: flex; gap: 14px; font-size: 12.5px; color: var(--ink-2); text-align: right; }
.user-stats b { display: block; font-size: 16px; color: var(--ink); font-weight: 800; }
@media (max-width: 640px) { .user-card { grid-template-columns: 44px 1fr; } .user-stats { grid-column: 1 / -1; justify-content: flex-start; padding-left: 56px; } }

/* detailed user card (home page) */
.user-card.detailed { display: block; padding: 16px; }
.ud-head { display: flex; gap: 12px; align-items: center; }
.ud-head .user-main { min-width: 0; }
.ud-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 18px; margin-top: 14px; font-size: 13.5px; }
.ud-grid > div > span { display: block; font-size: 10.5px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 1px; }
.ud-grid b { font-weight: 700; overflow-wrap: anywhere; }
.ud-grid .verified { font-size: 11.5px; color: var(--good-text); font-weight: 700; }
.ud-stats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; margin-top: 14px; padding: 10px 6px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); text-align: center; font-variant-numeric: tabular-nums; }
.ud-stats > div { padding: 4px 2px; }
.ud-stats b { display: block; font-size: 18px; font-weight: 800; overflow-wrap: anywhere; line-height: 1.25; }
.ud-stats > div > span { font-size: 10.5px; color: #6b6150; font-weight: 700; }
@media (max-width: 640px) {
  .ud-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ud-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); row-gap: 8px; }
}

/* profile header */
.profile { display: grid; grid-template-columns: 64px 1fr; gap: 14px; align-items: start; }
.profile .avatar { width: 64px; height: 64px; font-size: 24px; }
.profile h1 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.profile-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--ink-2); margin-top: 6px; }
.profile-meta span b { color: var(--ink); font-weight: 700; }
.kv { display: grid; grid-template-columns: minmax(120px, 34%) 1fr; gap: 7px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); font-weight: 600; overflow-wrap: anywhere; } .kv dd { margin: 0; overflow-wrap: anywhere; font-weight: 500; }
.kv dd.bool-true::before { content: "✓ "; color: var(--good-text); } .kv dd.bool-false::before { content: "✕ "; color: var(--muted); }

/* tabs (pill style, as the mockup's segmented controls) */
.tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 22px 0 14px; padding: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: none; padding: 8px 14px; border: 0; background: none; border-radius: 999px; font-size: 13.5px; font-weight: 600; color: var(--ink-2); cursor: pointer; transition: background 0.2s ease, color 0.2s ease; }
.tabs button .count { margin-left: 6px; font-size: 11px; font-weight: 700; color: var(--muted); background: rgba(255,255,255,0.7); padding: 1px 7px; border-radius: 999px; }
.tabs button.active { background: linear-gradient(135deg, var(--accent-light), var(--accent-deep)); color: #fff; box-shadow: 0 8px 18px -10px var(--accent-soft); }
.tabs button.active .count { background: rgba(255,255,255,0.22); color: #fff; }

/* filter chips row */
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.filters button { border: 1.5px solid var(--border); background: #fff; color: var(--ink-2); padding: 6px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 600; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.filters button.active { background: var(--ink); color: #fffdf9; border-color: var(--ink); }
.filters .dot { width: 8px; height: 8px; border-radius: 50%; }

/* timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 18px 1fr auto; gap: 12px; padding: 11px 0; border-bottom: 1px dashed var(--border); align-items: start; }
.timeline li:last-child { border-bottom: 0; }
.tl-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; box-shadow: 0 0 0 3px var(--surface); justify-self: center; }
.tl-title { font-weight: 700; }
.tl-detail { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.tl-time { font-size: 12px; color: var(--muted); white-space: nowrap; text-align: right; font-weight: 500; }
.tl-amount { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 13.5px; text-align: right; }
.tl-amount.neg { color: var(--ink-2); } .tl-amount.pos { color: var(--good-text); }
.tl-kind { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; margin-right: 6px; }
.tl-who { font-size: 12.5px; color: var(--ink-2); }
.tl-who a { color: var(--accent) !important; font-weight: 700; }

/* tables (mockup rate-table look) */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 10px; text-align: left; border-top: 1px solid var(--border); vertical-align: top; white-space: nowrap; }
thead th { border-top: 0; }
td.wrap { white-space: normal; min-width: 160px; overflow-wrap: anywhere; }
th { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 700; position: sticky; top: 0; background: var(--surface); }
td.num, th.num { text-align: right; }
td.num b { color: var(--metal-gold); }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; background: var(--surface-2); color: var(--ink-2); }
.pill.good { background: var(--labour-bg); color: var(--labour); }
.pill.critical { background: #fdecea; color: var(--accent-deep); }
.pill.warning { background: var(--metal-gold-bg); color: #8a6508; }

/* charts */
.chart-box { width: 100%; min-height: 200px; position: relative; }
.chart { display: block; width: 100%; height: auto; overflow: visible; font-family: inherit; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-weight: 600; }
.chart .label { fill: var(--ink-2); font-size: 11.5px; font-weight: 700; }
.chart .bar { transition: opacity 0.12s ease; }
.chart .bar.dim { opacity: 0.4; }
.chart .hit { cursor: crosshair; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { opacity: 0.12; }
.chart .marker { stroke: var(--surface); stroke-width: 2; }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--ink-2); margin-top: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.hbars { display: grid; grid-template-columns: minmax(90px, 32%) 1fr auto; gap: 8px 12px; align-items: center; font-size: 13.5px; }
.hbar-label { min-width: 0; font-weight: 600; }
.hbar-label .sub { display: block; font-size: 11.5px; color: var(--muted); font-weight: 500; }
.hbar-label, .hbar-label a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { height: 14px; position: relative; }
.hbar-fill { height: 14px; border-radius: 0 4px 4px 0; background: var(--series-1); min-width: 2px; transition: width 0.25s ease; }
.hbar-value { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 13px; }
.empty { padding: 26px; text-align: center; color: var(--muted); font-size: 14px; font-weight: 500; background: var(--surface-2); border: 1px dashed var(--border); border-radius: 14px; }
.card .empty { background: none; border: 0; }
.tooltip { position: fixed; z-index: 50; pointer-events: none; background: #15120d; color: #fffdf9; padding: 8px 11px; border-radius: 12px; font-size: 12.5px; line-height: 1.35; box-shadow: 0 14px 28px -14px rgba(21,18,13,0.4); max-width: 260px; }
.tooltip b { display: block; font-weight: 700; margin-bottom: 1px; }
.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 40px 0; justify-content: center; font-size: 14px; font-weight: 600; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2.5px solid var(--border); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-box { padding: 16px; border-radius: 14px; background: #fdecea; border: 1px solid #f4c6c1; color: var(--accent-deep); font-size: 14px; font-weight: 600; }
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 13.5px; font-weight: 600; margin-bottom: 12px; padding: 7px 12px; border-radius: 999px; background: var(--surface-2); }
.back:hover { color: var(--ink); }
.range { display: inline-flex; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px; }
.range button { border: 0; background: none; padding: 5px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.range button.active { background: var(--ink); color: #fffdf9; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } }
.param-group { margin-bottom: 14px; }
.param-group summary { cursor: pointer; font-family: var(--serif); font-weight: 700; font-size: 16px; padding: 8px 0; list-style: none; display: flex; justify-content: space-between; align-items: center; }
.param-group summary::-webkit-details-marker { display: none; }
.param-group summary .count { font-family: var(--sans); font-size: 12px; color: var(--muted); font-weight: 600; }
.param-group[open] summary { border-bottom: 1px dashed var(--border); margin-bottom: 10px; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 4px 10px; font-size: 12.5px; }
.perm-grid span::before { content: "✕ "; color: var(--muted); } .perm-grid span.on::before { content: "✓ "; color: var(--good-text); }
.perm-grid span.on { color: var(--ink); font-weight: 600; } .perm-grid span { color: var(--muted); }

/* access key + in-app server button */
.key-card { max-width: 420px; margin: 40px auto; }
.key-card p { margin: 6px 0 14px; font-size: 14px; }
.key-input { width: 100%; height: 50px; border-radius: 14px; border: 1.5px solid var(--border); background: #fff; color: var(--ink); padding: 0 16px; font-size: 16px; font-family: inherit; letter-spacing: 0.1em; }
.key-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.primary-btn { width: 100%; height: 52px; border: 0; border-radius: 999px; background: linear-gradient(135deg, var(--accent-light), var(--accent-deep)); color: #fff; font-weight: 700; font-size: 16px; margin-top: 14px; cursor: pointer; box-shadow: 0 12px 26px -10px var(--accent-soft); }
.primary-btn:active { transform: scale(0.97); }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: none; background: var(--surface-2); display: grid; place-items: center; cursor: pointer; }
.icon-btn svg { width: 19px; height: 19px; fill: none; stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- phone layout ---------- */
@media (max-width: 760px) {
  .topbar { grid-template-columns: 1fr auto; gap: 10px; padding: 12px 16px; }
  .topbar .search { grid-column: 1 / -1; grid-row: 2; }
  .view { padding: 16px 16px 36px; }
  h1 { font-size: 24px; }
  .hero-figure { font-size: 44px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .table-wrap { margin: 0 -16px; padding: 0 16px; }
}
