/* ============================================================
   Living Architecture — mapa interativo de infra/projetos
   Skins: bio (biológico), diagram (clássico), urban (prédios), mech (engrenagens)
   ============================================================ */

/* ── ROOT CONTAINER ──────────────────────────────────────── */
.living-root {
  position: relative;
  width: 100%;
  height: calc(100vh - 0px);
  display: flex;
  flex-direction: column;
  background: var(--color-bg, #06060f);
  color: #e2e8f0;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ── HEADER ──────────────────────────────────────────────── */
.living-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: rgba(15, 23, 42, 0.95);
  border-bottom: 1px solid var(--color-border, rgba(255,255,255,0.08));
  z-index: 10;
  flex-shrink: 0;
}

.living-header__left { flex: 1; }
.living-header__center { flex: 2; display: flex; justify-content: center; }
.living-header__right { flex: 1; display: flex; align-items: center; justify-content: flex-end; gap: 8px; }

/* ── BREADCRUMB ──────────────────────────────────────────── */
.living-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.living-breadcrumb__item {
  display: flex;
  align-items: center;
  gap: 4px;
  color: #94a3b8;
}

.living-breadcrumb__item--active { color: #e2e8f0; font-weight: 600; }

.living-breadcrumb__item--link {
  color: #6366f1;
  cursor: pointer;
  text-decoration: none;
  transition: color 0.2s;
}
.living-breadcrumb__item--link:hover { color: #818cf8; }

.living-breadcrumb__sep { color: #475569; margin: 0 2px; }
.living-breadcrumb__icon { font-size: 14px; }

/* ── METRICS ─────────────────────────────────────────────── */
.living-metrics {
  display: flex;
  gap: 24px;
}

.living-metric {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.living-metric__value {
  font-size: 18px;
  font-weight: 700;
  color: #e2e8f0;
  font-variant-numeric: tabular-nums;
}

.living-metric__label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
}

/* ── SKIN SWITCHER ───────────────────────────────────────── */
.living-skin-switcher {
  display: flex;
  gap: 4px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--color-border, rgba(255,255,255,0.08));
  border-radius: 8px;
  padding: 2px;
}

.living-skin-btn {
  width: 32px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.living-skin-btn:hover { background: rgba(255,255,255,0.08); }
.living-skin-btn.active {
  background: rgba(99, 102, 241, 0.2);
  box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.4);
}

/* ── CHAT TOGGLE ─────────────────────────────────────────── */
.living-chat-toggle {
  position: relative;
  width: 36px;
  height: 36px;
  border: 1px solid var(--color-border, rgba(255,255,255,0.08));
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.8);
  color: #94a3b8;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.living-chat-toggle:hover { background: rgba(99, 102, 241, 0.15); color: #e2e8f0; }

.living-chat-toggle__badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
}

/* ── BACK BUTTON ─────────────────────────────────────────── */
.living-back-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border: 1px solid var(--color-border, rgba(255,255,255,0.08));
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.8);
  color: #94a3b8;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
}
.living-back-btn:hover { background: rgba(99, 102, 241, 0.15); color: #e2e8f0; }

/* ── CANVAS ──────────────────────────────────────────────── */
.living-canvas {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.living-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.living-bg {
  fill: transparent;
}

.living-infra-label {
  fill: #475569;
  font-size: 11px;
  letter-spacing: 0.03em;
}

/* ── HINT ────────────────────────────────────────────────── */
.living-hint {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid var(--color-border, rgba(255,255,255,0.08));
  border-radius: 8px;
  font-size: 11px;
  color: #64748b;
  z-index: 5;
  transition: opacity 1s ease;
  pointer-events: none;
}

/* ── ZOOM CONTROLS ───────────────────────────────────────── */
.living-zoom-controls {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 5;
}

.living-zoom-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--color-border, rgba(255,255,255,0.08));
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.9);
  color: #94a3b8;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.living-zoom-btn:hover { background: rgba(99, 102, 241, 0.15); color: #e2e8f0; }

