:root {
  color-scheme: light;
  --bg: #f8f9fa;
  --sheet: #ffffff;
  --sheet-2: #f1f3f4;
  --sheet-3: #e8eaed;
  --ink: #202124;
  --muted: #5f6368;
  --line: #dadce0;
  --accent: #1a73e8;
  --accent-soft: rgba(26, 115, 232, 0.12);
  --mark: #fff59d;
  --selected: #e8f0fe;
  --shadow: 0 1px 3px rgba(60, 64, 67, 0.18), 0 4px 12px rgba(60, 64, 67, 0.12);
  --radius: 12px;
  --font: "Arial", "Helvetica Neue", sans-serif;
  --table-scale: 0.85;
  --inventory-drawer-width: 420px;
  --catalog-drawer-width: 420px;
}

body.dark-theme {
  color-scheme: dark;
  --bg: #202124;
  --sheet: #2b2c2f;
  --sheet-2: #303134;
  --sheet-3: #3c4043;
  --ink: #e8eaed;
  --muted: #bdc1c6;
  --line: #5f6368;
  --accent: #8ab4f8;
  --accent-soft: rgba(138, 180, 248, 0.16);
  --mark: rgba(255, 241, 118, 0.32);
  --selected: rgba(138, 180, 248, 0.16);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
}

button, input, select { font: inherit; }

.app-shell {
  min-height: 100vh;
  padding: 16px;
}

.topbar,
.filters-panel,
.table-section,
.drawer {
  background: var(--sheet);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius);
}

.eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 4px;
}

h1, h2, p { margin: 0; }
h1 { font-size: 24px; font-weight: 600; }

.topbar-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.zoom-control {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.session-control,
.session-check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.session-control input {
  width: 84px;
  border: 1px solid var(--line);
  background: var(--sheet);
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 10px;
}

.zoom-control input[type="range"] { width: 110px; }

.ghost-btn,
.primary-btn {
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 8px 12px;
  cursor: pointer;
  background: var(--sheet);
  color: var(--ink);
}

.primary-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.ping-btn {
  min-width: 76px;
  height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--sheet-2);
  color: var(--ink);
  cursor: pointer;
  font-weight: 600;
}

.ping-btn:disabled {
  opacity: 0.7;
  cursor: wait;
}

.ping-btn.is-good {
  background: #d7f8dd;
  border-color: #4caf50;
  color: #166534;
}

.ping-btn.is-warn {
  background: #fff3cd;
  border-color: #f0ad4e;
  color: #8a5300;
}

.ping-btn.is-bad {
  background: #fde2e1;
  border-color: #d93025;
  color: #a50e0e;
}

body.dark-theme .ping-btn {
  background: var(--sheet-3);
  color: var(--ink);
}

body.dark-theme .ping-btn.is-good {
  background: rgba(52, 168, 83, 0.2);
  color: #9ef0ae;
}

body.dark-theme .ping-btn.is-warn {
  background: rgba(251, 188, 5, 0.2);
  color: #ffd86b;
}

body.dark-theme .ping-btn.is-bad {
  background: rgba(217, 48, 37, 0.2);
  color: #ff9b94;
}

body.dark-theme .primary-btn { color: #202124; }

.primary-btn.is-active {
  background: #c58b00;
  border-color: #c58b00;
}

.filters-panel {
  margin-top: 12px;
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}

.sheet-tabs {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 10px;
  padding: 6px 0 0;
  overflow: auto;
}

.mode-tabs {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.mode-tab {
  border: 1px solid var(--line);
  background: var(--sheet);
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
}

.mode-tab.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

body.dark-theme .mode-tab.is-active {
  color: #202124;
}

.sheet-tab {
  border: 1px solid var(--line);
  background: var(--sheet);
  color: var(--muted);
  border-radius: 10px 10px 0 0;
  padding: 9px 14px;
  cursor: pointer;
  white-space: nowrap;
}

.sheet-tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--sheet);
  box-shadow: inset 0 -2px 0 var(--sheet), 0 -1px 0 var(--line), 1px 0 0 var(--line), -1px 0 0 var(--line);
}

.filter {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.filter.wide { grid-column: span 2; }
.filter-actions { justify-content: flex-end; }

.filter span {
  font-size: 12px;
  color: var(--muted);
}

.inline-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 40px;
}

.inline-actions-wrap {
  flex-wrap: wrap;
}

.filter input,
.filter select,
.multi-select summary {
  border: 1px solid var(--line);
  background: var(--sheet);
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
}

.checkbox-filter {
  position: relative;
}

.multi-select {
  position: relative;
}

