/* ============================================================
   DESIGN TOKENS — Light mode (default)
   ============================================================ */
:root {
  --bg-page:       #f6f8fa;
  --bg-surface:    #ffffff;
  --bg-raised:     #f6f8fa;
  --bg-th:         #f0f3f7;
  --bg-frozen:     #ffffff;
  --bg-frozen-th:  #f0f3f7;
  --bg-hover:      rgba(59, 130, 246, 0.04);

  --text-primary:   #24292f;
  --text-secondary: #57606a;
  --text-muted:     #8c959f;
  --text-on-accent: #ffffff;

  --border:        #d0d7de;
  --border-strong: #bbc1c8;

  --accent:       #0969da;
  --accent-hover: #0550ae;

  --danger:       #cf222e;
  --danger-hover: #a40e26;

  --success:      #1a7f37;

  /* Status cells — subtle, readable */
  --cell-green-bg:  #dafbe1;
  --cell-green-fg:  #116329;
  --cell-blue-bg:   #ddf4ff;
  --cell-blue-fg:   #0550ae;
  --cell-red-bg:    #ffebe9;
  --cell-red-fg:    #82071e;

  --radius:    8px;
  --radius-sm: 5px;
  --shadow:    0 1px 3px rgba(31,35,40,.12);
  --shadow-md: 0 3px 6px rgba(140,149,159,.15);
  --transition: 0.18s ease;
}

/* ============================================================
   DARK MODE
   ============================================================ */
[data-theme="dark"] {
  --bg-page:       #0d1117;
  --bg-surface:    #161b22;
  --bg-raised:     #21262d;
  --bg-th:         #0d1117;
  --bg-frozen:     #161b22;
  --bg-frozen-th:  #0d1117;
  --bg-hover:      rgba(99, 155, 255, 0.07);

  --text-primary:   #e6edf3;
  --text-secondary: #8b949e;
  --text-muted:     #6e7681;

  --border:        #30363d;
  --border-strong: #3d444d;

  --accent:       #58a6ff;
  --accent-hover: #79b8ff;

  --danger:       #f85149;
  --danger-hover: #ff7b72;

  --success:      #3fb950;

  --cell-green-bg:  #0a2516;
  --cell-green-fg:  #3fb950;
  --cell-blue-bg:   #051937;
  --cell-blue-fg:   #58a6ff;
  --cell-red-bg:    #280d0b;
  --cell-red-fg:    #f85149;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.5;
  transition: background-color var(--transition), color var(--transition);
  min-height: 100vh;
}

/* ============================================================
   HEADER
   ============================================================ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 52px;
  background: #0d1117;
  border-bottom: 1px solid #30363d;
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #e6edf3;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-decoration: none;
}

.brand-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: 6px;
  color: white;
  font-size: 14px;
}

.brand-name {
  color: #e6edf3;
}

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: transparent;
  border: 1px solid #30363d;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 16px;
  color: #8b949e;
  transition: border-color var(--transition), background var(--transition), color var(--transition);
  flex-shrink: 0;
}

.theme-toggle:hover {
  background: #21262d;
  border-color: #3d444d;
  color: #e6edf3;
}

/* ============================================================
   CONTAINER
   ============================================================ */
.container {
  max-width: 100%;
  padding: 20px 24px;
}

/* ============================================================
   TOOLBAR
   ============================================================ */
.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  transition: background var(--transition), border-color var(--transition);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.toolbar-sep {
  width: 1px;
  height: 24px;
  background: var(--border);
  flex-shrink: 0;
  margin: 0 4px;
}

.hidden {
  display: none !important;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition);
  white-space: nowrap;
  line-height: 1.4;
  font-family: inherit;
}

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

.btn-ghost {
  background: var(--bg-surface);
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn-ghost:hover {
  background: var(--bg-raised);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.view-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text-on-accent);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: transparent;
  padding: 4px 8px;
  font-size: 12px;
}
.btn-danger:hover {
  background: var(--cell-red-bg);
  border-color: var(--cell-red-fg);
}

/* Botão somente ícone */
.icon-btn {
  padding: 6px 8px;
  min-width: 32px;
  justify-content: center;
}

/* Label estilizada como botão (esconde o file input interno) */
label.btn input[type="file"] {
  display: none;
}

/* Split button: Exportar + seletor de formato lado a lado */
.export-group {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color var(--transition);
}

