:root {
  --brand-primary: #163c3a;
  --brand-accent: #e4573d;
  --raps-spring: #4ba33a;
  --raps-cabernet: #94264f;
  --raps-steel: #849fc0;
  --raps-sky: #8cc7f9;
  --raps-gunmetal: #6d6e70;
  --raps-kumquat: #faac2e;
  --raps-butter: #dcc65e;
  --raps-powder: #e2e7e6;
  --color-canvas: #f4f7f5;
  --color-surface: #ffffff;
  --color-text: var(--brand-primary);
  --color-text-muted: var(--raps-gunmetal);
  --color-border: #d6e0dc;
  --color-primary: var(--brand-primary);
  --color-accent: var(--brand-accent);
  --color-success-surface: #a4cf97;
  --color-info-surface: #bcdbf3;
  --color-warning-surface: #ffcf82;
  --color-offline-surface: #eade9e;
  --color-error: var(--raps-cabernet);
  --font-display: "Segoe UI", Arial, sans-serif;
  --font-ui: "Segoe UI", Arial, sans-serif;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --radius-control: 6px;
  --radius-card: 8px;
  --shadow-soft: 0 8px 24px rgba(25, 32, 74, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  color: var(--color-text);
  font-family: var(--font-ui);
  background: var(--color-canvas);
}

body {
  margin: 0;
  min-width: 320px;
}

.app-loading {
  display: grid;
  min-height: 100vh;
  place-items: center;
  color: var(--brand-primary);
  font-size: 18px;
  font-weight: 700;
}

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

button {
  min-height: 44px;
}

.app-shell {
  display: grid;
  min-height: 100vh;
  grid-template-columns: 248px 1fr;
  background: var(--color-canvas);
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  gap: var(--space-6);
  padding: var(--space-6);
  color: #ffffff;
  background: var(--brand-primary);
  box-shadow: inset -4px 0 0 var(--brand-accent);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.brand-mark {
  display: flex;
  width: 56px;
  height: 56px;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  color: var(--brand-primary);
  background: #ffffff;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

html[data-brand="raps"] .brand-mark {
  width: 72px;
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  color: #ffffff;
  background: transparent;
}

.brand-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 800;
  line-height: 1.1;
}

.brand-subtitle {
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 14px;
}

.deployment-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius-control);
  font-size: 13px;
}

.deployment-status span {
  padding: 3px 7px;
  border-radius: 999px;
  color: var(--brand-primary);
  background: #ffffff;
  font-weight: 700;
}

.deployment-status strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-chip {
  padding: var(--space-4);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-left: 5px solid var(--brand-accent);
  border-radius: var(--radius-card);
  background: rgba(255, 255, 255, 0.08);
}

.event-chip strong,
.event-chip span {
  display: block;
}

.event-chip span {
  margin-top: var(--space-1);
  color: rgba(255, 255, 255, 0.78);
  font-size: 14px;
}

.nav {
  display: grid;
  gap: var(--space-2);
}

.nav-button {
  display: flex;
  width: 100%;
  align-items: center;
  gap: var(--space-3);
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  color: #ffffff;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.nav-button:hover,
.nav-button.active {
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.12);
}

.nav-button svg {
  flex: 0 0 auto;
}

.sync-panel {
  margin-top: auto;
  padding: var(--space-4);
  border-radius: var(--radius-card);
  color: var(--brand-primary);
  background: var(--color-offline-surface);
}

.sync-panel strong,
.sync-panel span {
  display: block;
}

.sync-panel span {
  margin-top: var(--space-1);
  font-size: 14px;
}

.sync-button {
  width: 100%;
  margin-top: var(--space-3);
  border: 1px solid var(--brand-primary);
  border-radius: var(--radius-control);
  color: #ffffff;
  background: var(--brand-primary);
  font-weight: 700;
  cursor: pointer;
}

.sync-button:disabled {
  border-color: rgba(25, 32, 74, 0.28);
  color: rgba(25, 32, 74, 0.58);
  background: transparent;
  cursor: not-allowed;
}

.main {
  min-width: 0;
  padding: var(--space-6);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.page-title h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 28px;
  line-height: 34px;
}

.page-title p {
  margin: var(--space-1) 0 0;
  color: var(--color-text-muted);
}

.role-switcher {
  display: grid;
  min-width: 220px;
  gap: var(--space-1);
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 700;
}

.role-switcher select {
  min-height: 40px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control);
  color: var(--brand-primary);
  background: #ffffff;
  font: inherit;
}

.access-notice {
  margin-top: calc(var(--space-4) * -1);
  margin-bottom: var(--space-4);
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.pill,
.icon-button,
.primary,
.secondary,
.danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border-radius: var(--radius-control);
  font-weight: 700;
  cursor: pointer;
}

.pill {
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  color: var(--brand-primary);
  background: #ffffff;
}

.pill.active {
  border-color: var(--brand-primary);
  color: #ffffff;
  background: var(--brand-primary);
}

.primary,
.secondary,
.danger {
  padding: 10px 14px;
  border: 1px solid transparent;
}

.primary:disabled,
.secondary:disabled,
.danger:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.primary {
  color: #ffffff;
  background: var(--brand-primary);
}

