/* ============================================================
   Penalty Matrix Editor — Glassmorphism / Yandex Premium Style
   ============================================================ */

:root {
  --primary: #10b981;
  --primary-hover: #059669;
  --primary-light: rgba(16, 185, 129, 0.12);
  --primary-glow: rgba(16, 185, 129, 0.25);

  --bg: #e8f5e9;
  --glass-bg: rgba(255, 255, 255, 0.55);
  --glass-bg-strong: rgba(255, 255, 255, 0.72);
  --glass-border: rgba(255, 255, 255, 0.40);
  --glass-border-strong: rgba(255, 255, 255, 0.55);

  --text: #0f172a;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;

  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.08);
  --warn: #f59e0b;
  --warn-bg: rgba(245, 158, 11, 0.10);

  --basic: #3b82f6;
  --team: #8b5cf6;
  --multi: #f59e0b;

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 24px;

  --blur: blur(16px);
  --blur-heavy: blur(24px);

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  color: var(--text);
  background: linear-gradient(135deg, #d5f0d5 0%, #e8f5e9 30%, #f0f7f0 60%, #f8fcf8 100%);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.bg-blobs {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.3;
}

.blob--1 {
  width: 600px; height: 600px;
  top: -200px; left: -150px;
  background: radial-gradient(circle, rgba(76,175,80,0.35), transparent 70%);
}

.blob--2 {
  width: 450px; height: 450px;
  top: 100px; right: -100px;
  background: radial-gradient(circle, rgba(200,230,201,0.40), transparent 70%);
}

.blob--3 {
  width: 400px; height: 400px;
  bottom: -100px; left: 25%;
  background: radial-gradient(circle, rgba(165,214,167,0.30), transparent 70%);
}

.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-md);
  box-shadow:
    0 4px 24px rgba(0, 0, 0, 0.04),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.app {
  position: relative;
  z-index: 1;
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 10px 32px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  flex-wrap: wrap;
}

.topbar__left { display: flex; flex-direction: column; gap: 2px; }

.topbar__badge {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--primary);
  background: var(--primary-light);
  padding: 2px 6px;
  border-radius: 5px;
  width: fit-content;
}

.topbar__title {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
}

.topbar__meta {
  font-size: 11px;
  color: var(--text-muted);
}

.topbar__right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  padding: 8px 14px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.18s ease;
  user-select: none;
  white-space: nowrap;
}

.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn--primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.30);
}

.btn--primary:hover:not(:disabled) {
  background: var(--primary-hover);
  box-shadow: 0 4px 16px rgba(16, 185, 129, 0.35);
}

.btn--outline {
  background: var(--glass-bg-strong);
  backdrop-filter: var(--blur);
  color: var(--text);
  border: 1px solid var(--glass-border-strong);
}

.btn--outline:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.85);
}

.btn--danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.15);
}

.btn--danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.14);
}

.pill {
  font-size: 10px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.pill--warn {
  background: var(--warn-bg);
  color: #b45309;
  border: 1px solid rgba(245, 158, 11, 0.20);
}

.pill--hidden { display: none; }

.products-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.product-group {
  border-radius: var(--r-md);
  overflow: hidden;
  transition: all 0.2s ease;
}

.product-group[open] {
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.06);
}

.product-group__head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  cursor: pointer;
  user-select: none;
  list-style: none;
  font-size: 12px;
  font-weight: 600;
  transition: background 0.15s ease;
}

.product-group__head::-webkit-details-marker { display: none; }

.product-group__head::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.product-group[open] > .product-group__head::before {
  transform: rotate(90deg);
}

.product-group--basic .product-group__head::before { background: var(--basic); }
.product-group--team .product-group__head::before { background: var(--team); }
.product-group--multi .product-group__head::before { background: var(--multi); }

.product-group__rates-hint {
  margin-left: auto;
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
}

.product-group__products { padding: 0 14px 8px; }

.product-group__list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.product-group__list li {
  font-size: 9px;
  font-family: var(--mono);
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.50);
  border: 1px solid var(--glass-border);
  color: var(--text-secondary);
  line-height: 1.4;
}

.product-group__rates { padding: 0 14px 12px; }

.product-group__rates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
}

