{
  "dashboard": {
    "title": "PedScribe Overview",
    "tags": ["pedscribe"],
    "timezone": "browser",
    "refresh": "30s",
    "time": {"from": "now-24h", "to": "now"},
    "panels": [
      {
        "id": 1, "title": "Audit Events", "type": "timeseries",
        "gridPos": {"h": 8, "w": 24, "x": 0, "y": 0},
        "datasource": {"type": "loki"},
        "targets": [{"expr": "count_over_time({app=\"pedscribe\"} [5m])", "legendFormat": "{{action}}"}],
        "fieldConfig": {"defaults": {"custom": {"drawStyle": "bars", "fillOpacity": 30}}}
      },
      {
        "id": 2, "title": "By Category", "type": "piechart",
        "gridPos": {"h": 8, "w": 8, "x": 0, "y": 8},
        "datasource": {"type": "loki"},
        "targets": [{"expr": "sum by (category) (count_over_time({app=\"pedscribe\"} [24h]))"}]
      },
      {
        "id": 3, "title": "By Action", "type": "piechart",
        "gridPos": {"h": 8, "w": 8, "x": 8, "y": 8},
        "datasource": {"type": "loki"},
        "targets": [{"expr": "sum by (action) (count_over_time({app=\"pedscribe\"} [24h]))"}]
      },
      {
        "id": 4, "title": "Success vs Failure", "type": "piechart",
        "gridPos": {"h": 8, "w": 8, "x": 16, "y": 8},
        "datasource": {"type": "loki"},
        "targets": [{"expr": "sum by (status) (count_over_time({app=\"pedscribe\"} [24h]))"}]
      },
      {
        "id": 5, "title": "Auth Events", "type": "logs",
        "gridPos": {"h": 8, "w": 12, "x": 0, "y": 16},
        "datasource": {"type": "loki"},
        "targets": [{"expr": "{app=\"pedscribe\", category=\"auth\"}"}],
        "options": {"showTime": true, "sortOrder": "Descending", "enableLogDetails": true}
      },
      {
        "id": 6, "title": "Clinical Events", "type": "logs",
        "gridPos": {"h": 8, "w": 12, "x": 12, "y": 16},
        "datasource": {"type": "loki"},
        "targets": [{"expr": "{app=\"pedscribe\", category=\"clinical\"}"}],
        "options": {"showTime": true, "sortOrder": "Descending", "enableLogDetails": true}
      },
      {
        "id": 7, "title": "All Logs", "type": "logs",
        "gridPos": {"h": 10, "w": 24, "x": 0, "y": 24},
        "datasource": {"type": "loki"},
        "targets": [{"expr": "{app=\"pedscribe\"}"}],
        "options": {"showTime": true, "sortOrder": "Descending", "enableLogDetails": true}
      }
    ]
  },
  "overwrite": true
}