.export-group:hover {
  border-color: var(--border-strong);
}

.export-group .btn {
  border: none;
  border-right: 1px solid var(--border);
  border-radius: 0;
  transition: background var(--transition), color var(--transition);
}

.export-group .btn:hover {
  border-right-color: var(--border);
}

.export-type-select {
  padding: 0 6px 0 4px;
  background: var(--bg-surface);
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: background var(--transition), color var(--transition);
  -webkit-appearance: auto;
  appearance: auto;
}

.export-type-select:hover {
  background: var(--bg-raised);
  color: var(--text-primary);
}

/* ============================================================
   FILE INPUT CUSTOM
   ============================================================ */
.file-label {
  cursor: pointer;
}

.file-label input[type="file"] {
  display: none;
}

.file-name {
  font-size: 12px;
  color: var(--text-muted);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================================
   TOGGLE SWITCH (auto-sync)
   ============================================================ */
.sync-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  user-select: none;
  transition: color var(--transition);
}
.sync-label:hover {
  color: var(--text-primary);
}

.toggle-input {
  display: none;
}

.toggle-track {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  background: var(--border-strong);
  border-radius: 10px;
  transition: background var(--transition);
  flex-shrink: 0;
}

.toggle-track::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  background: white;
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: transform var(--transition);
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
}

.toggle-input:checked ~ .toggle-track {
  background: var(--success);
}

.toggle-input:checked ~ .toggle-track::after {
  transform: translateX(16px);
}

.sync-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  display: none;
  animation: pulse 1.4s infinite;
}

.sync-dot.active {
  display: inline-block;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ============================================================
   ADD COLUMN FORM
   ============================================================ */
.add-col-form {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.add-col-form input {
  width: 100px;
}

/* Remove seta nativa do browser em inputs com datalist */
input[list]::-webkit-calendar-picker-indicator {
  opacity: 0;
  pointer-events: none;
}

/* ============================================================
   INPUTS (toolbar / general)
   ============================================================ */
input[type="text"] {
  padding: 5px 9px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}

input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(9, 105, 218, 0.1);
}

[data-theme="dark"] input[type="text"]:focus {
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.12);
}

input[type="text"]::placeholder {
  color: var(--text-muted);
}

/* ============================================================
   COMPACT MATRIX
   ============================================================ */
.compact-matrix {
  margin-bottom: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: background var(--transition), border-color var(--transition);
}

.matrix-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
}

.matrix-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.matrix-title span {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}

.matrix-title small {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.matrix-legend {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 11px;
}

.matrix-legend span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.matrix-dot {
  width: 9px;
  height: 9px;
  display: inline-block;
  border-radius: 2px;
  border: 1px solid var(--border);
}

.matrix-scroll {
  max-height: 260px;
  overflow: auto;
  scrollbar-width: thin;
}

.matrix-grid {
  display: grid;
  width: max-content;
  min-width: 100%;
  background: var(--border);
  gap: 1px;
}

.matrix-corner,
.matrix-col,
.matrix-row-label,
.matrix-cell {
  background: var(--bg-surface);
}

.matrix-corner {
  position: sticky;
  left: 0;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: flex-end;
  height: 86px;
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  background: var(--bg-th);
}

.matrix-col {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  height: 86px;
  padding: 5px 0;
  background: var(--bg-th);
}

.matrix-col span {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  max-height: 76px;
  max-width: 18px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
}

.matrix-row-label {
  position: sticky;
  left: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  height: 22px;
  padding: 0 8px;
  background: var(--bg-frozen);
}

.matrix-robot {
  width: 42px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.matrix-group {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  color: var(--text-muted);
}

.matrix-cell {
  width: 20px;
  height: 22px;
  border: 1px solid transparent;
}

.matrix-cell--green {
  background: var(--cell-green-bg);
  border-color: var(--cell-green-fg);
}

.matrix-cell--blue {
  background: var(--cell-blue-bg);
  border-color: var(--cell-blue-fg);
}

.matrix-cell--red {
  background: var(--cell-red-bg);
  border-color: var(--cell-red-fg);
}

.matrix-cell--neutral {
  background: var(--bg-raised);
  border-color: var(--border-strong);
}

.matrix-cell--empty {
  background:
    linear-gradient(135deg, transparent 0 42%, var(--border) 43% 57%, transparent 58% 100%),
    var(--bg-surface);
  border-color: var(--border);
}

.matrix-cell:hover {
  filter: brightness(0.95);
}

/* ============================================================
   TABLE WRAPPER
   ============================================================ */
.table-wrapper {
  overflow: auto;
  max-height: calc(100vh - 200px);
  position: relative;
  margin-bottom: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: var(--bg-surface);
  transition: border-color var(--transition);
}

/* ============================================================
   TABLE
   ============================================================ */
table {
  border-collapse: collapse;
  table-layout: fixed;
  width: max-content;
  min-width: 100%;
}

/* --- Header row --- */
thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-th);
  border-bottom: 2px solid var(--border-strong);
  border-right: 1px solid var(--border);
  padding: 0;
  vertical-align: top;
  transition: background var(--transition), border-color var(--transition);
}

