:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --border: #30363d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --success: #3fb950;
  --success-hover: #56d364;
  --create: #a371f7;
  --create-hover: #bc8cff;
  --danger: #f85149;
  --radius: 8px;
  --font-sans: 'Outfit', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* {
  box-sizing: border-box;
}

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

.app {
  max-width: none;
  margin: 0;
  padding: 0.5rem;
  display: flex;
  flex-direction: row;
  gap: 1.5rem;
  min-height: 100vh;
}

.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Collapsible nav panel (sidebar with tab buttons) */
.nav-panel {
  display: flex;
  flex-direction: column;
  width: 3.5rem;
  flex-shrink: 0;
  max-height: 50vh;
  align-self: flex-start;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: width 0.2s ease;
}

.nav-panel.collapsed {
  width: 2rem;
}

.nav-panel.collapsed .nav-panel-body {
  display: none;
}

.nav-panel.collapsed .nav-panel-label {
  display: none;
}

.nav-panel.collapsed .nav-panel-chevron {
  transform: rotate(-90deg);
}

.nav-panel-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  width: 100%;
  padding: 0.5rem;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  border: none;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  min-height: 2.5rem;
}

.nav-panel-toggle:hover {
  color: var(--text-primary);
  background: var(--border);
}

.nav-panel-chevron {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transform-origin: center;
  transition: transform 0.2s;
  flex-shrink: 0;
}

.nav-panel-body {
  padding: 0.5rem;
  padding-top: 0.25rem;
  overflow-y: auto;
  min-height: 0;
}

.tabs {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  width: 100%;
  flex-shrink: 0;
  padding-top: 0;
}

.tab-btn {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 1rem 0.5rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
  width: 100%;
  min-height: 6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  letter-spacing: 0.05em;
}

.tab-btn:hover {
  color: var(--text-primary);
  background: var(--border);
}

.tab-btn.active {
  background: var(--accent);
  color: var(--bg-primary);
  border-color: var(--accent);
}

.tab-panel {
  display: none;
  flex-direction: column;
  gap: 2rem;
}

.tab-panel.active {
  display: flex;
}

.header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.header h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0.25rem 0 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.content {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.form-section,
.master-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.form-section h2,
.master-section h2 {
  margin: 0 0 1.25rem;
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text-primary);
}

.section-desc {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.section-desc code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  padding: 0.15em 0.4em;
  background: var(--bg-tertiary);
  border-radius: 4px;
}

.price-subsection {
  margin-bottom: 1.5rem;
}

.price-subsection:last-child {
  margin-bottom: 0;
}

