/* ============================================================
   Imaginations — Item Master Panel  
   Estilo escuro fantasia
   ============================================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg-dark: #0d0d1a;
  --bg-panel: #13132b;
  --bg-card: #1a1a3e;
  --bg-card-hover: #232355;
  --bg-input: #1e1e42;
  --border: #2a2a5e;
  --text: #e0e0f0;
  --text-muted: #8888aa;
  --accent: #7c3aed;
  --accent-hover: #9b5de5;
  --danger: #e74c3c;
  --success: #2ecc71;
  --gold: #f1c40f;
  --rarity-common: #aaaacc;
  --rarity-uncommon: #2ecc71;
  --rarity-rare: #3498db;
  --rarity-very-rare: #9b59b6;
  --rarity-legendary: #f39c12;
  --header-height: 56px;
}

html, body { height: 100%; font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg-dark); color: var(--text); }

/* ---- Header ---- */
#app-header {
  height: var(--header-height);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  z-index: 100; position: relative;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.logo { height: 36px; width: 36px; border-radius: 8px; object-fit: cover; }
#app-header h1 { font-size: 18px; font-weight: 700; color: var(--text); }
.subtitle { font-weight: 400; color: var(--text-muted); font-size: 14px; }
.header-right { display: flex; align-items: center; gap: 16px; }
.placement-count { background: var(--bg-card); padding: 6px 14px; border-radius: 20px; font-size: 14px; font-weight: 600; }

/* ---- Layout ---- */
#app-layout {
  display: flex; height: calc(100vh - var(--header-height));
}

/* ---- Sidebar ---- */
#sidebar {
  width: 360px; min-width: 300px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 8px;
}
.sidebar-header h2 { font-size: 16px; font-weight: 600; }
.btn-icon {
  background: var(--accent); border: none; color: #fff;
  width: 32px; height: 32px; border-radius: 8px;
  font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.btn-icon:hover { background: var(--accent-hover); }

/* Filters */
.filters { padding: 8px 16px 12px; display: flex; flex-direction: column; gap: 8px; }
.filters input, .filters select {
  background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text); padding: 8px 12px; border-radius: 8px; font-size: 13px;
  outline: none; transition: border 0.2s;
}
.filters input:focus, .filters select:focus { border-color: var(--accent); }

/* Item list */
.item-list {
  flex: 1; overflow-y: auto; padding: 0 8px 8px;
}
.item-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; margin-bottom: 8px;
  cursor: grab; transition: all 0.2s; position: relative;
  user-select: none;
}
.item-card:hover { background: var(--bg-card-hover); border-color: var(--accent); transform: translateX(2px); }
.item-card:active { cursor: grabbing; }
.item-card.dragging { opacity: 0.5; transform: scale(0.95); }

