/* ═══════════════════════════════════════════════════
   Modal System — Shared across all pop-ups
   Width, header, footer, close button all standardized.
   ═══════════════════════════════════════════════════ */

/* ── Overlay ── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.4); backdrop-filter: blur(4px);
  z-index: 500; align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
#edit-cat-modal { z-index: 600; }

/* ── Modal box ── */
.modal {
  background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border); width: 520px; max-width: 95vw;
  height: 85vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg); animation: modalIn .2s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(.96) translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ── Header ── */
.modal-head {
  padding: 22px 24px 0;
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px; flex-shrink: 0;
}
.modal-title { font-size: 17px; font-weight: 700; }
.modal-close {
  width: 30px; height: 30px; border-radius: 8px;
  border: 1px solid var(--border); background: transparent;
  cursor: pointer; font-size: 16px; color: var(--text3);
  display: flex; align-items: center; justify-content: center;
  transition: all .12s; flex-shrink: 0;
}
.modal-close:hover { background: var(--red-light); color: var(--red); border-color: var(--red); }

/* ── Body ── */
.modal-body { padding: 0 24px 24px; flex: 1; overflow-y: auto; }
.modal-body .field { margin-bottom: 14px; }

/* ── Footer ── */
.modal-footer {
  padding: 16px 24px; border-top: 1px solid var(--surface2);
  display: flex; gap: 10px; justify-content: flex-end;
  flex-shrink: 0;
}
/* Variant: delete button on left, cancel+save on right */
.modal-footer.has-delete { justify-content: space-between; }
.modal-footer.has-delete .modal-footer-actions {
  display: flex; gap: 10px; align-items: center;
}

