:root {
  --navy: #0f3d5e;
  --blue: #1769aa;
  --blue-dark: #0b4f84;
  --green: #1d7a46;
  --red: #b42318;
  --bg: #f4f7fa;
  --card: #ffffff;
  --border: #d7e0e8;
  --text: #16212b;
  --muted: #61707d;
  --shadow: 0 12px 30px rgba(15, 61, 94, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.app-shell {
  width: min(100% - 32px, 960px);
  margin: 0 auto;
  padding: 24px 0 48px;
}

/* Header */

.app-header {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 180px;
  align-items: center;
  gap: 20px;
  width: 100%;
  margin-bottom: 44px;
}

.brand {
  display: contents;
}

.company-logo {
  grid-column: 1;
  justify-self: start;
  display: block;
  width: 260px;
  height: 115px;
  object-fit: contain;
  object-position: left center;
}

.brand-title {
  grid-column: 2;
  min-width: 0;
  text-align: center;
}

.app-title {
  margin: 0;
  color: var(--blue);
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1.2;
  white-space: nowrap;
}

.user-actions {
  grid-column: 3;
  justify-self: end;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: right;
}

#userName {
  max-width: 180px;
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Shared components */

.card {
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.auth-card {
  width: min(100%, 440px);
  margin: 48px auto;
}

.auth-card p,
.search-result small,
.transaction-item small {
  color: var(--muted);
}

form {
  display: grid;
  gap: 16px;
  margin-top: 20px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  outline: 3px solid rgba(23, 105, 170, 0.14);
}

.button {
  border: 0;
  border-radius: 10px;
  padding: 12px 16px;
  font-weight: 800;
}

.button-primary {
  background: var(--blue);
  color: #fff;
}

.button-primary:hover {
  background: var(--blue-dark);
}

.button-secondary {
  background: #e7eef5;
  color: var(--navy);
}

.button-danger {
  background: var(--red);
  color: #fff;
}

.hidden {
  display: none !important;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.09em;
}

/* Login and actions */

.action-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.action-card {
  display: grid;
  gap: 8px;
  min-height: 150px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow);
  text-align: left;
}

.action-card:hover {
  border-color: var(--blue);
  transform: translateY(-2px);
}

.action-card span:not(.action-icon) {
  font-size: 1.1rem;
  font-weight: 800;
}

.action-card small {
  color: var(--muted);
  line-height: 1.35;
}

.action-icon {
  font-size: 2rem;
}

/* Operations */

#operationView {
  margin-top: 24px;
}

.section-heading,
.search-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.search-row {
  margin: 24px 0 16px;
}

.search-row input {
  flex: 1;
}

.search-results {
  display: grid;
  gap: 8px;
}

.search-result {
  width: 100%;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  text-align: left;
}

.search-result:hover {
  border-color: var(--blue);
}

.search-result strong,
.search-result small {
  display: block;
}

.search-result small {
  margin-top: 4px;
}

/* Product card */

.product-card {
  margin-top: 18px;
  padding: 18px;
  border: 1px solid #bed8ed;
  border-radius: 12px;
  background: #edf6fd;
}

.product-card h3 {
  margin: 0 0 16px;
}

.product-details-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin: 0;
}

.product-details-grid > div {
  min-width: 0;
  padding: 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.72);
}

.product-details-grid dt {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.product-details-grid dd {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 1rem;
  font-weight: 800;
}

/* Operation form */

.operation-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.operation-form > label:last-of-type,
.operation-form > button {
  grid-column: 1 / -1;
}

/*
  Serial number takes the complete first row.
  Manufacturer model takes the complete second row.
  This prevents the Scan serial button from pushing the model field down.
*/
#operationForm #serialField,
#operationForm #manufacturerModelField {
  grid-column: 1 / -1;
}

#serialField {
  width: 100%;
}

#serialField > label {
  display: block;
  margin-bottom: 7px;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
}

.serial-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.serial-input-row input {
  min-width: 0;
  flex: 1;
}

.serial-scan-button {
  flex: 0 0 auto;
  min-width: 120px;
  white-space: nowrap;
}

/* Scanner */

