/* BSK Inventory — Binkley Striping of Knoxville brand system
   Asphalt Black #0E0E0D · Safety Yellow #F5C400 · Knox Orange #E86618 (rare accent)
   Concrete #F4F2EC · White. Oswald condensed headlines, Inter body. */

:root {
  --bg: #F4F2EC;           /* Concrete */
  --card: #ffffff;
  --ink: #0E0E0D;
  --muted: #6d6b64;
  --line: #e5e2d9;
  --brand: #F5C400;        /* Safety Yellow */
  --brand-ink: #0E0E0D;
  --dark: #0E0E0D;         /* Asphalt Black */
  --knox: #E86618;         /* Knox Orange — small local accent only */
  --ok: #1a7f37;
  --ok-bg: #e4f3e9;
  --warn: #b45309;
  --warn-bg: #fdf0e0;
  --bad: #b3261e;
  --bad-bg: #fbe9e7;
  --info-bg: #eef1ff;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(14, 14, 13, 0.08), 0 4px 14px rgba(14, 14, 13, 0.06);
  --head: 'Oswald', 'Arial Narrow', 'Helvetica Neue', sans-serif;
  --body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--body);
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }

/* ---------- header ---------- */
.app-header {
  background: var(--dark);
  color: #fff;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 0;
  position: sticky;
  top: 0;
  z-index: 40;
}
.app-header .brand-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  max-width: 960px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; padding: 6px 0 10px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; background: var(--brand);
  display: grid; place-items: center; flex: none;
}
.brand-mark svg { display: block; }
.brand-name {
  font-family: var(--head); font-weight: 700; font-style: italic;
  font-size: 19px; letter-spacing: 0.5px; text-transform: uppercase;
}
.brand-sub {
  font-size: 9.5px; color: var(--knox); margin-top: -2px;
  font-weight: 700; letter-spacing: 2.5px;
}
.header-links { display: flex; gap: 6px; }
.header-links a {
  color: #d9d9de; text-decoration: none; font-size: 13px; font-weight: 600;
  padding: 8px 10px; border-radius: 8px;
}
.header-links a:hover { background: rgba(255,255,255,0.08); }
.stripe-line {
  height: 7px;
  background:
    linear-gradient(var(--knox), var(--knox)) bottom/100% 2px no-repeat,
    repeating-linear-gradient(90deg, var(--brand) 0 34px, transparent 34px 58px) top/100% 4px no-repeat,
    var(--dark);
}

