@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&display=swap');

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

/* Smooth animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Sileent Dark - Warm & Cozy */
:root {
  --bg: #0a0a0a;
  --sidebar-bg: #121212;
  --main-bg: #0e0e0e;
  --surface: #1a1a1a;
  --border: #2a2a2a;
  --border-light: #1f1f1f;
  --accent: #e8e8e8;
  --accent-dim: rgba(232,232,232,0.08);
  --text: #e8e8e8;
  --text-dim: #b4b4b4;
  --text-muted: #6a6a6a;
  --warm-tint: #1c1816;
  --radius: 0px;
  --cell-radius: 2px;
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  font-size: 13px;
  line-height: 1.5;
  letter-spacing: 0.02em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body {
  color: rgba(237, 237, 237, 1);
  background-clip: unset;
  -webkit-background-clip: unset;
}

/* Warm overlay for cozy feel */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, rgba(28,24,22,0.2) 0%, transparent 50%, rgba(28,24,22,0.1) 100%);
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
}

/* â”€â”€ Layout â”€â”€ */
.app {
  display: flex;
  height: 100vh;
}
/* When main is hidden (no range selected), sidebar fills the viewport */
.app.main-hidden .sidebar,
.app:has(.main.no-range) .sidebar {
  flex: 1;
  min-height: 100vh;
}

/* â”€â”€ Sidebar â”€â”€ */
.sidebar {
  width: 400px;
  min-width: 280px;
  max-width: 60vw;
  min-height: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
  transition: width 0.2s, min-width 0.2s;
}
.sidebar.collapsed {
  width: 0;
  min-width: 0;
  border-right: none;
  overflow: visible;
}
.sidebar.collapsed .sidebar-body,
.sidebar.collapsed .resize-handle { display: none; }

.sidebar-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}
.sidebar-body::-webkit-scrollbar { width: 6px; }
.sidebar-body::-webkit-scrollbar-track { background: transparent; }
.sidebar-body::-webkit-scrollbar-thumb {
  background: rgba(232,232,232,0.15);
  border-radius: 3px;
}
.sidebar-body::-webkit-scrollbar-thumb:hover {
  background: rgba(232,232,232,0.25);
}

.show-filters-btn {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 50;
  padding: 8px 14px;
  font-size: 12px;
  font-family: inherit;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  letter-spacing: 0.03em;
  transition: background 0.15s, border-color 0.15s;
}
.show-filters-btn:hover {
  background: rgba(232,232,232,0.08);
  border-color: var(--accent);
}

.resize-handle {
  position: absolute;
  top: 0;
  right: -4px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  z-index: 100;
  background: transparent;
  transition: background 0.15s;
}
.resize-handle:hover, .resize-handle.active {
  background: var(--accent);
}

.matrix-resize-handle {
  position: relative;
  width: 100%;
  height: 8px;
  cursor: row-resize;
  margin: 8px 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.matrix-resize-handle::before {
  content: '';
  width: 60px;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  transition: all 0.15s;
}
.matrix-resize-handle:hover::before,
.matrix-resize-handle.active::before {
  width: 100px;
  background: var(--accent);
}

/* Toolbar: range dropdown trigger + reset + hide (same line, same height) */
.sidebar-toolbar {
  display: flex;
  align-items: stretch;
  gap: 8px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  margin-bottom: 16px;
}
.sidebar-toolbar .range-dropdown-trigger {
  flex: 1;
  min-width: 0;
}
.sidebar-toolbar .reset-btn,
.sidebar-toolbar .sidebar-hide-btn {
  height: 32px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.sidebar-hide-btn {
  padding: 4px 8px;
  font-size: 10px;
  font-family: inherit;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  letter-spacing: 0.05em;
  transition: all 0.15s;
}
.sidebar-hide-btn:hover {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(232,232,232,0.05);
}

.sidebar-header h1 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  margin-bottom: 14px;
  text-transform: lowercase;
}

/* Search */
.search-wrap {
  position: relative;
  margin-top: 36px;
}

.search-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  outline: none;
  transition: all 0.2s ease;
}
.search-input::placeholder {
  color: var(--text-muted);
  letter-spacing: 0.02em;
}
.search-input:focus {
  border-color: var(--accent);
  background: rgba(232,232,232,0.03);
  box-shadow: 0 0 0 1px rgba(232,232,232,0.1);
}