.rate-card {
  background: rgba(255, 255, 255, 0.45);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 8px 10px;
  transition: all 0.15s ease;
}

.rate-card:hover { background: rgba(255, 255, 255, 0.65); }
.rate-card__label { font-size: 11px; font-weight: 700; }

.rate-card__criterion {
  margin-top: 2px;
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.3;
}

.refs-panel { overflow: hidden; }

.refs-panel__toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 10px 14px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: none;
  border: none;
  cursor: pointer;
  user-select: none;
  list-style: none;
  transition: background 0.15s ease;
}

.refs-panel__toggle::-webkit-details-marker { display: none; }
.refs-panel__toggle svg { color: var(--text-muted); flex-shrink: 0; }

.refs-panel__body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 0 14px 14px;
  border-top: 1px solid var(--glass-border);
}

.refs-panel__col h3 {
  margin: 10px 0 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.refs-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.refs-list li {
  font-size: 11px;
  padding: 6px 9px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.40);
  border: 1px solid var(--glass-border);
  line-height: 1.3;
  cursor: pointer;
  transition: all 0.15s ease;
}

.refs-list li:active { transform: scale(0.98); }

.refs-list li:hover {
  background: var(--primary-light);
  border-color: rgba(16, 185, 129, 0.20);
}

.refs-list li em {
  font-style: normal;
  color: var(--text-muted);
  font-size: 9px;
  margin-left: 5px;
}

.filters { padding: 10px 12px; }

.filters__row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.filters__footer {
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
}

.filters__count {
  font-size: 11px;
  color: var(--text-muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.field--grow { flex: 1 1 200px; }

.field--chip {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  min-width: auto;
}

.field--chip span {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
}

input, select, textarea {
  font-family: var(--font);
  font-size: 12px;
  border: 1px solid var(--glass-border-strong);
  border-radius: 8px;
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.55);
  color: var(--text);
  outline: none;
  transition: all 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
  background: rgba(255, 255, 255, 0.75);
}

input[type="checkbox"] {
  width: 14px; height: 14px;
  accent-color: var(--primary);
  cursor: pointer;
}

input[type="search"] { width: 100%; }

.table-shell { overflow: hidden; }

.table-wrap {
  overflow: auto;
  max-height: calc(100dvh - 320px);
  -webkit-overflow-scrolling: touch;
}

.matrix-table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.matrix-table th,
.matrix-table td {
  padding: 7px 8px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  font-size: 11px;
  vertical-align: top;
  background: transparent;
  white-space: nowrap;
}

.matrix-table th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: rgba(240, 244, 248, 0.85);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.matrix-table .sticky-col {
  position: sticky;
  left: 0;
  z-index: 2;
  background: rgba(255, 255, 255, 0.70);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: 2px 0 0 rgba(0, 0, 0, 0.04);
}

.matrix-table thead .sticky-col { z-index: 4; background: rgba(240, 244, 248, 0.90); }

.matrix-table tbody tr { transition: background 0.12s ease; }

.matrix-table tbody tr:hover td {
  background: rgba(16, 185, 129, 0.04);
}

.matrix-table tbody tr:hover .sticky-col {
  background: rgba(16, 185, 129, 0.06);
}

.section-row td {
  background: var(--primary-light) !important;
  color: var(--primary-hover);
  font-weight: 700;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  position: sticky;
  left: 0;
  z-index: 1;
}

.rate-col--basic { background: rgba(59, 130, 246, 0.04); }
.rate-col--team { background: rgba(139, 92, 246, 0.04); }
.rate-col--multi { background: rgba(245, 158, 11, 0.05); }

.rate-cell {
  font-family: var(--mono);
  font-size: 11px;
  text-align: center;
  min-width: 52px;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.12s ease;
}

.rate-cell:hover { background: var(--primary-light); }
.rate-cell--empty { color: var(--text-muted); }
.rate-cell--editing { padding: 4px; }

.rate-cell input {
  width: 44px;
  padding: 4px 5px;
  text-align: center;
  font-family: var(--mono);
  font-size: 11px;
  border-radius: 6px;
}

.text-cell { max-width: 160px; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; }

.mode-pill {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 600;
  background: var(--primary-light);
  color: var(--primary-hover);
}

.mode-pill--manual {
  background: rgba(139, 92, 246, 0.10);
  color: #7c3aed;
}

.row-actions { display: flex; gap: 4px; }

.icon-btn {
  width: 28px; height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--glass-border);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.50);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s ease;
}