/* ---------- layout ---------- */
main#view {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 14px calc(96px + env(safe-area-inset-bottom, 0px));
}
.page-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 14px; flex-wrap: wrap; }
.page-title h1 {
  font-size: 26px; margin: 0; font-weight: 600;
  font-family: var(--head); text-transform: uppercase; letter-spacing: 0.6px;
}
.page-title .sub { color: var(--muted); font-size: 14px; width: 100%; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card h2 { margin: 0 0 10px; font-size: 17px; font-weight: 600; font-family: var(--head); letter-spacing: 0.4px; text-transform: uppercase; }
.card h3 { margin: 14px 0 6px; font-size: 14px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.card .card-link { text-decoration: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err-card { border-left: 4px solid var(--bad); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- KPIs ---------- */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; text-decoration: none; }
.kpi .kpi-num { font-size: 27px; font-weight: 600; line-height: 1.1; font-family: var(--head); }
.kpi .kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi.kpi-warn .kpi-num { color: var(--warn); }
.kpi.kpi-bad .kpi-num { color: var(--bad); }
.kpi.kpi-ok .kpi-num { color: var(--ok); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: 12px; cursor: pointer;
  padding: 12px 18px; font-weight: 700; font-size: 15px;
  min-height: 46px;
  text-decoration: none;
  transition: transform 0.05s ease, filter 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-dark { background: var(--dark); color: #fff; }
.btn-ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-sm { padding: 8px 12px; min-height: 36px; font-size: 13px; border-radius: 9px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.btn-row.left { justify-content: flex-start; }

/* ---------- forms ---------- */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 5px; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; border: 1.5px solid var(--line); border-radius: 10px;
  padding: 11px 12px; background: #fff; min-height: 46px;
}
.input:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
textarea.input { min-height: 130px; resize: vertical; }
.input-sm { min-height: 38px; padding: 7px 10px; width: 90px; text-align: center; }

.seg { display: inline-flex; background: #e9e9e4; border-radius: 11px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button {
  border: none; background: transparent; border-radius: 9px; padding: 9px 14px;
  font-weight: 700; font-size: 14px; cursor: pointer; color: var(--muted); min-height: 40px;
}
.seg button.active { background: var(--dark); color: #fff; }
.seg.seg-brand button.active { background: var(--brand); color: var(--brand-ink); }

/* ---------- chips & badges ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 700; border-radius: 999px; padding: 4px 10px;
  background: #ecece6; color: var(--muted);
}
.chip-status-planned { background: var(--info-bg); color: #3546a8; }
.chip-status-packing { background: var(--warn-bg); color: var(--warn); }
.chip-status-out { background: #e3e6ff; color: #4338ca; }
.chip-status-returning { background: var(--warn-bg); color: var(--warn); }
.chip-status-closed { background: var(--ok-bg); color: var(--ok); }
.chip-learned { background: #e8f0fe; color: #1a56db; }
.chip-low { background: var(--bad-bg); color: var(--bad); }
.chip-type { background: #ececed; color: var(--ink); }

/* ---------- lists / rows ---------- */
.list { display: flex; flex-direction: column; }
.list-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 2px;
  border-bottom: 1px solid var(--line); text-decoration: none;
}
.list-row:last-child { border-bottom: none; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .title { font-weight: 700; }
.list-row .sub { font-size: 13px; color: var(--muted); }
.list-row .num { font-weight: 800; font-size: 17px; white-space: nowrap; }

/* pack checklist rows */
.check-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 10px;
  border-radius: 12px; border: 1.5px solid var(--line); margin-bottom: 8px;
  background: #fff;
}
.check-row .ck {
  width: 34px; height: 34px; border-radius: 999px; flex: none;
  display: grid; place-items: center; font-size: 17px; font-weight: 900;
  background: #eee; color: #aaa; border: 2px solid var(--line);
}
.check-row.done { border-color: var(--ok); background: var(--ok-bg); }
.check-row.done .ck { background: var(--ok); border-color: var(--ok); color: #fff; }
.check-row.partial { border-color: var(--warn); background: #fffaf2; }
.check-row.partial .ck { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); }
.check-row.over { border-color: #1a56db; }
.check-row .grow { flex: 1; min-width: 0; }
.check-row .iname { font-weight: 700; }
.check-row .isub { font-size: 12.5px; color: var(--muted); }
.check-row .count { font-weight: 800; font-size: 18px; white-space: nowrap; }
.check-row .count .of { color: var(--muted); font-weight: 600; font-size: 13px; }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); padding: 8px 8px; border-bottom: 2px solid var(--line); white-space: nowrap; }
.tbl td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl .r { text-align: right; }
.tbl .num { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  background: var(--dark);
  display: flex; justify-content: space-around; align-items: stretch;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -2px 12px rgba(0,0,0,0.18);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: #9a9aa2; text-decoration: none; font-size: 10.5px; font-weight: 700;
  padding: 6px 2px; border-radius: 10px; max-width: 96px;
}
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.active { color: var(--brand); }
.tabbar a.tab-scan {
  background: var(--brand); color: var(--brand-ink);
  border-radius: 16px; margin: -14px 4px 0; padding: 10px 2px 6px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.25);
}
.tabbar a.tab-scan.active { color: var(--brand-ink); }

/* ---------- toasts ---------- */
#toasts { position: fixed; top: calc(env(safe-area-inset-top, 0px) + 64px); left: 0; right: 0; z-index: 200; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: var(--dark); color: #fff; font-weight: 600; font-size: 14px;
  padding: 11px 18px; border-radius: 12px; box-shadow: var(--shadow);
  opacity: 0; transform: translateY(-8px); transition: all 0.25s ease;
  max-width: 92vw;
}
.toast.show { opacity: 1; transform: none; }
.toast-ok { background: var(--ok); }
.toast-err { background: var(--bad); }
.toast-warn { background: var(--warn); }

/* ---------- modals ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,15,18,0.55); z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 640px) { .modal-overlay { align-items: center; } }
.modal {
  background: var(--card); width: 100%; max-width: 560px; max-height: 88vh; overflow: auto;
  border-radius: 18px 18px 0 0; padding: 16px;
}
@media (min-width: 640px) { .modal { border-radius: 18px; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.modal-title { font-weight: 800; font-size: 17px; }
.modal-x { border: none; background: #ececec; border-radius: 999px; width: 34px; height: 34px; cursor: pointer; font-size: 15px; }
.confirm-msg { font-size: 15px; }

/* ---------- camera scanner ---------- */
.modal-scan { padding: 14px; }
#cam-reader { border-radius: 12px; overflow: hidden; background: #000; min-height: 220px; }
#cam-reader video { border-radius: 12px; }
.cam-hint { text-align: center; font-size: 13px; color: var(--muted); margin-top: 8px; }
.cam-last { text-align: center; font-weight: 700; min-height: 22px; margin-top: 4px; }
.cam-err { color: #fff; padding: 24px 16px; text-align: center; font-size: 14px; }
.manual-row { display: flex; gap: 8px; margin-top: 10px; }
.manual-row .input { flex: 1; }

/* ---------- misc ---------- */
.page-loading { display: grid; place-items: center; padding: 70px 0; }
.road-spinner {
  width: 60px; height: 8px; border-radius: 4px;
  background: repeating-linear-gradient(90deg, var(--brand) 0 12px, #d8d8d2 12px 20px);
  animation: roadmove 0.7s linear infinite;
}
@keyframes roadmove { from { background-position: 0 0; } to { background-position: 20px 0; } }

.banner {
  border-radius: 12px; padding: 12px 14px; font-weight: 600; font-size: 14px; margin-bottom: 12px;
}
.banner-ok { background: var(--ok-bg); color: var(--ok); }
.banner-warn { background: var(--warn-bg); color: var(--warn); }
.banner-info { background: var(--info-bg); color: #3546a8; }

.searchbar { display: flex; gap: 8px; margin-bottom: 12px; }
.searchbar .input { flex: 1; }

.stock-pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: #efefe9; margin: 2px 4px 2px 0; }

.progressbar { height: 8px; border-radius: 4px; background: #e8e8e2; overflow: hidden; }
.progressbar > div { height: 100%; background: var(--brand); border-radius: 4px; transition: width 0.3s ease; }
.progressbar.done > div { background: var(--ok); }

.metric-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.metric-grid .field { margin-bottom: 0; }

.divider { height: 1px; background: var(--line); margin: 14px 0; }

.empty { text-align: center; color: var(--muted); padding: 26px 10px; font-size: 14px; }
.empty .big { font-size: 34px; display: block; margin-bottom: 6px; }

/* sign-in gate — asphalt with laid-down stripes, like the deck cover */
body.locked .app-header, body.locked .tabbar { display: none; }
body.locked {
  background:
    linear-gradient(105deg, transparent 0 68%, var(--brand) 68% 74%, transparent 74% 77%, var(--knox) 77% 79.5%, transparent 79.5%) no-repeat 0 -6vh / 100% 46vh,
    var(--dark);
}
.login-wrap { min-height: 92vh; display: flex; align-items: center; justify-content: center; padding: 20px 12px; }
.login-card { width: 100%; max-width: 400px; padding: 28px 24px; }
.login-brand { text-align: center; margin-bottom: 16px; }
.login-brand .brand-mark { display: inline-grid; background: transparent; }
.login-brand h1 {
  margin: 10px 0 0; font-size: 26px; font-family: var(--head);
  font-weight: 700; font-style: italic; text-transform: uppercase; letter-spacing: 0.8px;
}
.login-brand .of-knox { color: var(--knox); font-weight: 700; letter-spacing: 3px; font-size: 10.5px; }

/* labels printing */
.label-sheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.label-card { border: 1.5px dashed #bbb; border-radius: 8px; padding: 10px; text-align: center; background: #fff; }
.label-card .lname { font-weight: 700; font-size: 13px; margin-bottom: 4px; }
.label-card .lcode { font-size: 12px; letter-spacing: 1px; margin-top: 3px; }

/* ---------- More menu ---------- */
.menu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.menu-tile {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 14px; text-decoration: none; display: flex; flex-direction: column; gap: 6px;
  border-bottom: 3px solid transparent;
}
.menu-tile:active { border-bottom-color: var(--brand); }
.menu-tile .mt-ico { font-size: 26px; }
.menu-tile .mt-name { font-family: var(--head); font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; font-size: 14.5px; }
.menu-tile .mt-sub { font-size: 12px; color: var(--muted); }

/* ---------- time clock ---------- */
.clock-card { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.clock-state { flex: 1; min-width: 180px; }
.clock-state .cs-big { font-family: var(--head); font-weight: 600; font-size: 21px; text-transform: uppercase; letter-spacing: 0.4px; }
.clock-state .cs-sub { font-size: 13px; color: var(--muted); }
.clock-dot { display: inline-block; width: 10px; height: 10px; border-radius: 99px; background: #c2c2ba; margin-right: 6px; }
.clock-dot.on { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-bg); }
.hours-week { border-left: 4px solid var(--brand); }

/* ---------- calendar ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-head .cal-month { font-family: var(--head); font-weight: 600; font-size: 20px; text-transform: uppercase; letter-spacing: 0.6px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: 10.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; padding: 4px 0; }
.cal-day {
  min-height: 74px; background: #fff; border-radius: 8px; border: 1px solid var(--line);
  padding: 4px; font-size: 11px; overflow: hidden; cursor: pointer;
}
.cal-day.out { background: transparent; border-color: transparent; }
.cal-day.today { border: 2px solid var(--brand); }
.cal-day .cd-num { font-weight: 700; font-size: 11.5px; margin-bottom: 2px; }
.cal-day.today .cd-num { color: var(--knox); }
.cal-evt {
  display: block; background: var(--dark); color: var(--brand); border-radius: 5px;
  padding: 2px 5px; margin-bottom: 2px; font-weight: 600; font-size: 10px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-decoration: none;
}
.cal-evt.closed { background: #d8d5cc; color: #6d6b64; }
@media (max-width: 640px) { .cal-day { min-height: 58px; } }

/* ---------- estimates & invoices ---------- */
.doc-status { text-transform: uppercase; }
.doc-sheet {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 0; overflow: hidden; margin-bottom: 14px;
}
.doc-head {
  background: var(--dark); color: #fff; padding: 26px 30px 20px;
  position: relative; overflow: hidden;
}
.doc-head::after {
  content: ''; position: absolute; right: -30px; top: -40px; width: 190px; height: 240px;
  background: linear-gradient(105deg, transparent 0 52%, var(--brand) 52% 66%, transparent 66% 72%, var(--knox) 72% 78%, transparent 78%);
  transform: rotate(8deg);
}
.doc-head .dh-name { font-family: var(--head); font-style: italic; font-weight: 700; font-size: 26px; text-transform: uppercase; letter-spacing: 1px; line-height: 1.05; }
.doc-head .dh-knox { color: var(--knox); font-weight: 700; letter-spacing: 3px; font-size: 10.5px; margin-top: 2px; }
.doc-head .dh-type { font-family: var(--head); font-weight: 600; text-transform: uppercase; letter-spacing: 2px; font-size: 15px; color: var(--brand); margin-top: 16px; }
.doc-body { padding: 22px 30px 26px; }
.doc-meta { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.doc-meta .dm-block { font-size: 13.5px; }
.doc-meta .dm-label { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: 3px; }
table.doc-lines { width: 100%; border-collapse: collapse; font-size: 13.5px; margin: 6px 0 14px; }
.doc-lines th { text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.8px; padding: 8px 6px; border-bottom: 2px solid var(--dark); }
.doc-lines td { padding: 9px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.doc-lines .r { text-align: right; white-space: nowrap; }
.doc-totals { margin-left: auto; max-width: 260px; font-size: 14px; }
.doc-totals .row { display: flex; justify-content: space-between; padding: 4px 0; }
.doc-totals .grand { border-top: 2px solid var(--dark); font-family: var(--head); font-weight: 600; font-size: 19px; padding-top: 8px; margin-top: 4px; }
.doc-footer { font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); margin-top: 18px; padding-top: 12px; }
.line-editor .le-row { display: grid; grid-template-columns: 1fr 74px 96px 90px 34px; gap: 6px; margin-bottom: 6px; align-items: center; }
.line-editor .le-amount { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 14px; }
@media (max-width: 560px) { .line-editor .le-row { grid-template-columns: 1fr 58px 80px 70px 30px; } }

@media print {
  .app-header, .tabbar, .no-print, #toasts { display: none !important; }
  body { background: #fff; }
  main#view { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 1px solid #ddd; page-break-inside: avoid; }
  .label-card { page-break-inside: avoid; }
  .doc-sheet { box-shadow: none; border-radius: 0; }
  body.printing-doc #view :not(.doc-sheet):not(.doc-sheet *) { display: none !important; }
  body.printing-doc #view .doc-sheet, body.printing-doc #view .doc-sheet * { display: revert !important; }
  .doc-head::after { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .doc-head { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
