/* ── MtkTable: переиспользуемый табличный компонент ─────────────────
   Использует CSS-переменные родительской страницы (--accent, --surface, ...)
   Префикс классов: ct- (compact-table)
*/

.ct-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  overflow-x: auto;
  overflow-y: visible;
  box-shadow: var(--shadow);
  position: relative;
}

.ct-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.ct-toolbar-spacer { flex: 1; }
.ct-groupby {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text2);
}
.ct-groupby select {
  font-family: var(--font);
  font-size: 12px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
}

.ct-table {
  width: 100%;
  min-width: max-content;
  border-collapse: separate;
  border-spacing: 0;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  table-layout: fixed;
}

/* Trailing "+" column fills remaining horizontal space */
.ct-th.ct-add-col, .ct-td.ct-add-col {
  width: auto;
  min-width: 40px;
  cursor: default;
  border-bottom: 1px solid var(--border);
  padding: 0;
}
.ct-td.ct-add-col {
  background: inherit;       /* подхватываем фон строки (hover/selected/active) */
}
.ct-th.ct-add-col {
  background: var(--surface2);
  cursor: pointer;
  position: sticky;
  top: 0;
  z-index: 3;
}
.ct-add-col-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--border2);
  background: var(--surface);
  font-size: 14px;
  font-weight: 400;
  color: var(--text3);
  margin: 0 8px;
  user-select: none;
  transition: all 0.12s;
  line-height: 1;
}
.ct-th.ct-add-col:hover .ct-add-col-btn { border-color: var(--accent); color: var(--accent); }

/* ── Header row ─────────────────────────────────────────────────── */
.ct-thead { background: var(--surface2); }
.ct-th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--surface2);
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
  cursor: default;
}
.ct-th.ct-sticky { left: 0; z-index: 4; }
.ct-th.ct-sortable { cursor: pointer; }
.ct-th.ct-sortable:hover { color: var(--text); }
.ct-th { position: relative; }
.ct-th .ct-sort-icon { font-size: 10px; margin-left: 4px; opacity: 0.6; }
.ct-th-label { display: inline-block; pointer-events: none; }
.ct-th-menu { position: absolute; right: 18px; top: 50%; transform: translateY(-50%); font-size: 14px; color: var(--text3); cursor: pointer; padding: 0 4px; opacity: 0; transition: opacity 0.12s; z-index: 4; user-select: none; line-height: 1; }
.ct-th:hover .ct-th-menu { opacity: 1; }
.ct-th-menu:hover { color: var(--text); }
.ct-th-label { display: inline-flex; align-items: center; gap: 0; pointer-events: none; }
.ct-th-link { display: inline-flex; align-items: center; justify-content: center; margin-left: 5px; cursor: pointer; color: var(--text3); pointer-events: auto; vertical-align: middle; transition: color 0.12s; }
.ct-th-link:hover { color: var(--accent); }
.ct-col-resize {
  position: absolute;
  right: -6px;
  top: 0;
  bottom: 0;
  width: 14px;
  cursor: col-resize;
  z-index: 10;
  user-select: none;
  background: transparent;
}
.ct-col-resize::after {
  content: '';
  position: absolute;
  right: 6px;
  top: 4px;
  bottom: 4px;
  width: 2px;
  background: transparent;
  border-radius: 1px;
  transition: background 0.12s, width 0.12s;
}
.ct-th:hover .ct-col-resize::after { background: var(--border2); }
.ct-col-resize:hover::after { background: var(--accent); width: 3px; right: 5px; }
.ct-th[draggable="true"] { cursor: grab; }
.ct-th.ct-col-dragging { opacity: 0.5; }
.ct-th.ct-col-drop-before { box-shadow: inset 2px 0 0 0 var(--accent); }
.ct-th.ct-col-drop-after  { box-shadow: inset -2px 0 0 0 var(--accent); }