.secondary {
  border-color: var(--raps-steel);
  color: var(--brand-primary);
  background: #ffffff;
}

.danger {
  color: #ffffff;
  background: var(--color-error);
}

.icon-button {
  width: 44px;
  border: 1px solid var(--color-border);
  color: var(--brand-primary);
  background: #ffffff;
}

.grid {
  display: grid;
  gap: var(--space-4);
}

.grid.two {
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.82fr);
}

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

.panel {
  min-width: 0;
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  background: var(--color-surface);
  box-shadow: var(--shadow-soft);
}

.panel.flat {
  box-shadow: none;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.panel h2,
.panel h3 {
  margin: 0;
  font-size: 18px;
  line-height: 24px;
}

.panel p {
  color: var(--color-text-muted);
}

.metric {
  display: grid;
  min-height: 116px;
  align-content: space-between;
}

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

.metric strong {
  display: block;
  margin-top: var(--space-2);
  font-family: var(--font-display);
  font-size: 30px;
  line-height: 34px;
}

.metric small {
  color: var(--raps-gunmetal);
}

.searchbar {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.field {
  display: grid;
  gap: var(--space-1);
}

.field label {
  font-weight: 700;
}

.field input,
.field select,
.field textarea,
.searchbar input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control);
  color: var(--brand-primary);
  background: #ffffff;
}

.field textarea {
  min-height: 168px;
  resize: vertical;
}

.file-picker {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  padding: var(--space-3);
  border: 1px dashed var(--raps-steel);
  border-radius: var(--radius-control);
  background: #f7f9fb;
  font-weight: 700;
}

.file-picker input {
  max-width: 220px;
}

.file-name {
  margin: 0 0 var(--space-3);
  font-size: 14px;
}

.mapping-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-3);
}

.conflict-list {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.conflict-card {
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-left: 5px solid var(--raps-kumquat);
  border-radius: var(--radius-control);
}

.conflict-source {
  display: block;
  margin-top: var(--space-1);
  color: var(--color-text-muted);
  font-size: 14px;
}

.conflict-fields {
  display: grid;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.conflict-field {
  display: grid;
  grid-template-columns: minmax(120px, 0.6fr) repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-top: 1px solid var(--color-border);
}

.conflict-field span,
.conflict-field small {
  display: block;
}

.conflict-field small {
  margin-bottom: 2px;
  color: var(--color-text-muted);
}

.conflict-bulk-actions {
  margin-top: 0;
}

.import-batch {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border);
  font-size: 14px;
}

.import-batch span {
  display: block;
  color: var(--color-text-muted);
}

.import-batch small {
  display: block;
  margin-top: var(--space-1);
  color: var(--color-text-muted);
}

.import-batch button {
  flex: 0 0 auto;
}

.searchbar input {
  flex: 1;
}

.list {
  display: grid;
  gap: var(--space-2);
}

.row {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control);
  background: #ffffff;
}

.row.clickable {
  cursor: pointer;
}

.row.clickable:hover,
.row.selected {
  border-color: var(--brand-accent);
  box-shadow: inset 4px 0 0 var(--brand-accent);
}

.row-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.row-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  color: var(--color-text-muted);
  font-size: 14px;
}

.row-meta span {
  line-height: 20px;
}

.row-meta span + span::before {
  margin-right: var(--space-2);
  color: var(--raps-steel);
  content: "/";
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  min-height: 28px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
}

.badge.success {
  background: var(--color-success-surface);
}

.badge.info {
  background: var(--color-info-surface);
}

.badge.warning {
  background: var(--color-warning-surface);
}

.badge.offline {
  background: var(--color-offline-surface);
}

.badge.error {
  color: #ffffff;
  background: var(--color-error);
}

.badge.neutral {
  background: var(--raps-powder);
}

.status-card {
  display: grid;
  gap: var(--space-3);
  min-height: 136px;
  padding: var(--space-4);
  border-radius: var(--radius-card);
  color: var(--brand-primary);
}

.status-card.success {
  background: var(--color-success-surface);
}

.status-card.warning {
  background: var(--color-warning-surface);
}

.status-card.error {
  color: #ffffff;
  background: var(--color-error);
}

.status-card.neutral {
  background: var(--raps-powder);
}

.status-card.offline {
  background: var(--color-offline-surface);
}

.status-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 24px;
  font-weight: 700;
  line-height: 30px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}

.detail-item {
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control);
}

.detail-item span {
  display: block;
  color: var(--color-text-muted);
  font-size: 14px;
}

.detail-item strong {
  display: block;
  margin-top: 4px;
}

.action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.camera-box {
  position: relative;
  display: grid;
  overflow: hidden;
  min-height: 340px;
  place-items: center;
  border-radius: var(--radius-card);
  color: #ffffff;
  background:
    linear-gradient(rgba(25, 32, 74, 0.72), rgba(25, 32, 74, 0.72)),
    repeating-linear-gradient(45deg, #34365a 0 16px, #19204a 16px 32px);
}

.scan-guide {
  position: relative;
  z-index: 2;
  display: grid;
  width: min(72%, 280px);
  aspect-ratio: 1;
  place-items: center;
  border: 3px solid rgba(255, 255, 255, 0.9);
  border-radius: 18px;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.65);
}

