/* ai monitor — dashboard.css v2
   Dark mode, responsive, Linear.app-inspired
*/

:root {
  --bg:          #0d1117;
  --bg2:         #161b22;
  --bg3:         #21262d;
  --border:      #30363d;
  --text:        #e6edf3;
  --text-muted:  #8b949e;
  --accent:      #58a6ff;
  --green:       #3fb950;
  --yellow:      #d29922;
  --red:         #f85149;
  --purple:      #bc8cff;
  --orange:      #ffa657;
  --radius:      8px;
  --font:        'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
  --header-h:    52px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Header ── */
header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 100;
  overflow-x: auto;
  scrollbar-width: none;
}
header::-webkit-scrollbar { display: none; }

header .logo {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
  white-space: nowrap;
  flex-shrink: 0;
}
header .logo span { color: var(--text-muted); font-weight: 400; }

.stat-pill {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  white-space: nowrap;
  flex-shrink: 0;
}
.stat-pill .label { color: var(--text-muted); }
.stat-pill .value { color: var(--text); font-weight: 600; }
.stat-pill .value.cost  { color: var(--yellow); }
.stat-pill .value.active{ color: var(--green); }

.conn-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--red);
  transition: background 0.3s;
  flex-shrink: 0;
}
.conn-dot.connected { background: var(--green); }

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Tab bar (mobile) ── */
#tab-bar {
  display: none;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  gap: 0;
}
.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  padding: 10px 14px;
  font-family: var(--font);
  font-size: 12px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── Main layout ── */
main {
  display: grid;
  grid-template-columns: 1fr 360px;
  grid-template-rows: 1fr;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

/* ── Left: Live event feed ── */
#feed-panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden;
  min-width: 0;
}

.panel-header {
  padding: 8px 14px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.7px;
  flex-shrink: 0;
}
.panel-header .title { color: var(--text); font-weight: 600; }