.multi-select summary {
  list-style: none;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.multi-select[open] summary {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.multi-select summary::-webkit-details-marker {
  display: none;
}

.checkbox-list {
  position: absolute;
  z-index: 20;
  top: calc(100% - 1px);
  left: 0;
  right: 0;
  max-height: 240px;
  overflow: auto;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-top: 0;
  border-bottom-left-radius: 8px;
  border-bottom-right-radius: 8px;
  box-shadow: var(--shadow);
  padding: 8px;
  display: grid;
  gap: 6px;
}

.checkbox-item {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 13px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 10px minmax(320px, var(--inventory-drawer-width));
  gap: 12px;
  margin-top: 12px;
  min-height: calc(100vh - 220px);
}

.catalogs-view {
  margin-top: 12px;
}

.office-view {
  margin-top: 12px;
}

.office-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.office-panel {
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.office-panel-wide {
  grid-column: 1 / -1;
}

.office-list {
  display: grid;
  gap: 8px;
  padding: 12px;
  max-height: 42vh;
  overflow: auto;
}

.office-card {
  border: 1px solid var(--line);
  background: var(--sheet-2);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 10px;
}

.office-card-main {
  display: grid;
  gap: 4px;
}

.office-card-main span,
.office-log-row,
.office-empty {
  color: var(--muted);
  font-size: 13px;
}

.office-log-row {
  border: 1px solid var(--line);
  background: var(--sheet-2);
  border-radius: 10px;
  padding: 10px 12px;
}

.office-note-body {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  white-space: normal;
  word-break: break-word;
}

.catalogs-shell {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 12px;
}

.catalogs-sidebar,
.catalogs-main {
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.catalogs-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.catalog-list {
  display: grid;
  gap: 8px;
  padding: 12px;
  max-height: calc(100vh - 250px);
  overflow: auto;
}

.catalog-card,
.catalog-entry {
  border: 1px solid var(--line);
  background: var(--sheet-2);
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
}

.catalog-entry-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.catalog-entry-top {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.catalog-entry-check {
  margin: 2px 0 0;
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.catalog-mini-btn {
  border: 1px solid var(--line);
  background: var(--sheet);
  color: var(--ink);
  border-radius: 8px;
  padding: 5px 9px;
  cursor: pointer;
  font-size: 12px;
}

.catalog-card.is-active,
.catalog-entry.is-active,
.catalog-entry:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.catalog-entry.is-selected-bulk {
  background: var(--mark);
  border-color: #f9ab00;
}

body.dark-theme .catalog-entry.is-selected-bulk {
  background: rgba(255, 241, 118, 0.22);
  border-color: #fbc02d;
}

.catalog-card strong,
.catalog-entry strong,
.catalog-current-title {
  display: block;
  font-size: 16px;
}

.catalog-card .muted,
.catalog-entry .muted {
  margin-top: 4px;
  font-size: 13px;
}

.catalog-breadcrumbs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 16px 0;
}

.catalog-meta {
  margin: 12px 16px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--sheet-2);
  display: grid;
  gap: 8px;
}

.catalog-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.catalog-crumb {
  border: 1px solid var(--line);
  background: var(--sheet-2);
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 13px;
}

.catalog-view {
  display: grid;
  gap: 10px;
  padding: 16px;
  align-content: start;
  align-items: start;
}

.catalog-content-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 10px minmax(320px, var(--catalog-drawer-width));
  gap: 12px;
  padding: 16px;
}

.drawer-resizer {
  position: relative;
  width: 10px;
  cursor: col-resize;
  align-self: stretch;
}

.drawer-resizer::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: linear-gradient(to right, transparent 30%, var(--line) 30%, var(--line) 70%, transparent 70%);
  opacity: 0.65;
}

.drawer-resizer:hover::before,
.drawer-resizer.is-dragging::before {
  background: linear-gradient(to right, transparent 20%, var(--accent) 20%, var(--accent) 80%, transparent 80%);
  opacity: 1;
}

.catalog-drawer {
  min-height: 540px;
}

.catalog-view-empty {
  padding: 18px 16px;
  color: var(--muted);
}

.catalog-grid {
  display: grid;
  gap: 10px;
  align-content: start;
  align-items: start;
  grid-auto-rows: min-content;
}

.table-section,
.drawer {
  border-radius: var(--radius);
  overflow: hidden;
}

.table-section {
  display: flex;
  flex-direction: column;
}

.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--sheet);
}

.stats-line,
#pageLabel {
  color: var(--muted);
  font-size: 13px;
}

.paging {
  display: flex;
  align-items: center;
  gap: 8px;
}

.table-wrap {
  overflow: auto;
  background: var(--sheet-2);
}

.table-scaler {
  transform: scale(var(--table-scale));
  transform-origin: top left;
  width: calc(100% / var(--table-scale));
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  background: var(--sheet);
}

.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--sheet-2);
  padding: 8px 6px;
  border: 1px solid var(--line);
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.data-table thead th[data-sort] { cursor: pointer; }
.data-table thead th.is-sorted {
  color: var(--accent);
}

.data-table tbody td {
  padding: 6px 6px;
  border: 1px solid var(--line);
  vertical-align: top;
  font-size: 12px;
  line-height: 1.25;
  word-break: break-word;
}

.data-table tbody tr {
  background: var(--sheet);
  cursor: pointer;
}

.data-table tbody tr:hover { background: var(--accent-soft); }
.data-table tbody tr.is-selected { background: var(--selected); }
.data-table tbody tr.is-marked { background: var(--mark); }

.number-cell { font-weight: 700; }
.muted { color: var(--muted); }