/* ── TOOLTIP ─────────────────────────────────────────────── */
.living-tooltip {
  position: absolute;
  padding: 10px 14px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: 8px;
  font-size: 12px;
  color: #e2e8f0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 20;
  max-width: 280px;
  line-height: 1.5;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.living-tooltip.is-visible { opacity: 1; }
.living-tooltip__role { color: #94a3b8; font-size: 11px; }

/* ── CELL SELECTION ──────────────────────────────────────── */
.living-cell {
  transition: transform 0.3s ease, filter 0.3s ease;
  outline: none;
}

.living-cell:hover {
  filter: brightness(1.3);
}

.living-cell:focus-visible {
  outline: 2px solid #6366f1;
  outline-offset: 4px;
}

.living-cell.is-selected {
  filter: brightness(1.4) drop-shadow(0 0 12px rgba(99, 102, 241, 0.5));
}

/* ── IDLE PULSE ───────────────────────────────────────────── */
@keyframes living-idle-pulse {
  0%   { opacity: 1; }
  50%  { opacity: 0.7; }
  100% { opacity: 1; }
}

.living-cell.is-idle-pulse {
  animation: living-idle-pulse 2s ease-in-out;
}

/* ── BIO SKIN ANIMATIONS ─────────────────────────────────── */
@keyframes bio-halo-breathe {
  0%, 100% { r: inherit; opacity: 0.12; }
  50%      { opacity: 0.25; }
}

@keyframes bio-membrane-rotate {
  from { stroke-dashoffset: 0; }
  to   { stroke-dashoffset: 40; }
}

.skin-bio .bio-halo {
  animation: bio-halo-breathe 4s ease-in-out infinite;
}

.skin-bio .bio-membrane {
  animation: bio-membrane-rotate 20s linear infinite;
}

.skin-bio .bio-body {
  transition: fill 0.3s, stroke 0.3s;
}

.skin-bio .bio-organelle {
  animation: bio-orbit 12s linear infinite;
  transform-origin: 0 0;
}

@keyframes bio-orbit {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

.skin-bio .living-cell.is-selected .bio-body {
  stroke: rgba(99, 102, 241, 0.8);
  stroke-width: 3;
}

.skin-bio .living-cell.is-selected .bio-membrane {
  stroke: rgba(99, 102, 241, 0.5);
  stroke-dasharray: 6,3;
}

/* ── DIAGRAM SKIN ────────────────────────────────────────── */
.skin-diagram .diag-card {
  transition: stroke 0.3s, box-shadow 0.3s;
}

.skin-diagram .living-cell.is-selected .diag-card {
  stroke: rgba(99, 102, 241, 0.8);
  stroke-width: 2;
  filter: drop-shadow(0 0 8px rgba(99, 102, 241, 0.3));
}

/* ── URBAN SKIN ──────────────────────────────────────────── */
@keyframes urban-window-flicker {
  0%, 90%, 100% { opacity: 1; }
  95%           { opacity: 0.3; }
}

.skin-urban .urban-window {
  animation: urban-window-flicker 8s ease-in-out infinite;
  animation-delay: calc(var(--i, 0) * 1.5s);
}

.skin-urban .living-cell.is-selected .urban-building {
  stroke: rgba(99, 102, 241, 0.8);
  stroke-width: 2;
}

/* ── MECH SKIN ────────────────────────────────────────────── */
@keyframes mech-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

.skin-mech .mech-gear {
  animation: mech-spin 30s linear infinite;
  transform-origin: 0 0;
}

.skin-mech .living-cell.is-selected .mech-gear {
  stroke: rgba(99, 102, 241, 0.8);
  stroke-width: 2;
}

/* ── CONNECTIONS ──────────────────────────────────────────── */
.living-connection {
  transition: stroke 0.3s, stroke-width 0.3s;
}

.living-cell.is-selected ~ .living-connections .living-connection,
.living-connection.is-highlighted {
  stroke: rgba(99, 102, 241, 0.4);
  stroke-width: 2;
}

/* ── CHAT PANEL ──────────────────────────────────────────── */
.living-chat-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 380px;
  height: 100%;
  background: rgba(15, 23, 42, 0.98);
  border-left: 1px solid var(--color-border, rgba(255,255,255,0.08));
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 30;
}

.living-chat-panel.is-open {
  transform: translateX(0);
}

.living-chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border, rgba(255,255,255,0.08));
  flex-shrink: 0;
}

.living-chat-header__title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 13px;
  flex: 1;
}

.living-chat-context {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: #64748b;
  margin-left: auto;
}

.living-chat-context__label { color: #475569; }
.living-chat-context__value { color: #94a3b8; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.living-chat-close {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #64748b;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.living-chat-close:hover { background: rgba(255,255,255,0.08); color: #e2e8f0; }

/* ── CHAT MESSAGES ───────────────────────────────────────── */
.living-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.living-chat-welcome {
  text-align: center;
  padding: 32px 16px;
  color: #64748b;
}

.living-chat-welcome__icon {
  font-size: 32px;
  margin-bottom: 12px;
}

.living-chat-welcome p { margin: 4px 0; font-size: 13px; }
.living-chat-welcome__hint { font-size: 11px; color: #475569; }

.living-chat-msg {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  max-width: 90%;
  animation: chat-msg-in 0.3s ease;
}

@keyframes chat-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.living-chat-msg--user {
  align-self: flex-end;
  background: rgba(99, 102, 241, 0.2);
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: #e2e8f0;
}

.living-chat-msg--assistant {
  align-self: flex-start;
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid var(--color-border, rgba(255,255,255,0.08));
  color: #cbd5e1;
}

.living-chat-msg--system {
  align-self: center;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  font-size: 11px;
}

.living-chat-msg.is-typing .living-chat-msg__text {
  opacity: 0.5;
  font-style: italic;
}

/* ── CHAT FORM ───────────────────────────────────────────── */
.living-chat-form {
  padding: 12px 16px;
  border-top: 1px solid var(--color-border, rgba(255,255,255,0.08));
  flex-shrink: 0;
}

.living-chat-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.living-chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--color-border, rgba(255,255,255,0.08));
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.8);
  color: #e2e8f0;
  font-size: 13px;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}

.living-chat-input:focus {
  border-color: rgba(99, 102, 241, 0.5);
}

.living-chat-input::placeholder { color: #475569; }

.living-chat-send {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: rgba(99, 102, 241, 0.3);
  color: #e2e8f0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
.living-chat-send:hover { background: rgba(99, 102, 241, 0.5); }

/* ── LEVEL TRANSITION OVERLAY ─────────────────────────────── */
.living-level-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

.living-level-overlay.is-active {
  opacity: 1;
  pointer-events: all;
  background: rgba(6, 6, 15, 0.8);
}

.living-level-overlay__cell {
  position: absolute;
  border-radius: 50%;
  background: rgba(99, 102, 241, 0.3);
  transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.living-level-overlay__cell.is-expanding {
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
  border-radius: 0;
  background: rgba(6, 6, 15, 0.95);
}

/* ── RESPONSIVE ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .living-header {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
  }

  .living-header__center { order: 3; flex: 0 0 100%; }
  .living-metrics { gap: 12px; }
  .living-metric__value { font-size: 14px; }

  .living-chat-panel { width: 100%; }
}