.subsection-header {
  margin: 0 0 0.85rem;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.section-separator {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

.product-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

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

.form-row-two-thirds {
  grid-template-columns: 2fr 1fr;
}

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

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-group.full-width {
  grid-column: 1 / -1;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-group input[type="date"] {
  min-height: 2.5rem;
}

.form-group input,
.form-group select,
.form-group textarea {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  padding: 0.6rem 0.75rem;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  transition: border-color 0.15s;
}

.form-group input::placeholder,
.form-group textarea::placeholder {
  color: var(--text-secondary);
  opacity: 0.7;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.form-group select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b949e' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.25rem;
}

.select-wrapper {
  display: flex;
  gap: 0.35rem;
  align-items: stretch;
}

.select-wrapper select {
  flex: 1;
  min-width: 0;
}

.add-option-btn {
  flex-shrink: 0;
  width: 36px;
  height: 38px;
  padding: 0;
  font-size: 1.1rem;
  font-weight: 500;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}

.add-option-btn:hover {
  background: var(--accent);
  color: var(--bg-primary);
  border-color: var(--accent);
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.btn {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.6rem 1.25rem;
  border-radius: 6px;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: var(--bg-primary);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

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

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

.btn-success {
  background: var(--success);
  color: var(--bg-primary);
  border: 1px solid var(--success);
}

.btn-success:hover {
  background: var(--success-hover);
  border-color: var(--success-hover);
}

.btn-create {
  background: var(--create);
  color: var(--bg-primary);
  border: 1px solid var(--create);
}

.btn-create:hover {
  background: var(--create-hover);
  border-color: var(--create-hover);
}

.btn-danger {
  background: var(--danger);
  color: var(--bg-primary);
  border: 1px solid var(--danger);
}

.btn-danger:hover {
  background: #e03e36;
  border-color: #e03e36;
  color: var(--bg-primary);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}

/* Collapsible sections */
.section-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin: -0.25rem 0 0;
}

.section-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.collapsible .section-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  max-width: max-content;
  padding: 0.25rem 0;
  margin: 0;
  font: inherit;
  color: inherit;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 4px;
  transition: color 0.15s;
}

.collapsible .section-toggle:hover {
  color: var(--accent);
}

.collapsible .section-toggle h2 {
  margin: 0;
}

.section-chevron {
  display: inline-block;
  width: 0.6rem;
  height: 0.6rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transform-origin: center;
  transition: transform 0.2s;
  flex-shrink: 0;
  margin-top: -0.15rem;
}

.collapsible.collapsed .section-chevron {
  transform: rotate(-45deg);
}

.collapsible .section-body {
  overflow: hidden;
  transition: opacity 0.2s;
}

.collapsible.collapsed .section-body {
  display: none;
}

.collapsible .section-header-row + .section-body {
  margin-top: 1rem;
}

.collapsible.collapsed .section-header-row {
  margin-bottom: 0;
}

.search-box input {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  padding: 0.5rem 0.75rem;
  width: 220px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
}

.search-box .filter-input-wrapper {
  display: inline-block;
  width: 220px;
}

.filter-input-wrapper {
  position: relative;
  display: block;
  width: 100%;
}

.filter-input-wrapper .column-filter,
.filter-input-wrapper input[type="search"] {
  width: 100%;
  padding-right: 1.6rem;
  box-sizing: border-box;
}

.filter-clear-btn {
  position: absolute;
  top: 50%;
  right: 0.3rem;
  transform: translateY(-50%);
  width: 1.25rem;
  height: 1.25rem;
  padding: 0;
  border: none;
  border-radius: 3px;
  background: transparent;
  color: var(--text-tertiary);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.filter-clear-btn[hidden] {
  display: none;
}

.filter-clear-btn:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

.search-box input::placeholder {
  color: var(--text-secondary);
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent);
}

.table-wrapper {
  overflow: auto;
  max-height: 70vh;
}

.master-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.master-table th,
.master-table td {
  padding: 0.65rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.master-table th {
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Sticky column header rows when scrolling vertically */
.master-table thead tr:first-child th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 var(--border);
}
.master-table thead tr.filter-row th {
  position: sticky;
  top: 2.5rem;
  z-index: 3;
}

.master-table th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.master-table th.sortable:hover {
  color: var(--accent);
}

.master-table tbody tr:hover {
  background: var(--bg-tertiary);
}

.master-table .price {
  font-family: var(--font-mono);
  font-weight: 500;
}

.master-table .col-date {
  min-width: 7.5rem;
  white-space: nowrap;
}

.master-table .col-type {
  min-width: 8rem;
}

.master-table .col-brand {
  min-width: 10rem;
}

.master-table .col-series {
  min-width: 16rem;
}

.master-table .col-name {
  min-width: 30rem;
}

.master-table .col-actions {
  min-width: 7rem;
  white-space: nowrap;
}

/* Column filter row */
.master-table thead .filter-row th {
  padding: 0.35rem 0.5rem;
  vertical-align: middle;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}
.master-table .column-filter {
  width: 100%;
  min-width: 0;
  padding: 0.35rem 0.5rem;
  font-size: 0.8rem;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.master-table .column-filter::placeholder {
  color: var(--text-tertiary);
}
.master-table .column-filter:focus {
  outline: none;
  border-color: var(--accent);
}
.master-table .filter-placeholder {
  color: var(--text-tertiary);
  font-size: 0.8rem;
}
.master-table thead .filter-row th:nth-child(1),
.master-table thead .filter-row th:nth-child(2),
.master-table thead .filter-row th:nth-child(3),
.master-table thead .filter-row th:nth-child(4) {
  z-index: 2;
}

/* Action column: single button (Product Master, Price History, Trade History) */
#tab-product-master .master-table .col-actions,
#tab-price-entry .master-table .col-actions,
#tab-trade-history .master-table .col-actions {
  min-width: 15rem;
}

/* Same-size Edit + Delete buttons on Products and Prices tables */
#tab-product-master .master-table .col-actions .btn,
#tab-price-entry .master-table .col-actions .btn {
  width: 6rem !important;
  min-width: 6rem !important;
  max-width: 6rem;
  box-sizing: border-box;
  text-align: center;
}

/* Action column: two buttons (e.g. Wishlist: Trade + Delete) */
#tab-wishlist .master-table .col-actions {
  min-width: 15rem;
}

#tab-wishlist .master-table .col-actions .btn {
  min-width: 7.25rem;
}

/* Pinned (sticky) first columns when scrolling horizontally */
/* Product Master: Date, Type, Manufacturer, Brand - fixed widths so left values match */
#tab-product-master .master-table th:nth-child(1),
#tab-product-master .master-table td:nth-child(1) {
  position: sticky;
  left: 0;
  z-index: 1;
  width: 7.5rem;
  min-width: 7.5rem;
  max-width: 7.5rem;
  background: var(--bg-secondary);
}
#tab-product-master .master-table thead th:nth-child(1) { z-index: 3; }
#tab-product-master .master-table th:nth-child(2),
#tab-product-master .master-table td:nth-child(2) {
  position: sticky;
  left: 7.5rem;
  z-index: 1;
  width: 8rem;
  min-width: 8rem;
  max-width: 8rem;
  background: var(--bg-secondary);
}
#tab-product-master .master-table thead th:nth-child(2) { z-index: 3; }
#tab-product-master .master-table th:nth-child(3),
#tab-product-master .master-table td:nth-child(3) {
  position: sticky;
  left: 15.5rem;
  z-index: 1;
  width: 10rem;
  min-width: 10rem;
  max-width: 10rem;
  background: var(--bg-secondary);
}
#tab-product-master .master-table thead th:nth-child(3) { z-index: 3; }
#tab-product-master .master-table th:nth-child(4),
#tab-product-master .master-table td:nth-child(4) {
  position: sticky;
  left: 25.5rem;
  z-index: 1;
  width: 10rem;
  min-width: 10rem;
  max-width: 10rem;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
}
#tab-product-master .master-table thead th:nth-child(4) { z-index: 3; }
#tab-product-master .master-table tbody tr:hover td:nth-child(1),
#tab-product-master .master-table tbody tr:hover td:nth-child(2),
#tab-product-master .master-table tbody tr:hover td:nth-child(3),
#tab-product-master .master-table tbody tr:hover td:nth-child(4) {
  background: var(--bg-tertiary);
}

