/* ============================================================
   Imaginations — Combat Overlay  (Grade Tática D20)
   Tema: dark purple + gold #fdb927 + teal #00d4ff
   ============================================================ */

/* ── Vars ── */
:root {
  --cb-bg:        #07050f;
  --cb-surface:   #0e0a1e;
  --cb-panel:     #130d24;
  --cb-border:    #2a1a45;
  --cb-border2:   #3a2060;
  --cb-gold:      #fdb927;
  --cb-teal:      #00d4ff;
  --cb-purple:    #9b6fd4;
  --cb-purple-dim:#6a3a9a;
  --cb-text:      #e2d8f5;
  --cb-text-dim:  #8a7aaa;
  --cb-green:     #4de68a;
  --cb-red:       #e05555;
  --cb-orange:    #e09030;
  --cb-grid-line: rgba(120, 60, 200, 0.18);
  --cb-cell:      50px;
}

/* ── Overlay ── */
#combat-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  background: var(--cb-bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: var(--cb-text);
}
#combat-overlay.hidden { display: none; }

/* ── Header ── */
#combat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: linear-gradient(135deg, #150a2e 0%, #0a0618 100%);
  border-bottom: 1px solid var(--cb-border2);
  flex-shrink: 0;
}
#combat-title {
  font-size: 15px;
  font-weight: 800;
  color: var(--cb-gold);
  letter-spacing: .06em;
  text-transform: uppercase;
  text-shadow: 0 0 14px rgba(253,185,39,.35);
  flex-shrink: 0;
}

/* Unidade cards no header */
#combat-units {
  display: flex;
  gap: 8px;
  flex: 1;
  overflow: hidden;
}
.unit-card {
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--cb-border);
  border-radius: 8px;
  padding: 5px 10px 5px 6px;
  min-width: 0;
  max-width: 180px;
}
.unit-card.enemy-card  { border-color: rgba(200,60,60,.35); }
.unit-card.player-card { border-color: rgba(0,212,255,.25); }
.unit-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--cb-border2);
  flex-shrink: 0;
  background: #1a0a2e;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.unit-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.unit-info { flex: 1; min-width: 0; }