/* ── Group header ───────────────────────────────────────────────── */
.ct-group-row td {
  padding: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.ct-group-head {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface2);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  position: sticky;
  left: 0;
  cursor: pointer;
  user-select: none;
  width: max-content;
  max-width: calc(100vw - 60px);
  z-index: 2;
}
.ct-group-row td { background: var(--surface2); }
.ct-group-toggle {
  font-size: 10px;
  color: var(--text3);
  transition: transform 0.15s;
  width: 12px;
  display: inline-block;
  text-align: center;
}
.ct-group-row.collapsed .ct-group-toggle { transform: rotate(-90deg); }
.ct-group-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
}
.ct-group-count {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text3);
  margin-left: 4px;
}
.ct-group-checkbox {
  margin-right: 6px;
  cursor: pointer;
  accent-color: var(--accent);
}

/* ── Body rows ──────────────────────────────────────────────────── */
.ct-tr {
  background: var(--surface);
  transition: background 0.08s;
}
.ct-tr:hover { background: var(--surface2); }
.ct-tr.selected { background: var(--accent-bg); }
.ct-tr.selected:hover { background: var(--accent-bg); }
.ct-tr.ct-tr-active { background: var(--accent-bg); box-shadow: inset 3px 0 0 0 var(--accent); }
.ct-tr.ct-tr-active:hover { background: var(--accent-bg); }
.ct-group-row.collapsed + .ct-tr { display: none; }
.ct-tr.hidden-by-group { display: none; }

.ct-td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  height: 36px;
  max-height: 36px;
  background: inherit;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  position: relative;
}
.ct-td.ct-sticky {
  position: sticky;
  left: 0;
  z-index: 1;
  box-shadow: 1px 0 0 0 var(--border);
  background: inherit;
}
.ct-tr:hover .ct-td.ct-sticky,
.ct-tr.selected .ct-td.ct-sticky {
  /* keep sticky cell background in sync with row */
}
.ct-td.ct-editable { cursor: text; }
.ct-td.ct-editable:hover { background: rgba(29,92,58,0.04); }

/* ── Cell: avatar (sticky first column) ─────────────────────────── */
.ct-cell-avatar {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ct-checkbox {
  cursor: pointer;
  accent-color: var(--accent);
  opacity: 0;
  transition: opacity 0.1s;
  flex-shrink: 0;
}
.ct-tr:hover .ct-checkbox,
.ct-tr.selected .ct-checkbox,
.ct-has-selection .ct-checkbox { opacity: 1; }
.ct-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  font-family: var(--mono);
  color: #1a1917;
  flex-shrink: 0;
  border: 1.5px solid #fff;
  box-shadow: 0 0 0 1px var(--border2);
}
.ct-cell-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  font-weight: 500;
}
.ct-cell-name:hover { color: var(--accent); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; }

/* ── Cell: pill ─────────────────────────────────────────────────── */
.ct-cell-pill {
  display: inline-block;
  padding: 3px 11px;
  border-radius: 12px;
  font-size: 11.5px;
  font-weight: 500;
  color: #fff;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ct-cell-pill.ct-empty {
  background: transparent;
  color: var(--text3);
  border: 1px dashed var(--border2);
  font-style: italic;
}

/* ── Cell: pills-multi ──────────────────────────────────────────── */
.ct-cell-pills {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  max-width: 100%;
}
.ct-cell-pills .ct-mini-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  background: var(--surface2);
  color: var(--text2);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.ct-cell-pills .ct-mini-pill.colored {
  color: #1a1917;
  border-color: rgba(0,0,0,0.06);
}
.ct-cell-pills .ct-overflow {
  font-size: 11px;
  color: var(--text3);
  font-family: var(--mono);
}