.suggestions {
  position: absolute;
  top: 100%;
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  max-height: 220px;
  overflow-y: auto;
  z-index: 100;
  display: none;
}
.suggestions.open { display: block; }

.suggestion-item {
  padding: 8px 12px;
  font-size: 11px;
  cursor: pointer;
  color: var(--text-dim);
  transition: background 0.1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-bottom: 1px solid var(--border-light);
}
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover, .suggestion-item.active {
  background: rgba(232,232,232,0.08);
  color: var(--text);
  border-left: 2px solid var(--accent);
}
.suggestion-item span { color: var(--text); font-weight: 500; }


.filter-dropdown {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23999'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
.filter-dropdown:focus { border-color: var(--accent); }
.filter-dropdown option { background: var(--surface); color: var(--text); }

.reset-btn {
  padding: 8px 16px;
  font-size: 11px;
  font-family: inherit;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 0;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  flex-shrink: 0;
  letter-spacing: 0.03em;
}
.reset-btn:hover {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(232,232,232,0.05);
}

/* Filters: vertical rows, each with dropdown + selected chips */
.filters-area {
  padding: 0 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow: visible;
  min-height: 0;
}

.filter-rows {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.filter-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.filter-row-selected.filter-row-selected-empty {
  display: none;
}

.filter-row-header {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  font-weight: 500;
  transition: color 0.15s;
}
.filter-row-header:hover {
  color: var(--text-dim);
}

.filter-row-selected {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  min-height: 20px;
}

.filter-chip {
  padding: 5px 8px;
  font-size: 11px;
  font-family: inherit;
  background: transparent;
  border: none;
  border-left: 2px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  text-align: left;
  transition: all 0.1s;
  white-space: nowrap;
}
.filter-chip:hover {
  background: rgba(232,232,232,0.05);
}
.filter-chip.active {
  border-left-color: var(--accent);
  font-weight: 600;
  background: rgba(232,232,232,0.08);
}

.filter-dropdown-menu {
  position: fixed;
  min-width: 140px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  max-height: 200px;
  overflow-y: auto;
  z-index: 500;
  display: none;
}
.filter-dropdown-menu.open { display: block; }

.filter-dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  font-size: 11px;
  cursor: pointer;
  color: var(--text-dim);
  transition: background 0.1s;
  gap: 8px;
}
.filter-dropdown-item:hover {
  background: rgba(0,0,0,0.04);
}
.filter-dropdown-item .item-toggle {
  flex-shrink: 0;
  color: var(--text-muted);
  font-weight: bold;
  font-size: 12px;
  min-width: 14px;
  text-align: center;
}
.filter-dropdown-item:hover .item-toggle { color: var(--accent); }
.filter-dropdown-item.active-filter {
  background: rgba(232,232,232,0.1);
}

/* Range Selector */
.range-selector-wrap {
  flex: 1 0 auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}
.range-selector-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 2px;
}
.range-selector-label {
  font-size: 11px;
}
.range-selector-count {
  color: var(--text-muted);
  font-weight: 300;
  font-size: 11px;
}
.range-selector-filters {
  color: var(--text-muted);
  font-weight: 300;
  font-size: 8px;
  flex: 1;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.range-filters-reset {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 0 4px;
  margin-left: 4px;
  transition: color 0.15s;
  line-height: 1;
}
.range-filters-reset:hover {
  color: var(--accent);
}
.range-browser-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 10px;
  padding: 2px 4px;
  cursor: pointer;
  line-height: 1;
}
.range-browser-toggle:hover { color: var(--text-dim); }
.range-browser-toggle.collapsed { transform: rotate(-90deg); }
.range-browser-new-folder {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 9px;
  padding: 2px 6px;
  cursor: pointer;
  font-family: inherit;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.range-browser-new-folder:hover { color: var(--text-dim); }
.range-browser-content {
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}
.range-selector-wrap.collapsed .range-browser-content {
  display: none;
}
.range-browser-tree {
  padding: 4px 0;
}
.range-browser-node {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px 2px 0;
  font-size: 11px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  min-height: 22px;
}
.range-browser-node:hover { background: rgba(232,232,232,0.06); color: var(--text); }
.range-browser-node.selected { background: rgba(232,232,232,0.08); color: var(--text); }
.range-browser-node.depth-0 { padding-left: 4px; }
.range-browser-node.depth-1 { padding-left: 18px; }
.range-browser-node.depth-2 { padding-left: 32px; }
.range-browser-node.depth-3 { padding-left: 46px; }
.range-browser-node.depth-4 { padding-left: 60px; }
.range-browser-node.depth-5 { padding-left: 74px; }
.range-browser-node .range-browser-toggle-icon {
  flex-shrink: 0;
  width: 12px;
  text-align: center;
  color: var(--text-muted);
  font-size: 8px;
}
.range-browser-node.leaf .range-browser-icon {
  flex-shrink: 0;
  width: 12px;
  color: var(--text-muted);
  font-size: 10px;
}
.range-browser-node .range-browser-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.range-browser-node .range-browser-dot-btn {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.range-browser-node .range-browser-dot-btn:hover {
  color: var(--text);
  background: rgba(255,255,255,0.08);
}
.range-browser-folder-menu {
  position: fixed;
  z-index: 1000;
  min-width: 140px;
  padding: 4px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  font-size: 12px;
}
.range-browser-folder-menu button {
  display: block;
  width: 100%;
  padding: 6px 12px;
  border: none;
  background: none;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
}
.range-browser-folder-menu button:hover:not(:disabled) {
  background: var(--bg-hover);
}
.range-browser-folder-menu button:disabled {
  color: var(--text-muted);
  cursor: default;
}
.range-dropdown-trigger {
  width: 100%;
  height: 32px;
  padding: 0 12px;
  box-sizing: border-box;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
  transition: all 0.1s;
}
.range-dropdown-trigger:hover {
  background: rgba(232,232,232,0.03);
  border-color: var(--accent);
}
.range-dropdown-trigger.has-selection {
  color: var(--text);
}
.range-dropdown-trigger #rangeDropdownLabel {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: rgba(180, 180, 180, 1);
}
.range-dropdown-search {
  flex: 1;
  min-width: 0;
  padding: 0;
  background: transparent;
  border: none;
  color: var(--text);
  font: inherit;
  outline: none;
}
.range-dropdown-search::placeholder {
  color: var(--text-muted);
}
.range-dropdown-arrow {
  font-size: 8px;
  color: var(--text-muted);
  flex-shrink: 0;
  cursor: pointer;
}
.range-dropdown-arrow:hover {
  color: var(--text);
}
.range-dropdown-menu-custom {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  max-height: 400px;
  overflow-y: auto;
  z-index: 500;
  display: none;
}
.sidebar-toolbar .range-dropdown-menu-custom:not(.open) {
  flex: 0 0 0;
  width: 0;
  min-width: 0;
}
.range-dropdown-menu-custom.open {
  display: block;
}
.range-dropdown-search-wrap {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: rgba(232,232,232,0.03);
  position: sticky;
  top: 0;
  z-index: 11;
}
.range-dropdown-search-input {
  width: 100%;
  box-sizing: border-box;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}
.range-dropdown-search-input::placeholder {
  color: var(--text-dim);
}
.range-dropdown-search-input:focus {
  outline: none;
  border-color: var(--accent);
}
.range-dropdown-group-header {
  padding: 10px 12px 6px;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  font-weight: 600;
  background: rgba(232,232,232,0.03);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.range-dropdown-menu-item {
  padding: 8px 12px 8px 24px;
  font-size: 11px;
  cursor: pointer;
  color: var(--text-dim);
  transition: background 0.1s;
  border-bottom: 1px solid var(--border-light);
}
.range-dropdown-menu-item:last-child {
  border-bottom: none;
}
.range-dropdown-menu-item:hover {
  background: rgba(232,232,232,0.05);
  color: var(--text);
}
.range-dropdown-menu-item.selected {
  background: rgba(232,232,232,0.08);
  color: var(--text);
  border-left: 2px solid var(--accent);
}
.range-info-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 12px;
  width: 100%;
  max-width: min(900px, 92vmin);
  margin: 12px auto 0;
  background: rgba(232,232,232,0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 11px;
}
.range-info-subtitle {
  font-size: 11px;
  color: rgba(180, 180, 180, 1);
  font-weight: 400;
}
.range-info-source-select {
  padding: 1px 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 10px;
  cursor: pointer;
  outline: none;
  border-radius: 2px;
}
.range-info-source-select:focus {
  border-color: var(--accent);
  color: var(--text);
}
.range-info-meta-section {
  padding: 8px 0;
  border-top: 1px solid var(--border-light);
}
.range-info-meta-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  font-size: 10px;
  color: var(--text-muted);
}
.range-info-meta-line .meta-label {
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 9px;
}
.range-info-meta-line .meta-value {
  color: var(--text-dim);
}
.range-info-meta-line .meta-separator {
  color: var(--border);
  margin: 0 2px;
}
.range-info-file-section {
  padding: 6px 0;
  border-top: 1px solid var(--border-light);
}
.range-info-file-line {
  font-size: 10px;
  color: var(--text-muted);
  word-break: break-all;
}
.range-info-meta-line select {
  padding: 2px 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 10px;
  cursor: pointer;
  outline: none;
  border-radius: 2px;
}
.range-info-meta-line select:focus {
  border-color: var(--accent);
  color: var(--text);
}
.range-info-notes-section {
  padding: 8px 0;
  border-top: 1px solid var(--border-light);
}
.range-info-notes-toggle {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.range-info-notes-toggle:hover {
  color: var(--text);
}
.range-info-notes-editor {
  margin-top: 8px;
}
.range-info-notes-editor textarea {
  width: 100%;
  min-height: 60px;
  padding: 8px 10px;
  font-size: 11px;
  font-family: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  resize: vertical;
  box-sizing: border-box;
}
.range-info-notes-editor textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.range-info-actions-section {
  padding: 8px 0 0;
  border-top: 1px solid var(--border-light);
}
.range-info-actions-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 8px;
}
.range-info-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
}
.range-info-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
}
.range-info-legend-chip {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
}
.range-info-legend-label {
  color: var(--text);
  flex: 1;
}
.range-info-legend-stat {
  color: var(--text-muted);
  font-size: 10px;
}