.unit-name {
  font-size: 11px; font-weight: 700;
  color: var(--cb-text); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
  text-transform: uppercase; letter-spacing: .05em;
}
.unit-hp-bar {
  height: 3px; border-radius: 2px;
  background: var(--cb-border); margin-top: 3px; overflow: hidden;
}
.unit-hp-fill {
  height: 100%; border-radius: 2px;
  background: linear-gradient(90deg, #1a7a40, var(--cb-green));
  transition: width .4s;
}
.unit-hp-fill.warn   { background: linear-gradient(90deg, #9a6010, var(--cb-orange)); }
.unit-hp-fill.danger { background: linear-gradient(90deg, #8a1a1a, var(--cb-red)); }
.unit-hp-text { font-size: 10px; color: var(--cb-text-dim); white-space: nowrap; }

#combat-round-badge {
  background: var(--cb-surface);
  border: 1px solid var(--cb-border2);
  color: var(--cb-purple);
  border-radius: 6px;
  padding: 4px 11px;
  font-size: 12px; font-weight: 700;
  flex-shrink: 0;
}
.combat-status-badge {
  border-radius: 6px; padding: 4px 11px;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  flex-shrink: 0;
}
.combat-status-badge.active  { background: #0d2a18; border: 1px solid #1a6a30; color: var(--cb-green); }
.combat-status-badge.ended   { background: #2a0d0d; border: 1px solid #6a1a1a; color: var(--cb-red); }
.combat-status-badge.pending { background: #2a230d; border: 1px solid #6a580d; color: var(--cb-gold); }
.cb-close-btn {
  background: transparent; border: 1px solid var(--cb-border);
  color: var(--cb-text-dim); border-radius: 6px;
  padding: 5px 12px; font-size: 12px; font-weight: 600;
  cursor: pointer; transition: all .15s; flex-shrink: 0;
}
.cb-close-btn:hover { border-color: var(--cb-red); color: var(--cb-red); }

/* ── Corpo ── */
#combat-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* ── Coluna esquerda: iniciativa ── */
#combat-initiative {
  width: 150px;
  flex-shrink: 0;
  background: var(--cb-surface);
  border-right: 1px solid var(--cb-border);
  overflow-y: auto;
  padding: 10px 0;
}
.cb-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--cb-text-dim);
  padding: 0 12px 8px;
  border-bottom: 1px solid var(--cb-border);
}
.initiative-entry {
  display: flex; align-items: center; gap: 7px;
  padding: 8px 12px;
  transition: background .15s;
  position: relative;
}
.initiative-entry.current-turn {
  background: rgba(253,185,39,.08);
  border-left: 3px solid var(--cb-gold);
}
.initiative-entry.current-turn::after {
  content: '▶';
  position: absolute; right: 8px;
  color: var(--cb-gold); font-size: 9px;
  animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.initiative-entry.unconscious { opacity: .4; }
.initiative-entry.dead        { opacity: .25; text-decoration: line-through; }
.initiative-entry.fled        { opacity: .3; font-style: italic; }
.init-avatar-placeholder {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--cb-panel); border: 1px solid var(--cb-border2);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0;
}
.init-info { flex: 1; min-width: 0; }
.init-name {
  font-size: 11px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.init-hp-bar {
  height: 3px; border-radius: 2px;
  background: var(--cb-border); margin-top: 3px; overflow: hidden;
}
.init-hp-fill { height: 100%; border-radius: 2px; background: linear-gradient(90deg, #1a7a40, var(--cb-green)); transition: width .4s; }
.init-hp-fill.danger { background: linear-gradient(90deg, #8a1a1a, var(--cb-red)); }
.init-roll { font-size: 10px; color: var(--cb-text-dim); font-weight: 700; flex-shrink: 0; }

/* ── Centro: grade tática ── */
#combat-grid-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: #05030d;
}
#combat-grid-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 14px;
  background: rgba(30,15,60,.7);
  border-bottom: 1px solid var(--cb-border);
  flex-shrink: 0;
}
#grid-label {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--cb-purple);
}
#turn-banner {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--cb-gold);
  background: rgba(253,185,39,.12);
  border: 1px solid rgba(253,185,39,.3);
  border-radius: 5px;
  padding: 3px 10px;
  display: none;
}
#turn-banner.visible { display: block; }

#combat-grid-container {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  position: relative;
}

/* Grade tática */
#combat-grid {
  display: grid;
  gap: 0;
  position: relative;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent calc(var(--cb-cell) - 1px),
    var(--cb-grid-line) calc(var(--cb-cell) - 1px),
    var(--cb-grid-line) var(--cb-cell)
  ),
  repeating-linear-gradient(
    90deg,
    transparent,
    transparent calc(var(--cb-cell) - 1px),
    var(--cb-grid-line) calc(var(--cb-cell) - 1px),
    var(--cb-grid-line) var(--cb-cell)
  );
  border: 1px solid var(--cb-border2);
  border-radius: 4px;
  box-shadow: 0 0 40px rgba(100,40,180,.15), inset 0 0 60px rgba(5,3,15,.5);
}

.grid-cell {
  width: var(--cb-cell);
  height: var(--cb-cell);
  position: relative;
  cursor: default;
  transition: background .12s;
}
.grid-cell.reachable {
  background: rgba(0, 212, 255, 0.08);
  cursor: pointer;
}
.grid-cell.reachable:hover {
  background: rgba(0, 212, 255, 0.18);
}
.grid-cell.drop-target {
  background: rgba(0, 212, 255, 0.28) !important;
  outline: 2px dashed rgba(0, 212, 255, 0.6);
  outline-offset: -2px;
}
.grid-cell.attack-range {
  background: rgba(220, 50, 50, 0.07);
}

/* Tokens */
.combat-token {
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  border: 2px solid transparent;
  cursor: default;
  z-index: 2;
  transition: box-shadow .2s;
  user-select: none;
}
.combat-token.player-token {
  background: radial-gradient(circle at 35% 35%, #2a1060, #150830);
  border-color: var(--cb-teal);
  box-shadow: 0 0 10px rgba(0,212,255,.4), 0 0 0 3px rgba(0,212,255,.1);
}
.combat-token.player-token.my-token {
  cursor: grab;
}
.combat-token.player-token.my-token:active {
  cursor: grabbing;
}
.combat-token.player-token.dragging {
  opacity: .5;
  box-shadow: none;
}
.combat-token.enemy-token {
  background: radial-gradient(circle at 35% 35%, #3a0a0a, #1a0505);
  border-color: var(--cb-red);
  box-shadow: 0 0 10px rgba(220,50,50,.4), 0 0 0 3px rgba(220,50,50,.1);
}
.combat-token img {
  width: 100%; height: 100%; border-radius: 50%; object-fit: cover;
}
.combat-token.current-turn-token {
  animation: token-pulse 1.5s ease-in-out infinite;
}
@keyframes token-pulse {
  0%, 100% { box-shadow: 0 0 10px rgba(253,185,39,.5), 0 0 0 4px rgba(253,185,39,.15); }
  50%       { box-shadow: 0 0 20px rgba(253,185,39,.8), 0 0 0 6px rgba(253,185,39,.25); }
}
.token-hp-bar {
  position: absolute;
  bottom: -7px; left: 0; right: 0;
  height: 3px; border-radius: 2px;
  background: var(--cb-border); overflow: hidden;
}
.token-hp-fill {
  height: 100%; border-radius: 2px;
  background: var(--cb-green); transition: width .4s;
}
.token-hp-fill.warn   { background: var(--cb-orange); }
.token-hp-fill.danger { background: var(--cb-red); }

/* Movimento restante */
#movement-indicator {
  position: absolute;
  top: 8px; left: 8px;
  background: rgba(0,212,255,.15);
  border: 1px solid rgba(0,212,255,.4);
  color: var(--cb-teal);
  font-size: 11px; font-weight: 700;
  padding: 3px 8px; border-radius: 5px;
  pointer-events: none;
  display: none;
}
#movement-indicator.visible { display: block; }

/* Thinking */
#enemy-thinking {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  background: rgba(60,20,100,.3);
  border-top: 1px solid var(--cb-border);
  color: var(--cb-purple); font-size: 12px;
  flex-shrink: 0;
}
#enemy-thinking.hidden { display: none; }
.spinner-small {
  width: 14px; height: 14px;
  border: 2px solid var(--cb-border2);
  border-top-color: var(--cb-purple);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Direita: hostis + log ── */
#combat-right {
  width: 200px;
  flex-shrink: 0;
  background: var(--cb-surface);
  border-left: 1px solid var(--cb-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#combat-hostiles {
  padding: 8px;
  flex-shrink: 0;
}
.hostile-card {
  background: rgba(200,40,40,.08);
  border: 1px solid rgba(200,40,40,.2);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 6px;
}
.hostile-name {
  font-size: 12px; font-weight: 700;
  color: #e08080; margin-bottom: 4px;
  display: flex; align-items: center; gap: 5px;
}
.hostile-hp-bar {
  height: 4px; border-radius: 2px;
  background: var(--cb-border); overflow: hidden;
}
.hostile-hp-fill {
  height: 100%; border-radius: 2px;
  background: linear-gradient(90deg, #8a1a1a, var(--cb-red));
  transition: width .4s;
}
.hostile-stats {
  font-size: 10px; color: var(--cb-text-dim);
  margin-top: 4px;
  display: flex; gap: 8px;
}
#combat-log {
  flex: 1; overflow-y: auto;
  padding: 6px 8px;
  display: flex; flex-direction: column; gap: 4px;
}
.log-entry {
  font-size: 11px; line-height: 1.45;
  padding: 6px 8px; border-radius: 5px;
  border-left: 2px solid transparent;
  background: rgba(255,255,255,.025);
  animation: fadeSlide .2s ease;
}
@keyframes fadeSlide { from { opacity:0; transform:translateY(3px); } to { opacity:1; transform:none; } }
.log-entry.attack    { border-left-color: var(--cb-red); }
.log-entry.spell     { border-left-color: #8050e0; }
.log-entry.dodge     { border-left-color: var(--cb-teal); }
.log-entry.disengage { border-left-color: var(--cb-orange); }
.log-entry.flee      { border-left-color: var(--cb-orange); }
.log-entry.death_save{ border-left-color: #e07050; }
.log-entry.other     { border-left-color: var(--cb-green); color: #90d0b0; }
.log-entry.system    { border-left-color: var(--cb-gold); color: var(--cb-gold); font-weight: 700; }
.log-entry.enemy-action { border-left-color: var(--cb-red); background: rgba(200,40,40,.07); }

/* ── Rodapé: tabs + ações ── */
#combat-bottom {
  flex-shrink: 0;
  background: var(--cb-panel);
  border-top: 1px solid var(--cb-border2);
}
#combat-tabs {
  display: flex;
  border-bottom: 1px solid var(--cb-border);
}
.cb-tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--cb-text-dim);
  font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em;
  padding: 10px 6px;
  cursor: pointer;
  transition: all .15s;
  display: flex; align-items: center; justify-content: center; gap: 5px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.cb-tab:hover { color: var(--cb-text); background: rgba(255,255,255,.03); }
.cb-tab.active {
  color: var(--cb-gold);
  border-bottom-color: var(--cb-gold);
  background: rgba(253,185,39,.05);
}

#combat-actions { padding: 10px 14px; }
#combat-actions.hidden { display: none; }
.cb-tab-panel { display: flex; flex-direction: column; gap: 8px; }
.cb-tab-panel.hidden { display: none; }
.cb-empty { color: var(--cb-text-dim); font-size: 12px; margin: 0; }

/* Target selector */
#target-selector {
  display: flex; align-items: center; gap: 8px;
}
#target-selector label { font-size: 11px; color: var(--cb-text-dim); white-space: nowrap; }
#target-select {
  flex: 1; background: var(--cb-surface); border: 1px solid var(--cb-border2);
  color: var(--cb-text); border-radius: 5px; padding: 5px 8px; font-size: 12px;
}
#target-select:focus { outline: none; border-color: var(--cb-purple-dim); }

/* Botões de ação */
#action-buttons {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.action-btn {
  background: var(--cb-surface);
  border: 1px solid var(--cb-border2);
  color: var(--cb-purple);
  border-radius: 7px;
  padding: 7px 12px;
  font-size: 12px; font-weight: 700;
  cursor: pointer;
  display: flex; align-items: center; gap: 5px;
  transition: all .15s;
  text-transform: uppercase; letter-spacing: .05em;
}
.action-btn:hover:not(:disabled) {
  background: rgba(155,111,212,.15);
  border-color: var(--cb-purple);
  color: var(--cb-text);
  transform: translateY(-1px);
}
.action-btn:disabled { opacity: .3; cursor: not-allowed; }
.action-btn .btn-icon { font-size: 14px; }
.action-btn.primary {
  background: rgba(253,185,39,.12);
  border-color: rgba(253,185,39,.4);
  color: var(--cb-gold);
}
.action-btn.primary:hover:not(:disabled) {
  background: rgba(253,185,39,.2);
  border-color: var(--cb-gold);
}
.action-btn.danger { border-color: rgba(200,50,50,.4); color: var(--cb-red); }
.action-btn.danger:hover:not(:disabled) { background: rgba(200,50,50,.12); border-color: var(--cb-red); }