/* Price History & Trade History: Type, Manufacturer, Brand
   Use fixed widths on pinned columns so sticky left values match and no overlap */
#tab-price-entry .master-table th:nth-child(1),
#tab-price-entry .master-table td:nth-child(1),
#tab-trade-history .master-table th:nth-child(1),
#tab-trade-history .master-table td:nth-child(1) {
  position: sticky;
  left: 0;
  z-index: 1;
  width: 8rem;
  min-width: 8rem;
  max-width: 8rem;
  background: var(--bg-secondary);
}
#tab-price-entry .master-table thead th:nth-child(1),
#tab-trade-history .master-table thead th:nth-child(1) { z-index: 3; }
#tab-price-entry .master-table th:nth-child(2),
#tab-price-entry .master-table td:nth-child(2),
#tab-trade-history .master-table th:nth-child(2),
#tab-trade-history .master-table td:nth-child(2) {
  position: sticky;
  left: 8rem;
  z-index: 1;
  width: 10rem;
  min-width: 10rem;
  max-width: 10rem;
  background: var(--bg-secondary);
}
#tab-price-entry .master-table thead th:nth-child(2),
#tab-trade-history .master-table thead th:nth-child(2) { z-index: 3; }
#tab-price-entry .master-table th:nth-child(3),
#tab-price-entry .master-table td:nth-child(3),
#tab-trade-history .master-table th:nth-child(3),
#tab-trade-history .master-table td:nth-child(3) {
  position: sticky;
  left: 18rem;
  z-index: 1;
  width: 10rem;
  min-width: 10rem;
  max-width: 10rem;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
}
#tab-price-entry .master-table thead th:nth-child(3),
#tab-trade-history .master-table thead th:nth-child(3) { z-index: 3; }
#tab-price-entry .master-table tbody tr:hover td:nth-child(1),
#tab-price-entry .master-table tbody tr:hover td:nth-child(2),
#tab-price-entry .master-table tbody tr:hover td:nth-child(3),
#tab-trade-history .master-table tbody tr:hover td:nth-child(1),
#tab-trade-history .master-table tbody tr:hover td:nth-child(2),
#tab-trade-history .master-table tbody tr:hover td:nth-child(3) {
  background: var(--bg-tertiary);
}