/* Old range list CSS removed - now using dropdown */

/* â”€â”€ Main Content â”€â”€ */
.main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--main-bg);
}
.main.no-range {
  display: none;
}
.main.has-range .matrix-wrap {
  animation: matrixSlideOpen 0.35s ease-out;
}
@keyframes matrixSlideOpen {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

.main-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 32px;
}

.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
  letter-spacing: 0.02em;
  font-weight: 400;
  text-transform: lowercase;
}

/* Legend: constrained to matrix width */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  margin-bottom: 28px;
  justify-content: center;
  padding: 12px 0;
  max-width: 100%;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-dim);
  min-width: 0;
}

.legend-chip {
  width: 14px;
  height: 14px;
  border-radius: 2px;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.3);
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.legend-label { font-weight: 500; color: var(--text); font-size: 11px; overflow-wrap: break-word; word-break: break-word; }
.legend-stat { color: var(--text-muted); font-size: 10px; }

/* Matrix */
.matrix-spot-heading {
  width: 100%;
  max-width: min(900px, 92vmin);
  margin: 0 auto 4px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text);
  letter-spacing: 0.3px;
  text-align: center;
}
.matrix-legend {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 2px 10px;
  max-width: min(900px, 92vmin);
  margin: 0 auto 8px;
  font-size: 10px;
  color: var(--text-muted);
}
.matrix-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.matrix-legend-chip {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex-shrink: 0;
}
.matrix-legend-pct {
  opacity: 0.55;
  font-size: 9px;
}
.matrix-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.matrix-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: min(900px, 92vmin);
  min-width: 300px;
  animation: fadeIn 0.4s ease-out;
  position: relative;
}
.matrix-block::-webkit-scrollbar {
  width: 6px;
}
.matrix-block::-webkit-scrollbar-track {
  background: transparent;
}
.matrix-block::-webkit-scrollbar-thumb {
  background: rgba(232,232,232,0.15);
  border-radius: 3px;
}
.matrix-block::-webkit-scrollbar-thumb:hover {
  background: rgba(232,232,232,0.25);
}