/* --- Body cells --- */
tbody td {
  position: relative;
  z-index: 0;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 0;
  transition: background var(--transition), border-color var(--transition);
}

tbody tr:last-child td {
  border-bottom: none;
}

/* ================================
   🔥 HOVER → LINHA EM NEGRITO
================================ */
tbody tr:hover td {
  background: var(--bg-hover);
}
/* ================================
   🎯 HOVER → COLUNA 1 EM DESTAQUE
================================ */
tbody tr:hover td:nth-child(1) input {
  color: #337E1B;
  font-weight: 600; /* opcional, combina bem com o destaque */
}

/* frozen column keeps solid background on hover (semi-transparent hover would bleed scrolled cells through) */
tbody tr:hover td.frozen-col {
  background: var(--bg-frozen);
}

/* hover must not override color cells */
tbody tr:hover td.green,
tbody tr:hover td.blue,
tbody tr:hover td.red {
  filter: brightness(0.97);
}

/* frozen colored cells: keep their color on hover too */
tbody tr:hover td.frozen-col.green { background: var(--cell-green-bg); filter: none; }
tbody tr:hover td.frozen-col.blue  { background: var(--cell-blue-bg);  filter: none; }
tbody tr:hover td.frozen-col.red   { background: var(--cell-red-bg);   filter: none; }

/* ============================================================
   HISTORY VIEW
   ============================================================ */
.history-view {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

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

.history-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.history-title strong {
  color: var(--text-primary);
  font-size: 14px;
}

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

.history-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.history-tabs-bar {
  margin: 0;
  padding: 8px 10px 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
}

.history-tab-count {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
}

.tab.active .history-tab-count {
  color: var(--accent);
}

.history-search,
.history-limit {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 12px;
  outline: none;
}

.history-search {
  width: min(420px, 64vw);
  padding: 7px 9px;
}

.history-limit {
  padding: 7px 8px;
}

.history-search:focus,
.history-limit:focus {
  border-color: var(--accent);
}

.history-table-wrapper {
  max-height: calc(100vh - 250px);
  overflow: auto;
}

.history-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  table-layout: auto;
}

.history-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 9px 10px;
  border-bottom: 2px solid var(--border-strong);
  border-right: 1px solid var(--border);
  background: var(--bg-th);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 700;
  text-align: left;
  text-transform: uppercase;
}

.history-col-header {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 104px;
}

.history-col-title {
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 700;
  text-transform: none;
}

.history-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 12px;
  white-space: nowrap;
}

.history-table tr:hover td {
  background: var(--bg-hover);
}

.history-version {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.history-version-old {
  color: var(--text-muted);
}

.history-version-new {
  color: var(--cell-green-fg);
  font-weight: 700;
}

.history-empty {
  padding: 22px;
  text-align: center;
  color: var(--text-muted);
}

/* ============================================================
   COLUMN HEADER CONTENT
   ============================================================ */
.col-header {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 10px;
  min-width: 0;
  width: 100%;
  position: relative;
}

.col-input {
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  color: var(--text-primary);
  font-family: inherit;
  outline: none;
  width: 100%;
  padding: 2px 0;
  transition: border-color var(--transition), color var(--transition);
}

.col-input:focus {
  border-bottom-color: var(--accent);
}

.col-input::placeholder {
  color: var(--text-muted);
  font-size: 11px;
}

.col-input-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.col-input-sub {
  font-size: 11px;
  color: var(--text-secondary);
}

.default-control {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
}

.default-control .col-input {
  min-width: 0;
}

.default-hw-btn {
  flex: 0 0 auto;
  height: 18px;
  padding: 0 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-raised);
  color: var(--text-secondary);
  font-size: 9px;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
}