/* provider badge */
.provider-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.provider-anthropic { background:#1a2a1a; color:#3fb950; }
.provider-openai    { background:#1a2535; color:#58a6ff; }
.provider-deepseek  { background:#1a1a35; color:#bc8cff; }
.provider-fal       { background:#2a1a1a; color:#ffa657; }
.provider-elevenlabs{ background:#2a1a2a; color:#ff79c6; }
.provider-unknown   { background:var(--bg3); color:var(--text-muted); }

#event-list {
  flex: 1;
  overflow-y: auto;
}

.event-item {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 26px 1fr auto;
  gap: 9px;
  align-items: start;
  cursor: pointer;
  transition: background 0.1s;
}
.event-item:hover { background: var(--bg2); }
.event-item.pre  { border-left: 3px solid #30363d; }
.event-item.post { border-left: 3px solid var(--green); }
.event-item.stop { border-left: 3px solid var(--orange); }

.tool-icon {
  width: 26px; height: 26px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}

.event-body .row1 {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.event-body .tool-name { font-weight: 600; color: var(--text); font-size: 12px; }
.event-body .session-id { color: var(--text-muted); font-size: 10px; }
.event-body .summary {
  color: var(--text-muted);
  font-size: 11px;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.event-meta { text-align: right; flex-shrink: 0; }
.event-meta .time  { color: var(--text-muted); font-size: 10px; }
.event-meta .cost  { color: var(--yellow); font-size: 10px; margin-top: 1px; }
.event-meta .dur   { color: var(--text-muted); font-size: 10px; }

/* ── Right panel ── */
#right-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Tabs in right panel ── */
#right-tabs {
  display: flex;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.rtab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  padding: 8px 4px;
  font-family: var(--font);
  font-size: 10px;
  cursor: pointer;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: color 0.15s, border-color 0.15s;
}
.rtab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Sessions panel ── */
#sessions-panel, #costs-panel, #providers-panel {
  flex: 1;
  overflow-y: auto;
  display: none;
}
#sessions-panel.visible, #costs-panel.visible, #providers-panel.visible {
  display: block;
}

.session-item {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
.session-item:hover { background: var(--bg3); }
.session-item.active .sid::after { content:' ●'; color:var(--green); }

.sid {
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}
.session-meta {
  display: flex;
  gap: 8px;
  margin-top: 3px;
  font-size: 10px;
  color: var(--text-muted);
  flex-wrap: wrap;
}
.session-meta .cost   { color: var(--yellow); }
.session-meta .tools  { color: var(--purple); }
.session-meta .proj   { color: var(--orange); }

/* ── Costs panel ── */
.cost-section { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.cost-section h3 { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.7px; margin-bottom: 8px; }

.cost-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 11px;
  border-bottom: 1px solid var(--border);
}
.cost-row:last-child { border-bottom: none; }
.cost-row .label { color: var(--text-muted); }
.cost-row .val   { color: var(--yellow); font-weight: 600; }

.chart-container {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.chart-container h3 { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.7px; margin-bottom: 8px; }
.chart-container canvas { width: 100% !important; }

/* ── Providers panel ── */
.provider-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.provider-info { flex: 1; min-width: 0; }
.provider-name { font-weight: 600; font-size: 12px; }
.provider-key  { font-size: 10px; color: var(--text-muted); margin-top: 2px; }
.provider-proj { font-size: 10px; color: var(--orange); }
.provider-cost { font-size: 11px; color: var(--yellow); font-weight: 600; white-space: nowrap; }

/* Add provider form */
#add-provider-form {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
}
#add-provider-form h3 { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.7px; margin-bottom: 8px; }
.form-row { margin-bottom: 6px; }
.form-row label { font-size: 10px; color: var(--text-muted); display: block; margin-bottom: 3px; }
.form-row input, .form-row select {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 8px;
  border-radius: 4px;
  font-family: var(--font);
  font-size: 11px;
}
.form-row input:focus, .form-row select:focus {
  outline: none;
  border-color: var(--accent);
}
.btn-primary {
  background: var(--accent);
  color: #000;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  margin-top: 4px;
}
.btn-primary:hover { opacity: 0.85; }

/* ── Chart panel (bottom of right) ── */
#chart-panel {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
  height: 160px;
}
#chart-panel .panel-header { margin: -10px -14px 8px; padding: 7px 14px; }
#cost-chart { width: 100% !important; height: 110px !important; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Tool icon colors ── */
.icon-bash      { background:#1f3a1f; color:var(--green); }
.icon-read      { background:#1a2a3a; color:var(--accent); }
.icon-write     { background:#2a1a3a; color:var(--purple); }
.icon-edit      { background:#2a2a1a; color:var(--yellow); }
.icon-grep      { background:#3a1a2a; color:#ff79c6; }
.icon-glob      { background:#1a3a3a; color:#8be9fd; }
.icon-agent     { background:#2a1a1a; color:var(--red); }
.icon-webfetch  { background:#1a2535; color:var(--accent); }
.icon-default   { background:var(--bg3); color:var(--text-muted); }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 32px 16px;
  font-size: 11px;
}
.empty-state .emoji { font-size: 28px; display: block; margin-bottom: 6px; }

/* ═══════════════════════════════════════
   RESPONSIVE — mobile first
   ═══════════════════════════════════════ */

@media (max-width: 768px) {
  :root { --header-h: 48px; }

  header { gap: 7px; padding: 0 12px; }
  header .logo { font-size: 13px; }

  #tab-bar { display: flex; }

  main {
    display: block;
    height: calc(100vh - var(--header-h) - 41px);
    overflow: hidden;
  }

  /* Only show active panel on mobile */
  #feed-panel, #right-panel {
    height: 100%;
    border-right: none;
    overflow: hidden;
    display: none;
  }
  #feed-panel.mobile-active  { display: flex; }
  #right-panel.mobile-active { display: flex; }

  /* Hide desktop right-tabs on mobile (use tab-bar instead) */
  #right-tabs { display: none; }

  #right-panel {
    flex-direction: column;
  }

  /* Always show sessions on right panel mobile */
  #sessions-panel  { display: block; flex: 1; overflow-y: auto; }
  #costs-panel     { display: none; }
  #providers-panel { display: none; }

  .event-body .summary { max-width: 180px; }

  #chart-panel { height: 140px; }
}

@media (max-width: 400px) {
  .stat-pill .label { display: none; }
  .event-body .summary { max-width: 120px; }
}