.matrix-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
  text-align: center;
  letter-spacing: -0.02em;
  text-transform: lowercase;
}

.matrix {
  display: grid;
  grid-template-columns: repeat(13, 1fr);
  gap: 2px;
  width: 100%;
  aspect-ratio: 1;
  transition: width 0.2s ease;
  padding: 2px;
  background: rgba(0,0,0,0.2);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5), inset 0 0 0 1px rgba(42,42,42,0.8);
}

.cell {
  position: relative;
  border-radius: var(--cell-radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(7px, 1vw, 11px);
  font-weight: 600;
  color: rgba(232,232,232,0.95);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
  overflow: hidden;
  aspect-ratio: 1;
  border: 1px solid rgba(42,42,42,0.4);
}

.cell:hover {
  transform: scale(1.12);
  z-index: 10;
  box-shadow: 0 4px 24px rgba(0,0,0,0.6), 0 0 0 1px rgba(232,232,232,0.1);
  border-color: rgba(232,232,232,0.2);
}

.cell .cell-label {
  position: relative;
  z-index: 2;
  text-shadow: 0 1px 2px rgba(0,0,0,0.35);
  pointer-events: none;
}

/* Info Panel */
.info-panel {
  flex: 0 0 auto;
  width: 200px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 11px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

.info-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  font-size: 11px;
}

.info-meta dt {
  color: var(--text-muted);
  font-size: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
}
.info-meta dd { color: var(--text); margin: 0 0 4px 0; }

.info-hover {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border-light);
  font-size: 11px;
  color: var(--text-dim);
  min-height: 18px;
  width: 100%;
  text-align: center;
}

