:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-strong: #eef4fb;
  --text: #1f2937;
  --muted: #4b5b73;
  --line: #d6e2ef;
  --blue: #064ca8;
  --green: #087a55;
  --yellow: #ffc429;
  --danger: #b42318;
  --shadow: 0 14px 38px rgba(17, 38, 75, 0.1);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111614;
  --surface: #1a211e;
  --surface-strong: #22342c;
  --text: #eef7f2;
  --muted: #a5b5ae;
  --line: #33433d;
  --blue: #8db2ff;
  --green: #32c083;
  --yellow: #ffc429;
  --danger: #ff9c93;
  --shadow: 0 16px 42px rgba(0, 0, 0, 0.32);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

.companion-app {
  min-height: 100vh;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 14px calc(28px + env(safe-area-inset-bottom, 0px));
}

.companion-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 78px;
  border-radius: 18px;
  background: var(--blue);
  color: #ffffff;
  padding: 14px;
  box-shadow: var(--shadow);
}

.companion-header img {
  width: 58px;
  height: 58px;
  border-radius: 16px;
  background: #ffffff;
  padding: 8px;
}

.companion-header p,
.companion-header h1,
.module-head p,
.module-head h2,
.section-row h3,
.form-message {
  margin: 0;
}

.companion-header p {
  color: var(--yellow);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.companion-header h1 {
  font-size: 28px;
  line-height: 1;
}

.home-view,
.module-view {
  margin-top: 14px;
}

.quick-grid {
  display: grid;
  gap: 12px;
}

.module-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  min-height: 82px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  padding: 16px;
  box-shadow: var(--shadow);
  text-align: left;
}

.module-button span {
  font-weight: 900;
}

.module-button strong {
  color: var(--blue);
  font-size: 24px;
}

.module-button.active {
  border-color: color-mix(in srgb, var(--green) 42%, var(--line));
}

.module-button.soon {
  opacity: 0.72;
}

.module-view[hidden],
.home-view[hidden],
[hidden] {
  display: none !important;
}

.module-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.module-head h2 {
  color: var(--blue);
  font-size: 24px;
}

.module-head p {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.back-button,
.primary-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 14px;
  font-weight: 900;
}

.back-button {
  background: var(--surface);
  color: var(--text);
}

.primary-button {
  width: 100%;
  border-color: var(--green);
  background: var(--green);
  color: #ffffff;
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.ageing-strip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(138px, 42vw);
  gap: 10px;
  margin-bottom: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.ageing-card,
.check-form,
.records-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.ageing-card {
  display: grid;
  gap: 6px;
  min-height: 86px;
  padding: 12px;
}

.ageing-card span,
.ageing-card small,
.check-form label span,
.section-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.ageing-card strong {
  color: var(--blue);
  font-size: 20px;
}

.check-form {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.check-form label {
  display: grid;
  gap: 6px;
}

.check-form input,
.check-form select {
  min-height: 44px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
}

.photo-drop {
  position: relative;
  min-height: 96px;
  align-content: center;
  border: 1px dashed color-mix(in srgb, var(--blue) 45%, var(--line));
  border-radius: 14px;
  background: var(--surface-strong);
  color: var(--blue);
  padding: 14px;
  text-align: center;
}

.photo-drop input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.photo-drop.has-file {
  border-style: solid;
  border-color: var(--green);
  color: var(--green);
}

.photo-drop strong {
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.payee-field {
  position: relative;
}

.payee-results {
  position: absolute;
  z-index: 10;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  display: grid;
  max-height: 240px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.payee-results button {
  min-height: 42px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  padding: 0 12px;
  text-align: left;
}

.form-message {
  min-height: 18px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.form-message.error {
  color: var(--danger);
}

.records-card {
  margin-top: 12px;
  padding: 14px;
}

.section-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.section-row h3 {
  color: var(--blue);
  font-size: 17px;
}

.record-list {
  display: grid;
  gap: 10px;
}

.record-item {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-strong);
  padding: 12px;
}

.record-item strong {
  color: var(--text);
}

.record-item span,
.record-item small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.record-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.clear-check-button {
  min-height: 40px;
  width: 100%;
  border: 1px solid var(--green);
  border-radius: 12px;
  background: color-mix(in srgb, var(--green) 12%, var(--surface));
  color: var(--green);
  font-weight: 900;
}

@media (min-width: 720px) {
  .companion-app {
    width: min(760px, 100%);
    margin: 0 auto;
  }

  .quick-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .check-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .primary-button,
  .form-message,
  .payee-field,
  #manualPayeeField {
    grid-column: span 2;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

nav.quick-grid {
  margin-top: 14px;
}

.inventory-view {
  margin-top: 22px;
}

.inventory-view .section-row {
  align-items: end;
}

.inventory-view h2,
.inventory-view p {
  margin: 0;
}

.inventory-view h2 {
  color: var(--blue);
  font-size: 24px;
}

#inventoryStatus {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.search-box input,
.scan-button,
.scanner-panel button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 13px;
  font: inherit;
  font-weight: 800;
}

.search-box input {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  padding: 0 14px;
  font-weight: 600;
}

.scan-button {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
  padding: 0 17px;
}

.scanner-panel {
  position: relative;
  overflow: hidden;
  margin: 8px 0 12px;
  border-radius: 16px;
  background: #050505;
}

.scanner-panel video {
  display: block;
  width: 100%;
  min-height: 250px;
  max-height: 55vh;
  object-fit: cover;
}

.scan-guide {
  position: absolute;
  inset: 24% 12%;
  border: 3px solid var(--yellow);
  border-radius: 14px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, .28);
}

.scanner-panel button {
  position: absolute;
  right: 12px;
  bottom: 12px;
  border-color: #fff;
  background: rgba(0, 0, 0, .7);
  color: #fff;
  padding: 0 14px;
}

.inventory-table-wrap {
  overflow-x: auto;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.inventory-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 13px;
}

.inventory-table th,
.inventory-table td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  vertical-align: top;
}

.inventory-table th {
  position: sticky;
  top: 0;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  white-space: nowrap;
}

.inventory-table td:nth-child(3),
.inventory-table td:nth-child(4),
.inventory-table td:nth-child(5) {
  white-space: nowrap;
}

.inventory-table tbody tr:last-child td {
  border-bottom: 0;
}

@media (max-width: 520px) {
  .companion-header {
    min-height: 68px;
  }

  .companion-header img {
    width: 48px;
    height: 48px;
  }

  .companion-header h1 {
    font-size: 24px;
  }

  .module-button {
    min-height: 62px;
  }
}
