{
  "dashboard": {
    "title": "PedScribe Audit & Usage",
    "uid": "pedscribe-audit",
    "timezone": "browser",
    "refresh": "30s",
    "time": { "from": "now-24h", "to": "now" },
    "panels": [
      {
        "title": "Login Activity",
        "type": "timeseries",
        "gridPos": { "h": 8, "w": 12, "x": 0, "y": 0 },
        "targets": [{
          "datasource": "Loki",
          "expr": "count_over_time({app=\"pedscribe\", category=\"auth\"} |= \"login\" [5m])",
          "legendFormat": "Logins"
        }]
      },
      {
        "title": "Failed Logins",
        "type": "timeseries",
        "gridPos": { "h": 8, "w": 12, "x": 12, "y": 0 },
        "targets": [{
          "datasource": "Loki",
          "expr": "count_over_time({app=\"pedscribe\", category=\"auth\"} |= \"login_failed\" [5m])",
          "legendFormat": "Failed"
        }]
      },
      {
        "title": "Clinical Actions",
        "type": "timeseries",
        "gridPos": { "h": 8, "w": 12, "x": 0, "y": 8 },
        "targets": [{
          "datasource": "Loki",
          "expr": "count_over_time({app=\"pedscribe\", category=\"clinical\"} [5m])",
          "legendFormat": "Clinical Actions"
        }]
      },
      {
        "title": "API Calls by Model",
        "type": "timeseries",
        "gridPos": { "h": 8, "w": 12, "x": 12, "y": 8 },
        "targets": [{
          "datasource": "Loki",
          "expr": "count_over_time({app=\"pedscribe\", type=\"api_call\"} [5m])",
          "legendFormat": "API Calls"
        }]
      },
      {
        "title": "Recent Audit Events",
        "type": "logs",
        "gridPos": { "h": 10, "w": 24, "x": 0, "y": 16 },
        "targets": [{
          "datasource": "Loki",
          "expr": "{app=\"pedscribe\"}",
          "maxLines": 100
        }],
        "options": {
          "showTime": true,
          "showLabels": true,
          "showCommonLabels": false,
          "wrapLogMessage": true,
          "prettifyLogMessage": false,
          "enableLogDetails": true,
          "sortOrder": "Descending"
        }
      }
    ]
  }
}
