/* Grid/Table */
.grid {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

/* ---- List column styles ---- */
.grid .list-cell { display: flex; gap: 6px; align-items: center; }
.grid .list-select {
  background: var(--panel);
  color: var(--primary);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: 8px;
  appearance: none;
}
.grid .list-select:focus { border-color: var(--primary); }
.grid .list-select option { background: var(--panel-2); color: var(--primary); }
.grid .btn.btn-xs { padding: 4px 8px; font-size: 12px; border-radius: 6px; }
.grid .list-select:disabled {
  background: var(--panel-2);
  color: var(--muted);
  border-color: var(--border);
  opacity: 0.7;
}

/* When rules disable a list cell, mark wrapper and hide the add button */
.grid .list-cell.disabled {
  opacity: 0.6;
}
.grid .list-cell.disabled .btn { display: none; }
/* ---- Hyperlink column styles ---- */
.grid .hyperlink-cell { display: flex; align-items: center; gap: 6px; }
.grid .hyperlink-cell input { flex: 1 1 auto; min-width: 0; }
.grid .hyperlink-cell .link-open-btn { flex: 0 0 auto; white-space: nowrap; }
.grid-header, .grid-row {
  display: grid;
  grid-auto-columns: minmax(140px, 1fr);
  grid-auto-flow: column;
}
.grid-header {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.grid .col-header { position: relative; }
.grid .col-drag-handle { cursor: grab; }
.grid .col-header.drag-over { outline: 2px dashed var(--primary); outline-offset: -4px; }
.grid-cell {
  padding: 10px 12px;
  border-right: 1px solid var(--border);
  position: relative;
}
.grid-row:nth-child(odd) { background: rgba(255,255,255,0.02); }
.grid-row:last-child { border-bottom: 1px solid var(--border); }
.grid input, .grid select {
  width: 100%;
  background: transparent;
  color: var(--text);
  border: 1px dashed transparent;
  padding: 8px 10px;
  outline: none;
}
.grid input:focus, .grid select:focus { border-color: var(--primary); }

/* Date input: make native calendar indicator visible/clickable on dark theme */
.grid input[type="date"] { color-scheme: dark; }
.grid input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(1) brightness(2);
  opacity: 0.9;
  cursor: pointer;
}

/* Custom date UI (text + button) */
.grid .date-text { padding-right: 32px; }
.grid .date-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}
.grid .date-btn:hover { background: rgba(255,255,255,0.06); }
.grid .date-btn::before {
  content: '';
  display: block;
  width: 16px;
  height: 16px;
  margin: 3px auto;
  background-repeat: no-repeat;
  background-size: 16px 16px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='%23ffffff'%3E%3Cpath d='M3 2.5a.5.5 0 0 0-1 0V3H2A2 2 0 0 0 0 5v1h16V5a2 2 0 0 0-2-2h0v-.5a.5.5 0 0 0-1 0V3H3v-.5z'/%3E%3Cpath d='M16 14V7H0v7a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2z'/%3E%3C/svg%3E");
}

/* Invisible native date input positioned by the icon so the picker anchors correctly */
.grid .date-hidden {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 1px;
  height: 1px;
  opacity: 0;
  border: 0;
  background: transparent;
  color: transparent;
}

/* Column resize handle */
.col-resize-handle {
  position: absolute;
  top: 4px;
  right: 0;
  width: 6px;
  height: calc(100% - 8px);
  cursor: col-resize;
  border-right: 2px solid transparent;
}
.col-resize-handle:hover {
  border-right-color: var(--primary);
}

/* Cell save status dot */
.cell-status {
  position: absolute;
  bottom: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: transparent;
  opacity: 0.6;
}
.cell-status.saving {
  background: var(--primary);
  animation: pulse 1s infinite ease-in-out;
}
.cell-status.saved {
  background: var(--success);
}

@keyframes pulse {
  0% { transform: scale(0.9); opacity: 0.5; }
  50% { transform: scale(1.1); opacity: 0.9; }
  100% { transform: scale(0.9); opacity: 0.5; }
}

/* Row gutter with delete icon */
.grid .row-gutter {
  width: 36px;
  padding: 6px 6px;
  border-right: 1px solid var(--border);
}
.grid .row-del-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  opacity: 0.3;
  transition: background-color 120ms ease, border-color 120ms ease, opacity 120ms ease;
}
.grid .grid-row:hover .row-del-btn { opacity: 1; }
.grid .row-del-btn:hover, .grid .row-del-btn:focus-visible {
  background: rgba(220, 38, 38, 0.12); /* red-600 at low alpha */
  border-color: rgba(220, 38, 38, 0.6);
}
.grid .row-del-btn::before {
  content: '';
  display: block;
  width: 16px;
  height: 16px;
  margin: 3px auto;
  background-repeat: no-repeat;
  background-size: 16px 16px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='%23ffffff'%3E%3Cpath d='M5.5 5a.5.5 0 0 1 .5.5V12a.5.5 0 0 1-1 0V5.5a.5.5 0 0 1 .5-.5zm3 0a.5.5 0 0 1 .5.5V12a.5.5 0 0 1-1 0V5.5a.5.5 0 0 1 .5-.5z'/%3E%3Cpath fill-rule='evenodd' d='M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1 0-2H5h6h2.5a1 1 0 0 1 1 1zM5.118 4 5 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L10.882 4H5.118zM6 2a1 1 0 0 0-1 1h6a1 1 0 0 0-1-1H6z'/%3E%3C/svg%3E");
  filter: opacity(0.9);
}
.grid .row-del-btn:hover::before, .grid .row-del-btn:focus-visible::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='%23ef4444'%3E%3Cpath d='M5.5 5a.5.5 0 0 1 .5.5V12a.5.5 0 0 1-1 0V5.5a.5.5 0 0 1 .5-.5zm3 0a.5.5 0 0 1 .5.5V12a.5.5 0 0 1-1 0V5.5a.5.5 0 0 1 .5-.5z'/%3E%3Cpath fill-rule='evenodd' d='M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1 0-2H5h6h2.5a1 1 0 0 1 1 1zM5.118 4 5 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L10.882 4H5.118zM6 2a1 1 0 0 0-1 1h6a1 1 0 0 0-1-1H6z'/%3E%3C/svg%3E");
}

/* Contact Person column styles */
.grid .contact-cell { display: flex; align-items: center; }
.grid .contact-btn {
  width: 100%;
  text-align: center;
  background: var(--panel-2);
  color: var(--primary);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background-color 150ms ease, border-color 150ms ease;
}
.grid .contact-btn:hover:not(:disabled) {
  background: var(--primary);
  color: var(--bg);
  border-color: var(--primary);
}
.grid .contact-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.grid .contact-btn-warning {
  background: rgba(255, 193, 7, 0.15);
  color: #ffc107;
  border-color: rgba(255, 193, 7, 0.4);
  font-style: italic;
}
.grid .contact-btn-warning:hover:not(:disabled) {
  background: rgba(255, 193, 7, 0.25);
  border-color: #ffc107;
}
