:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --border: #e2e6ef;
  --text: #1a1f36;
  --muted: #6b7287;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #dc2626;
  --basic: #2563eb;
  --team: #7c3aed;
  --multi: #d97706;
  --shadow: 0 10px 30px rgba(26, 31, 54, 0.08);
  --radius: 14px;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(79, 70, 229, 0.08), transparent 28%),
    radial-gradient(circle at top right, rgba(217, 119, 6, 0.06), transparent 24%),
    var(--bg);
  min-height: 100vh;
}

.app {
  max-width: 1600px;
  margin: 0 auto;
  padding: 24px 20px 40px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  margin-bottom: 20px;
}

.topbar__eyebrow {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--primary);
}

.topbar h1 {
  margin: 4px 0 6px;
  font-size: 28px;
  font-weight: 700;
}

.topbar__meta {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

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

.badge {
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 999px;
  background: #fff7ed;
  color: #c2410c;
  border: 1px solid #fed7aa;
}

.badge--hidden { display: none; }

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.btn:hover:not(:disabled) { filter: brightness(1.03); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

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

.btn--primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn--ghost {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.btn--danger {
  background: #fef2f2;
  color: var(--danger);
  border-color: #fecaca;
}

.drawer__custom-input {
  margin-top: 4px;
}

.drawer__custom-input--hidden {
  display: none;
}

.products-row {
  display: grid;
  grid-template-columns: 3fr 4fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}

.product-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.product-group--basic { border-top: 3px solid var(--basic); }
.product-group--team { border-top: 3px solid var(--team); }
.product-group--multi { border-top: 3px solid var(--multi); }

.product-group__head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  cursor: pointer;
  user-select: none;
}

.product-group__head::-webkit-details-marker { display: none; }

.product-group__head::before {
  content: "\25B6";
  font-size: 9px;
  flex-shrink: 0;
  transition: transform 0.15s ease;
  color: var(--muted);
}

.product-group[open] > .product-group__head::before {
  transform: rotate(90deg);
}

.product-group__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.product-group--basic .product-group__dot { background: var(--basic); }
.product-group--team .product-group__dot { background: var(--team); }
.product-group--multi .product-group__dot { background: var(--multi); }

.product-group__title {
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
}

.product-group__rates-hint {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.product-group__products {
  padding: 0 14px 10px;
}

.product-group__list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.product-group__list li {
  font-size: 10px;
  font-family: var(--mono);
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  line-height: 1.4;
}

.product-group__rates {
  padding: 0 14px 14px;
  display: grid;
  gap: 8px;
}

.product-group__rates-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0;
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  color: var(--primary);
  background: none;
  border: none;
  cursor: pointer;
}

.product-group__rates-toggle::before {
  content: "\25B6";
  font-size: 8px;
  transition: transform 0.15s ease;
}

.product-group__rates[open] > .product-group__rates-toggle::before,
.product-group__rates.is-open > .product-group__rates-toggle::before {
  transform: rotate(90deg);
}

.product-group__rates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}

.rate-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.rate-card__label {
  font-size: 12px;
  font-weight: 700;
}

.rate-card__criterion {
  margin-top: 3px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.35;
}

.refs-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  overflow: hidden;
}

.refs-panel__toggle {
  padding: 14px 18px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  list-style: none;
}

.refs-panel__toggle::-webkit-details-marker { display: none; }
.refs-panel__toggle::before {
  content: "\25B6";
  display: inline-block;
  margin-right: 10px;
  font-size: 10px;
  transition: transform 0.15s ease;
}
.refs-panel[open] > .refs-panel__toggle::before { transform: rotate(90deg); }

.refs-panel__body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  padding: 0 18px 18px;
  border-top: 1px solid var(--border);
}

.refs-panel__col h3 {
  margin: 14px 0 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.refs-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.refs-list li {
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  line-height: 1.35;
  cursor: pointer;
  transition: background 0.12s ease;
}

.refs-list li:hover { background: #eef2ff; }

.refs-list li em {
  font-style: normal;
  color: var(--muted);
  font-size: 11px;
  margin-left: 6px;
}

.filters {
  display: flex;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 140px;
}

.field--grow { flex: 1 1 260px; }

.field--checkbox {
  flex-direction: row;
  align-items: center;
  min-width: auto;
  padding-bottom: 8px;
}

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

input, select, textarea {
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text);
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(79, 70, 229, 0.25);
  border-color: var(--primary);
}

.filters__count {
  margin-left: auto;
  font-size: 13px;
  color: var(--muted);
  padding-bottom: 8px;
}

.table-shell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 340px);
}

.matrix-table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.matrix-table th,
.matrix-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: top;
  background: var(--surface);
}

.matrix-table th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--surface-2);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.matrix-table .sticky-col {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
  box-shadow: 2px 0 0 var(--border);
}

.matrix-table .sticky-col-2 {
  left: 220px;
}

.matrix-table thead .sticky-col { z-index: 4; background: var(--surface-2); }

.matrix-table tbody tr:hover td { background: #fafbff; }
.matrix-table tbody tr:hover .sticky-col { background: #fafbff; }

.section-row td {
  background: #eef2ff !important;
  color: #3730a3;
  font-weight: 700;
  position: sticky;
  left: 0;
  z-index: 1;
}

.rate-col--basic { background: rgba(37, 99, 235, 0.04); }
.rate-col--team { background: rgba(124, 58, 237, 0.04); }
.rate-col--multi { background: rgba(217, 119, 6, 0.06); }

.rate-cell {
  font-family: var(--mono);
  font-size: 12px;
  text-align: center;
  min-width: 72px;
  cursor: pointer;
  border-radius: 8px;
}

.rate-cell:hover { background: rgba(79, 70, 229, 0.08); }
.rate-cell--empty { color: #c4c9d4; }
.rate-cell--editing { padding: 4px; }

.rate-cell input {
  width: 56px;
  padding: 6px 8px;
  text-align: center;
  font-family: var(--mono);
  font-size: 12px;
}

.text-cell {
  max-width: 220px;
  line-height: 1.4;
}

.mode-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: #eef2ff;
  color: #4338ca;
}

.mode-pill--manual {
  background: #fdf4ff;
  color: #a21caf;
}

.row-actions {
  display: flex;
  gap: 6px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.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.35);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.drawer--open .drawer__backdrop { opacity: 1; }

.drawer__panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(480px, 100vw);
  height: 100%;
  background: var(--surface);
  box-shadow: -12px 0 40px rgba(15, 23, 42, 0.12);
  transform: translateX(100%);
  transition: transform 0.22s ease;
  display: flex;
  flex-direction: column;
}

.drawer--open .drawer__panel { transform: translateX(0); }

.drawer__header,
.drawer__footer {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.drawer__footer {
  border-bottom: 0;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

.drawer__header h2 {
  margin: 0;
  font-size: 18px;
}

.drawer__form {
  padding: 18px;
  overflow: auto;
  display: grid;
  gap: 14px;
}

.drawer__form .field { min-width: 0; }

.drawer__rates {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #111827;
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 60;
}

.toast--hidden { display: none; }

@media (max-width: 1100px) {
  .products-row { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 720px) {
  .topbar { flex-direction: column; }
  .products-row { grid-template-columns: 1fr; }
  .matrix-table .sticky-col-2 { left: 160px; }
}