/* Wishlist: Type, Manufacturer, Brand
   Use fixed widths on pinned columns so sticky left values match and no overlap */
#tab-wishlist .master-table th:nth-child(1),
#tab-wishlist .master-table td:nth-child(1) {
  position: sticky;
  left: 0;
  z-index: 1;
  width: 8rem;
  min-width: 8rem;
  max-width: 8rem;
  background: var(--bg-secondary);
}
#tab-wishlist .master-table thead th:nth-child(1) { z-index: 3; }
#tab-wishlist .master-table th:nth-child(2),
#tab-wishlist .master-table td:nth-child(2) {
  position: sticky;
  left: 8rem;
  z-index: 1;
  width: 10rem;
  min-width: 10rem;
  max-width: 10rem;
  background: var(--bg-secondary);
}
#tab-wishlist .master-table thead th:nth-child(2) { z-index: 3; }
#tab-wishlist .master-table th:nth-child(3),
#tab-wishlist .master-table td:nth-child(3) {
  position: sticky;
  left: 18rem;
  z-index: 1;
  width: 10rem;
  min-width: 10rem;
  max-width: 10rem;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
}
#tab-wishlist .master-table thead th:nth-child(3) { z-index: 3; }
#tab-wishlist .master-table tbody tr:hover td:nth-child(1),
#tab-wishlist .master-table tbody tr:hover td:nth-child(2),
#tab-wishlist .master-table tbody tr:hover td:nth-child(3) {
  background: var(--bg-tertiary);
}

.master-table .empty-state {
  text-align: center;
  padding: 2rem;
  color: var(--text-secondary);
}

.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.pagination-info {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

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

.pagination-pages {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.product-combobox {
  position: relative;
}

.product-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 200px;
  overflow-y: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 6px 6px;
  z-index: 10;
  margin-top: -1px;
}

.form-warning {
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  background: rgba(248, 81, 73, 0.15);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  color: var(--danger);
  font-size: 0.9rem;
}

.hidden {
  display: none !important;
}

.product-list.hidden {
  display: none;
}

.product-list-item {
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.product-list-item:last-child {
  border-bottom: none;
}

.product-list-item:hover {
  background: var(--bg-tertiary);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal-overlay.hidden {
  display: none;
}

.price-entry-modal-product,
.wishlist-modal-product {
  margin: 0 0 1rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

#price-entry-modal-overlay .modal .form-group {
  margin-bottom: 1rem;
}

#price-entry-modal-overlay .modal .form-group.checkbox-group {
  flex-direction: row;
  align-items: center;
}

#price-entry-modal-overlay .modal .form-group:last-of-type {
  margin-bottom: 1.25rem;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  min-width: 320px;
}

.modal h3 {
  margin: 0 0 1rem;
  font-size: 1rem;
}

.modal input {
  width: 100%;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  padding: 0.6rem 0.75rem;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  margin-bottom: 1rem;
}

.modal .checkbox-group input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  margin-bottom: 0;
}

