/* Materials Catalog — styles (modularized)
   Keeps UI compact with popover filters and a clean table + modal. */

:root {
  --bg: #fff;
  --fg: #222;
  --muted: #666;
  --border: #e5e5e5;
  --accent: #0a7cff;
  --shadow: 0 8px 24px rgba(0,0,0,0.12);
}

html { height: 100%; touch-action: pan-y; overscroll-behavior-x: none; }
body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, sans-serif;
  margin: 24px; color: var(--fg); background: var(--bg);
  display: flex; flex-direction: column; align-items: flex-start;
  height: calc(100vh - 48px);
  overflow-x: hidden; /* Prevent horizontal body scroll */
  overscroll-behavior-x: none; /* Prevent horizontal overscroll gestures */
}
.table-wrapper {
  overflow-x: visible; /* let Tabulator holder manage horizontal scroll */
  flex: 1;
  min-height: 0; /* allow flex child (#table) to shrink so inner scroll works */
  border: 1px solid var(--border); border-radius: 10px; margin-bottom: 12px;
  width: 100%;
  touch-action: pan-x pan-y; /* allow both horizontal and vertical pan inside table area */
}
#table {
  height: 100%; /* so Tabulator height: '100%' has a reference */
  /* width controlled by Tabulator; allow inner holder to overflow */
}
h1 { font-size: 22px; margin: 0 0 8px; }
.sub { color: var(--muted); font-size: 13px; margin-bottom: 12px; }

/* Compact toolbar */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  border: 1px solid var(--border); border-radius: 10px; padding: 8px; margin-bottom: 12px; background: #fff;
}
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: #222; cursor: pointer; font-size: 13px;
}
.btn.active { border-color: var(--accent); color: var(--accent); }
.badge { background: #eef3ff; color: #2257d5; border-radius: 999px; padding: 0 6px; font-size: 11px; }
.divider { width: 1px; height: 28px; background: var(--border); margin: 0 4px; }

.search {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; background: #fff;
}
.search input {
  border: 0; outline: 0; font-size: 13px; width: 220px;
}

/* Branding */
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.logo { height: 36px; width: auto; display: block; }

/* Indicators */
.plus { color: #2257d5; font-weight: 700; margin-left: 6px; cursor: pointer; }
.thumb-wrap .swatch { box-shadow: 0 0 0 2px #fff, 0 0 0 3px rgba(0,0,0,.07); }

/* Align label size with selector buttons */
.toolbar label { font-size: 13px; color: var(--fg); }

/* Popover panels */
.panel {
  position: absolute; z-index: 10000; display: none;
  min-width: 240px; max-height: 320px; overflow: auto;
  background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
  padding: 8px;
}
.panel .row { display: grid; grid-template-columns: 18px 1fr; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 6px; }
.panel .row:hover { background: #f7faff; }
.panel h4 { margin: 6px 6px 8px; font-size: 12px; color: #777; text-transform: uppercase; letter-spacing: .04em; }

.footer { margin-top: 10px; font-size: 12px; color: var(--muted); }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: none; align-items: center; justify-content: center; z-index: 9999; }
.modal { background: #fff; max-width: 1100px; width: calc(100% - 32px); border-radius: 12px; overflow: hidden; box-shadow: 0 16px 40px rgba(0,0,0,0.25); }
.modal header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.modal header h2 { font-size: 18px; margin: 0; }
.modal .content { display: grid; grid-template-columns: 340px 1fr; gap: 16px; padding: 16px; }
.modal img { width: 100%; height: auto; border: 1px solid var(--border); border-radius: 8px; background: #fafafa; }
.close-btn { border: 0; background: #eee; border-radius: 8px; padding: 8px 12px; cursor: pointer; }
.chip { display: inline-block; padding: 2px 8px; border: 1px solid var(--border); border-radius: 999px; font-size: 12px; color: #444; margin: 0 6px 6px 0; background: #fff; }

table.variants { width: 100%; border-collapse: collapse; }
table.variants th, table.variants td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); font-size: 14px; }
table.variants th { background: #fafafa; }

/* Tabulator tweaks */
.thumb { width: 60px; height: 60px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); background: #fafafa; }
.tabulator-header .tabulator-col { font-weight: 600; }
.tabulator-row:hover { background-color: #f9fbff; }

/* Ensure horizontal scrolling is confined to the Tabulator holder on touch devices */
.tabulator { touch-action: pan-x pan-y; }
.tabulator .tabulator-tableholder {
  overflow-x: auto !important;
  overflow-y: auto; /* allow vertical scroll within table */
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
}
.tabulator .tabulator-col-resize-handle {
  display: none !important;
  width: 0 !important;
}

@media (max-width: 900px) {
  .search input { width: 120px; }
  .modal .content { grid-template-columns: 1fr; }
}

/* Tabulator responsive collapse styling for mobile readability */
.tabulator .tabulator-responsive-collapse {
  background: #fafafa;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
}
.tabulator .tabulator-responsive-collapse .tabulator-responsive-collapse-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 4px 8px;
  align-items: baseline;
  padding: 2px 0;
}
.tabulator .tabulator-responsive-collapse .tabulator-responsive-collapse-label {
  color: var(--muted);
  font-size: 12px;
}
.tabulator .tabulator-responsive-collapse .tabulator-responsive-collapse-value {
  color: var(--fg);
  font-size: 13px;
}

@media (max-width: 600px) {
  body { margin: 12px; }
  .thumb { width: 52px; height: 52px; }
  .btn { padding: 5px 8px; }
}