.info-hover .range-info-legend {
  justify-content: center;
}
.info-hover .hand-name { font-weight: 600; color: var(--text); font-size: 13px; }
.info-hover .hand-action { margin-left: 8px; }
.info-hover .hand-detail { color: var(--text-muted); margin-left: 8px; }
.info-hover .mix-row { margin-top: 4px; display: flex; align-items: center; gap: 6px; justify-content: center; }
.info-hover .mix-chip {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 2px;
  vertical-align: middle;
}

.info-hover .range-notes-section {
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--border-light);
  text-align: left;
}
.info-hover .range-notes-toggle {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.info-hover .range-notes-toggle:hover { color: var(--text); }
.info-hover .range-notes-editor {
  margin-top: 6px;
  display: none;
}
.info-hover .range-notes-editor.visible { display: block; }
.info-hover .range-notes-editor textarea {
  width: 100%;
  min-height: 60px;
  padding: 8px 10px;
  font-size: 11px;
  font-family: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  resize: vertical;
  box-sizing: border-box;
}
.info-hover .range-notes-editor textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.info-hover .range-notes-preview {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  max-height: 36px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.info-hover .cell-notes-ref {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--border-light);
  font-size: 10px;
  color: var(--text-muted);
}
.info-hover .cell-notes-ref-label {
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.info-hover .cell-notes-ref .cell-note-item {
  margin-bottom: 6px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border-light);
}
.info-hover .cell-notes-ref .cell-note-item:last-child {
  margin-bottom: 0;
  border-bottom: none;
}
.info-hover .cell-notes-ref .hand-tag {
  display: inline-block;
  padding: 2px 6px;
  margin-right: 6px;
  background: rgba(0,0,0,0.06);
  border-radius: 2px;
  cursor: pointer;
  color: var(--text-dim);
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.info-hover .cell-notes-ref .hand-tag:hover {
  background: var(--accent-dim);
  color: var(--text);
}
.info-hover .cell-notes-ref .cell-note-text {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Cell popup (on cell click) */
.cell-popup {
  position: fixed;
  z-index: 1100;
  min-width: 220px;
  max-width: 320px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 11px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  pointer-events: auto;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s, visibility 0.15s;
}
.cell-popup.visible {
  opacity: 1;
  visibility: visible;
}
.cell-popup .cell-popup-header {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-light);
}
.cell-popup .cell-popup-meta { font-size: 11px; color: var(--text-dim); margin-bottom: 8px; }
.cell-popup .cell-popup-notes-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.cell-popup .cell-popup-notes {
  width: 100%;
  min-height: 50px;
  padding: 6px 8px;
  font-size: 11px;
  font-family: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  resize: vertical;
  box-sizing: border-box;
}
.cell-popup .cell-popup-notes:focus {
  outline: none;
  border-color: var(--accent);
}
.cell-popup .cell-popup-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 20px;
  height: 20px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
.cell-popup .cell-popup-close:hover { color: var(--text); }

/* Move destination popup (folder / position picker) */
.move-destination-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
}
.move-destination-popup {
  min-width: 260px;
  max-width: 360px;
  max-height: 70vh;
  padding: 12px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.35);
  display: flex;
  flex-direction: column;
}
.move-destination-popup .move-destination-title {
  padding: 0 14px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.move-destination-popup .move-destination-list {
  overflow-y: auto;
  padding: 4px 0;
}
.move-destination-popup .move-destination-item {
  display: block;
  width: 100%;
  padding: 8px 14px;
  border: none;
  background: none;
  color: var(--text);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}
.move-destination-popup .move-destination-item:hover {
  background: var(--bg-hover);
}
.move-destination-popup .move-destination-item:disabled {
  color: var(--text-muted);
  cursor: default;
}

/* Range preview popup (on range item hover) */
.range-preview-popup {
  position: fixed;
  z-index: 1000;
  width: 200px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 11px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s, visibility 0.15s;
}
.range-preview-popup.visible {
  opacity: 1;
  visibility: visible;
}
.range-preview-popup .info-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  font-size: 11px;
}
.range-preview-popup .info-meta dt {
  color: var(--text-muted);
  font-size: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
}
.range-preview-popup .info-meta dd { color: var(--text); margin: 0 0 4px 0; }