.modal input:focus {
  outline: none;
  border-color: var(--accent);
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

.toggles-row {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 1.5rem;
}

.toggle-group {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0.4rem;
}

.checkbox-group {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.checkbox-group input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  cursor: pointer;
  accent-color: var(--accent);
}

.checkbox-group label {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
  cursor: pointer;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 26px;
  transition: 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  height: 20px;
  width: 20px;
  left: 2px;
  bottom: 2px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--accent);
  border-color: var(--accent);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(22px);
  background: var(--bg-primary);
}

body.auth-pending .app,
body.auth-locked .app {
  visibility: hidden;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: var(--bg-primary);
}

.auth-card {
  width: min(100%, 24rem);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.auth-card h2 {
  margin: 0;
}

.auth-card p {
  margin: 0;
  color: var(--text-secondary);
}

.auth-card input {
  font: inherit;
  color: var(--text-primary);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
}

.auth-error {
  color: var(--danger);
}

/* Mobile tools stay out of the desktop spreadsheet. */
.mobile-tools {
  display: none;
}

/*
  Mobile layout is selected in app.js (and the inline script in index.html)
  when the window is 1023px or narrower. Desktop styles above stay in effect
  at 1024px and wider.
*/
html[data-layout="mobile"] {
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
}

html[data-layout="mobile"] body {
  overflow-x: hidden;
}

html[data-layout="mobile"] .app {
  flex-direction: column;
  gap: 0;
  min-height: 100dvh;
  padding: calc(0.65rem + env(safe-area-inset-top)) 0.75rem calc(4.75rem + env(safe-area-inset-bottom));
}

html[data-layout="mobile"] .header {
  margin-bottom: 1rem;
  padding-bottom: 0.85rem;
}

html[data-layout="mobile"] .header h1 {
  font-size: 1.35rem;
}

html[data-layout="mobile"] .subtitle {
  font-size: 0.85rem;
}

html[data-layout="mobile"] .tab-panel {
  gap: 1rem;
}

html[data-layout="mobile"] .form-section,
html[data-layout="mobile"] .master-section {
  padding: 0.9rem;
  scroll-margin-bottom: calc(4.75rem + env(safe-area-inset-bottom));
}

html[data-layout="mobile"] .section-header-row,
html[data-layout="mobile"] .section-header {
  flex-direction: column;
  align-items: stretch;
}

html[data-layout="mobile"] .section-header-actions {
  flex-direction: column;
  align-items: stretch;
  width: 100%;
}

html[data-layout="mobile"] .section-header-row > .btn,
html[data-layout="mobile"] .section-header-actions > .btn {
  width: 100%;
  min-height: 2.75rem;
}

html[data-layout="mobile"] .search-box,
html[data-layout="mobile"] .search-box .filter-input-wrapper,
html[data-layout="mobile"] .search-box input {
  width: 100%;
}

html[data-layout="mobile"] .mobile-tools {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.5rem;
  width: 100%;
}

html[data-layout="mobile"] .mobile-filter-btn {
  min-height: 2.75rem;
  white-space: nowrap;
}

html[data-layout="mobile"] .mobile-filter-btn[aria-expanded="true"],
html[data-layout="mobile"] .mobile-filter-btn.is-active {
  border-color: var(--accent);
  color: var(--accent);
}

html[data-layout="mobile"] .mobile-sort {
  font-family: var(--font-sans);
  font-size: 16px;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  min-height: 2.75rem;
  padding: 0.4rem 2rem 0.4rem 0.7rem;
  width: 100%;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b949e' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
}

html[data-layout="mobile"] input,
html[data-layout="mobile"] select,
html[data-layout="mobile"] textarea {
  font-size: 16px;
}

html[data-layout="mobile"] .form-row,
html[data-layout="mobile"] .form-row-three,
html[data-layout="mobile"] .form-row-two-thirds {
  grid-template-columns: 1fr;
}

html[data-layout="mobile"] .form-group.full-width {
  grid-column: 1;
}

html[data-layout="mobile"] .form-actions {
  flex-direction: column;
  align-items: stretch;
}

html[data-layout="mobile"] .form-actions .btn,
html[data-layout="mobile"] .add-option-btn {
  min-height: 2.75rem;
}

html[data-layout="mobile"] .add-option-btn {
  width: 2.75rem;
  height: 2.75rem;
}

html[data-layout="mobile"] .checkbox-group {
  min-height: 2.75rem;
}

html[data-layout="mobile"] .checkbox-group input[type="checkbox"] {
  width: 1.25rem;
  height: 1.25rem;
}

html[data-layout="mobile"] .nav-panel,
html[data-layout="mobile"] .nav-panel.collapsed {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  width: 100%;
  max-height: none;
  height: auto;
  align-self: stretch;
  border-radius: 0;
  border-left: none;
  border-right: none;
  border-bottom: none;
  box-shadow: 0 -1px 0 var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  transition: transform 0.2s ease;
}

html[data-layout="mobile"] body.input-focused .nav-panel {
  transform: translateY(110%);
}

html[data-layout="mobile"] .nav-panel-toggle {
  display: none;
}

html[data-layout="mobile"] .nav-panel.collapsed .nav-panel-body {
  display: block;
}

html[data-layout="mobile"] .nav-panel-body {
  padding: 0;
  overflow: visible;
}

html[data-layout="mobile"] .tabs {
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 0;
  width: 100%;
}

html[data-layout="mobile"] .tab-btn {
  flex: 1 1 0;
  width: auto;
  min-height: 3.4rem;
  padding: 0.35rem 0.2rem;
  font-size: 0.78rem;
  letter-spacing: 0;
  writing-mode: horizontal-tb;
  text-orientation: mixed;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text-secondary);
}