#scannerContainer {
  margin: 16px 0;
}

#reader {
  width: 100%;
  max-width: 620px;
  margin: 0 auto 14px;
  overflow: hidden;
  border: 2px solid var(--blue);
  border-radius: 14px;
  background: #111;
}

#reader video {
  width: 100% !important;
  height: auto !important;
  object-fit: cover;
}

/* Messages */

.message {
  margin-bottom: 18px;
  padding: 14px;
  border-radius: 10px;
  font-weight: 700;
}

.message.success {
  border: 1px solid #a8e2bb;
  background: #dff6e7;
  color: #075d2b;
}

.message.error {
  border: 1px solid #f4bbb4;
  background: #fde7e4;
  color: #8f1b13;
}

/* History */

.transaction-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.transaction-item p {
  margin: 0;
}

.transaction-qty {
  font-weight: 800;
}

.transaction-qty.positive {
  color: var(--green);
}

.transaction-qty.negative {
  color: var(--red);
}

/* New-product flow */

.new-product-prompt {
  margin-top: 14px;
  padding: 16px;
  border: 1px dashed rgba(104, 156, 255, 0.55);
  border-radius: 14px;
  background: rgba(104, 156, 255, 0.08);
}

.new-product-prompt p {
  margin: 0 0 12px;
}

.new-product-panel {
  margin-top: 18px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card);
}

.new-product-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.new-product-panel-header h3 {
  margin: 4px 0 0;
}

.new-product-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.new-product-form label {
  display: grid;
  gap: 7px;
}

.new-product-checkbox-row {
  grid-column: 1 / -1;
  display: flex !important;
  align-items: center;
  gap: 10px;
  width: fit-content;
}

.new-product-checkbox-row input[type='checkbox'] {
  width: 18px;
  height: 18px;
  margin: 0;
  padding: 0;
  accent-color: var(--blue);
}

.new-product-conditional {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  padding: 14px;
  border-radius: 12px;
  background: rgba(104, 156, 255, 0.08);
}

.new-product-full-width {
  grid-column: 1 / -1;
}

.scan-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.scan-input-row input {
  min-width: 0;
  flex: 1 1 auto;
}

.scan-input-button {
  flex: 0 0 auto;
  min-width: 84px;
  white-space: nowrap;
}

/* Serialized-unit list */

.serialized-units {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.serialized-units__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.serialized-units__header h3 {
  margin: 0;
  font-size: 1rem;
}

.serialized-units__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.12);
  color: #1d4ed8;
  font-size: 0.85rem;
  font-weight: 800;
}

.serialized-units__list {
  display: grid;
  gap: 10px;
  max-height: 360px;
  overflow-y: auto;
}

.serialized-unit-item {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(248, 250, 252, 0.75);
}

.serialized-unit-item__serial {
  display: block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.serialized-unit-item__meta {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.83rem;
}

/* Miscellaneous */

.small-text {
  margin-top: 18px;
  text-align: center;
  font-size: 0.9rem;
}

.small-text a {
  color: var(--blue);
  font-weight: 700;
  text-decoration: none;
}

.small-text a:hover {
  text-decoration: underline;
}

/* Tablet and mobile */

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 20px, 960px);
    padding-top: 14px;
  }

  .app-header {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 24px;
  }

  .brand {
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .company-logo {
    width: 100px;
    height: 70px;
  }

  .brand-title {
    text-align: left;
  }

  .app-title {
    font-size: 1.15rem;
    white-space: normal;
  }

  .user-actions {
    align-self: flex-end;
    width: auto;
    align-items: flex-end;
    font-size: 0.78rem;
    text-align: right;
  }

  .section-heading,
  .search-row {
    align-items: stretch;
    flex-direction: column;
  }

  .search-row .button {
    width: 100%;
  }

  .action-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .product-details-grid,
  .operation-form {
    grid-template-columns: 1fr;
  }

  #operationForm #serialField,
  #operationForm #manufacturerModelField {
    grid-column: auto;
  }
}

