/* =========================================================================
 * Hermes Pixel Office — styles
 * Dark dashboard: pixel canvas on the left, live info sidebar on the right.
 * ========================================================================= */

:root {
  --bg:        #0f1419;
  --bg-2:      #151b23;
  --panel:     #1a2129;
  --panel-2:   #212a35;
  --border:    #2b3542;
  --text:      #e6edf3;
  --muted:     #8b98a6;
  --accent:    #3ddc84;
  --accent-2:  #4a90e2;
  --warn:      #f0c040;
  --danger:    #e05252;

  --task-thinking: #a06cd5;
  --task-coding:   #4a90e2;
  --task-reading:  #3ddc84;
  --task-browsing: #f2913d;
  --task-terminal: #d4d4d8;
  --task-meeting:  #f0c040;
  --task-sleeping: #6b7280;
  --task-error:    #e05252;
  --task-idle:     #56606b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 0;
  min-width: 0;
  overflow-x: hidden;
}

/* ------------------------------------------------------------- topbar */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: linear-gradient(180deg, #182029, #131a22);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  font-size: 26px; line-height: 1;
  color: var(--accent);
  filter: drop-shadow(0 0 8px rgba(61,220,132,0.5));
}
.topbar h1 {
  margin: 0; font-size: 15px; font-weight: 700; letter-spacing: .2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar .sub { margin: 0; font-size: 11px; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

.conn {
  font-size: 11px; font-family: ui-monospace, "SF Mono", Menlo, monospace;
  padding: 4px 9px; border-radius: 999px; white-space: nowrap;
  border: 1px solid transparent;
}
.conn.ok      { color: var(--accent); background: rgba(61,220,132,.10); border-color: rgba(61,220,132,.3); }
.conn.loading { color: var(--warn);   background: rgba(240,192,64,.10); border-color: rgba(240,192,64,.3); }
.conn.error   { color: var(--danger); background: rgba(224,82,82,.10);  border-color: rgba(224,82,82,.3); }

.btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 11px; font-size: 15px; cursor: pointer;
  transition: background .15s, transform .1s;
}
.btn:hover  { background: #2a3745; }
.btn:active { transform: scale(.94); }

/* ------------------------------------------------------------- layout */
.layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

/* Left column wraps the stage + its own legend row underneath. */
.stagewrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;   /* keep stage + legend inside the column */
}

.stage {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  background:
    radial-gradient(1200px 600px at 50% -10%, #1d2733 0%, var(--bg) 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
#office-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
/* Fill the stage regardless of padding/borders so the room never squashes. */
.stage #office-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Legend sits BELOW the office as its own row — it never overlays the map. */
.legendbar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  font-size: 10.5px;
  color: var(--muted);
  background: var(--bg-2);
  border-top: 1px solid var(--border);
}
.legendbar span { display: inline-flex; align-items: center; gap: 4px; }
.dot { width: 8px; height: 8px; border-radius: 2px; display: inline-block; flex: 0 0 auto; }

/* ------------------------------------------------------------ sidebar */
.sidebar {
  border-left: 1px solid var(--border);
  background: var(--bg-2);
  overflow-y: auto;
  padding: 12px;
  display: flex; flex-direction: column; gap: 12px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}
.card h2 {
  margin: 0 0 10px; font-size: 11px; text-transform: uppercase;
  letter-spacing: 1.2px; color: var(--muted); font-weight: 600;
}
.muted { color: var(--muted); }
.small { font-size: 12px; line-height: 1.5; }

.stat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px;
}
.stat {
  background: var(--panel-2); border-radius: 9px; padding: 8px 4px; text-align: center;
}
.stat b { display: block; font-size: 19px; color: var(--accent); font-variant-numeric: tabular-nums; }
.stat span { font-size: 9.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

.kv { margin: 0; display: flex; flex-direction: column; gap: 6px; }
.kv > div { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; }
.kv dt { color: var(--muted); flex: 0 0 auto; }
.kv dd {
  margin: 0; text-align: right; font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ------ activity log ------ */
.log-list { display: flex; flex-direction: column; gap: 7px; max-height: 260px; overflow-y: auto; }
.log-item {
  font-size: 11.5px; padding: 6px 8px; border-radius: 7px;
  background: var(--panel-2); display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.log-time { color: var(--muted); font-family: ui-monospace, monospace; font-size: 10.5px; }
.log-task { color: var(--muted); }
.log-detail {
  flex-basis: 100%; color: var(--muted); font-size: 10.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.task-dot { width: 7px; height: 7px; border-radius: 2px; flex: 0 0 auto; }

/* task colour classes -------------------------------------------------- */
.task-thinking { background: var(--task-thinking); }
.task-coding   { background: var(--task-coding); }
.task-typing   { background: var(--task-coding); }
.task-reading  { background: var(--task-reading); }
.task-browsing { background: var(--task-browsing); }
.task-terminal { background: var(--task-terminal); }
.task-meeting  { background: var(--task-meeting); }
.task-sleeping { background: var(--task-sleeping); }
.task-error    { background: var(--task-error); }
.task-idle     { background: var(--task-idle); }
.task-done     { background: var(--task-reading); }

/* ------------------------------------------------------- agent panel */
.agent-panel {
  position: fixed;
  right: 16px; bottom: 16px;
  width: 300px;
  max-width: calc(100vw - 32px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,.55);
  transform: translateY(20px) scale(.97);
  opacity: 0; pointer-events: none;
  transition: transform .18s ease, opacity .18s ease;
  z-index: 50;
}
.agent-panel.open { transform: none; opacity: 1; pointer-events: auto; }
.close-btn {
  position: absolute; top: 10px; right: 10px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
  width: 26px; height: 26px; border-radius: 7px; cursor: pointer; font-size: 13px;
}
.close-btn:hover { color: var(--text); background: #2a3745; }
.panel-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; padding-right: 30px; }
.panel-head h3 { margin: 0; font-size: 16px; }
.role { font-size: 11px; color: var(--muted); }
.task-chip {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600; color: #0f1419; text-transform: lowercase;
}
.live-chip { font-size: 11px; color: var(--muted); margin-left: 6px; }
.panel-body .kv { margin-top: 12px; }
/* the activity line may be long — let it wrap instead of truncating */
#p-activity {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  line-height: 1.4;
  word-break: break-word;
}

/* ----------------------------------------------------- responsiveness */

/* Tablet / small desktop: keep the two-column layout but narrow the sidebar. */
@media (max-width: 1100px) and (min-width: 861px) {
  .layout { grid-template-columns: minmax(0, 1fr) 280px; }
}

/* Phones: stack the scene above the sidebar. */
@media (max-width: 860px) {
  #app { height: auto; min-height: 100dvh; }

  .layout {
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow-x: hidden;
    overflow-y: visible;
  }

  .stage {
    /* Fixed height (not aspect-ratio, which would force the WIDTH and blow
       past the viewport). The canvas scales its content to fit. */
    width: 100%;
    min-width: 0;
    height: 44vh;
    min-height: 250px;
    max-height: 360px;
    flex: 0 0 auto;
  }

  .sidebar {
    width: 100%;
    min-width: 0;
    flex: 0 0 auto;
    border-left: none;
    border-top: 1px solid var(--border);
    overflow: visible;
    max-height: none;
  }

  .card { min-width: 0; }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }

  .agent-panel {
    left: 10px; right: 10px; bottom: 10px;
    width: auto;
    max-width: none;
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }
  .log-list { max-height: 220px; }
}

@media (max-width: 420px) {
  .topbar h1 { font-size: 13px; }
  .topbar .sub { display: none; }
  .stage { height: 40vh; min-height: 230px; max-height: 320px; }
  .legendbar {
    font-size: 9.5px;
    gap: 4px 8px;
    padding: 6px 8px;
    /* tidy 4-column grid on the narrowest phones */
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    justify-items: start;
  }
  /* on phones let log details wrap to two lines instead of a harsh ellipsis */
  .log-detail {
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .stat b { font-size: 16px; }
  .stat-grid { gap: 6px; }
}