html[data-layout="mobile"] .tab-btn:hover {
  background: transparent;
  color: var(--text-primary);
}

html[data-layout="mobile"] .tab-btn.active {
  background: transparent;
  color: var(--accent);
  border-color: transparent;
  box-shadow: inset 0 2px 0 var(--accent);
  font-weight: 600;
}

html[data-layout="mobile"] .table-wrapper {
  overflow: visible;
  max-height: none;
}

html[data-layout="mobile"] .master-table,
html[data-layout="mobile"] .master-table thead,
html[data-layout="mobile"] .master-table tbody {
  display: block;
  width: 100%;
}

html[data-layout="mobile"] #tab-product-master .master-table th,
html[data-layout="mobile"] #tab-product-master .master-table td,
html[data-layout="mobile"] #tab-price-entry .master-table th,
html[data-layout="mobile"] #tab-price-entry .master-table td,
html[data-layout="mobile"] #tab-trade-history .master-table th,
html[data-layout="mobile"] #tab-trade-history .master-table td,
html[data-layout="mobile"] #tab-wishlist .master-table th,
html[data-layout="mobile"] #tab-wishlist .master-table td {
  position: static;
  left: auto;
  width: auto;
  min-width: 0;
  max-width: none;
  white-space: normal;
  border-right: none;
  box-shadow: none;
}

html[data-layout="mobile"] .master-section:not(.filters-open) .master-table thead {
  display: none;
}

html[data-layout="mobile"] .master-section.filters-open .master-table thead tr:first-child {
  display: none;
}