.default-hw-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--bg-surface);
}

.default-help,
.hwd-help {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-muted);
  background: var(--bg-raised);
  font-size: 10px;
  font-weight: 700;
  cursor: help;
  user-select: none;
}

.default-help:hover,
.hwd-help:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.col-delete-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition), background var(--transition), color var(--transition);
  font-family: inherit;
  line-height: 1;
}

thead th:hover .col-delete-btn {
  opacity: 1;
}

.col-delete-btn:hover {
  background: var(--cell-red-bg);
  color: var(--danger);
  border-color: var(--danger);
}

.col-pos-input {
  position: absolute;
  top: 5px;
  right: 28px;
  width: 24px;
  height: 18px;
  text-align: center;
  font-size: 16px;
  font-family: inherit;
  padding: 0;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  border-radius: 3px;
  outline: none;
  opacity: 0;
  transition: opacity var(--transition), background var(--transition),
              border-color var(--transition), color var(--transition);
  -moz-appearance: textfield;
}

.col-pos-input::-webkit-inner-spin-button,
.col-pos-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

thead th:hover .col-pos-input {
  opacity: 1;
}

.col-pos-input:focus {
  opacity: 1;
  background: var(--bg-secondary);
  border-color: var(--accent);
  color: var(--text-primary);
}

/* ============================================================
   CELL INPUTS
   ============================================================ */
.version-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  width: 100%;
}

td input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  padding: 7px 10px;
  display: block;
  transition: color var(--transition);
}

.version-input {
  min-width: 0;
  flex: 1 1 auto;
}

.hardware-chip {
  flex: 0 1 auto;
  max-width: 92px;
  margin-right: 8px;
  padding: 1px 5px;
  border: 1px solid currentColor;
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 600;
  line-height: 1.35;
  opacity: 0.82;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: help;
}

td.green .hardware-chip {
  color: var(--cell-green-fg);
}

td.blue .hardware-chip {
  color: var(--cell-blue-fg);
}

td.red .hardware-chip {
  color: var(--cell-red-fg);
}

/* ============================================================
   FROZEN COLUMN (ID)
   ============================================================ */
.frozen-col {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--bg-frozen);
  box-shadow: 2px 0 4px rgba(0, 0, 0, 0.07);
  transition: background var(--transition);
}

thead th.frozen-col {
  z-index: 4;
  background: var(--bg-frozen-th);
}

/* ============================================================
   STATUS CELL COLORS
   ============================================================ */
td.green {
  background-color: var(--cell-green-bg);
}
td.green input {
  color: var(--cell-green-fg);
  font-weight: 600;
}

td.blue {
  background-color: var(--cell-blue-bg);
}
td.blue input {
  color: var(--cell-blue-fg);
  font-weight: 600;
}

td.red {
  background-color: var(--cell-red-bg);
}
td.red input {
  color: var(--cell-red-fg);
  font-weight: 600;
}

/* frozen + colored: give priority to the color */
td.frozen-col.green { background: var(--cell-green-bg); }
td.frozen-col.blue  { background: var(--cell-blue-bg); }
td.frozen-col.red   { background: var(--cell-red-bg); }

/* ============================================================
   COLUMN FILTER ROW (trigger inside header)
   ============================================================ */
.col-filter-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 5px;
  padding: 3px 4px;
  border-top: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  font-size: 11px;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
  user-select: none;
}

.col-filter-row:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.col-filter-row--active {
  color: var(--accent);
  border-top-color: var(--accent);
}

.col-sort-arrow {
  font-size: 12px;
  font-weight: 700;
  min-width: 10px;
}

.col-filter-label {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
}

.col-filter-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.col-filter-chevron {
  font-size: 10px;
  margin-left: auto;
}

/* ============================================================
   FILTER PANEL (floating dropdown)
   ============================================================ */
.filter-panel {
  position: fixed;
  z-index: 9999;
  width: 240px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  font-size: 13px;
  color: var(--text-primary);
  overflow: hidden;
}

.fp-section {
  padding: 8px;
}

.fp-sort-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.fp-sort-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 6px 8px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  color: var(--text-secondary);
  text-align: left;
  transition: background var(--transition), color var(--transition);
}

.fp-sort-btn:hover {
  background: var(--bg-raised);
  color: var(--text-primary);
}