/* ── TX Modal tabs ── */
.tx-tabs { display:flex; gap:4px; padding:14px 0 12px; margin-bottom:14px; border-bottom:1px solid var(--surface3); }
.tx-tab { flex:1; height:40px; border-radius:var(--radius-sm); border:1px solid var(--border); background:var(--surface2); font-family:inherit; font-size:13px; font-weight:500; cursor:pointer; color:var(--text2); transition:all .15s; }
.tx-tab:hover { background:var(--surface3); color:var(--text); }
.tx-tab.active { background:var(--accent); color:#fff; border-color:var(--accent); font-weight:600; box-shadow:0 2px 8px rgba(var(--accent-rgb),.25); }

/* ── Category grid (tx modal) ── */
.cat-grid { display:grid; grid-template-columns:repeat(6, 1fr); gap:6px; padding-bottom:16px; margin-bottom:14px; border-bottom:1px solid var(--surface3); }
.cat-item { display:flex; flex-direction:column; align-items:center; gap:5px; cursor:pointer; width:70px; padding:4px 2px; border-radius:var(--radius-sm); transition:background .1s; flex-shrink:0; }
.cat-item:hover { background:var(--surface2); }
.cat-item-icon { width:52px; height:52px; border-radius:50%; background:var(--surface2); border:2px solid var(--border); display:flex; align-items:center; justify-content:center; font-size:22px; transition:all .15s; flex-shrink:0; }
.cat-item.active .cat-item-icon { border-color:var(--accent); border-width:2.5px; background:rgba(var(--accent-rgb),.07); }
.cat-item-label { font-size:10px; color:var(--text2); text-align:center; line-height:1.3; word-break:break-word; max-width:68px; }
.cat-item.active .cat-item-label { color:var(--accent); font-weight:600; }
.cat-item-edit .cat-item-icon { border:2.5px dashed #f59e0b; background:#fffbeb; }
.cat-item-edit .cat-item-label { color:#f59e0b; }

/* ── Asset icon picker ── */
.asset-icon-grid { display:grid; grid-template-columns:repeat(8, 1fr); gap:4px; max-height:200px; overflow-y:auto; margin-bottom:14px; }
.asset-icon-item { display:flex; align-items:center; justify-content:center; aspect-ratio:1; font-size:20px; border-radius:8px; border:2px solid transparent; cursor:pointer; transition:all .12s; background:var(--surface2); }
.asset-icon-item:hover { background:var(--surface3); }
.asset-icon-item.active { border-color:var(--accent); background:rgba(var(--accent-rgb),.1); }

/* ── Category icon picker (edit-cat modal) ── */
.icon-picker-grid { display:grid; grid-template-columns:repeat(auto-fill, minmax(34px, 1fr)); gap:4px; max-height:160px; overflow-y:auto; padding:8px; background:var(--surface2); border-radius:var(--radius-sm); border:1px solid var(--border); margin-bottom:10px; }
.icon-pick-btn { width:100%; aspect-ratio:1; border:1.5px solid transparent; border-radius:8px; background:var(--surface); font-size:18px; cursor:pointer; display:flex; align-items:center; justify-content:center; transition:all .1s; }
.icon-pick-btn:hover { border-color:var(--accent); background:rgba(var(--accent-rgb),.08); }
.icon-pick-btn.selected { border-color:var(--accent); background:rgba(var(--accent-rgb),.1); }

/* ── Edit category rows ── */
.edit-cat-row { display:flex; align-items:center; gap:10px; padding:8px 0; border-bottom:1px solid var(--surface2); }
.edit-cat-row:last-child { border-bottom:none; }
.ecat-icon-btn { width:38px; height:38px; border-radius:50%; border:1.5px solid var(--border); background:var(--surface2); font-size:20px; cursor:pointer; display:flex; align-items:center; justify-content:center; flex-shrink:0; transition:border-color .12s; }
.ecat-icon-btn:hover { border-color:var(--accent); }
.ecat-name { flex:1; font-size:13.5px; font-weight:500; }
.ecat-name input { width:100%; height:34px; padding:0 8px; border:1px solid var(--accent); border-radius:6px; font-family:inherit; font-size:13px; outline:none; background:var(--surface); }
.ecat-btn { width:32px; height:32px; border:none; background:transparent; cursor:pointer; font-size:17px; display:flex; align-items:center; justify-content:center; border-radius:6px; transition:background .12s; }
.ecat-btn:hover { background:var(--surface2); }

/* ── Target list rows (target modal) ── */
.tm-target-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  margin-bottom: 8px; transition: opacity .15s, border-color .15s;
}
.tm-target-row:last-child { margin-bottom: 0; }
.tm-target-row.tm-editing { border-color: var(--accent); background: rgba(var(--accent-rgb),.02); }
.tm-target-row.tm-dimmed { opacity: 0.35; pointer-events: none; }
.tm-drag-handle { font-size: 16px; color: var(--text3); cursor: grab; user-select: none; flex-shrink: 0; line-height: 1; }
.tm-drag-handle:active { cursor: grabbing; }
.tm-drag-over { border-color: var(--accent) !important; background: rgba(var(--accent-rgb),.04) !important; }
.tm-icon-disp { font-size: 20px; flex-shrink: 0; width: 28px; text-align: center; }
.tm-action-btn {
  width: 28px; height: 28px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text3); cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 13px;
  transition: all .12s; flex-shrink: 0;
}
.tm-action-btn:hover { background: var(--surface2); }
.tm-action-btn.save { border-color: var(--green); background: var(--green-light); color: var(--green); }
.tm-action-btn.save:hover { background: #bbf7d0; }
.tm-action-btn.del:hover { background: var(--red-light); color: var(--red); border-color: var(--red); }
.tm-edit-input {
  width: 100%; height: 32px; padding: 0 8px;
  border: 1px solid var(--accent); border-radius: 6px;
  font-family: inherit; font-size: 13px; outline: none;
  background: var(--surface); color: var(--text);
}
.tm-empty { text-align: center; padding: 20px; color: var(--text3); font-size: 13px; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .modal { width: 96vw !important; max-width: 96vw !important; height: 85vh; border-radius: var(--radius-sm); }
  .cat-grid { grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); }
  .cat-item { width: auto; }
  .cat-item-icon { width: 44px; height: 44px; font-size: 20px; }
  .cat-item-label { max-width: none; }
  .asset-icon-grid { grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); }
}
