:root {
  --bg: #0d0f14;
  --surface: #161920;
  --panel: #1e2230;
  --border: #2a2f3f;
  --accent: #00e5a0;
  --accent2: #0096ff;
  --danger: #ff4d6a;
  --warn: #ffb300;
  --text: #e8eaf0;
  --muted: #6b7280;
  --radius: 12px;
  --mono: 'JetBrains Mono', monospace;
  --sans: 'Noto Sans JP', sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0
}

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6
}

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100
}

.logo {
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent)
}

.logo span {
  color: var(--muted)
}

#conn-status {
  font-size: 0.75rem;
  color: var(--muted)
}

.app {
  max-width: 860px;
  margin: 0 auto;
  padding: 20px 14px 60px
}

.tabs {
  display: flex;
  gap: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 20px
}

.tab-btn {
  flex: 1;
  padding: 9px 4px;
  background: transparent;
  border: none;
  border-radius: 9px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s
}

.tab-btn.active {
  background: var(--panel);
  color: var(--accent);
  box-shadow: 0 0 0 1px var(--border)
}

.tab-panel {
  display: none
}

.tab-panel.active {
  display: block
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px
}

.card-title {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 12px
}

/* Scanner */
#reader-container {
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid var(--border);
  background: #000;
  position: relative;
  width: 100%
}

#reader {
  width: 100%
}

#reader__scan_region {
  background: #000;
  line-height: 0
}

#reader__scan_region video {
  width: 100% !important;
  height: auto !important;
  display: block
}

#reader__scan_region img {
  display: none !important
}

#reader img[alt="Info icon"],
#reader select,
#reader__dashboard_section_swaplink,
#reader__dashboard_section_csr span {
  display: none !important
}

#scan-status {
  position: absolute;
  bottom: 8px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.76rem;
  color: var(--accent);
  font-family: var(--mono);
  text-shadow: 0 0 8px rgba(0, 229, 160, .9);
  pointer-events: none;
  padding: 0 8px;
  z-index: 10
}

#reader-container.flash {
  animation: flashGreen 0.35s ease
}

@keyframes flashGreen {

  0%,
  100% {
    border-color: var(--border)
  }

  50% {
    border-color: var(--accent);
    box-shadow: 0 0 18px rgba(0, 229, 160, .5)
  }
}

.scan-controls {
  display: flex;
  gap: 8px;
  margin-top: 10px
}

/* Inputs */
.field {
  margin-bottom: 12px
}

label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 5px;
  font-weight: 500
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  padding: 10px 13px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--sans);
  font-size: 0.93rem;
  transition: border-color 0.2s;
  outline: none
}

input:focus,
select:focus {
  border-color: var(--accent)
}

input[readonly] {
  color: var(--muted);
  cursor: default
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  font-family: var(--sans);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s;
  white-space: nowrap
}

.btn-primary {
  background: var(--accent);
  color: #0d1a13
}

.btn-primary:hover {
  background: #00ffb2
}

.btn-secondary {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border)
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent)
}

.btn-danger {
  background: var(--danger);
  color: #fff
}

.btn-danger:hover {
  opacity: .85
}

.btn-warn {
  background: var(--warn);
  color: #1a1200
}

.btn-warn:hover {
  opacity: .85
}

.btn:disabled {
  opacity: .38;
  cursor: not-allowed
}

.btn-sm {
  padding: 6px 11px;
  font-size: 0.8rem
}

/* Product Info */
.product-info {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 12px;
  min-height: 60px;
  display: flex;
  flex-direction: column;
  gap: 3px
}

.product-info .p-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent)
}

.product-info .p-id {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted)
}

.product-info.empty .p-name {
  color: var(--muted)
}

.product-info.found {
  border-color: var(--accent)
}

.product-info.not-found {
  border-color: var(--danger)
}

/* Toast */
.toast-wrap {
  position: fixed;
  bottom: 20px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  z-index: 999
}

.toast {
  padding: 11px 16px;
  border-radius: 10px;
  font-size: 0.86rem;
  font-weight: 500;
  border: 1px solid;
  max-width: 280px;
  animation: slideIn 0.22s ease
}

.toast.success {
  background: #0a2e1e;
  border-color: var(--accent);
  color: var(--accent)
}

