:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #657282;
  --line: #dfe5ea;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --warn: #b45309;
  --danger: #b91c1c;
  --repair: #5b4b8a;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

.form-error {
  min-height: 20px;
  color: var(--danger) !important;
  font-weight: 700;
}

.environment-banner {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: 12px 20px;
  border-bottom: 1px solid #d97706;
  background: #fef3c7;
  color: #78350f;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}

.environment-banner[data-mode="live"] {
  border-color: #15803d;
  background: #dcfce7;
  color: #14532d;
}

.environment-banner[data-mode="blocked"] {
  border-color: #b91c1c;
  background: #fee2e2;
  color: #991b1b;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  padding: 0 14px;
}

button.primary,
.scan-box button,
#newDeviceButton {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

button:hover {
  border-color: var(--accent);
}

.app-shell {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #15212d;
  color: #fff;
  padding: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--accent);
  font-weight: 700;
}

.brand span,
.role-picker span,
header p,
.panel-head p {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.sidebar .brand span,
.sidebar .role-picker span {
  color: #b9c4cf;
}

nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  border-color: transparent;
  background: transparent;
  color: #dce4ec;
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  background: #233344;
  border-color: #31465b;
}

.role-picker {
  display: grid;
  gap: 8px;
  margin-top: 28px;
}

.role-picker select {
  width: 100%;
}

.compact-button {
  min-height: 30px;
  padding: 0 9px;
  margin-left: 5px;
  font-size: 12px;
}

main {
  min-width: 0;
  padding: 26px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 18px;
}

.scan-box {
  display: flex;
  min-width: 380px;
  gap: 8px;
}

.scan-box input {
  flex: 1;
}

input,
select,
textarea {
  min-height: 38px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 8px 10px;
}

textarea {
  min-height: 84px;
  resize: vertical;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric {
  display: block;
  min-height: 0;
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  text-align: left;
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

.metric:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.metric.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.18);
}

.metric:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.28);
  outline-offset: 2px;
}

.metric strong {
  display: block;
  font-size: 26px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 12px;
}

.filters {
  display: flex;
  gap: 8px;
}

.section-note {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.table-wrap,
.selected-device,
.workflow-layout > section,
.audit-list {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #f7fafc;
}

#stockOverviewRows tr {
  cursor: default;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 6px;
  padding: 3px 8px;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.IN_STOCK {
  background: var(--accent);
}

.WITH_CUSTOMER {
  background: #2563eb;
}

.IN_REPAIR {
  background: var(--repair);
}

.DECOMMISSIONED {
  background: var(--danger);
}

.workflow-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.workflow-layout > section,
.master-panel {
  padding: 16px;
}

.master-data-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.master-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.customer-panel {
  max-width: 900px;
}

.master-panel h3 {
  margin: 0;
  font-size: 16px;
}

.master-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

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

.stack-form {
  display: grid;
  gap: 10px;
}

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

.compact-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.stock-take-workspace {
  display: grid;
  grid-template-columns: minmax(240px, 0.3fr) minmax(0, 1fr);
  gap: 16px;
}

.stock-take-detail {
  min-width: 0;
}

.list-row {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px;
  color: var(--ink);
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
}

.list-row.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 20%, transparent);
}

.list-row span,
.list-row small,
.stock-take-detail td small {
  display: block;
}

.list-row small,
.stock-take-detail td small,
.stock-take-head p {
  color: var(--muted);
  margin-top: 4px;
}

.stock-take-head,
.stock-take-summary,
.inline-count {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stock-take-head {
  justify-content: space-between;
  margin-bottom: 12px;
}

.stock-take-summary {
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.stock-take-summary span {
  min-width: 120px;
  padding: 10px 12px;
  background: var(--soft);
  border-radius: 6px;
}

.inline-count input {
  min-width: 120px;
  width: 160px;
}

.inline-count button,
.tracking-button {
  white-space: nowrap;
}

.variance-ok {
  color: #0f766e;
  font-weight: 800;
}

.variance-bad {
  color: #b42318;
  font-weight: 800;
}

.compact-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

.compact-row span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.compact-row button {
  min-height: 32px;
  padding: 0 10px;
}

.device-card {
  display: grid;
  gap: 10px;
}

.device-card dl {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 8px 12px;
  margin: 0;
}

.device-card dt {
  color: var(--muted);
}

.device-card dd {
  margin: 0;
}

.action-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.action-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.empty-state {
  color: var(--muted);
  padding: 18px 0;
}

.audit-list {
  display: grid;
}

.audit-row {
  display: grid;
  grid-template-columns: 180px 140px 1fr 160px;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 12px;
}

.audit-row:last-child {
  border-bottom: 0;
}

dialog {
  width: min(520px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
}

dialog.wide-dialog {
  width: min(860px, calc(100vw - 24px));
}

dialog.repair-dialog {
  width: min(1040px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow: auto;
}

.dialog-content {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.dialog-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.stock-location-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
}

.stock-location-controls > label {
  flex: 1 1 180px;
  min-width: 0;
}

.location-balance {
  display: block;
  white-space: nowrap;
  margin: 3px 0;
}

.stock-workbook-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.stock-workbook-actions p {
  flex: 1 1 260px;
  color: var(--muted);
  font-size: 13px;
}

#landingPriceUploadDialog {
  max-height: calc(100vh - 24px);
  overflow: auto;
}

.workbook-help {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

#landingPriceUploadDialog .stock-workbook-actions {
  margin-bottom: 0;
}

#landingPricePreview h3 {
  margin: 0 0 8px;
}

#landingPricePreviewSummary,
#landingPricePreviewExpiry {
  margin-bottom: 10px;
}

.price-preview-table {
  max-height: 300px;
  overflow: auto;
  margin-bottom: 10px;
}

.price-preview-table th {
  position: sticky;
  top: 0;
  background: var(--panel);
}

.price-preview-table td:not(:first-child) {
  white-space: nowrap;
}

#landingPriceUploadError:empty,
#landingPriceUploadFeedback:empty,
#stockWorkbookFeedback:empty {
  display: none;
}