/* Spell selector */
#spell-selector { display: none; align-items: center; gap: 6px; }
#spell-selector.visible { display: flex; }
#spell-select {
  flex: 1; background: var(--cb-surface); border: 1px solid var(--cb-border2);
  color: var(--cb-text); border-radius: 5px; padding: 5px 8px; font-size: 12px;
}
#cast-spell-btn {
  padding: 6px 12px; border-radius: 6px;
  background: rgba(128,80,224,.2); border: 1px solid #8050e0;
  color: #c0a0ff; font-size: 12px; font-weight: 700; cursor: pointer;
}
#cast-spell-btn:hover { filter: brightness(1.2); }

/* Footer */
#combat-footer {
  padding: 8px 14px;
  display: flex; align-items: center; gap: 12px;
  border-top: 1px solid var(--cb-border);
}
.footer-btn {
  background: var(--cb-surface); border: 1px solid var(--cb-border2);
  color: var(--cb-text-dim); border-radius: 6px;
  padding: 6px 14px; font-size: 12px; font-weight: 600;
  cursor: pointer; transition: all .15s;
}
.footer-btn:hover { border-color: var(--cb-purple); color: var(--cb-text); }
#combat-result-msg {
  flex: 1; text-align: center; font-size: 15px; font-weight: 700;
}
#combat-result-msg.win  { color: var(--cb-gold); text-shadow: 0 0 14px rgba(253,185,39,.5); }
#combat-result-msg.lose { color: var(--cb-red); }
#combat-result-msg.flee { color: var(--cb-teal); }

/* Condições */
.conditions-row { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 4px; }
.condition-badge {
  font-size: 9px; padding: 1px 5px; border-radius: 8px;
  background: var(--cb-panel); border: 1px solid var(--cb-border2); color: var(--cb-purple);
}

/* ── Responsive ── */
@media (max-width: 900px) {
  #combat-initiative { width: 110px; }
  #combat-right      { width: 160px; }
  :root { --cb-cell: 42px; }
}
@media (max-width: 680px) {
  #combat-body { flex-direction: column; }
  #combat-initiative {
    width: 100%; max-height: 90px;
    border-right: none; border-bottom: 1px solid var(--cb-border);
    display: flex; flex-direction: row; overflow-x: auto; overflow-y: hidden;
    padding: 6px;
  }
  .initiative-entry { flex-direction: column; min-width: 70px; text-align: center; border-radius: 6px; }
  .initiative-entry.current-turn::after { display: none; }
  #combat-right {
    width: 100%; max-height: 120px;
    border-left: none; border-top: 1px solid var(--cb-border);
    flex-direction: row;
  }
  #combat-hostiles { width: 50%; border-right: 1px solid var(--cb-border); }
  #combat-log { height: 120px; }
  :root { --cb-cell: 38px; }
}
