/* El Maestro: workshop-floor design tokens and shared components. */
:root {
  --bg: #E3E6E8; --card: #FBFCFC; --sunk: #EEF0F1; --fg: #1E2328; --mut: #57626C; --line: #CBD1D6; --line2: #B4BCC3;
  --acc: #F2C200; --acc-press: #D9AE00; --onacc: #1E2328; --ink: #1E2328;
  --red: #D3322A; --amb: #B86E00; --grn: #12894F; --grnbg: #E4F4EB; --redbg: #FBE9E7; --ambbg: #FBF0DD;
  --s-arr: #6B7580; --s-insp: #2B6CD4; --s-appr: #7A4FD1; --s-wip: #E39B00; --s-rdy: #12894F;
  --wa: #1A8F4A; --wa-press: #147A3E;
  --fs: 'Barlow', 'IBM Plex Sans Arabic', system-ui, -apple-system, 'Segoe UI', Roboto, Tahoma, sans-serif;
  --fc: 'Barlow Semi Condensed', 'IBM Plex Sans Arabic', system-ui, -apple-system, 'Segoe UI', Roboto, Tahoma, sans-serif;
  --r: 14px; --r-sm: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171A; --card: #1D2125; --sunk: #181B1F; --fg: #ECEEEF; --mut: #9BA5AE; --line: #2F353B; --line2: #434B53;
    --red: #F0584F; --amb: #E8A13A; --grn: #3CC585; --grnbg: #10291C; --redbg: #33191A; --ambbg: #2E2312;
    --s-arr: #8C96A1; --s-insp: #6FA0F5; --s-appr: #A98BF0; --s-wip: #E8A13A; --s-rdy: #3CC585;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14171A; --card: #1D2125; --sunk: #181B1F; --fg: #ECEEEF; --mut: #9BA5AE; --line: #2F353B; --line2: #434B53;
  --red: #F0584F; --amb: #E8A13A; --grn: #3CC585; --grnbg: #10291C; --redbg: #33191A; --ambbg: #2E2312;
  --s-arr: #8C96A1; --s-insp: #6FA0F5; --s-appr: #A98BF0; --s-wip: #E8A13A; --s-rdy: #3CC585;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
* { -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--fg);
  font: 500 16px/1.45 var(--fs);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
body::before { /* the hazard tape: the one loud thing */
  content: ''; display: block; height: 10px;
  padding-top: env(safe-area-inset-top, 0px);
  background: repeating-linear-gradient(-45deg, var(--acc) 0 12px, var(--ink) 12px 24px) bottom / 100% 10px no-repeat, var(--ink);
}
a { color: inherit; }
h1, h2, h3, .cond { font-family: var(--fc); font-weight: 700; margin: 0; letter-spacing: 0; }
h1 { font-size: 28px; line-height: 1.15; }
h2 { font-size: 20px; line-height: 1.2; }
h3 { font-size: 17px; }
p { margin: 0 0 12px; }
.mut { color: var(--mut); }
.small { font-size: 14px; }
:focus-visible { outline: 3px solid var(--fg); outline-offset: 2px; }
a, button, select, summary, label, .tap { touch-action: manipulation; }
.i { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[dir="rtl"] .flip { transform: scaleX(-1); }

/* ------------ page frame */
.wrap { max-width: 480px; margin: 0 auto; padding: 14px 16px 96px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0 14px; }
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; min-width: 0; }
.logo b { font: 700 23px/1 var(--fc); white-space: nowrap; }
.logo small { display: block; font: 600 13px/1.2 var(--fs); color: var(--mut); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }
.mk { /* CSS traffic light */
  width: 18px; height: 32px; border-radius: 6px; flex: none; background:
    radial-gradient(circle at 50% 20%, #F0584F 0 3.2px, transparent 3.7px),
    radial-gradient(circle at 50% 50%, #F2C200 0 3.2px, transparent 3.7px),
    radial-gradient(circle at 50% 80%, #3CC585 0 3.2px, transparent 3.7px), #1E2328;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}
.top-r { display: flex; align-items: center; gap: 6px; }
.lang { display: flex; border: 1.5px solid var(--line); border-radius: 10px; overflow: hidden; }
.lang button { min-height: 38px; min-width: 40px; padding: 0 8px; border: 0; border-radius: 0; background: transparent; color: var(--mut); font: 700 15px var(--fc); cursor: pointer; }
.lang button[aria-pressed="true"] { background: var(--ink); color: #fff; }
:root[data-theme="dark"] .lang button[aria-pressed="true"] { background: var(--fg); color: var(--bg); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .lang button[aria-pressed="true"] { background: var(--fg); color: var(--bg); } }
.ibtn { display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: 10px; border: 1.5px solid var(--line); background: transparent; color: var(--fg); cursor: pointer; text-decoration: none; }
.ibtn:active { background: var(--line); }

/* ------------ tabs (underlined, yellow indicator) */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 16px; }
.tabs a { flex: 1; text-align: center; padding: 12px 8px; font: 600 20px var(--fc); color: var(--mut); text-decoration: none; border-bottom: 4px solid transparent; margin-bottom: -2px; }
.tabs a[aria-current="page"] { color: var(--fg); border-bottom-color: var(--acc); }
.tabs .cnt { display: inline-block; min-width: 24px; margin-inline-start: 6px; padding: 0 7px; border-radius: 999px; background: var(--red); color: #fff; font-size: 15px; line-height: 22px; vertical-align: 2px; }

/* ------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 12px; border: 1.5px solid transparent;
  font: 700 17px/1 var(--fc); cursor: pointer; text-decoration: none; text-align: center;
  background: var(--acc); color: var(--onacc); transition: background-color .12s, transform .08s;
}
.btn:active { transform: scale(.98); background: var(--acc-press); }
.btn.sec { background: transparent; color: var(--fg); border-color: var(--line2); }
.btn.sec:active { background: var(--line); }
.btn.wa { background: var(--wa); color: #fff; min-height: 44px; font-size: 16px; padding: 0 14px; }
.btn.wa:active { background: var(--wa-press); }
.btn.danger { background: transparent; color: var(--red); border-color: color-mix(in srgb, var(--red) 45%, transparent); }
.btn.danger:active { background: var(--redbg); }
.btn.block { width: 100%; }
.btn.big { min-height: 58px; font-size: 21px; border-radius: 14px; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn .i { width: 20px; height: 20px; }
.btns { display: flex; gap: 10px; }
.btns > * { flex: 1; min-width: 0; }

/* ------------ forms with visible labels */
.f { display: block; margin-bottom: 12px; }
.f > span { display: block; font: 600 14px/1.3 var(--fs); color: var(--mut); margin-bottom: 5px; }
.f > small { display: block; color: var(--mut); font-size: 13px; margin-top: 4px; }
input, select, textarea {
  width: 100%; min-height: 48px; padding: 10px 12px; font: 500 17px var(--fs); color: var(--fg);
  background: var(--card); border: 1.5px solid var(--line2); border-radius: var(--r-sm); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--fg); }
input::placeholder { color: color-mix(in srgb, var(--mut) 75%, transparent); }
select { appearance: none; padding-inline-end: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2357626C' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
[dir="rtl"] select { background-position: left 10px center; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row2 > .f { min-width: 0; }
input[type="time"], input[type="month"] { min-width: 0; }

/* ------------ cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; margin-bottom: 14px; }
.card > h2:first-child, .card > .hd:first-child { margin-bottom: 12px; }
.hd { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* the plate badge: always LTR, EU strip on the left */
.pl { direction: ltr; unicode-bidi: isolate; display: inline-flex; align-items: center; background: #fff; color: #111; border: 2px solid #111; border-radius: 6px; padding: 0 8px 0 0; font: 700 16px/24px var(--fc); white-space: nowrap; }
.pl::before { content: ''; align-self: stretch; width: 12px; margin-right: 6px; background: #1F4FB4; border-radius: 3px 0 0 3px; }
.pl.lg { font-size: 20px; line-height: 30px; }
.pl.lg::before { width: 15px; }

.tag { display: inline-block; font: 600 14px/22px var(--fc); background: var(--sunk); border: 1px solid var(--line); color: var(--fg); border-radius: 6px; padding: 0 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; font: 700 14px/1 var(--fc); color: var(--c, var(--mut)); }
.chip::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.chip.solid { color: #fff; background: var(--c); border-radius: 999px; padding: 5px 10px; }
.chip.solid::before { display: none; }

/* status colors */
.s-arr { --c: var(--s-arr); } .s-insp { --c: var(--s-insp); } .s-appr { --c: var(--s-appr); } .s-wip { --c: var(--s-wip); } .s-rdy { --c: var(--s-rdy); }
.t-red { --c: var(--red); } .t-amb { --c: var(--amb); } .t-grn { --c: var(--grn); }

/* rail item: thick colored edge on the start side */
.item { display: flex; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line); border-inline-start: 8px solid var(--c, var(--line)); border-radius: var(--r); padding: 14px; margin-bottom: 10px; }
.item .it { flex: 1; min-width: 0; }
.item .nm { font: 700 19px/1.2 var(--fc); overflow-wrap: anywhere; }
.item .nt { color: var(--mut); font-size: 15px; overflow-wrap: anywhere; }
.item .pr { font: 700 18px var(--fc); white-space: nowrap; }
.ph { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; flex: none; background: var(--sunk); border: 1px solid var(--line); display: grid; place-items: center; color: var(--mut); }
button.ph { padding: 0; cursor: zoom-in; overflow: hidden; }
button.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* tracker */
.trk { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin: 12px 0 10px; list-style: none; padding: 0; }
.trk li { position: relative; padding-top: 12px; font: 600 13px/1.2 var(--fc); color: var(--mut); text-align: center; }
.trk li::before { content: ''; position: absolute; top: 0; inset-inline: 0; height: 6px; border-radius: 3px; background: var(--line); }
.trk li.done::before { background: color-mix(in srgb, var(--c) 45%, var(--line)); }
.trk li.on { color: var(--fg); }
.trk li.on::before { background: var(--c); }

.ban { display: flex; gap: 10px; align-items: flex-start; border-radius: 12px; padding: 12px 14px; margin: 10px 0 14px; background: var(--grnbg); border: 1px solid color-mix(in srgb, var(--grn) 55%, transparent); }
.ban .i { color: var(--grn); margin-top: 1px; }
.ban.warn { background: var(--ambbg); border-color: color-mix(in srgb, var(--amb) 55%, transparent); }
.ban.warn .i { color: var(--amb); }

.grp { margin: 16px 0 6px; }
.grp h3 { display: flex; align-items: center; gap: 8px; font-size: 19px; margin-bottom: 8px; }
.grp.ok h3 { color: var(--grn); } .grp.no h3 { color: var(--red); }
.grp h3 .sum { margin-inline-start: auto; color: var(--fg); }

/* signature pad */
.sig { position: relative; background: #fff; border: 2px dashed #8A949D; border-radius: 12px; }
.sig canvas { display: block; width: 100%; height: 160px; touch-action: none; cursor: crosshair; }
.sig span { position: absolute; inset: 0; display: grid; place-items: center; color: #8A949D; font: 600 18px var(--fc); pointer-events: none; }
.sig img { display: block; width: 100%; height: 120px; object-fit: contain; }

/* toast */
#toast { position: fixed; z-index: 50; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); width: calc(100% - 32px); max-width: 460px; display: flex; align-items: center; gap: 12px; justify-content: space-between; background: var(--ink); color: #fff; border-radius: 12px; padding: 10px 10px 10px 16px; font-size: 15px; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
#toast button { min-height: 38px; padding: 0 14px; border: 0; border-radius: 9px; background: var(--acc); color: var(--onacc); font: 700 16px var(--fc); cursor: pointer; flex: none; }
#toast.err { background: var(--red); }

.empty { padding: 10px 2px 14px; color: var(--mut); }
.spin { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--fg); border-radius: 50%; animation: sp .8s linear infinite; margin: 40px auto; }
@keyframes sp { to { transform: rotate(360deg); } }

dialog.lb { border: 0; padding: 0; background: transparent; max-width: min(96vw, 900px); }
dialog.lb::backdrop { background: rgba(10,12,14,.82); }
dialog.lb img { display: block; max-width: 100%; max-height: 86vh; border-radius: 10px; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }
@media print {
  body::before, .noprint, #toast { display: none !important; }
  body { background: #fff; color: #000; }
  .card, .item { break-inside: avoid; }
}
