:root {
  --brand: #0f3d5e; --accent: #1f7ae0; --ok: #1a8f4a; --warn: #c97a00; --bad: #c62828;
  --bg: #f3f5f8; --card: #fff; --text: #1b2430; --muted: #6b7684; --line: #e2e6ec;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); }
h1 { font-size: 1.35rem; margin: 0 0 .5rem; word-break: break-word; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; }
h3 { font-size: 1rem; margin: 0 0 .4rem; }
p { margin: .4rem 0 .8rem; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap;
  background: var(--brand); color: #fff;
  padding: calc(.7rem + env(safe-area-inset-top)) calc(1rem + env(safe-area-inset-right)) .7rem calc(1rem + env(safe-area-inset-left));
}
.top .brand { color: #fff; text-decoration: none; font-weight: 700; }
.top .who { font-size: .85rem; opacity: .9; }
.top nav.adm { display: flex; align-items: center; gap: .9rem; flex-wrap: wrap; }
.top nav.adm a, .top nav.adm .btn.link { color: #fff; font-size: .9rem; }

.wrap { max-width: 720px; margin: 0 auto; padding: .8rem max(.8rem, env(safe-area-inset-left)) 2rem max(.8rem, env(safe-area-inset-right)); }
.card { background: var(--card); border-radius: 14px; padding: 1rem; margin-bottom: .8rem; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.stack { display: flex; flex-direction: column; gap: .7rem; margin: .5rem 0; }
.inline { display: inline; margin: 0; }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; color: var(--muted); }
input, select, textarea {
  font: inherit; font-size: 16px; /* 16px stops iOS Safari from zooming */
  width: 100%; padding: .7rem .8rem; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--text); -webkit-appearance: none; appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 2rem; }
input.pin { text-align: center; font-size: 1.6rem; letter-spacing: .5rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--text);
  border-radius: 10px; padding: .65rem 1rem; min-height: 44px;
  -webkit-appearance: none; appearance: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: #eef7f1; border-color: #bfe3cc; color: var(--ok); }
.btn.danger { color: var(--bad); border-color: #f1c6c6; }
.btn.big { min-height: 60px; font-size: 1.15rem; width: 100%; }
.btn.small { min-height: 34px; padding: .3rem .7rem; font-size: .85rem; }
.btn.link { background: none; border: none; color: var(--accent); padding: .4rem 0; min-height: 0; font-weight: 500; }
.stack > .btn:not(.link) { width: 100%; }

.flash { padding: .7rem .9rem; border-radius: 10px; margin: .5rem 0; font-weight: 500; }
.flash.error { background: #fdecec; color: var(--bad); }
.flash.ok { background: #e9f7ef; color: var(--ok); }

.order-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.badge { font-size: .75rem; text-transform: uppercase; padding: .2rem .55rem; border-radius: 999px; background: #e7eef8; color: var(--brand); font-weight: 700; }
.badge.done { background: #e9f7ef; color: var(--ok); }
.badge.cancelled { background: #fdecec; color: var(--bad); }

.segs { display: flex; gap: .4rem; margin: .6rem 0; flex-wrap: wrap; }
.seg { flex: 1 1 0; min-width: 70px; text-align: center; padding: .55rem .5rem; border-radius: 10px; border: 1px solid var(--line); text-decoration: none; color: var(--text); font-weight: 600; background: #fff; }
.seg.on { background: var(--brand); color: #fff; border-color: var(--brand); }

.legs { display: grid; grid-template-columns: 1fr; gap: .8rem; }
@media (min-width: 560px) { .legs { grid-template-columns: 1fr 1fr; } }
.tl { list-style: none; margin: 0; padding: 0; }
.tl li { display: grid; grid-template-columns: 14px 1fr; column-gap: .55rem; padding: .3rem 0; }
.tl .dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--line); margin-top: .3rem; grid-row: span 2; }
.tl li.done .dot { background: var(--ok); border-color: var(--ok); }
.tl .step { font-weight: 600; }
.tl .meta { font-size: .85rem; color: var(--muted); }
.notes, .history, .devs { list-style: none; margin: 0 0 .5rem; padding: 0; }
.notes li, .history li { padding: .4rem 0; border-bottom: 1px solid var(--line); font-size: .92rem; word-break: break-word; }
.history li.undone { text-decoration: line-through; color: var(--muted); }

.search { display: flex; gap: .5rem; margin-bottom: .6rem; }
.search input { flex: 1; min-width: 0; }
.board .row, .row { border: 1px solid var(--line); border-radius: 12px; padding: .7rem .8rem; margin-bottom: .55rem; }
.row.late { border-color: #f1c6c6; background: #fff8f8; }
.row.off { opacity: .55; }
.row-head { display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap; margin-bottom: .3rem; }
.row-head a { font-weight: 700; text-decoration: none; }
.chip { display: inline-block; font-size: .8rem; background: #eef2f7; border-radius: 8px; padding: .2rem .5rem; margin: .15rem .15rem 0 0; }
.chip.warn { background: #fff3df; color: var(--warn); }
.od { color: var(--bad); font-size: .85rem; font-weight: 600; margin-top: .3rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .4rem; }

.qr svg { width: min(260px, 70vw); height: auto; }
.code { font: 700 1.6rem/1.2 ui-monospace, Menlo, monospace; letter-spacing: .25rem; }

/* Label printing */
.labels { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; padding: 8px; }
.label { border: 1px dashed #bbb; padding: 8px; text-align: center; break-inside: avoid; }
.label svg { width: 120px; height: 120px; }
.lno { font: 700 14px ui-monospace, Menlo, monospace; }
@media print {
  .noprint { display: none; }
  body.print { background: #fff; }
  .label { border-color: #ddd; }
}

/* Desktop dashboard */
.wrap.wide { max-width: 1680px; }
.dash-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; margin: .8rem 0; }
@media (min-width: 900px) { .stats { grid-template-columns: repeat(7, 1fr); } }
.stat { display: flex; flex-direction: column; padding: .8rem 1rem; border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: var(--text); background: #fff; }
.stat .num { font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.stat .lbl { font-size: .85rem; color: var(--muted); }
.stat.good .num { color: var(--ok); }
.stat.bad { background: #fff6f6; border-color: #f1c6c6; } .stat.bad .num { color: var(--bad); }
.stat.warn { background: #fffaf0; border-color: #f3dcb0; } .stat.warn .num { color: var(--warn); }
.stat.muted .num { color: var(--muted); }
.filters { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; align-items: end; }
@media (min-width: 900px) { .filters { grid-template-columns: repeat(7, minmax(0, 1fr)) auto; } }
.filters label { font-size: .8rem; }
.filters input, .filters select { padding: .5rem .6rem; min-height: 40px; }
.filter-btns { display: flex; gap: .4rem; flex-wrap: wrap; grid-column: 1 / -1; }
@media (min-width: 900px) { .filter-btns { grid-column: auto; } }
.filter-btns .btn { min-height: 40px; padding: .45rem .8rem; white-space: nowrap; }

.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: 10px; max-height: 75vh; }
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .85rem; }
.grid th, .grid td { padding: .45rem .6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; white-space: nowrap; }
.grid thead th { position: sticky; top: 0; background: #f7f9fb; z-index: 2; font-weight: 600; color: #3a4655; }
.grid thead tr:nth-child(2) th { top: 2.1rem; }
.grid th.wh { text-align: center; background: #e9eff6; color: var(--brand); border-left: 2px solid #fff; }
.grid td b { display: block; font-weight: 600; }
.grid td span { display: block; color: var(--muted); font-size: .78rem; }
.grid td.done { background: #f3faf6; }
.grid td.late { background: #fdecec; color: var(--bad); }
.grid td.empty { color: #c3cad3; text-align: center; }
.grid td.note { white-space: normal; min-width: 200px; max-width: 320px; }
.grid tr.row-late td.sticky { box-shadow: inset 4px 0 0 var(--bad); }
.grid .sticky { position: sticky; left: 0; background: #fff; z-index: 1; }
.grid thead .sticky { z-index: 3; background: #f7f9fb; }
.grid td.sticky a { font-weight: 700; text-decoration: none; }
.grid tbody tr:hover td { filter: brightness(.98); }
.tag { display: inline-block; font-size: .72rem; font-weight: 700; padding: .1rem .45rem; border-radius: 6px; margin-left: .25rem; }
.tag.bad { background: #fdecec; color: var(--bad); }
.tag.warn { background: #fff3df; color: var(--warn); }
.small-grid td, .small-grid th { text-align: center; }
.small-grid td:first-child, .small-grid th:first-child { text-align: left; }
.filters > label { min-width: 0; }
.filters input[type="date"] { min-width: 0; display: block; }
.notes li.issue { background: #fff6f6; border-left: 3px solid var(--bad); padding-left: .6rem; }
details > summary { cursor: pointer; font-weight: 600; padding: .3rem 0; }
.codes { font: 600 1.05rem/1.9 ui-monospace, Menlo, monospace; columns: 2; list-style: none; padding: 0; }
.secret { font: 600 1rem ui-monospace, Menlo, monospace; overflow-wrap: anywhere; }
table.grid td.wrap-cell { white-space: normal; overflow-wrap: anywhere; min-width: 160px; }
.hours-row { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: .4rem .5rem; align-items: center; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.hours-row .check { grid-column: 1 / -1; flex-direction: row; align-items: center; gap: .6rem; color: var(--text); font-size: 1rem; font-weight: 600; }
.hours-row .check input { flex: 0 0 22px; width: 22px; height: 22px; margin: 0; -webkit-appearance: checkbox; appearance: auto; }
.hours-row input[type="time"] { min-width: 0; width: 100%; padding: .55rem .6rem; }
@media (min-width: 560px) { .hours-row { grid-template-columns: 9rem minmax(0, 1fr) auto minmax(0, 1fr); } .hours-row .check { grid-column: auto; } }
textarea[wrap="off"] { white-space: pre; overflow-x: auto; }

/* Office help desk */
.syncbar { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin: .4rem 0 .8rem; }
.desk-grid { display: grid; grid-template-columns: 1fr; gap: .8rem; }
@media (min-width: 900px) { .desk-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.desk-tile { display: flex; flex-direction: column; gap: .5rem; border: 1px solid var(--line); border-radius: 12px; padding: 1rem; min-width: 0; }
.desk-tile h2 { margin: 0; }
table.kv th { width: 34%; white-space: normal; background: #f7f9fb; position: static; }
details.rules { margin: .4rem 0 .8rem; }
details.rules li { margin: .25rem 0; }
.btn.sso { background: #fff; border: 1px solid #c9d1db; color: var(--text); gap: .7rem; }
.btn.sso .logo { display: grid; grid-template-columns: 9px 9px; gap: 2px; }
.btn.sso .logo i { width: 9px; height: 9px; display: block; background: #f25022; }
.btn.sso .logo i:nth-child(2) { background: #7fba00; } .btn.sso .logo i:nth-child(3) { background: #00a4ef; } .btn.sso .logo i:nth-child(4) { background: #ffb900; }
.btn.sso .g { font: 700 1.2rem/1 Arial, sans-serif; color: #4285f4; }
.stack > .btn.sso + p { margin-top: -.4rem; }
details.pwlogin { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: .6rem; }
.mono { font-family: ui-monospace, Menlo, monospace; }
.code.small-code { font-size: 1.15rem; letter-spacing: .05rem; overflow-wrap: anywhere; }
