/* OpenClaw Widget - Pixel / Retro Style */

#openclaw-widget {
  --oc-bg: #1a1a2e;
  --oc-surface: #16213e;
  --oc-border: #0f3460;
  --oc-text: #e0e0e0;
  --oc-text-dim: #8888aa;
  --oc-accent: #00ff88;
  --oc-error: #ff4466;
  --oc-warn: #ffaa00;
  --oc-font: 'Courier New', 'Lucida Console', monospace;
  --oc-radius: 4px;
  --oc-shadow: 0 2px 16px rgba(0, 0, 0, 0.6);

  position: fixed;
  z-index: 99999;
  font-family: var(--oc-font);
  font-size: 13px;
  color: var(--oc-text);
  line-height: 1.4;
  user-select: none;
  pointer-events: none;
}

#openclaw-widget * {
  box-sizing: border-box;
}

/* Position variants */
#openclaw-widget.oc-bottom-right { bottom: 16px; right: 16px; }
#openclaw-widget.oc-bottom-left  { bottom: 16px; left: 16px; }
#openclaw-widget.oc-top-right    { top: 16px; right: 16px; }
#openclaw-widget.oc-top-left     { top: 16px; left: 16px; }

/* Main container */
.oc-container {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  pointer-events: auto;
}

#openclaw-widget.oc-bottom-left .oc-container,
#openclaw-widget.oc-top-left .oc-container {
  align-items: flex-start;
}

/* --- Log Panel --- */
.oc-log-panel {
  width: 280px;
  max-height: 180px;
  background: var(--oc-bg);
  border: 2px solid var(--oc-border);
  border-radius: var(--oc-radius);
  box-shadow: var(--oc-shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  image-rendering: pixelated;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.oc-log-panel.oc-collapsed {
  max-height: 0;
  border: none;
  opacity: 0;
  transform: translateY(8px);
}

.oc-log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: var(--oc-surface);
  border-bottom: 1px solid var(--oc-border);
  font-size: 11px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--oc-accent);
  cursor: pointer;
}

.oc-log-header:hover {
  background: var(--oc-border);
}

.oc-log-title {
  display: flex;
  align-items: center;
  gap: 6px;
}

.oc-log-title::before {
  content: '>';
  color: var(--oc-accent);
  animation: oc-blink 1s step-end infinite;
}

@keyframes oc-blink {
  50% { opacity: 0; }
}

.oc-log-close {
  background: none;
  border: none;
  color: var(--oc-text-dim);
  cursor: pointer;
  font-family: var(--oc-font);
  font-size: 14px;
  padding: 0 2px;
  line-height: 1;
}

.oc-log-close:hover {
  color: var(--oc-text);
}

.oc-log-body {
  flex: 1;
  overflow-y: auto;
  padding: 6px 10px;
  font-size: 11px;
  scrollbar-width: thin;
  scrollbar-color: var(--oc-border) transparent;
}

.oc-log-body::-webkit-scrollbar {
  width: 4px;
}

.oc-log-body::-webkit-scrollbar-track {
  background: transparent;
}

.oc-log-body::-webkit-scrollbar-thumb {
  background: var(--oc-border);
  border-radius: 2px;
}

.oc-log-entry {
  padding: 2px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  display: flex;
  align-items: baseline;
  gap: 6px;
  animation: oc-fade-in 0.2s ease;
}

@keyframes oc-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.oc-log-entry:last-child {
  border-bottom: none;
}

.oc-log-ts {
  color: var(--oc-text-dim);
  font-size: 10px;
  flex-shrink: 0;
}

.oc-log-msg { flex: 1; }
.oc-log-msg.oc-status  { color: var(--oc-accent); }
.oc-log-msg.oc-tool    { color: #66bbff; }
.oc-log-msg.oc-error   { color: var(--oc-error); }
.oc-log-msg.oc-done    { color: var(--oc-accent); font-weight: bold; }
.oc-log-msg.oc-info    { color: var(--oc-text); }

/* --- Speech Bubble --- */
.oc-bubble {
  background: var(--oc-surface);
  border: 2px solid var(--oc-border);
  border-radius: var(--oc-radius);
  padding: 6px 12px;
  font-size: 12px;
  max-width: 220px;
  box-shadow: var(--oc-shadow);
  position: relative;
  transition: opacity 0.25s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.oc-bubble::after {
  content: '';
  position: absolute;
  bottom: -8px;
  right: 20px;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 8px solid var(--oc-border);
}

#openclaw-widget.oc-bottom-left .oc-bubble::after,
#openclaw-widget.oc-top-left .oc-bubble::after {
  right: auto;
  left: 20px;
}

.oc-bubble.oc-state-error {
  border-color: var(--oc-error);
}

.oc-bubble.oc-state-error::after {
  border-top-color: var(--oc-error);
}

.oc-bubble-text {
  display: inline;
}

.oc-bubble-dots::after {
  content: '';
  animation: oc-dots 1.5s steps(4, end) infinite;
}

@keyframes oc-dots {
  0%  { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

/* --- Sprite Area --- */
.oc-sprite-wrap {
  cursor: pointer;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  -ms-interpolation-mode: nearest-neighbor;
  position: relative;
}

.oc-sprite-canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  -ms-interpolation-mode: nearest-neighbor;
}

/* Hover glow */
.oc-sprite-wrap:hover .oc-sprite-canvas {
  filter: drop-shadow(0 0 6px var(--oc-accent));
}

/* Status indicator dot */
.oc-status-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #555;
  border: 1px solid var(--oc-bg);
  transition: background 0.3s ease;
}

.oc-status-dot.oc-dot-idle     { background: #555; }
.oc-status-dot.oc-dot-thinking { background: var(--oc-warn); animation: oc-pulse 1s ease infinite; }
.oc-status-dot.oc-dot-working  { background: var(--oc-accent); animation: oc-pulse 0.6s ease infinite; }
.oc-status-dot.oc-dot-error    { background: var(--oc-error); }
.oc-status-dot.oc-dot-done     { background: var(--oc-accent); }

@keyframes oc-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}

/* --- Run Button --- */
.oc-run-btn {
  display: none;
  background: var(--oc-accent);
  color: var(--oc-bg);
  border: none;
  font-family: var(--oc-font);
  font-size: 11px;
  font-weight: bold;
  padding: 4px 12px;
  border-radius: var(--oc-radius);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 4px;
}

.oc-run-btn:hover {
  background: #33ffaa;
}

.oc-run-btn.oc-visible {
  display: inline-block;
}

.oc-run-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* --- Responsive --- */
@media (max-width: 480px) {
  .oc-log-panel {
    width: 240px;
    max-height: 140px;
  }
  .oc-bubble {
    max-width: 180px;
    font-size: 11px;
  }
}