html[data-layout="mobile"] .master-section.filters-open .filter-row {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  width: 100%;
  margin: 0 0 0.85rem;
  padding: 0.85rem;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 12px;
}

html[data-layout="mobile"] .master-section.filters-open .filter-row th:not([data-label]) {
  display: none;
}

html[data-layout="mobile"] .master-section.filters-open .filter-row th[data-label] {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.3rem;
  padding: 0;
  background: transparent;
  border: none;
}

html[data-layout="mobile"] .filter-row th[data-label]::before {
  content: attr(data-label);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

html[data-layout="mobile"] .column-filter {
  min-height: 2.75rem;
}

html[data-layout="mobile"] .master-table tbody tr:not(.empty-row) {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  width: 100%;
  margin: 0 0 0.75rem;
  padding: 0.9rem;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 12px;
}

html[data-layout="mobile"] .master-table tbody tr:not(.empty-row):last-child {
  margin-bottom: 0;
}

html[data-layout="mobile"] .master-table tbody td {
  display: block;
  padding: 0;
  border-bottom: none;
  background: transparent !important;
}

html[data-layout="mobile"] .master-table tbody td.mobile-hide {
  display: none !important;
}

html[data-layout="mobile"] .master-table tbody td[data-label]:not([data-label="Name"]) {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
}

html[data-layout="mobile"] .master-table tbody td[data-label]:not([data-label="Name"])::before {
  content: attr(data-label);
  flex: 0 0 38%;
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

html[data-layout="mobile"] .master-table tbody td > span {
  min-width: 0;
  text-align: right;
  overflow-wrap: anywhere;
}

html[data-layout="mobile"] .master-table tbody td[data-label="Name"] {
  order: -2;
  display: block;
  padding-bottom: 0.15rem;
}

html[data-layout="mobile"] .master-table tbody td[data-label="Name"] > span {
  display: block;
  text-align: left;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.35;
}

html[data-layout="mobile"] .master-table tbody td.is-price {
  order: -1;
  padding-bottom: 0.55rem;
  margin-bottom: 0.15rem;
  border-bottom: 1px solid var(--border);
}

html[data-layout="mobile"] .master-table tbody td.is-price > span {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--accent);
}

html[data-layout="mobile"] .master-table tbody td.col-actions {
  order: 1;
  display: flex;
  flex-direction: row;
  gap: 0.5rem;
  margin-top: 0.35rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
}

html[data-layout="mobile"] .master-table tbody td.col-actions::before {
  content: none;
}

html[data-layout="mobile"] #tab-product-master .master-table .col-actions .btn,
html[data-layout="mobile"] #tab-price-entry .master-table .col-actions .btn,
html[data-layout="mobile"] #tab-trade-history .master-table .col-actions .btn,
html[data-layout="mobile"] #tab-wishlist .master-table .col-actions .btn {
  flex: 1 1 0;
  width: auto !important;
  min-width: 0 !important;
  max-width: none !important;
  min-height: 2.75rem;
}

html[data-layout="mobile"] .master-table tr.empty-row {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  background: transparent;
  border: none;
}

html[data-layout="mobile"] .master-table td.empty-state {
  display: block;
  text-align: center;
  padding: 1.25rem 0.5rem;
}

html[data-layout="mobile"] .pagination {
  flex-direction: column;
  align-items: stretch;
}

html[data-layout="mobile"] .pagination-controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0.5rem;
}

html[data-layout="mobile"] .pagination-btn {
  min-height: 2.75rem;
}

html[data-layout="mobile"] .pagination-pages {
  text-align: center;
  align-self: center;
}

html[data-layout="mobile"] .modal {
  width: 100%;
  min-width: 0;
  max-height: calc(100dvh - 2rem);
  overflow: auto;
}

html[data-layout="mobile"] .modal-actions {
  flex-wrap: wrap;
}

html[data-layout="mobile"] .modal-actions .btn {
  flex: 1 1 8rem;
  min-height: 2.75rem;
}