.bool-badge,
.status-pill,
.photo-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  padding: 3px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--sheet-2);
  font-size: 11px;
}

.bool-badge.is-yes {
  background: #d7f7d4;
  border-color: #9cd59b;
  color: #137333;
}

body.dark-theme .bool-badge.is-yes {
  background: rgba(19, 115, 51, 0.25);
  color: #9ee6a8;
  border-color: rgba(158, 230, 168, 0.25);
}

.drawer {
  display: flex;
  flex-direction: column;
}

.drawer-empty,
.drawer-content {
  padding: 16px;
}

.drawer-empty {
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.drawer-content {
  display: grid;
  gap: 14px;
  overflow: auto;
}

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

.detail-number {
  font-size: 24px;
  font-weight: 700;
}

.detail-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.detail-nav {
  display: flex;
  gap: 8px;
}

.detail-nav .ghost-btn {
  flex: 1;
}

.meta-card {
  background: var(--sheet-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

.meta-card span {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
}

.meta-card .meta-subline {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
}

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

.photo-grid a {
  display: block;
  overflow: hidden;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--sheet-2);
  aspect-ratio: 4 / 3;
}

.photo-grid img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

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

.empty-photos {
  padding: 14px;
  border-radius: 10px;
  background: var(--sheet-2);
  border: 1px dashed var(--line);
  color: var(--muted);
}

.lightbox[hidden] {
  display: none;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(16, 18, 22, 0.88);
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 72px;
  align-items: center;
  padding: 28px;
}

.lightbox-figure {
  margin: 0;
  display: grid;
  gap: 12px;
  width: 100%;
  min-height: 82vh;
  align-content: center;
  justify-items: center;
}

.lightbox img {
  max-width: min(92vw, 1500px);
  max-height: 82vh;
  display: block;
  justify-self: center;
  border-radius: 12px;
  object-fit: contain;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  transform-origin: top left;
  will-change: transform;
  cursor: zoom-in;
}

.lightbox figcaption {
  color: #fff;
  font-size: 14px;
}

.lightbox-nav,
.lightbox-close {
  border: 0;
  cursor: pointer;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
}

.lightbox-nav {
  width: 52px;
  height: 52px;
  border-radius: 999px;
  justify-self: center;
  font-size: 20px;
}

.lightbox-close {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  font-size: 18px;
}

.loading-overlay[hidden] {
  display: none;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  background: rgba(248, 249, 250, 0.82);
  backdrop-filter: blur(4px);
}

body.dark-theme .loading-overlay {
  background: rgba(32, 33, 36, 0.82);
}

.settings-modal[hidden] {
  display: none;
}

.settings-modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 18px;
}

.settings-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(32, 33, 36, 0.46);
}

.settings-modal-card {
  position: relative;
  width: min(720px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow: auto;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 18px;
  display: grid;
  gap: 16px;
}

.settings-modal-header,
.settings-modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.settings-field,
.settings-check {
  display: grid;
  gap: 8px;
  padding: 12px;
  background: var(--sheet-2);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.settings-field span,
.settings-check span {
  font-size: 12px;
  color: var(--muted);
}

.settings-field input,
.settings-field select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--sheet);
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 10px;
}

.settings-check {
  grid-template-columns: 18px 1fr;
  align-items: center;
}

.settings-check span {
  font-size: 14px;
  color: var(--ink);
}

.settings-field-wide {
  grid-column: 1 / -1;
}

@media (max-width: 760px) {
  .settings-form-grid {
    grid-template-columns: 1fr;
  }
}

.loading-card {
  min-width: 280px;
  padding: 22px 24px;
  border-radius: 18px;
  background: var(--sheet);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  display: grid;
  justify-items: center;
  gap: 14px;
}

.loading-spinner {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 4px solid var(--sheet-3);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

.loading-text {
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
  text-align: center;
}

.task-notifications {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 140;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 24px));
  pointer-events: none;
}

.task-notice {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--sheet) 94%, transparent);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 180ms ease, transform 180ms ease;
  backdrop-filter: blur(8px);
}

.task-notice.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.task-notice.is-leaving {
  opacity: 0;
  transform: translateY(-8px);
}

.task-notice-spinner {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 2px solid var(--sheet-3);
  border-top-color: var(--accent);
  animation: spin 0.85s linear infinite;
  margin-top: 1px;
}

.task-notice-text {
  min-width: 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.35;
  font-weight: 600;
}

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

@media (max-width: 1500px) {
  .filters-panel { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 1100px) {
  .workspace,
  .catalogs-shell,
  .office-grid { grid-template-columns: 1fr; }
  .catalog-content-shell { grid-template-columns: 1fr; }
  .drawer-resizer { display: none; }
  .drawer { min-height: 500px; }
}

@media (max-width: 720px) {
  .app-shell { padding: 10px; }
  .topbar { flex-direction: column; align-items: stretch; }
  .filters-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter.wide { grid-column: span 2; }
  .detail-meta,
  .photo-grid { grid-template-columns: 1fr; }
  .lightbox {
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    padding: 14px;
  }
}