.toast.error {
  background: #2e0a14;
  border-color: var(--danger);
  color: var(--danger)
}

.toast.info {
  background: #0a1e2e;
  border-color: var(--accent2);
  color: var(--accent2)
}

@keyframes slideIn {
  from {
    transform: translateX(30px);
    opacity: 0
  }

  to {
    transform: translateX(0);
    opacity: 1
  }
}

/* Table */
.table-wrap {
  overflow-x: auto;
  border-radius: 10px;
  border: 1px solid var(--border)
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem
}

th {
  background: var(--panel);
  padding: 9px 12px;
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  white-space: nowrap
}

td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle
}

tr:last-child td {
  border-bottom: none
}

tr:hover td {
  background: rgba(255, 255, 255, .025)
}

.td-mono {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted)
}

/* Record Cards */
.record-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 10px
}

.record-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px
}

.record-card.own-record {
  border-left: 3px solid var(--accent2)
}

.rc-name {
  font-size: 0.93rem;
  font-weight: 700;
  color: var(--text);
  grid-column: 1
}

.rc-meta {
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--muted);
  grid-column: 1;
  line-height: 1.9
}

.rc-right {
  grid-column: 2;
  grid-row: 1/span 3;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 7px;
  min-width: 72px
}

.rc-qty-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px
}

.rc-qty-label {
  font-size: 0.7rem;
  color: var(--muted)
}

.rc-qty-val {
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.2;
  font-family: var(--mono);
  color: var(--accent)
}

@media(min-width:768px) {
  .record-list {
    display: none
  }

  .table-wrap-desktop {
    display: block !important
  }
}

@media(max-width:767px) {
  .table-wrap-desktop {
    display: none !important
  }

  .record-list {
    display: flex
  }

  .scan-controls {
    flex-direction: column
  }

  .scan-controls .btn {
    width: 100%
  }
}

/* Summary */
.diff-ok {
  color: var(--accent);
  font-weight: 700
}

.diff-over {
  color: var(--warn);
  font-weight: 700
}

.diff-under {
  color: var(--danger);
  font-weight: 700
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px
}

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px
}

.summary-card .s-name {
  font-size: 0.87rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis
}

.summary-card .s-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 3px
}

.summary-card .s-row span:last-child {
  font-family: var(--mono);
  font-weight: 600
}

/* Modal */
.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .72);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px
}

.modal-bg.hidden {
  display: none
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  width: 100%;
  max-width: 380px
}

.modal-title {
  font-size: .95rem;
  font-weight: 700;
  margin-bottom: 14px;
  color: var(--text)
}

.modal-pname {
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 14px;
  font-size: 1rem
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px
}

.modal-actions .btn {
  flex: 1
}

/* Misc */
.mode-toggle {
  display: flex;
  gap: 7px;
  margin-bottom: 12px
}

.mode-btn {
  padding: 7px 15px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-family: var(--sans);
  font-size: .84rem;
  cursor: pointer;
  transition: all .2s
}

.mode-btn.active {
  background: var(--panel);
  border-color: var(--accent2);
  color: var(--accent2)
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: .73rem;
  font-weight: 600
}

.badge-green {
  background: rgba(0, 229, 160, .13);
  color: var(--accent)
}

.badge-blue {
  background: rgba(0, 150, 255, .13);
  color: var(--accent2)
}

.filter-bar {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin-bottom: 12px;
  flex-wrap: wrap
}

.filter-bar .field {
  flex: 1;
  min-width: 130px;
  margin-bottom: 0
}

.sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 14px 0
}

.empty-state {
  text-align: center;
  padding: 36px 16px;
  color: var(--muted);
  font-size: .88rem
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block
}

@keyframes spin {
  to {
    transform: rotate(360deg)
  }
}

/* ── Summary filter buttons ── */
.summary-filter-btn {
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font-family: var(--sans);
  font-size: .83rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .18s;
}

.summary-filter-btn:hover {
  border-color: var(--accent2);
  color: var(--accent2)
}

.summary-filter-btn.active {
  background: var(--panel);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 700
}

.summary-filter-btn.active-warn {
  background: var(--panel);
  border-color: var(--warn);
  color: var(--warn);
  font-weight: 700
}