.scan-guide span {
  max-width: 220px;
  padding: 0 var(--space-2);
}

#cameraPreview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.capability-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.token-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.token-entry .field {
  margin: 0;
}

.test-controls {
  margin-top: var(--space-4);
}

.test-controls p {
  margin: var(--space-1) 0 0;
  color: var(--color-text-muted);
}

.badge-preview {
  display: grid;
  width: 100%;
  max-width: 360px;
  min-height: 220px;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-top: 10px solid var(--brand-accent);
  border-radius: var(--radius-card);
  background: #ffffff;
}

.badge-preview .name {
  font-size: 28px;
  font-weight: 700;
}

.qr {
  display: grid;
  width: 92px;
  height: 92px;
  place-items: center;
  border: 8px solid #ffffff;
  outline: 1px solid #111111;
  color: #111111;
  background:
    linear-gradient(90deg, #111 12px, transparent 12px) 0 0 / 24px 24px,
    linear-gradient(#111 12px, transparent 12px) 0 0 / 24px 24px,
    #ffffff;
  font-size: 12px;
  font-weight: 700;
}

.table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
}

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

.table th {
  color: var(--brand-primary);
  background: var(--raps-powder);
}

.report-preview {
  min-width: 620px;
}

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

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

.timeline {
  display: grid;
  gap: var(--space-3);
}

.timeline-item {
  padding-left: var(--space-4);
  border-left: 4px solid var(--brand-accent);
}

.timeline-item strong,
.timeline-item span {
  display: block;
}

.timeline-item span {
  color: var(--color-text-muted);
  font-size: 14px;
}

.sync-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-3);
}

.queue-list {
  display: grid;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.queue-item {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(110px, 0.7fr) auto;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-3);
  border-top: 1px solid var(--color-border);
  font-size: 14px;
}

.queue-item code {
  overflow: hidden;
  text-overflow: ellipsis;
}

.inline-notice,
.empty-state {
  padding: var(--space-3);
  border-radius: var(--radius-control);
  background: var(--color-info-surface);
}

.inline-notice {
  margin-top: var(--space-3);
}

.success-notice {
  background: var(--color-success-surface);
}

.error-notice {
  color: #ffffff;
  background: var(--color-error);
}

.brand-preview {
  display: flex;
  min-height: 112px;
  align-items: center;
  gap: var(--space-4);
  margin-top: var(--space-4);
  padding: var(--space-4);
  border-left: 8px solid var(--preview-accent);
  border-radius: var(--radius-control);
  color: #ffffff;
  background: var(--preview-primary);
}

.brand-preview .preview-logo {
  display: grid;
  min-width: 72px;
  min-height: 52px;
  place-items: center;
  padding: 8px;
  border: 1.5px solid currentColor;
  border-radius: var(--radius-control);
  font-family: var(--font-display);
  font-weight: 800;
}

.brand-preview strong,
.brand-preview span {
  display: block;
}

.brand-preview span {
  margin-top: var(--space-1);
  color: rgba(255, 255, 255, 0.78);
}

.mobile-tabs {
  display: none;
}

:focus-visible {
  outline: 3px solid var(--brand-accent);
  outline-offset: 2px;
}

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

  .sidebar {
    position: static;
    height: auto;
    padding: var(--space-4);
  }

  .nav {
    display: none;
  }

  .sync-panel {
    margin-top: 0;
  }

  .main {
    padding: var(--space-4);
  }

  .topbar,
  .row-main {
    align-items: stretch;
    flex-direction: column;
  }

  .role-switcher {
    width: 100%;
    min-width: 0;
  }

  .grid.two,
  .grid.three,
  .detail-grid,
  .sync-summary,
  .mapping-grid {
    grid-template-columns: 1fr;
  }

  .conflict-field {
    grid-template-columns: 1fr;
  }

  .import-batch {
    align-items: flex-start;
    flex-direction: column;
  }

  .queue-item {
    grid-template-columns: 1fr auto;
  }

  .queue-item code {
    grid-column: 1 / -1;
  }

  .file-picker {
    align-items: stretch;
    flex-direction: column;
  }

  .token-entry {
    grid-template-columns: 1fr;
  }

  .token-entry button {
    width: 100%;
  }

  .mobile-tabs {
    position: sticky;
    bottom: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    border-top: 1px solid var(--color-border);
    background: #ffffff;
  }

  .mobile-tabs button {
    min-height: 56px;
    border: 0;
    border-radius: 0;
    color: var(--brand-primary);
    background: transparent;
    font-size: 12px;
    font-weight: 700;
  }

  .mobile-tabs button.active {
    box-shadow: inset 0 4px 0 var(--brand-accent);
  }
}

@media print {
  body * {
    visibility: hidden;
  }

  .badge-preview,
  .badge-preview * {
    visibility: visible;
  }

  .badge-preview {
    position: absolute;
    top: 0;
    left: 0;
    width: 3.5in;
    min-height: 2.25in;
    box-shadow: none;
  }
}
