{% extends "ui/templates/base/layout.html" %}
{% block content %}
{% include "modules/consultants/templates/consultants/_consultant_tabs.html" %}
<div class="mx-auto max-w-4xl space-y-6">
  <div class="flex flex-wrap items-center justify-between gap-3"><div><h2 class="text-xl font-semibold text-slate-900">{{ request_row.request_no }}</h2><p class="text-sm text-slate-500">{{ request_row.subject }}</p></div><a href="{{ '/consultants/service-requests' if internal_view else '/consultant/service-requests' }}" class="rounded-xl border border-slate-300 px-4 py-2 text-sm font-semibold text-slate-700 hover:bg-slate-50">Back</a></div>
  <div class="rounded-2xl border border-slate-200 bg-white p-5 shadow-soft">
    <div class="grid gap-4 text-sm md:grid-cols-3">
      <div><div class="text-xs uppercase tracking-wide text-slate-500">Status</div><div class="font-medium text-slate-900">{{ request_row.status.replace('_',' ').title() }}</div></div>
      <div><div class="text-xs uppercase tracking-wide text-slate-500">Priority</div><div class="font-medium text-slate-900">{{ request_row.priority.replace('_',' ').title() }}</div></div>
      <div><div class="text-xs uppercase tracking-wide text-slate-500">Requested Date</div><div class="font-medium text-slate-900">{{ request_row.requested_due_date or '-' }}</div></div>
      <div><div class="text-xs uppercase tracking-wide text-slate-500">Consultant</div><div class="font-medium text-slate-900">{{ request_row.consultant.contact_person if request_row.consultant else '-' }}</div></div>
      <div><div class="text-xs uppercase tracking-wide text-slate-500">Client</div><div class="font-medium text-slate-900">{{ request_row.managed_client.client_name if request_row.managed_client else (request_row.firm_client.client_name if request_row.firm_client else '-') }}</div></div>
      <div><div class="text-xs uppercase tracking-wide text-slate-500">Service</div><div class="font-medium text-slate-900">{{ request_row.requested_service_name }}</div></div>
    </div>
  </div>
  <div class="grid gap-6 md:grid-cols-2">
    <div class="rounded-2xl border border-slate-200 bg-white p-5 shadow-soft"><h3 class="font-semibold text-slate-900">Description</h3><p class="mt-3 whitespace-pre-line text-sm text-slate-700">{{ request_row.description or '-' }}</p></div>
    <div class="rounded-2xl border border-slate-200 bg-white p-5 shadow-soft"><h3 class="font-semibold text-slate-900">Consultant Notes</h3><p class="mt-3 whitespace-pre-line text-sm text-slate-700">{{ request_row.consultant_notes or '-' }}</p></div>
  </div>
  <div class="rounded-2xl border border-slate-200 bg-white p-5 shadow-soft"><h3 class="font-semibold text-slate-900">Firm Response</h3><p class="mt-3 whitespace-pre-line text-sm text-slate-700">{{ request_row.firm_response or 'No response yet.' }}</p>{% if request_row.reviewed_by %}<p class="mt-2 text-xs text-slate-500">Reviewed by {{ request_row.reviewed_by.full_name or request_row.reviewed_by.email }} on {{ request_row.reviewed_at_utc.strftime('%d-%m-%Y %H:%M') if request_row.reviewed_at_utc else '-' }}</p>{% endif %}</div>
  {% if internal_view %}
  <form method="post" action="/consultants/service-requests/{{ request_row.id }}/status" class="rounded-2xl border border-slate-200 bg-white p-5 shadow-soft">
    <input type="hidden" name="csrf_token" value="{{ csrf_token }}">
    <h3 class="font-semibold text-slate-900">Update Firm Decision</h3>
    <div class="mt-4 grid gap-4 md:grid-cols-2"><div><label class="mb-2 block text-sm font-medium text-slate-700">Status</label><select name="status" class="w-full rounded-xl border border-slate-300 px-3 py-2 text-sm">{% for code,label in service_request_statuses %}<option value="{{ code }}" {% if request_row.status == code %}selected{% endif %}>{{ label }}</option>{% endfor %}</select></div><div><label class="mb-2 block text-sm font-medium text-slate-700">Action Note</label><input name="firm_response" value="{{ request_row.firm_response or '' }}" class="w-full rounded-xl border border-slate-300 px-3 py-2 text-sm"></div></div>
    <div class="mt-4 flex justify-end"><button class="rounded-xl bg-brand-600 px-4 py-2 text-sm font-semibold text-white hover:bg-brand-700">Save Decision</button></div>
  </form>
  {% endif %}
</div>
{% endblock %}