@media (max-width: 640px) {
  .new-product-panel-header {
    flex-direction: column;
  }

  .new-product-form,
  .new-product-conditional {
    grid-template-columns: 1fr;
  }

  .scan-input-row {
    flex-direction: column;
    align-items: stretch;
  }

  .scan-input-button {
    width: 100%;
  }
}

@media (max-width: 520px) {
  .serial-input-row {
    flex-direction: column;
    align-items: stretch;
  }

  .serial-scan-button {
    width: 100%;
  }
}

.transaction-reference,
.transaction-notes {
  display: block;
  margin-top: 5px;
}

.transaction-notes {
  color: var(--navy);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 700;
}

/* Selected product: collapsible item details */
.product-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.product-card-header h3 {
  margin-bottom: 0;
}

.product-details-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: 0 0 auto;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.68);
  color: var(--navy);
  font-size: 0.86rem;
  font-weight: 800;
}

.product-details-toggle:hover {
  border-color: var(--blue);
  background: #fff;
}

.product-details-toggle-icon {
  font-size: 1.15rem;
  line-height: 1;
}

#selectedProductDetails {
  margin-top: 16px;
}

/*
  The serial list is outside #selectedProductDetails,
  so it remains visible when item details are collapsed.
*/
#selectedProductDetails + .serialized-units {
  margin-top: 18px;
}

#selectedProductDetails.hidden + .serialized-units {
  margin-top: 14px;
  padding-top: 14px;
}

@media (max-width: 640px) {
  .product-card-header {
    align-items: center;
  }

  .product-card-header h3 {
    margin-bottom: 0;
  }

  .product-details-toggle {
    min-width: 42px;
    padding: 9px;
  }

  .product-details-toggle-label {
    display: none;
  }
}

@media (max-width: 420px) {
  .action-grid {
    grid-template-columns: 1fr;
  }

  .card {
    padding: 18px;
  }

.history-empty-state {
  margin: 0;
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: rgba(23, 105, 170, 0.05);
  color: var(--muted);
  line-height: 1.5;
  text-align: center;
}

/* User management */

.user-management-intro {
  margin: 18px 0;
  color: var(--muted);
  line-height: 1.5;
}

.user-list {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.user-list-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}

.user-list-item h3,
.user-list-item p {
  margin: 0;
}

.user-list-item h3 {
  overflow-wrap: anywhere;
  font-size: 1rem;
}

.user-list-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 7px !important;
  color: var(--muted);
  font-size: 0.84rem;
}

.user-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 800;
}

.user-badge.role-admin {
  background: #e4eff9;
  color: var(--blue-dark);
}

.user-badge.role-supervisor {
  background: #fff0d6;
  color: #8a4b00;
}

.user-badge.role-technician {
  background: #e6f5eb;
  color: #075d2b;
}

.user-badge.status-active {
  background: #dff6e7;
  color: #075d2b;
}

.user-badge.status-inactive {
  background: #fde7e4;
  color: #8f1b13;
}

.edit-user-panel {
  margin-top: 22px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
}

.edit-user-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.edit-user-form > label:first-child {
  grid-column: 1 / -1;
}

.user-management-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  grid-column: 1 / -1;
}

@media (max-width: 640px) {
  .user-list-item {
    grid-template-columns: 1fr;
  }

  .user-list-item .button {
    width: 100%;
  }

  .edit-user-form {
    grid-template-columns: 1fr;
  }

  .edit-user-form > label:first-child {
    grid-column: auto;
  }

  .user-management-actions {
    flex-direction: column-reverse;
    grid-column: auto;
  }

  .user-management-actions .button {
    width: 100%;
  }
}

/* Create user invitation */

.create-user-panel {
  margin: 22px 0;
  padding: 22px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.create-user-panel h3 {
  margin: 0;
}

.create-user-help {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.create-user-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.create-user-form > label:first-child {
  grid-column: 1 / -1;
}

.create-user-form > button {
  grid-column: 1 / -1;
}

@media (max-width: 640px) {
  .create-user-form {
    grid-template-columns: 1fr;
  }

  .create-user-form > label:first-child,
  .create-user-form > button {
    grid-column: auto;
  }

  .create-user-form > button {
    width: 100%;
  }
}

}