/* ── Cell: stars ────────────────────────────────────────────────── */
.ct-cell-stars {
  position: relative;
  display: inline-block;
  font-size: 14px;
  line-height: 1;
  user-select: none;
  cursor: pointer;
}
.ct-cell-stars .ct-stars-bg { color: #e2e0da; letter-spacing: 1px; }
.ct-cell-stars .ct-stars-fg { position: absolute; left: 0; top: 0; color: #f5b800; white-space: nowrap; overflow: hidden; pointer-events: none; letter-spacing: 1px; }
.ct-cell-stars .ct-stars-zones { position: absolute; left: 0; top: 0; bottom: 0; right: 0; display: flex; }
.ct-cell-stars .ct-stars-zone { flex: 1; }

/* ── Cell: chips-3 (price 1-3) ──────────────────────────────────── */
.ct-cell-chips3 {
  display: inline-flex;
  gap: 2px;
  cursor: pointer;
  user-select: none;
}
.ct-chip3 {
  font-size: 13px;
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface);
  opacity: 0.4;
  transition: opacity 0.1s;
}
.ct-chip3.active { opacity: 1; background: var(--amber-bg); border-color: #f0c080; }
.ct-cell-chips3:hover .ct-chip3 { opacity: 0.7; }
.ct-cell-chips3:hover .ct-chip3.active { opacity: 1; }

/* ── Cell: link ─────────────────────────────────────────────────── */
.ct-cell-link a { color: var(--accent); text-decoration: none; }
.ct-cell-link a:hover { text-decoration: underline; }

/* ── Cell: text/textarea inline editor ──────────────────────────── */
.ct-cell-text { color: var(--text); }
.ct-cell-text.ct-empty { color: var(--text3); font-style: italic; }
.ct-cell-input {
  width: 100%;
  font-family: var(--font);
  font-size: 13px;
  padding: 4px 6px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
}
.ct-cell-input:focus { outline: none; }

/* ── Calculate row ──────────────────────────────────────────────── */
.ct-calc-row td {
  padding: 6px 12px;
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text3);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.ct-calc-row td.ct-sticky { position: sticky; left: 0; background: var(--bg); }

/* ── Bulk action bar ────────────────────────────────────────────── */
.ct-bulk-bar {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1a1917;
  color: #fff;
  border-radius: 12px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.25);
  z-index: 100;
  transition: transform 0.18s ease-out;
  font-size: 13px;
}
.ct-bulk-bar.show { transform: translateX(-50%) translateY(0); }
.ct-bulk-count {
  background: rgba(255,255,255,0.12);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
}
.ct-bulk-close {
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
}
.ct-bulk-close:hover { color: #fff; }
.ct-bulk-action {
  font-family: var(--font);
  font-size: 12px;
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  background: rgba(255,255,255,0.08);
  color: #fff;
  cursor: pointer;
  transition: background 0.1s;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.ct-bulk-action:hover { background: rgba(255,255,255,0.18); }
.ct-bulk-action.danger { color: #fca5a5; }
.ct-bulk-action.danger:hover { background: rgba(252,165,165,0.18); color: #fff; }
.ct-bulk-sep { width: 1px; height: 20px; background: rgba(255,255,255,0.15); }

/* ── Popover (для pill / pills-multi / etc.) ────────────────────── */
.ct-popover {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.18);
  z-index: 200;
  padding: 6px;
  min-width: 180px;
  max-height: 300px;
  overflow-y: auto;
}
.ct-popover-item {
  padding: 6px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.ct-popover-item:hover { background: var(--surface2); }
.ct-popover-item.active { background: var(--accent-bg); color: var(--accent); font-weight: 600; }
.ct-popover-item .ct-popover-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  color: #fff;
  font-weight: 600;
}
.ct-popover-divider { height: 1px; background: var(--border); margin: 4px 0; }
.ct-popover-input {
  width: 100%;
  font-family: var(--font);
  font-size: 12.5px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface);
}
.ct-popover-input:focus { outline: none; border-color: var(--accent); }

/* Tag input for pills-multi */
.ct-tag-list { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px; min-height: 30px; }
.ct-tag-list .ct-mini-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.ct-tag-list .ct-mini-pill button {
  background: none; border: none; cursor: pointer; padding: 0 2px; font-size: 13px; color: rgba(0,0,0,0.4);
}
.ct-tag-list .ct-mini-pill button:hover { color: rgba(0,0,0,0.8); }

/* ── Drag & drop ────────────────────────────────────────────────── */
.ct-tr[draggable="true"] { cursor: grab; }
.ct-tr.ct-drop-before > td { box-shadow: 0 -2px 0 0 var(--accent) inset; }
.ct-tr.ct-drop-after > td { box-shadow: 0 2px 0 0 var(--accent) inset; }
.ct-group-row.ct-drop-after > td > .ct-group-head { box-shadow: inset 0 -2px 0 0 var(--accent); }

/* ── Empty state ────────────────────────────────────────────────── */
.ct-empty-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--text3);
}
.ct-empty-state-icon { font-size: 36px; opacity: 0.3; margin-bottom: 8px; }
.ct-empty-state-title { font-size: 14px; font-weight: 600; color: var(--text2); }
