/* ============================================================
   Deal Detail (case detail) page.

   The page is built from design-system components; this sheet only places
   them and lays out the two pieces that are page markup rather than
   components: the case-summary header and the :target dialogs.

   Structure in @layer layout, paint in @layer design. Read only --t-* and
   --c-surface-* tokens: the summary is a raised surface, so its text takes
   the surface's inks.
   ============================================================ */

@layer layout {

	.deal-detail-page {
		display: grid;
		gap: var(--t-space-5);
		align-content: start;
	}

	/* Every form on the page (note, coach, acknowledgement, transitions and
	   the two decision dialogs) stacks its fields and its submit button. */
	.deal-detail-page form {
		display: grid;
		gap: var(--t-space-4);
		align-content: start;
	}

	/* Case summary: avatar beside the heading, the status badge trailing. */
	.deal-summary {
		display: grid;
		grid-template-columns: auto minmax(0, 1fr) auto;
		gap: var(--t-space-4);
		align-items: center;
		padding: var(--t-space-5);
		border-radius: var(--t-radius-lg);
	}

	.deal-summary-avatar {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		inline-size: var(--t-space-12);
		block-size: var(--t-space-12);
		flex-shrink: 0;
		border-radius: var(--t-radius-pill);
		font-weight: var(--t-font-weight-bold);
	}

	.deal-summary-heading {
		display: grid;
		gap: var(--t-space-2);
		min-inline-size: 0;
	}

	.deal-summary-meta,
	.deal-summary-status {
		margin: 0;
	}

	.deal-summary-meta {
		font-size: var(--t-font-size-sm);
	}

	.deal-summary-meta span {
		font-weight: var(--t-font-weight-semibold);
	}

	/* The participant variant has no avatar. */
	.deal-summary.participant {
		grid-template-columns: 1fr;
	}

	@container (max-width: 40rem) {
		.deal-summary {
			grid-template-columns: auto minmax(0, 1fr);
		}

		/* The status is a wide, single-line badge: give it its own row so it
		   cannot widen the avatar column and squeeze the name off-screen. */
		.deal-summary-status {
			grid-column: 1 / -1;
		}
	}

	/* Two-up body: main column + sidebar. The base split it at a desktop
	   viewport, not at the content column's width: a participant's page is
	   capped at tablet width, and still put the sidebar beside the tasks
	   there. Below a desktop viewport the columns stack. */
	.deal-detail-columns {
		display: grid;
		grid-template-columns: minmax(0, 1fr);
		gap: var(--t-space-6);
		align-items: start;
	}

	.deal-detail-main,
	.deal-detail-aside {
		display: grid;
		gap: var(--t-space-5);
		align-content: start;
		min-inline-size: 0;
	}

	@media (min-width: 56rem) {
		.deal-detail-columns {
			grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
		}
	}

	/* One numbered step of a decision dialog: a heading with a divider, set
	   apart from the fields under it. */
	.deal-detail-page .deal-decision-step {
		display: grid;
		gap: var(--t-space-3);
		min-inline-size: 0;
		margin: 0;
		padding: var(--t-space-3) 0 0;
		border: 0;
		border-block-start-width: var(--t-border-width-interactive);
		border-block-start-style: solid;
	}

	.da-case-pc summary {
		cursor: pointer;
		font-weight: var(--t-font-weight-semibold);
	}

	/* The timeline's event marker sits inline with the event's title. */
	.deal-detail-page .timeline-event-icon {
		display: inline-flex;
		vertical-align: -0.125em;
	}

	/* The dialogs open from a #fragment, with no script. inset:0 + margin:auto
	   is what CENTRES a fixed box; without the offsets, position: fixed
	   resolves to the element's static position, which sits far below the
	   fold on a real deal page. */
	/* The dialog and its backdrop sit on the modal layer, above the signed-in
	   shell's sticky top bar; at z-index 1 the bar's county seal drew over
	   the dialog's title. A <dialog> opened by script would be in the top
	   layer; one opened from a #fragment stacks like any other box. */
	.deal-detail-page dialog:target {
		display: block;
		z-index: calc(var(--mea-z-modal) + 1);
		position: fixed;
		inset: 0;
		margin: auto;
		inline-size: auto;
		max-inline-size: 48rem;

		& ~ .dialog-backdrop {
			display: block;
		}
	}

	.deal-detail-page .dialog-backdrop {
		display: none;
		position: fixed;
		z-index: var(--mea-z-modal);
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
	}

	.deal-detail-page dialog {
		top: 5vh;
		max-height: 90vh;
		overflow: hidden;
		padding: 0;

		& section {
			max-height: 90vh;
			display: flex;
			flex-direction: column;
			padding: var(--t-space-5);
			overflow: hidden;

			& header {
				flex: 0 0 0;
			}

			& form {
				flex: 1 1 min-content;
				display: flex;
				flex-direction: column;
				overflow: hidden;

				& main {
					display: flex;
					flex-direction: column;
					overflow-y: auto;
					padding-block: var(--t-space-5);
				}

				& .dialog-footer {
					flex: 0 0 0;
				}
			}
		}
	}

	/* The dialog title is the heading component, so its <hgroup> is the
	   header's middle item; it takes the free space the base gave the bare
	   <h2>, keeping the close button at the far edge. */
	.deal-detail-page .dialog-header > .heading {
		flex-grow: 1;
		min-inline-size: 0;
	}
}

@layer design {

	/* The base's avatar was one flat accent fill; the interactive surface
	   carries a button gradient, so drop the image and keep its fill. */
	.deal-summary-avatar {
		background-image: none;
	}

	.deal-summary-meta {
		color: var(--c-surface-text-color-muted);
	}

	.deal-detail-page .deal-decision-step {
		border-block-start-color: var(--t-border);
	}

	/* A compliance note's words are the row's content, not a detail under a
	   title: the base set them at body size in the base ink. The rows
	   component sets every non-title line small and muted, so the note opts
	   back into the body scale. Its selector outweighs that default. */
	.deal-detail-page .rows .main p.deal-note-body {
		font-size: var(--t-font-size-md);
		color: var(--c-surface-text-color-base);
	}

	/* The delivery state is the panel's headline news, so it takes the accent
	   ink beside the panel's title. */
	.deal-delivery-state {
		font-size: var(--t-font-size-sm);
		color: var(--c-surface-text-color-interactive);
	}

	.deal-summary-meta span {
		color: var(--c-surface-text-color-base);
	}

	/* Each timeline event keeps the colour family the base gave it. The route
	   already neutralises a participant's red events, so this is where that
	   decision reaches the page. */
	.deal-detail-page .timeline-event-icon[data-tone="blue"] {
		color: var(--t-accent);
	}

	.deal-detail-page .timeline-event-icon[data-tone="green"] {
		color: var(--t-success);
	}

	.deal-detail-page .timeline-event-icon[data-tone="amber"] {
		color: var(--t-warning);
	}

	.deal-detail-page .timeline-event-icon[data-tone="red"] {
		color: var(--t-error);
	}
}
