:root {
  --navy: #003142;
  --navy-2: #004a64;
  --blue: #0147ff;
  --ink: #292929;
  --muted: #5c6770;
  --paper: #eef2f5;
  --line: #d5dee4;
  --low: #9a3412;
  --low-bg: #fff4ed;
  --ok: #166534;
  --ok-bg: #ecfdf3;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif; color: var(--ink); background: var(--paper); }
.app { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }
aside {
  background: var(--navy);
  color: white;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}
.brand { padding: 2px 2px 16px; text-align: center; }
.brand img {
  width: 100%;
  height: auto;
  display: block;
}
.phone-logo { display: none; }
.short-label { display: none; }
.brand p {
  margin: 8px 0 0;
  color: #fff;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1.3;
}
nav { display: grid; gap: 4px; }
.nav {
  text-align: left; border: 0; background: transparent; color: #d5e2e8;
  border-radius: 8px; padding: 10px 12px; font-weight: 650; cursor: pointer; font-size: 0.95rem;
}
.nav.is-on, .nav:hover { background: #0b4558; color: white; }
.side-note { margin-top: auto; padding: 12px; color: #9eb4be; font-size: 0.82rem; line-height: 1.45; }
.side-note a { color: white; }
.workspace { min-width: 0; }
.top {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 16px;
  padding: 18px 24px; background: white; border-bottom: 1px solid var(--line);
}
.crumb { margin: 0; color: var(--muted); font-size: 0.78rem; letter-spacing: 0.04em; text-transform: uppercase; }
h1 { margin: 2px 0 0; font-size: 1.45rem; color: var(--navy); }
.search { display: flex; gap: 8px; min-width: 320px; }
.search input, .filter {
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 0.95rem;
}
.search input { width: 280px; }
.search button, .qty button {
  border: 0; border-radius: 8px; background: var(--blue); color: white; font-weight: 700; cursor: pointer;
}
.search button { padding: 0 16px; }
#view { padding: 20px 24px 40px; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi, .panel { background: white; border: 1px solid var(--line); border-radius: 12px; }
.kpi { padding: 14px 16px; }
.kpi span { display: block; color: var(--muted); font-size: 0.78rem; letter-spacing: 0.04em; text-transform: uppercase; }
.kpi strong { display: block; margin-top: 6px; font-size: 1.45rem; color: var(--navy); }
.kpi em { font-style: normal; color: var(--low); font-weight: 700; }
.split { display: grid; grid-template-columns: 1.3fr 0.7fr; gap: 12px; }
.panel h2 { margin: 0; padding: 14px 16px 0; font-size: 1rem; color: var(--navy); }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.toolbar-actions { display: flex; align-items: center; gap: 8px; }
.toolbar p { margin: 0; color: var(--muted); }
.add {
  border: 0; border-radius: 8px; background: var(--blue); color: white;
  font-weight: 700; cursor: pointer; padding: 8px 14px;
}
.customer-form[hidden], .part-edit[hidden] { display: none; }
.customer-form, .part-edit { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; max-width: 720px; }
.customer-form h2, .part-edit h2 { margin: 0; }
.customer-form .wide, .part-edit .wide { grid-column: 1 / -1; }
.customer-form label, .part-edit label { display: grid; gap: 4px; color: var(--muted); font-size: 0.82rem; }
.customer-form input, .customer-form textarea, .customer-form select, .part-edit input, .part-edit textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
  font: inherit; font-size: 0.95rem; color: var(--ink); resize: vertical; background: white;
}
.picture-preview { width: 160px; height: 160px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.form-actions { display: flex; gap: 8px; }
.form-error { margin: 0; color: var(--low); font-weight: 700; }
.contact-card { margin-bottom: 12px; }
.contact-card h2 { margin: 0; padding: 0; }
.contact-card .facts { margin-top: 12px; }
.contact-card .facts dd { white-space: pre-line; }
.contact-card a { color: var(--blue); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--navy-2); font-size: 0.75rem; letter-spacing: 0.04em; text-transform: uppercase; }
tr.low td { background: var(--low-bg); }
.pill { display: inline-block; border-radius: 999px; padding: 2px 8px; font-size: 0.78rem; font-weight: 700; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.low { background: #ffedd5; color: var(--low); }
.pill.open { background: #e8efff; color: var(--blue); }
tr[data-oem], tr[data-customer] { cursor: pointer; }
tr[data-oem]:hover td, tr[data-customer]:hover td { background: #f4f8fb; }
tr.low[data-oem]:hover td { background: #ffeadc; }
.pick, .text-btn { color: var(--blue); }
.text-btn {
  border: 0; background: none; padding: 0; font: inherit; font-weight: 700;
  cursor: pointer; text-align: left;
}
.back {
  border: 1px solid var(--line); background: white; color: var(--navy);
  border-radius: 8px; padding: 8px 12px; font-weight: 700; cursor: pointer;
}
.order { margin-bottom: 12px; }
.order-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding-right: 16px; }
.order-head h2 { padding-bottom: 0; }
.panel.order .order-head { padding: 16px 18px 8px; align-items: center; }
.panel.order .order-head h2 { padding: 0; }
.panel.order .order-head .meta { margin: 4px 0 0; }
.order-tools { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.cross-add {
  display: grid;
  grid-template-columns: 12rem minmax(16rem, 22rem) max-content;
  gap: 8px 10px;
  align-items: end;
  padding: 0 16px 12px;
}
.cross-add label { display: grid; gap: 4px; color: var(--muted); font-size: 0.82rem; min-width: 0; }
.cross-add input, .cross-add select, .cross-add .add {
  height: 42px;
  min-height: 42px;
  box-sizing: border-box;
  margin: 0;
}
.cross-add input, .cross-add select {
  width: 100%;
  border: 1px solid var(--line); border-radius: 8px; padding: 0 12px;
  font: inherit; font-size: 16px; color: var(--ink); background: white; min-width: 0;
}
.cross-add .add { width: auto; justify-self: start; padding: 0 16px; }
.cross-add .form-error { grid-column: 1 / -1; }
.crosses .text-btn, .panel.order .text-btn {
  color: var(--blue);
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
}
.crosses .meta { margin: 0; padding: 4px 16px 10px; }
#order-form { max-width: none; }
.order-line {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 0.55fr) minmax(0, 0.7fr) auto;
  gap: 10px;
  align-items: end;
  min-width: 0;
  max-width: 100%;
}
.order-line .wide { grid-column: 1 / -1; }
.order-line select, .order-line input { min-width: 0; max-width: 100%; }
.order-lines { grid-column: 1 / -1; display: grid; gap: 12px; min-width: 0; max-width: 100%; }
.order-total { margin: 0; padding: 12px 16px 14px; text-align: right; font-weight: 700; color: var(--navy); }
.callout {
  display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: baseline;
  margin: 12px 0 0; padding: 10px 12px; background: #e8efff; border-radius: 8px;
}
.callout span { color: var(--muted); font-size: 0.75rem; letter-spacing: 0.04em; text-transform: uppercase; }
.callout strong { color: var(--navy); margin-right: 8px; }
th.num, td.num { text-align: center; vertical-align: middle; }
.on-hand-stack { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.qty { display: inline-flex; align-items: center; gap: 8px; }
.reorder-qty {
  width: 3.2rem; border: 1px solid var(--line); border-radius: 8px;
  padding: 4px 2px; font: inherit; font-weight: 700; text-align: center; color: var(--navy);
}
.qty button { width: 28px; height: 28px; padding: 0; }
.qty input {
  width: 3.2rem; border: 1px solid var(--line); border-radius: 8px;
  padding: 4px 2px; font: inherit; font-weight: 700; text-align: center; color: var(--navy);
}
.stock-line, .reorder-edit { display: inline-flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.reorder-edit { margin-left: 4px; }
.detail.no-photo { grid-template-columns: 1fr; }
.detail {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 18px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
}
.detail img {
  width: 100%;
  height: 280px;
  object-fit: cover;
  border-radius: 10px;
  background: #e7edf1;
}
.detail h2 { margin: 0 0 4px; color: var(--navy); }
.detail h3 { margin: 16px 0 0; font-size: 0.95rem; color: var(--navy); }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin: 14px 0; }
.facts div { margin: 0; }
.facts dt { color: var(--muted); font-size: 0.75rem; letter-spacing: 0.04em; text-transform: uppercase; }
.facts dd { margin: 2px 0 0; font-weight: 700; color: var(--navy); }
.card { background: white; border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; margin-bottom: 12px; }
.card h2 { margin: 0 0 4px; color: var(--navy); }
.meta { color: var(--muted); }
.customers { list-style: none; margin: 10px 0 0; padding: 0; }
.customers li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.hit { background: #e8efff; border-radius: 6px; padding: 4px 8px; }
.empty { color: var(--muted); padding: 8px 16px 16px; }
.move-up { color: var(--ok); font-weight: 700; }
.move-down { color: var(--low); font-weight: 700; }
.app[hidden], .login[hidden] { display: none !important; }
.login {
  min-height: 100vh;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 16px;
  padding: calc(24px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  background: var(--navy);
}
.login img { width: min(220px, 70vw); height: auto; }
.login form {
  width: min(420px, 100%);
  display: grid;
  gap: 10px;
  background: white;
  border-radius: 12px;
  padding: 18px;
}
.login form[hidden] { display: none !important; }
.login h1 { margin: 0; color: var(--navy); font-size: 1.35rem; }
.login .meta { margin: 0; color: var(--muted); }
.login .text-btn { justify-self: start; }
.form-ok { margin: 0; color: var(--ok); font-weight: 700; }
.login label { display: grid; gap: 4px; color: var(--muted); font-size: 0.82rem; }
.login input {
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
  font: inherit; font-size: 16px; color: var(--ink);
}
.session { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.session span { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.session button {
  border: 1px solid var(--line); background: white; color: var(--navy);
  border-radius: 8px; min-height: 40px; padding: 6px 10px; font: inherit; font-weight: 700; cursor: pointer;
}
.user-password { display: flex; gap: 8px; align-items: center; }
.user-password input { width: 9rem; border: 1px solid var(--line); border-radius: 8px; padding: 8px; font: inherit; }
.settings-form {
  display: grid;
  gap: 12px;
  max-width: 440px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 12px;
}
.settings-form h2 { margin: 0; color: var(--navy); }
.settings-form .meta { margin: 0; }
.settings-form label { display: grid; gap: 4px; color: var(--muted); font-size: 0.82rem; }
.settings-form input, .settings-form select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: white;
}
.settings-form .add { justify-self: start; min-height: 44px; padding: 8px 16px; }
#levels-form h2 { margin: 8px 0 12px; color: var(--navy); }
#levels-form .add { min-height: 44px; padding: 8px 16px; }
.level-list { display: grid; gap: 12px; max-width: 720px; margin-bottom: 12px; }
.level-list article {
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
}
.level-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.level-head h3 { margin: 0; color: var(--navy); }
.level-head .back { min-height: 36px; }
.check { display: flex; align-items: center; gap: 8px; margin: 8px 0 0; color: var(--ink); font-size: 0.95rem; }
.check input { width: 18px; height: 18px; }
.settings-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.settings-tabs button {
  border: 1px solid var(--line);
  background: white;
  color: var(--navy);
  border-radius: 999px;
  min-height: 40px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.settings-tabs button.is-on { background: var(--navy); color: white; border-color: var(--navy); }
.person-dialog {
  border: 0;
  border-radius: 14px;
  padding: 0;
  width: min(480px, calc(100vw - 24px));
  max-height: min(720px, calc(100vh - 24px));
  box-shadow: 0 18px 40px rgba(0, 20, 30, 0.28);
}
.person-dialog::backdrop { background: rgba(0, 25, 35, 0.5); }
.person-dialog .settings-form { max-width: none; margin: 0; border: 0; max-height: min(720px, calc(100vh - 24px)); overflow: auto; }
.locked-note { color: var(--low); font-weight: 700; }
.person-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.person-dialog .person-actions button {
  width: 100%;
  min-height: 36px;
  margin: 0;
  padding: 6px 12px;
  border-radius: 8px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.row-actions button {
  width: 84px;
  min-height: 34px;
  padding: 4px 8px;
  border-radius: 8px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}
.lock-btn { background: #fff4ed; color: var(--low); border: 2px solid #ea580c; }
.delete-btn { background: #dc2626; color: white; border: 2px solid #dc2626; }
#levels-form .meta { max-width: 720px; }
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .search { min-width: 0; }
  .panel { overflow-x: auto; }
}

@media (max-width: 980px) {
  .app {
    display: block;
    min-height: 100vh;
    padding-bottom: calc(62px + env(safe-area-inset-bottom));
  }
  aside {
    display: block;
    background: transparent;
    padding: 0;
    min-height: 0;
  }
  .brand, .side-note { display: none; }
  nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0;
    background: var(--navy);
    padding: 4px 2px calc(4px + env(safe-area-inset-bottom));
    border-top: 1px solid #0b4558;
  }
  .nav {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 44px;
    padding: 6px 2px;
    font-size: 0.68rem;
    line-height: 1.15;
    border-radius: 8px;
  }
  .wide-label { display: none; }
  .short-label { display: inline; }
  .nav.is-on { background: #0b4558; color: white; }
  .top {
    position: sticky;
    top: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 10px 12px;
    background: var(--navy);
    border-bottom: 0;
    padding: calc(10px + env(safe-area-inset-top)) 14px 12px;
  }
  .phone-logo { display: block; width: 92px; height: auto; }
  .titles { min-width: 0; }
  .crumb { display: none; }
  h1 { color: white; font-size: 1.15rem; }
  .session {
    grid-column: 1 / -1;
    margin-left: 0;
    justify-content: flex-start;
    flex-wrap: wrap;
  }
  .session span { color: #d5e2e8; width: 100%; }
  .session button { flex: 1; background: #0b4558; color: white; border-color: transparent; min-height: 44px; }
  .search {
    grid-column: 1 / -1;
    display: flex;
    min-width: 0;
    width: 100%;
  }
  .search input, .filter, .customer-form input, .customer-form textarea, .customer-form select, .part-edit input, .part-edit textarea, .reorder-qty {
    font-size: 16px;
  }
  .search input { width: 100%; min-width: 0; background: white; }
  .search button { min-width: 64px; min-height: 44px; }
  #view { padding: 14px 14px 28px; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi { padding: 12px; }
  .kpi strong { font-size: 1.2rem; }
  .split, .detail, .facts, .customer-form, .part-edit { grid-template-columns: 1fr; }
  .detail { padding: 12px; }
  .detail img { height: 200px; }
  .toolbar, .toolbar-actions, .order-head { flex-direction: column; align-items: stretch; }
  .toolbar-actions .add, .toolbar-actions .filter, .form-actions .add, .form-actions .back { width: 100%; min-height: 44px; }
  .row-actions { width: 100%; }
  .row-actions button { flex: 1; width: auto; }
  .back { min-height: 44px; }
  .panel { background: transparent; border: 0; overflow: visible; }
  .panel h2 { padding: 0 0 8px; }
  .panel.order, .contact-card, .crosses {
    background: white;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px;
  }
  .panel.order h2, .contact-card h2, .crosses h2 { padding: 0; }
  .crosses .meta { padding: 0 0 8px; }
  .panel.order .order-head { padding: 2px 2px 8px; align-items: flex-start; }
  .order-line { grid-template-columns: 1fr; }
  .cross-add { grid-template-columns: 1fr; padding: 0 0 8px; }
  .cross-add input, .cross-add select, .cross-add .add { width: 100%; }
  table, tbody { display: block; }
  thead { display: none; }
  tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 12px;
    background: white;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 10px;
  }
  tr.low { background: var(--low-bg); }
  th, td { display: block; border: 0; padding: 0; text-align: left; }
  td.num { text-align: left; }
  td[data-label]::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 2px;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }
  td.cell-title, td.cell-wide { grid-column: 1 / -1; }
  td.cell-title::before { display: none; }
  .on-hand-stack, .qty { align-items: flex-start; }
  .qty button { width: 44px; height: 44px; font-size: 1.2rem; }
  .panel.order table, .panel.order tbody { display: block; }
  .panel.order tr {
    margin-bottom: 0;
    border: 0;
    border-top: 1px solid var(--line);
    border-radius: 0;
    padding: 12px 0;
    background: transparent;
  }
  .order-total { text-align: left; padding: 8px 0 0; }
  .customers li { flex-wrap: wrap; }
  .picture-preview { width: 120px; height: 120px; }
}
