:root {
  --bg: #fec3db;
  --paper: #ffe3ef;
  --paper-strong: #fff5fa;
  --text: #2f1836;
  --muted: #70418b;
  --line: #d79bbb;
  --accent: #b74163;
  --accent-2: #c24c92;
  --danger: #70418b;
  --shadow: 0 16px 38px rgba(112, 65, 139, 0.2);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Cairo", "Segoe UI", Tahoma, sans-serif;
  background: radial-gradient(circle at 15% 10%, #fec3db 0%, #f4a8cf 45%, #e593c4 100%);
  color: var(--text);
  overflow-x: hidden;
}

.bg-orb {
  position: fixed;
  border-radius: 999px;
  filter: blur(2px);
  z-index: -3;
  opacity: 0.34;
  pointer-events: none;
}

.orb-1 {
  width: 420px;
  height: 420px;
  background: radial-gradient(circle, #b74163 0%, #b7416300 72%);
  top: -120px;
  right: -120px;
  animation: floatOrb 12s ease-in-out infinite;
}

.orb-2 {
  width: 460px;
  height: 460px;
  background: radial-gradient(circle, #70418b 0%, #70418b00 70%);
  bottom: -140px;
  left: -140px;
  animation: floatOrb 16s ease-in-out infinite reverse;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image: linear-gradient(to right, #ffffff38 1px, transparent 1px),
    linear-gradient(to bottom, #ffffff38 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: radial-gradient(circle at center, #000 55%, transparent 100%);
  z-index: -2;
  pointer-events: none;
}

.container {
  max-width: 1280px;
  margin: 2.3rem auto;
  padding: 0 1rem;
}

.card {
  position: relative;
  background: linear-gradient(145deg, #fff0f8f5, #ffe1f0de);
  border: 1px solid #ffffffb3;
  border-radius: 20px;
  padding: 1.2rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
  animation: cardIn 420ms ease both;
}

.hidden {
  display: none;
}

h1 {
  margin: 0 0 0.3rem;
  font-size: clamp(1.35rem, 2vw, 2rem);
  line-height: 1.1;
}

p {
  margin: 0;
  color: var(--muted);
}

form {
  display: grid;
  gap: 0.75rem;
  max-width: 360px;
  margin-top: 0.85rem;
}

label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.95rem;
}

input {
  width: 100%;
  border: 1px solid #d38cb1;
  border-radius: 10px;
  padding: 0.62rem 0.72rem;
  font-size: 1rem;
  font-family: inherit;
  background: var(--paper-strong);
  color: var(--text);
  transition: border-color 150ms ease, box-shadow 150ms ease, transform 120ms ease;
}

input:focus {
  outline: 0;
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px #c24c9238;
  transform: translateY(-1px);
}

button {
  border: 0;
  border-radius: 11px;
  padding: 0.5rem 0.82rem;
  color: #fff;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  letter-spacing: 0.15px;
  transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease;
}

button:hover {
  filter: brightness(1.04);
  transform: translateY(-1px);
  box-shadow: 0 8px 16px #b7416338;
}

button:active {
  transform: translateY(0);
}

button.danger {
  background: linear-gradient(145deg, #8a4cb8, var(--danger));
}

.icon-btn {
  min-width: 42px;
  min-height: 42px;
  font-size: 1rem;
  padding: 0.5rem;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.9rem;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
}

.toolbar-title p {
  font-size: 0.9rem;
}

.search-wrap {
  min-width: 220px;
  flex: 1 1 320px;
}

.search-wrap input {
  width: 100%;
}

.actions {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.hint {
  margin-bottom: 0.7rem;
  padding: 0.38rem 0.58rem;
  width: fit-content;
  border-radius: 9px;
  background: #ffe9f3;
  border: 1px solid #e8b3cf;
  font-size: 0.85rem;
}

.tableWrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 14px;
  border: 1px solid #e0a6c4;
  background: var(--paper);
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 820px;
}

th,
td {
  border-left: 1px solid #e9b8d0;
  border-top: 1px solid #e9b8d0;
  padding: 0.46rem;
  text-align: right;
  vertical-align: top;
}

th:first-child,
td:first-child {
  border-right: 1px solid #e9b8d0;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: linear-gradient(160deg, #ffd7e8, #f7c0de);
}

tbody tr:nth-child(even) td {
  background: #ffedf6;
}

tbody tr:hover td {
  background: #ffe0ef;
}

td input {
  border: 1px solid #e2a7c7;
  border-radius: 8px;
  width: 100%;
  background: #fff;
  min-width: 120px;
}

td input.selected-cell {
  outline: 2px solid var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px #b741632e;
}

td input.auto-cell {
  background: #f8d8e8;
  color: #70418b;
  font-weight: 700;
  cursor: default;
}

.col-controls,
.row-controls {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
  margin-top: 0.3rem;
}

.mini {
  padding: 0.22rem 0.44rem;
  font-size: 0.79rem;
  border-radius: 8px;
}

.drag-handle {
  cursor: grab;
  touch-action: none;
  background: linear-gradient(145deg, #70418b, #5c3473);
}

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

[data-col-head].dragging,
[data-row-item].dragging td {
  opacity: 0.55;
}

[data-col-head],
[data-row-item] {
  will-change: transform;
}

[data-col-head].drop-target,
[data-row-item].drop-target td {
  box-shadow: inset 0 0 0 2px #b74163;
  background: #ffd9ea;
}

.error {
  color: var(--danger);
  min-height: 1.2rem;
}

@keyframes floatOrb {
  0%,
  100% {
    transform: translate(0, 0);
  }
  50% {
    transform: translate(14px, 22px);
  }
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 880px) {
  .container {
    margin-top: 1rem;
  }

  .card {
    padding: 0.9rem;
    border-radius: 16px;
  }

  .toolbar {
    align-items: stretch;
  }

  .toolbar-title {
    width: 100%;
  }

  .search-wrap {
    width: 100%;
    flex-basis: 100%;
  }

  .actions {
    width: 100%;
  }

  .actions button {
    flex: 1 1 calc(33.33% - 0.4rem);
    min-height: 42px;
  }

  .hint {
    width: 100%;
    font-size: 0.8rem;
  }

  table {
    min-width: 700px;
  }

  .mini {
    min-height: 36px;
    min-width: 36px;
  }
}

@media (max-width: 540px) {
  .container {
    padding: 0 0.55rem;
  }

  .actions button {
    flex: 1 1 calc(25% - 0.35rem);
  }

  input {
    min-height: 42px;
  }

  .toolbar {
    gap: 0.65rem;
  }

  .toolbar-title p {
    font-size: 0.8rem;
  }

  .tableWrap {
    border: 0;
    background: transparent;
    overflow: visible;
  }

  table {
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0 0.6rem;
  }

  thead {
    display: none;
  }

  tbody {
    display: block;
  }

  tbody tr {
    display: block;
    border: 1px solid #e0a6c4;
    border-radius: 14px;
    padding: 0.5rem;
    background: #fff0f8;
    box-shadow: 0 6px 14px rgba(112, 65, 139, 0.14);
  }

  tbody td {
    display: block;
    border: 0;
    padding: 0.3rem 0;
    background: transparent !important;
  }

  tbody td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    color: #70418b;
    margin-bottom: 0.2rem;
  }

  tbody td input {
    min-height: 40px;
  }

  .row-controls {
    justify-content: flex-start;
  }
}