.item-card-header { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.item-icon { font-size: 24px; width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; background: rgba(255,255,255,0.05); border-radius: 8px; flex-shrink: 0; }
.item-thumb { width: 36px; height: 36px; border-radius: 8px; object-fit: cover; flex-shrink: 0; border: 1px solid var(--border); }
.item-info { flex: 1; min-width: 0; }
.item-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-category { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

.item-stats { display: flex; gap: 6px; flex-wrap: wrap; }
.stat-badge {
  font-size: 11px; padding: 2px 8px; border-radius: 12px;
  background: rgba(255,255,255,0.06); color: var(--text-muted);
}

.rarity-badge {
  font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: 10px;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.rarity-common { background: rgba(170,170,204,0.15); color: var(--rarity-common); }
.rarity-uncommon { background: rgba(46,204,113,0.15); color: var(--rarity-uncommon); }
.rarity-rare { background: rgba(52,152,219,0.15); color: var(--rarity-rare); }
.rarity-very_rare { background: rgba(155,89,182,0.15); color: var(--rarity-very-rare); }
.rarity-legendary { background: rgba(243,156,18,0.15); color: var(--rarity-legendary); }

.item-actions {
  position: absolute; top: 8px; right: 8px;
  display: flex; gap: 4px; opacity: 0; transition: opacity 0.2s;
}
.item-card:hover .item-actions { opacity: 1; }
.item-action-btn {
  background: rgba(255,255,255,0.08); border: none; color: var(--text-muted);
  width: 26px; height: 26px; border-radius: 6px; font-size: 12px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.item-action-btn:hover { background: rgba(255,255,255,0.15); color: var(--text); }
.item-action-btn.delete:hover { background: rgba(231,76,60,0.2); color: var(--danger); }

/* ---- Map ---- */
#map-container { flex: 1; position: relative; }
#map { width: 100%; height: 100%; }

/* Drop overlay */
#drop-overlay {
  position: absolute; inset: 0;
  background: rgba(124, 58, 237, 0.15);
  border: 3px dashed var(--accent);
  display: flex; align-items: center; justify-content: center;
  z-index: 50; pointer-events: none;
}
#drop-overlay.hidden { display: none; }
.drop-message {
  background: var(--bg-panel); color: var(--text);
  padding: 16px 32px; border-radius: 12px; font-size: 18px; font-weight: 600;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

/* Placement panel */
#placement-panel {
  position: absolute; top: 16px; right: 16px;
  width: 340px; max-height: calc(100% - 32px);
  overflow-y: auto; background: rgba(19,19,43,0.97);
  border-radius: 12px; padding: 20px; z-index: 60;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
  border: 1px solid var(--border);
}
#placement-panel.hidden { display: none; }
#placement-panel .close-btn { position: absolute; top: 10px; right: 14px; }

.placement-detail h3 { margin-bottom: 8px; font-size: 16px; }
.placement-detail .detail-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; border-bottom: 1px solid rgba(255,255,255,0.05); }
.placement-detail .detail-label { color: var(--text-muted); }
.placement-detail .detail-value { font-weight: 600; }
.placement-detail .stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.placement-detail .stat-box { background: rgba(255,255,255,0.05); padding: 8px; border-radius: 8px; text-align: center; }
.placement-detail .stat-box .stat-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; }
.placement-detail .stat-box .stat-val { font-size: 18px; font-weight: 700; }

/* ---- Modal ---- */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.7); }
.modal-content {
  position: relative; background: var(--bg-panel);
  border-radius: 16px; padding: 24px; width: 90%; max-width: 680px;
  max-height: 85vh; overflow-y: auto;
  border: 1px solid var(--border);
  box-shadow: 0 12px 48px rgba(0,0,0,0.6);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal-header h2 { font-size: 20px; font-weight: 700; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group.full-width { grid-column: 1 / -1; }
.form-group label { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.form-group input, .form-group select, .form-group textarea {
  background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text); padding: 8px 12px; border-radius: 8px; font-size: 13px;
  outline: none; font-family: inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--accent); }

.form-fieldset {
  grid-column: 1 / -1; border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; margin-top: 4px;
}
.form-fieldset.hidden { display: none; }
.form-fieldset legend { font-size: 14px; font-weight: 600; padding: 0 8px; color: var(--accent); }
.form-grid-inner { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.form-grid-inner .full-width { grid-column: 1 / -1; }

/* ---- Image Upload ---- */
.image-upload-area {
  border: 2px dashed var(--border); border-radius: 12px;
  overflow: hidden; transition: border-color 0.2s;
  position: relative;
}
.image-upload-area.drag-over { border-color: var(--accent); background: rgba(124,58,237,0.05); }
.image-placeholder {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 24px; cursor: pointer; color: var(--text-muted);
  transition: color 0.2s;
}
.image-placeholder:hover { color: var(--accent); }
.upload-icon { font-size: 28px; }
.upload-hint { font-size: 11px; opacity: 0.6; }
.image-preview {
  position: relative; display: flex; align-items: center; justify-content: center;
  padding: 12px; background: rgba(0,0,0,0.2);
}
.image-preview.hidden { display: none; }
.image-preview img {
  max-width: 100%; max-height: 180px; border-radius: 8px;
  object-fit: contain;
}
.image-remove-btn {
  position: absolute; top: 8px; right: 8px;
  background: rgba(231,76,60,0.85); border: none; color: #fff;
  width: 26px; height: 26px; border-radius: 50%; font-size: 14px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.image-remove-btn:hover { background: var(--danger); }
.image-uploading {
  display: flex; align-items: center; justify-content: center;
  gap: 10px; padding: 24px; color: var(--text-muted);
}
.image-uploading.hidden { display: none; }
.spinner-small {
  width: 20px; height: 20px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }

.btn {
  padding: 10px 24px; border: none; border-radius: 10px;
  font-size: 14px; font-weight: 600; cursor: pointer; transition: all 0.2s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-secondary:hover { background: rgba(255,255,255,0.05); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #c0392b; }

.close-btn {
  background: none; border: none; color: var(--text-muted);
  font-size: 20px; cursor: pointer; padding: 4px;
}
.close-btn:hover { color: var(--text); }

/* ---- Toast ---- */
#toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg-panel); border: 1px solid var(--border);
  color: var(--text); padding: 12px 20px; border-radius: 10px;
  font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  animation: slideIn 0.3s ease; min-width: 250px;
}
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--accent); }

@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Map markers on placed items */
.map-marker-label {
  background: rgba(19,19,43,0.9); color: var(--text);
  padding: 4px 10px; border-radius: 8px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--border); white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.map-marker-icon {
  font-size: 28px; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
  cursor: pointer;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ---- Responsive ---- */
@media (max-width: 768px) {
  #app-layout { flex-direction: column; }
  #sidebar { width: 100%; height: 40vh; min-width: unset; border-right: none; border-bottom: 1px solid var(--border); }
  #map-container { height: 60vh; }
  .modal-content { width: 95%; max-height: 90vh; }
  #placement-panel { width: calc(100% - 32px); }
}