.fp-sort-btn.fp-active {
  color: var(--accent);
  font-weight: 600;
  background: var(--bg-raised);
}

.fp-sort-clear {
  color: var(--danger);
  font-size: 12px;
}

.fp-sort-clear:hover {
  background: var(--cell-red-bg);
  color: var(--danger);
}

.fp-sep {
  height: 1px;
  background: var(--border);
  margin: 0;
}

.fp-search {
  width: 100%;
  padding: 5px 8px;
  font-size: 12px;
  font-family: inherit;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  outline: none;
}

.fp-search:focus {
  border-color: var(--accent);
}

.fp-search::placeholder {
  color: var(--text-muted);
}

.fp-values-section {
  max-height: 200px;
  overflow-y: auto;
  padding: 4px 8px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.fp-check-label {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 4px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  transition: background var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fp-check-label:hover {
  background: var(--bg-raised);
  color: var(--text-primary);
}

.fp-select-all-label {
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  padding-bottom: 6px;
}

.fp-check-label input[type="checkbox"] {
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.fp-check-label span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.fp-footer {
  display: flex;
  gap: 6px;
  padding: 8px;
}

.fp-btn {
  flex: 1;
  padding: 6px 10px;
  font-size: 12px;
  font-family: inherit;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  transition: background var(--transition), border-color var(--transition);
}

.fp-btn-apply {
  background: var(--accent);
  color: var(--text-on-accent);
  border: 1px solid var(--accent);
}

.fp-btn-apply:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.fp-btn-clear {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.fp-btn-clear:hover {
  background: var(--bg-raised);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

/* ============================================================
   HARDWARE DEFAULT PANEL
   ============================================================ */
.hardware-default-panel {
  position: fixed;
  z-index: 10000;
  width: 340px;
  max-height: 360px;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  color: var(--text-primary);
  overflow: hidden;
}

.hwd-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px 2px;
  font-size: 13px;
  font-weight: 700;
}

.hwd-subtitle {
  padding: 0 12px 8px;
  color: var(--text-secondary);
  font-size: 11px;
  border-bottom: 1px solid var(--border);
}

.hwd-grid {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 8px;
  overflow-y: auto;
}

.hwd-row {
  display: grid;
  grid-template-columns: minmax(92px, 1fr) 150px;
  align-items: center;
  gap: 8px;
  padding: 4px;
  border-radius: 4px;
}

.hwd-row:hover {
  background: var(--bg-raised);
}

.hwd-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
}

.hwd-input {
  width: 100%;
  min-width: 0;
  padding: 5px 7px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 12px;
}

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

.hwd-empty {
  padding: 0 12px 8px;
  color: var(--text-muted);
  font-size: 11px;
}

.hwd-footer {
  display: flex;
  gap: 6px;
  padding: 8px;
  border-top: 1px solid var(--border);
}

/* ============================================================
   TABS BAR
   ============================================================ */
.tabs-bar {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  padding: 0 4px;
  margin-bottom: -1px;
  position: relative;
  z-index: 1;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs-bar::-webkit-scrollbar {
  display: none;
}

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  user-select: none;
  max-width: 180px;
}

.tab:hover {
  background: var(--bg-surface);
  color: var(--text-primary);
}

.tab.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border);
  font-weight: 600;
  position: relative;
}

.tab.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--bg-surface);
}

.tab-name {
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

.tab-close {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  font-size: 14px;
  line-height: 1;
  border-radius: 3px;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity var(--transition), background var(--transition), color var(--transition);
}

.tab:hover .tab-close,
.tab.active .tab-close {
  opacity: 1;
}

.tab-close:hover {
  background: var(--cell-red-bg);
  color: var(--danger);
}

.tab-add {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 30px;
  font-size: 18px;
  line-height: 1;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-bottom: 1px;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  font-family: inherit;
}

.tab-add:hover {
  background: var(--bg-raised);
  border-color: var(--border);
  color: var(--accent);
}

.tabs-bar .tab-close,
.tabs-bar .tab-add {
  display: none !important;
}

/* Dark mode overrides for tabs */
[data-theme="dark"] .tab {
  background: var(--bg-raised);
}

[data-theme="dark"] .tab.active {
  background: var(--bg-surface);
}

[data-theme="dark"] .tab.active::after {
  background: var(--bg-surface);
}