.icon-btn:active { transform: scale(0.93); }

.icon-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: rgba(16, 185, 129, 0.25);
}

.drawer {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
}

.drawer--open { pointer-events: auto; }

.drawer__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.30);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 0.22s ease;
}

.drawer--open .drawer__backdrop { opacity: 1; }

.drawer__panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(460px, 100vw);
  height: 100%;
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  border-radius: 0;
  border-left: 1px solid var(--glass-border);
}

.drawer--open .drawer__panel { transform: translateX(0); }

.drawer__header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer__header h2 { font-size: 16px; font-weight: 700; }

.drawer__form {
  padding: 16px;
  overflow: auto;
  flex: 1;
  display: grid;
  gap: 12px;
}

.drawer__form .field { min-width: 0; }

.drawer__rates {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.drawer__footer {
  padding: 12px 16px;
  border-top: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.drawer__custom-input { margin-top: 4px; }
.drawer__custom-input--hidden { display: none; }

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: var(--text);
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  z-index: 60;
  opacity: 1;
  transform: translateY(0);
  transition: all 0.25s ease;
}

.toast--hidden {
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
}

@media (max-width: 1100px) {
  .products-row { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
  .app { padding: 10px 8px 24px; gap: 8px; }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
  }

  .topbar__right { justify-content: flex-end; }

  .products-row { grid-template-columns: 1fr; }
  .drawer__panel { width: 100vw; }
  .refs-panel__body { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .topbar__title { font-size: 15px; }
  .btn { padding: 7px 10px; font-size: 11px; }
  .table-hint { display: none; }
}

/* --- Tooltip for truncated text --- */
.cell-tooltip { cursor: default; }

.floating-tooltip {
  position: fixed;
  max-width: 320px;
  padding: 6px 10px;
  background: var(--text);
  color: #fff;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.4;
  border-radius: 8px;
  white-space: normal;
  word-wrap: break-word;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.floating-tooltip.visible { opacity: 1; }

/* --- Column resize --- */
.matrix-table th {
  position: relative;
}

.col-resize-handle {
  position: absolute;
  right: -1px;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: col-resize;
  background: transparent;
  z-index: 5;
  transition: background 0.15s ease;
}

.col-resize-handle::before {
  content: "";
  position: absolute;
  right: 2px;
  top: 4px;
  bottom: 4px;
  width: 2px;
  background: rgba(0, 0, 0, 0.10);
  border-radius: 1px;
  transition: background 0.15s ease, width 0.15s ease;
}

.col-resize-handle:hover::before {
  background: var(--primary);
  opacity: 0.6;
}

.col-resize-handle:hover {
  background: rgba(16, 185, 129, 0.06);
}

.col-resize-handle.resizing::before {
  background: var(--primary);
  opacity: 0.8;
  width: 3px;
}

.col-resize-handle.resizing {
  background: rgba(16, 185, 189, 0.08);
}

/* Table hint */
.table-hint {
  font-size: 10px;
  color: var(--text-muted);
  padding: 0 12px 8px;
  margin: 0;
  line-height: 1.4;
}

/* Column collapsed state */
.matrix-table .col--collapsed {
  display: none !important;
}

/* Restore bar */
.col-restore-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.70);
  backdrop-filter: var(--blur);
  border-radius: 10px;
  border: 1px dashed rgba(0, 0, 0, 0.12);
  margin-top: 8px;
  flex-wrap: wrap;
}

.col-restore-bar__label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.col-restore-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  font-size: 10px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-light);
  border: 1px solid rgba(16, 185, 129, 0.20);
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.col-restore-pill:hover {
  background: rgba(16, 185, 129, 0.20);
  border-color: var(--primary);
}

.col-restore-pill:active {
  transform: scale(0.95);
}

.col-restore-pill__icon {
  font-size: 12px;
  line-height: 1;
}

/* --- Product groups toggle-all state --- */
.products-row.all-open .product-group {
  /* no extra style needed, just a marker */
}