/* Scrollbar global - subtle dark */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(232,232,232,0.15);
  border-radius: 2px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(232,232,232,0.25);
}

/* â”€â”€ Mobile responsive (< 768px) â”€â”€ */
@media (max-width: 767px) {
  html, body { overflow: auto; }
  .app {
    flex-direction: column;
    min-height: 100vh;
    height: auto;
  }
  .sidebar {
    width: 100%;
    min-width: 0;
    max-width: none;
    max-height: 42vh;
    flex-shrink: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar.collapsed {
    max-height: 0;
    min-height: 0;
    overflow: hidden;
    border-bottom: none;
  }
  .resize-handle { display: none; }
  .matrix-resize-handle { display: none; }
  .main {
    flex: 1;
    min-height: 60vh;
  }
  .matrix-block {
    height: auto !important;
    max-height: 90vh;
  }
  .main-scroll {
    padding: 12px 16px 24px;
    justify-content: flex-start;
  }
  .matrix-block {
    max-width: 100%;
  }
  .matrix-title { font-size: 16px; }
  .legend { gap: 8px 12px; margin-bottom: 16px; }
  .legend-item { font-size: 10px; }
  .legend-chip { width: 12px; height: 12px; }
  .legend-label { font-size: 10px; }
  .filter-columns {
    grid-template-columns: 1fr 1fr;
    gap: 0;
  }
  .filter-col { padding: 8px 12px; }
  .sidebar-toolbar { padding: 10px 12px; }
  
  /* Full-screen dropdowns on mobile */
  .filter-dropdown-menu.open,
  .range-dropdown-menu-custom.open {
    position: fixed !important;
    left: 0 !important;
    top: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    min-width: 0 !important;
    z-index: 9999;
    padding-top: 32px;
  }
  
  /* Close button for mobile dropdowns */
  .filter-dropdown-menu.open::before,
  .range-dropdown-menu-custom.open::before {
    content: '×';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 32px;
    background: transparent;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 16px;
    font-size: 24px;
    font-weight: 300;
    color: var(--text-muted);
    cursor: pointer;
    z-index: 10000;
    transition: color 0.15s;
  }
  .filter-dropdown-menu.open::before:hover,
  .range-dropdown-menu-custom.open::before:hover {
    color: var(--text);
  }
  .range-info-panel {
    margin-top: 8px;
    padding: 12px 10px;
  }
}