@import url('https://fonts.googleapis.com/css2?family=Barlow:wght@400;500;600;700&family=Barlow+Semi+Condensed:wght@600;700;800&display=swap');

:root {
  --red: #D8202A; --red-dark: #A8121A; --red-soft: #FBE9EA;
  --black: #000; --steel: #2E323A; --steel-light: #3C414A;
  --bg: #EBEDF0; --card: #fff; --line: #D4D7DC; --muted: #5C6370; --text: #111;
  --amber: #E8930C; --amber-soft: #FDF1DC; --green: #178A44; --green-soft: #E1F3E7; --blue: #1F5FBF; --blue-soft: #E3ECFA;
  --r: 6px; --shadow: 0 1px 2px rgba(20, 24, 32, .12);
  --tap: 48px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: 'Barlow', system-ui, sans-serif; font-size: 15px; line-height: 1.4; color: var(--text); background: var(--bg); }
h1, h2, h3, .cond { font-family: 'Barlow Semi Condensed', 'Barlow', sans-serif; letter-spacing: -.01em; margin: 0; }
h1 { font-size: 26px; font-weight: 800; } h2 { font-size: 20px; font-weight: 700; } h3 { font-size: 16px; font-weight: 700; }
a { color: var(--red); }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--text); width: 100%; padding: 10px 12px; border: 1px solid #B8BCC4; border-radius: var(--r); background: #fff; min-height: 44px; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 3px solid rgba(216, 32, 42, .35); outline-offset: 1px; border-color: var(--red); }
textarea { min-height: 88px; resize: vertical; }
label { display: block; font-weight: 600; font-size: 13px; margin: 10px 0 4px; color: #222; }
label small { font-weight: 400; color: var(--muted); }
.row { display: flex; gap: 10px; } .row > * { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .right { text-align: right; } .center { text-align: center; }
.mt { margin-top: 12px; } .mb { margin-bottom: 12px; }
.hide { display: none !important; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap); padding: 10px 18px; border-radius: var(--r); border: 1px solid transparent; font-weight: 600; background: var(--steel); color: #fff; text-decoration: none; white-space: nowrap; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--red); } .btn.primary:hover { background: var(--red-dark); }
.btn.ghost { background: #fff; color: var(--text); border-color: #B8BCC4; }
.btn.green { background: var(--green); } .btn.amber { background: var(--amber); } .btn.blue { background: var(--blue); }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }

/* cards & lists */
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 14px; margin-bottom: 10px; }
.card h3 { margin-bottom: 8px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-weight: 500; }
.ticket { position: relative; padding-left: 20px; overflow: hidden; }
.ticket::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 8px; background: var(--muted); }
.ticket.s-New::before, .ticket.s-Assigned::before { background: var(--steel); }
.ticket.s-Travelling::before, .ticket.s-On.site::before { background: var(--blue); }
.ticket.s-On.hold::before, .ticket.s-Follow-up.required::before { background: var(--amber); }
.ticket.s-Completed::before, .ticket.s-Invoiced::before { background: var(--green); }
.ticket.p-Urgent::before { background: var(--red); }
.ticket .ref { font-family: 'Barlow Semi Condensed'; font-weight: 800; font-size: 22px; }
.ticket .title { font-weight: 600; font-size: 16px; }
.ticket .meta { color: var(--muted); font-size: 13px; }
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: #E3E5E9; color: #333; vertical-align: middle; }
.badge.red { background: var(--red-soft); color: var(--red-dark); } .badge.amber { background: var(--amber-soft); color: #8A5300; }
.badge.green { background: var(--green-soft); color: #0F5E2E; } .badge.blue { background: var(--blue-soft); color: #143F80; } .badge.dark { background: var(--steel); color: #fff; }
.empty { text-align: center; color: var(--muted); padding: 30px 12px; }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 4px; }

/* tables */
table.data { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; font-size: 14px; }
table.data th { text-align: left; padding: 10px 12px; background: var(--steel); color: #fff; font-weight: 600; font-size: 13px; white-space: nowrap; }
table.data td { padding: 9px 12px; border-bottom: 1px solid #ECEEF1; vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tr.clickable { cursor: pointer; } table.data tr.clickable:hover td { background: #F6F7F9; }
.table-wrap { overflow-x: auto; }

/* modal / sheet */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 720px) { .overlay { align-items: center; } }
.sheet { background: #fff; width: 100%; max-width: 640px; max-height: 94vh; overflow: auto; border-radius: 12px 12px 0 0; padding: 18px 16px 24px; }
@media (min-width: 720px) { .sheet { border-radius: 10px; } .sheet.wide { max-width: 900px; } }
.sheet h2 { margin-bottom: 8px; }
.sheet .actions { display: flex; gap: 8px; margin-top: 16px; position: sticky; bottom: -24px; background: #fff; padding: 12px 0 4px; }
.sheet .actions .btn { flex: 1; }

/* toast */
#toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--black); color: #fff; padding: 10px 16px; border-radius: 6px; font-weight: 600; z-index: 100; max-width: 92vw; opacity: 0; transition: opacity .2s; pointer-events: none; }
#toast.on { opacity: 1; } #toast.err { background: var(--red); } #toast.ok { background: var(--green); }
.spinner { width: 22px; height: 22px; border: 3px solid #ccc; border-top-color: var(--red); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } .btn:active { transform: none; } }

/* login */
.login-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; background: var(--steel); }
.login-card { background: #fff; width: 100%; max-width: 420px; padding: 24px; border-radius: 10px; border-top: 8px solid var(--red); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand .mark { font-family: 'Barlow Semi Condensed'; font-weight: 800; font-size: 26px; color: var(--red); letter-spacing: -.02em; }
.brand .mark span { color: var(--black); }
.brand .sub { font-size: 13px; color: var(--muted); font-weight: 500; }
.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.pinpad button { min-height: 60px; font-size: 24px; font-weight: 600; border-radius: 8px; border: 1px solid #B8BCC4; background: #fff; }
.pinpad button:active { background: var(--red-soft); }
.pin-dots { display: flex; gap: 12px; justify-content: center; margin: 14px 0 4px; height: 20px; }
.pin-dots span { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--steel); }
.pin-dots span.on { background: var(--red); border-color: var(--red); }
.engineer-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.engineer-pick button { min-height: 56px; border: 1px solid #B8BCC4; background: #fff; border-radius: 8px; font-weight: 600; }
.engineer-pick button.on { border-color: var(--red); background: var(--red-soft); }

/* engineer shell */
.app-top { background: var(--black); color: #fff; padding: 10px 14px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 20; }
.app-top .mark { font-family: 'Barlow Semi Condensed'; font-weight: 800; font-size: 20px; color: var(--red); } .app-top .mark span { color: #fff; }
.app-top .who { font-size: 13px; color: #C7CBD3; }
.app-top .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--green); display: inline-block; margin-right: 6px; }
.app-top .dot.off { background: var(--amber); }
.app-main { padding: 12px 12px 90px; max-width: 760px; margin: 0 auto; }
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--line); display: flex; z-index: 30; padding-bottom: env(safe-area-inset-bottom); }
.tabbar button { flex: 1; border: 0; background: none; padding: 8px 4px 10px; font-size: 12px; font-weight: 600; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 56px; }
.tabbar button svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 2; }
.tabbar button.on { color: var(--red); }
.tabbar button .cnt { position: absolute; margin-left: 26px; margin-top: -4px; background: var(--red); color: #fff; font-size: 10px; border-radius: 999px; padding: 1px 5px; }
.status-strip { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.status-strip button { flex: 1; min-width: 96px; }
.timer { font-family: 'Barlow Semi Condensed'; font-size: 32px; font-weight: 800; }
.seg { display: flex; border: 1px solid #B8BCC4; border-radius: var(--r); overflow: hidden; }
.seg button { flex: 1; border: 0; background: #fff; padding: 10px; font-weight: 600; min-height: 44px; }
.seg button.on { background: var(--steel); color: #fff; }
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.photo-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 4px; }
.sig-pad { border: 2px dashed #B8BCC4; border-radius: var(--r); background: #fff; touch-action: none; width: 100%; height: 160px; }
.check { display: flex; align-items: center; gap: 10px; padding: 8px 0; font-weight: 500; }
.check input { width: 22px; height: 22px; min-height: 0; margin: 0; }
.scanbox { position: relative; background: #000; border-radius: var(--r); overflow: hidden; min-height: 240px; }
.scanbox video { width: 100%; display: block; }
.list-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid #ECEEF1; }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.qty { display: flex; align-items: center; gap: 4px; }
.qty button { width: 38px; height: 38px; border: 1px solid #B8BCC4; background: #fff; border-radius: 6px; font-size: 18px; }
.qty input { width: 52px; text-align: center; min-height: 38px; padding: 4px; }
.timeline { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.timeline li { padding: 6px 0 6px 14px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ''; position: absolute; left: -5px; top: 11px; width: 8px; height: 8px; border-radius: 50%; background: var(--red); }

/* admin shell */
.admin { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--black); color: #fff; padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow: auto; }
.side .brand .mark span { color: #fff; } .side .brand .sub { color: #9AA0AA; }
.side nav { margin-top: 18px; display: flex; flex-direction: column; gap: 2px; }
.side nav button { text-align: left; background: none; border: 0; color: #C7CBD3; padding: 10px 12px; border-radius: 6px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.side nav button.on { background: var(--red); color: #fff; } .side nav button:hover:not(.on) { background: var(--steel); color: #fff; }
.side .foot { margin-top: auto; padding-top: 20px; font-size: 13px; color: #9AA0AA; }
.main { padding: 22px 26px 60px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .tools { display: flex; gap: 8px; flex-wrap: wrap; }
.page-head .tools input, .page-head .tools select { width: auto; min-width: 160px; min-height: 40px; padding: 6px 10px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { background: #fff; border-radius: var(--r); box-shadow: var(--shadow); padding: 12px 14px; border-left: 5px solid var(--steel); }
.stat .n { font-family: 'Barlow Semi Condensed'; font-size: 30px; font-weight: 800; line-height: 1; }
.stat .l { color: var(--muted); font-size: 13px; margin-top: 4px; }
.stat.red { border-color: var(--red); } .stat.amber { border-color: var(--amber); } .stat.green { border-color: var(--green); } .stat.blue { border-color: var(--blue); }
.board { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.board .col { background: #DFE2E7; border-radius: var(--r); padding: 8px; min-height: 200px; }
.board .col h3 { padding: 2px 6px 8px; font-size: 14px; display: flex; justify-content: space-between; }
.board .ticket { padding: 8px 8px 8px 16px; margin-bottom: 8px; cursor: pointer; }
.board .ticket .ref { font-size: 17px; }
#map { height: 420px; border-radius: var(--r); box-shadow: var(--shadow); }
.day-grid { display: grid; grid-template-columns: 120px repeat(2, 1fr); gap: 6px; align-items: start; }
.day-grid .eng { font-weight: 700; padding-top: 10px; }
.day-grid .slot { background: #fff; border-radius: var(--r); min-height: 64px; padding: 6px; box-shadow: var(--shadow); }
.day-grid .slot .ticket { padding: 6px 6px 6px 14px; margin-bottom: 6px; cursor: pointer; } .day-grid .slot .ref { font-size: 15px; }
.day-grid .slot.drop { outline: 2px dashed var(--red); }
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 14px; }
.tabs button { border: 0; background: none; padding: 10px 14px; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -2px; }
.tabs button.on { color: var(--red); border-bottom-color: var(--red); }
.menu-toggle { display: none; }
@media (max-width: 860px) {
  .admin { grid-template-columns: 1fr; }
  .side { position: fixed; left: -260px; width: 240px; transition: left .2s; z-index: 40; } .side.open { left: 0; }
  .menu-toggle { display: inline-flex; }
  .main { padding: 14px; }
  .grid3 { grid-template-columns: 1fr; }
}
@media (max-width: 600px) { .grid2 { grid-template-columns: 1fr; } .row { flex-direction: column; } }
@media print { body * { visibility: hidden; } #print-area, #print-area * { visibility: visible; } #print-area { position: absolute; left: 0; top: 0; width: 100%; } }
