:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --border: rgba(15, 23, 42, 0.1);
  --ink: #0f172a;
  --muted: #64748b;
  --shadow: 0 14px 28px rgba(15, 23, 42, 0.07);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: 'DM Sans', sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: linear-gradient(180deg, #f8fafc 0%, #f3f4f6 100%);
}

.shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px 40px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-start;
}

.eyebrow {
  margin: 0;
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  font-weight: 600;
  color: #475569;
}

h1, h2 { margin: 8px 0 0; }
h1 { font-size: clamp(28px, 4.5vw, 40px); }
h2 { font-size: 1.1rem; }

.muted {
  margin-top: 8px;
  color: var(--muted);
}

.actions { display: inline-flex; gap: 8px; }

.btn {
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn.dark {
  background: #0f172a;
  color: #fff;
}

.btn.ghost {
  background: rgba(15, 23, 42, 0.08);
  color: #1f2937;
}

.status {
  margin: 10px 2px;
  min-height: 1.2rem;
  font-weight: 600;
}

.status.ok { color: #11623e; }
.status.err { color: #b42318; }

.grid {
  display: grid;
  gap: 10px;
}

.stack {
  margin-top: 10px;
  display: grid;
  gap: 8px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.86rem;
  font-weight: 500;
}

input {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px;
  font: inherit;
}

input:focus {
  outline: none;
  border-color: #64748b;
  box-shadow: 0 0 0 4px rgba(100, 116, 139, 0.14);
}

.stats {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.stats div {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  background: #fcfcfd;
}

.stats span {
  color: var(--muted);
  font-size: 0.8rem;
}

.stats strong {
  display: block;
  margin-top: 5px;
  font-size: 1.2rem;
}

.table-card { margin-top: 10px; }

.table-wrap {
  margin-top: 10px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

th, td {
  text-align: left;
  padding: 10px;
  border-bottom: 1px solid var(--border);
  font-size: 0.86rem;
}

th {
  background: #f8fafc;
  color: #334155;
  font-weight: 600;
}

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

.badge {
  display: inline-flex;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: #fff;
}

.hidden { display: none !important; }

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

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

/* Header Filters */
.inventory-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

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

.input-text, .input-select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font: inherit;
  font-size: 0.86rem;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin-top: 16px;
  font-size: 0.9rem;
  font-weight: 500;
}

.pagination .btn {
  padding: 6px 12px;
  font-size: 0.86rem;
}

/* Actions in Table */
.btn-sm {
  padding: 6px 10px;
  font-size: 0.75rem;
  border-radius: 8px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-card {
  background: var(--card);
  border-radius: 20px;
  box-shadow: 0 24px 48px -12px rgba(15, 23, 42, 0.18);
  width: 100%;
  max-width: 480px;
  overflow: hidden;
  animation: modal-enter 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
}

@keyframes modal-enter {
  from { opacity: 0; transform: scale(0.96) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f8fafc;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--ink);
}

.btn-icon {
  background: rgba(15, 23, 42, 0.05);
  border: none;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 8px;
  transition: all 0.2s;
}

.btn-icon:hover {
  color: var(--ink);
  background: rgba(15, 23, 42, 0.1);
}

.modal-body {
  padding: 24px;
  flex: 1;
  overflow-y: auto;
}

/* Tabs */
.send-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  gap: 16px;
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 4px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.tab-btn:hover {
  color: var(--ink);
}

.tab-btn.active {
  color: var(--ink);
  border-bottom-color: var(--ink);
}

.tab-content {
  animation: fade-in 0.2s ease-in;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.qr-preview-container {
  display: flex;
  justify-content: center;
  margin: 16px 0;
  background: #f8fafc;
  padding: 20px;
  border-radius: 16px;
  border: 1px solid var(--border);
}

.qr-preview {
  width: 220px;
  height: 220px;
  border-radius: 8px;
  background: white;
}

.center {
  display: flex;
  justify-content: center;
  gap: 12px;
}

/* Tag Details Info Box */
.info-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

.info-box h3 {
  margin: 0 0 12px 0;
  font-size: 0.95rem;
  color: var(--ink);
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 0.9rem;
}

.info-row:last-child {
  margin-bottom: 0;
}

.info-label {
  color: var(--muted);
  font-weight: 500;
}

.info-value {
  color: var(--ink);
  font-weight: 500;
  text-align: right;
  word-break: break-all;
  max-width: 65%;
}

.info-value a {
  color: #0ea5e9;
  text-decoration: none;
}

.info-value a:hover {
  text-decoration: underline;
}

.details-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.details-stats div {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
}

.details-stats span {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.details-stats strong {
  font-size: 1.2rem;
  color: var(--ink);
}

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

/* Mobile Optimizations */
@media (max-width: 768px) {
  .shell {
    padding: 16px 12px 30px;
  }

  .top {
    flex-direction: column;
    gap: 16px;
  }

  .actions {
    width: 100%;
    justify-content: stretch;
  }

  .actions .btn {
    flex: 1;
  }

  .stats {
    grid-template-columns: 1fr 1fr;
  }

  .inventory-header {
    flex-direction: column;
    align-items: stretch;
  }

  .filters {
    flex-direction: column;
  }

  .input-text, .input-select {
    width: 100%;
  }

  .table-wrap {
    border: none;
    background: transparent;
    overflow: visible; /* Fix width issues on mobile */
  }

  table {
    min-width: unset; /* Remove the 900px minimum width constraint on mobile */
    width: 100%;
  }

  /* Stacked card layout for table rows on mobile */
  table, thead, tbody, th, td, tr {
    display: block;
  }

  thead {
    display: none;
  }

  tr {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 12px;
    padding: 12px;
    box-shadow: 0 4px 6px rgba(15, 23, 42, 0.02);
  }

  tr:last-child {
    margin-bottom: 0;
  }

  td {
    border: none;
    padding: 6px 0;
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    word-break: break-all;
  }

  td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    font-size: 0.8rem;
    margin-right: 12px;
    white-space: nowrap;
  }

  td:last-child {
    margin-top: 8px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    justify-content: flex-end;
  }

  .send-tabs {
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .tab-btn {
    padding: 8px 4px;
    font-size: 0.86rem;
  }

  .modal-card {
    max-height: 90vh;
  }

  .center {
    flex-direction: column;
  }
  
  .center .btn {
    width: 100%;
  }
}