#landingPriceUploadError ul {
  max-height: 180px;
  overflow: auto;
  padding-left: 22px;
  margin: 8px 0 0;
}

#landingPriceWorkbook {
  max-width: 100%;
}

.location-list-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

#locationForm {
  padding: 0;
}

.transfer-unit-list {
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-top: 8px;
}

dialog .checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
}

dialog .checkbox-label input {
  width: 18px;
  min-height: 18px;
  height: 18px;
  flex: 0 0 18px;
}

dialog .transfer-unit {
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

.transfer-unit small {
  display: block;
  color: var(--muted);
  margin-top: 4px;
}

#transferSelectedCount {
  margin-top: 8px;
}

#transferStockDialog, #stockUnitsDialog, #locationsDialog {
  max-height: calc(100vh - 24px);
  overflow: auto;
}

.repair-filters input {
  min-width: 250px;
}

#standardItemSearch {
  min-width: 320px;
}

.repair-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.repair-form-grid .span-two {
  grid-column: 1 / -1;
}

.client-report-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  border: 1px solid #b9d9d3;
  border-radius: 8px;
  background: #f0f8f6;
  padding: 14px;
}

.client-report-panel > div,
.client-report-panel > label:last-child {
  grid-column: 1 / -1;
}

.client-report-panel p {
  color: var(--muted);
  font-size: 13px;
  margin: 4px 0 0;
}

.repair-photos {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.repair-photos p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.repair-photo-upload {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 1fr) auto;
  gap: 8px;
  margin-top: 12px;
}

.repair-status {
  display: inline-block;
  border-radius: 999px;
  background: #e7e5f2;
  color: #443d73;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

dialog form {
  display: grid;
  gap: 12px;
  padding: 18px;
}

dialog label {
  display: grid;
  gap: 6px;
}

menu {
  display: flex;
  justify-content: end;
  gap: 8px;
  margin: 6px 0 0;
  padding: 0;
}

.detail-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.summary-item {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

.summary-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.timeline-list {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.attachment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.attachment-card {
  display: grid;
  gap: 6px;
  color: inherit;
  text-decoration: none;
}

.client-photo-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}

.client-photo-card a {
  color: inherit;
  text-decoration: none;
}

.client-photo-toggle {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 7px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}

.client-photo-toggle input {
  width: auto;
  min-height: auto;
}

.attachment-card img {
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 6px;
  object-fit: cover;
  background: #fff;
}

.attachment-card span,
.attachment-card small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-card small {
  color: var(--muted);
}

.timeline-item {
  border-left: 4px solid var(--accent);
  background: #fff;
  border-radius: 6px;
  padding: 10px 12px;
  box-shadow: inset 0 0 0 1px var(--line);
}

.timeline-item strong {
  display: block;
}

.timeline-item span,
.timeline-item p {
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
  }

  .sidebar .brand {
    gap: 8px;
    margin: 0;
  }

  .sidebar .brand-mark {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
  }

  .sidebar nav {
    grid-column: 1 / -1;
    grid-row: 2;
    display: flex;
    gap: 6px;
    overflow-x: auto;
    min-width: 0;
    padding-bottom: 4px;
    scrollbar-width: thin;
  }

  .sidebar .nav-item {
    flex: 0 0 auto;
    width: auto;
    white-space: nowrap;
    padding: 0 10px;
  }

  .sidebar .role-picker {
    grid-column: 2;
    grid-row: 1;
    gap: 4px;
    margin: 0;
    width: 100%;
    max-width: 240px;
    justify-self: end;
    min-width: 0;
  }

  main {
    padding: 16px;
  }

  .topbar {
    gap: 12px;
    margin-bottom: 16px;
  }

  .topbar h1 {
    font-size: 24px;
  }

  .topbar,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .scan-box,
  .filters {
    min-width: 0;
    width: 100%;
  }

  .filters {
    flex-direction: column;
  }

  .filters select {
    width: 100%;
  }

  .metrics,
  .workflow-layout,
  .master-data-layout,
  .stock-take-workspace {
    grid-template-columns: 1fr;
  }

  #stockOverviewView .filters {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #stockOverviewView .filters > * {
    min-width: 0;
    width: 100%;
  }

  #stockOverviewSearch {
    grid-column: 1 / -1;
  }

  #stockOverviewMetrics {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }

  #stockOverviewMetrics .metric {
    padding: 10px;
  }

  .table-wrap {
    overflow-x: auto;
  }

  .audit-row {
    grid-template-columns: 1fr;
  }

  .detail-summary {
    grid-template-columns: 1fr;
  }

  .repair-form-grid,
  .repair-photo-upload {
    grid-template-columns: 1fr;
  }

  .repair-form-grid .span-two {
    grid-column: auto;
  }

  .client-report-panel {
    grid-template-columns: 1fr;
  }

  .client-report-panel > div,
  .client-report-panel > label:last-child {
    grid-column: auto;
  }
}

@media (max-width: 520px) {
  .sidebar .brand span {
    display: none;
  }

  .sidebar .role-picker span {
    font-size: 11px;
  }

  .sidebar .role-picker select {
    font-size: 12px;
  }

  #stockOverviewMetrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
