* {
  box-sizing: border-box;
}

body {
  font-family: "Inter", sans-serif;
  background: #f8fafc;
  margin: 0;
  padding: 24px;
  min-height: 100vh;
  color: #1e293b;
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: #1e293b;
  letter-spacing: -0.02em;
  margin: 0 0 4px 0;
}

p.subtitle {
  font-size: 0.8rem;
  color: #94a3b8;
  margin: 0;
}

.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  margin-top: 4px;
}

button.action-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

button.action-btn:disabled:hover {
  background: white;
  border-color: #e2e8f0;
}

button.action-btn {
  font-size: 0.8rem;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  color: #475569;
  background: white;
  cursor: pointer;
  font-weight: 500;
  font-family: inherit;
  transition:
    background 0.15s,
    border-color 0.15s;
}

button.action-btn:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.scroll-wrap {
  overflow-x: auto;
}

table {
  border-collapse: separate;
  border-spacing: 4px 0;
}

th,
td {
  padding: 0;
  vertical-align: top;
}

td.label-cell {
  vertical-align: middle;
  padding-right: 8px;
  white-space: nowrap;
}

td.label-cell .label-inner {
  display: flex;
  align-items: center;
  gap: 4px;
}

.drag-handle {
  color: #cbd5e1;
  cursor: grab;
  font-size: 0.875rem;
  user-select: none;
  line-height: 1;
}

.drag-handle:active {
  cursor: grabbing;
}

button.remove-btn {
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0 2px;
  line-height: 1;
  font-family: inherit;
  transition: color 0.15s;
}

button.remove-btn:hover {
  color: #f87171;
}

input.label-input {
  background: transparent;
  border: none;
  outline: none;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.875rem;
  color: #475569;
  width: 100px;
  text-align: right;
}

.platform-header {
  border-radius: 12px 12px 0 0;
  border-width: 2px 2px 0 2px;
  border-style: solid;
  padding: 8px 12px;
  min-width: 144px;
}

.platform-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

input.platform-label-input {
  background: transparent;
  border: none;
  outline: none;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.875rem;
  color: #334155;
  width: 80px;
}

.chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 24px;
  border-radius: 6px;
  transition: background-color 0.1s;
  padding: 2px;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 600;
  border-width: 1px;
  border-style: solid;
  cursor: grab;
  transition: opacity 0.15s;
  user-select: none;
}

.chip:hover {
  opacity: 0.8;
}
.chip:active {
  cursor: grabbing;
}
.chip.clickable {
  cursor: pointer;
}
.chip.clickable:active {
  cursor: pointer;
}

.add-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 9999px;
  background: #f1f5f9;
  color: #94a3b8;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition:
    background 0.15s,
    color 0.15s;
  flex-shrink: 0;
}

.add-chip:hover {
  background: #dbeafe;
  color: #3b82f6;
}

td.platform-cell {
  transition: background-color 0.1s;
}

td.platform-cell .cell-inner {
  padding: 8px 12px;
  min-width: 144px;
}

td.side-cell {
  padding-left: 4px;
  vertical-align: middle;
  transition: background-color 0.1s;
  border-radius: 8px;
}

td.side-cell .chips-row {
  min-width: 80px;
}

td.xfn-header {
  padding-left: 4px;
  vertical-align: bottom;
  font-size: 0.7rem;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding-bottom: 12px;
}

td.add-platform-cell {
  vertical-align: bottom;
  padding-left: 8px;
}

.add-row-form {
  display: flex;
  gap: 4px;
  align-items: center;
}

input.add-input {
  border: 1px solid #93c5fd;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.8rem;
  font-family: inherit;
  outline: none;
  width: 128px;
}

button.confirm-btn {
  background: none;
  border: none;
  color: #3b82f6;
  font-weight: 700;
  font-size: 0.875rem;
  cursor: pointer;
  font-family: inherit;
}

button.cancel-btn {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 0.875rem;
  cursor: pointer;
  font-family: inherit;
}

button.dashed-btn {
  background: none;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  padding: 4px 12px;
  font-size: 0.8rem;
  color: #94a3b8;
  cursor: pointer;
  font-family: inherit;
  transition:
    color 0.15s,
    border-color 0.15s;
}

button.dashed-btn:hover {
  color: #3b82f6;
  border-color: #93c5fd;
}

.legend {
  margin-top: 32px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.legend-label {
  font-size: 0.7rem;
  font-weight: 500;
  color: #94a3b8;
  margin-right: 4px;
}

.legend .chip {
  cursor: default;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal {
  background: white;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  width: 320px;
}

.modal.wide {
  width: 520px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.modal h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #1f2937;
  margin: 0 0 4px 0;
}

.modal p {
  font-size: 0.8rem;
  color: #64748b;
  margin: 0 0 12px 0;
}

.modal label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: #4b5563;
  margin-bottom: 4px;
}

.modal input,
.modal select {
  width: 100%;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.8rem;
  font-family: inherit;
  outline: none;
  margin-bottom: 12px;
}

.modal input:focus,
.modal select:focus {
  box-shadow: 0 0 0 2px #93c5fd;
}

.modal textarea {
  flex: 1;
  min-height: 240px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.7rem;
  font-family: monospace;
  outline: none;
  resize: none;
}

.modal textarea:focus {
  box-shadow: 0 0 0 2px #93c5fd;
}

.modal .error {
  font-size: 0.7rem;
  color: #ef4444;
  margin: 4px 0 0 0;
}

.modal-btns {
  display: flex;
  gap: 8px;
  margin-top: 20px;
}

button.btn-primary {
  flex: 1;
  background: #3b82f6;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 8px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}

button.btn-primary:hover {
  background: #2563eb;
}

button.btn-danger {
  background: #fee2e2;
  color: #dc2626;
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}

button.btn-danger:hover {
  background: #fecaca;
}

button.btn-secondary {
  background: #f3f4f6;
  color: #4b5563;
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}

button.btn-secondary:hover {
  background: #e5e7eb;
}

tr.drag-over-row td.platform-cell {
  outline: 2px solid #3b82f6;
  outline-offset: -2px;
}

/* Save/Load */
.save-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.save-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.1s;
}

.save-list li:hover {
  background: #f1f5f9;
}

.save-list .save-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #1e293b;
}

.save-list .save-date {
  font-size: 0.7rem;
  color: #94a3b8;
}

.save-list .save-delete {
  background: none;
  border: none;
  color: #cbd5e1;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 2px 4px;
  line-height: 1;
  transition: color 0.15s;
  flex-shrink: 0;
}

.save-list .save-delete:hover {
  color: #f87171;
}

.save-empty {
  text-align: center;
  padding: 24px 0;
  font-size: 0.8rem;
  color: #94a3b8;
}

.modal .hint {
  font-size: 0.7rem;
  color: #94a3b8;
  margin: 0 0 12px 0;
}