/* FR-08.5.3 reopening forms and read-only visit history. Design-system tokens only (Light/Dark/System). */

.reopen-entry {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 16px;
    margin-top: 14px;
    padding: 12px 14px;
    border: 1px dashed var(--fo-border-strong);
    border-radius: var(--fo-radius-md);
    background: var(--fo-surface-subtle);
}

.reopen-entry p {
    margin: 0;
    flex: 1 1 260px;
    color: var(--fo-text-secondary);
    font-size: var(--fo-font-small);
}

.reopen-entry.crew {
    margin: 0;
    padding: 10px 17px;
    border: 0;
    border-top: 1px solid var(--fo-border);
    border-radius: 0;
    justify-content: flex-end;
}

.reopen-panel {
    display: grid;
    gap: 14px;
    margin-top: 14px;
    padding: 16px;
    border: 1px solid var(--fo-primary-200);
    border-radius: var(--fo-radius-md);
    background: var(--fo-surface);
    box-shadow: var(--fo-shadow-card);
    min-width: 0;
}

.reopen-panel.crew {
    margin: 0;
    border-width: 1px 0 0;
    border-radius: 0;
    box-shadow: none;
    background: var(--fo-surface-subtle);
}

.reopen-panel header h3 {
    margin: 2px 0 4px;
    color: var(--fo-text);
    font-size: var(--fo-font-title);
}

.reopen-panel header p {
    margin: 0;
    color: var(--fo-text-secondary);
    font-size: var(--fo-font-small);
    line-height: var(--fo-line-height);
}

.reopen-kicker {
    color: var(--fo-text-muted);
    font-size: var(--fo-font-caption);
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.reopen-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px 16px;
}

.reopen-field {
    display: grid;
    gap: 6px;
    min-width: 0;
    color: var(--fo-text);
    font-size: var(--fo-font-small);
    font-weight: 600;
}

.reopen-field:last-child { grid-column: 1 / -1; }

.reopen-field small {
    color: var(--fo-text-muted);
    font-weight: 400;
}

.reopen-field select,
.reopen-field textarea {
    width: 100%;
    min-height: var(--fo-control-height);
    padding: 9px 12px;
    border: 1px solid var(--fo-border-strong);
    border-radius: var(--fo-radius-sm);
    background: var(--fo-input-background);
    color: var(--fo-text);
    font: inherit;
    font-weight: 400;
}

.reopen-field textarea {
    min-height: 92px;
    resize: vertical;
}

.reopen-field select:focus-visible,
.reopen-field textarea:focus-visible {
    outline: 2px solid var(--fo-focus);
    outline-offset: 1px;
    box-shadow: 0 0 0 4px var(--fo-focus-halo);
}

.reopen-field select:disabled,
.reopen-field textarea:disabled {
    background: var(--fo-disabled-background);
    color: var(--fo-disabled-text);
}

.reopen-date {
    display: flex;
    gap: 6px;
    align-items: center;
}

.reopen-clear-date {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--fo-border);
    border-radius: var(--fo-radius-sm);
    background: var(--fo-surface);
    color: var(--fo-text-secondary);
    cursor: pointer;
}

.reopen-review {
    display: grid;
    gap: 8px;
    margin: 0;
    padding: 12px 14px;
    border: 1px solid var(--fo-border);
    border-radius: var(--fo-radius-sm);
    background: var(--fo-surface-subtle);
}

.reopen-review div {
    display: grid;
    grid-template-columns: minmax(110px, 160px) 1fr;
    gap: 10px;
}

.reopen-review dt {
    color: var(--fo-text-muted);
    font-size: var(--fo-font-small);
}

.reopen-review dd {
    margin: 0;
    color: var(--fo-text);
    overflow-wrap: anywhere;
}

.reopen-panel footer {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.reopen-message {
    margin: 0;
    padding: 10px 12px;
    border: 1px solid transparent;
    border-radius: var(--fo-radius-sm);
    font-size: var(--fo-font-small);
    line-height: var(--fo-line-height);
    overflow-wrap: anywhere;
}

.reopen-message.error { border-color: var(--fo-danger-200); background: var(--fo-danger-100); color: var(--fo-danger-800); }
.reopen-message.warning { background: var(--fo-warning-100); color: var(--fo-warning-700); }
.reopen-message.success { border-color: var(--fo-success-200); background: var(--fo-status-success-surface); color: var(--fo-status-success-text); }
.crew-selection-card > .reopen-message { margin: 0 17px 10px; }

/* Visit history */
.visit-history-card {
    border: 1px solid var(--fo-border);
    border-radius: var(--fo-radius-lg);
    background: var(--fo-surface);
    box-shadow: var(--fo-shadow-card);
    min-width: 0;
}

.visit-history-disclosure > summary {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 20px;
    cursor: pointer;
    list-style: none;
}

.visit-history-disclosure > summary::-webkit-details-marker { display: none; }

.visit-history-icon {
    display: inline-grid;
    place-items: center;
    flex: none;
    width: 38px;
    height: 38px;
    border-radius: var(--fo-radius-md);
    background: var(--fo-surface-muted);
    color: var(--fo-text-secondary);
}

.visit-history-heading {
    display: grid;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.visit-history-heading strong { color: var(--fo-text); font-size: var(--fo-font-title); }
.visit-history-heading small { color: var(--fo-text-muted); }

.visit-history-chevron {
    width: 20px;
    height: 20px;
    color: var(--fo-text-muted);
    transition: transform var(--fo-transition);
}

.visit-history-disclosure[open] .visit-history-chevron { transform: rotate(180deg); }

.visit-history-body {
    display: grid;
    gap: 12px;
    padding: 0 20px 18px;
}

.visit-history-note {
    margin: 0;
    color: var(--fo-text-secondary);
    font-size: var(--fo-font-small);
}

.visit-history-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.visit-history-filter button {
    min-height: 32px;
    padding: 4px 12px;
    border: 1px solid var(--fo-border);
    border-radius: var(--fo-radius-pill);
    background: var(--fo-surface);
    color: var(--fo-text-secondary);
    font: inherit;
    font-size: var(--fo-font-small);
    cursor: pointer;
}

.visit-history-filter button.selected {
    border-color: var(--fo-primary-200);
    background: var(--fo-selected);
    color: var(--fo-link);
}

.visit-history-list {
    display: grid;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.visit-history-item {
    border: 1px solid var(--fo-border);
    border-left: 3px solid var(--fo-border-strong);
    border-radius: var(--fo-radius-sm);
    background: var(--fo-surface-subtle);
}

.visit-history-item > summary {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 10px;
    padding: 10px 14px;
    cursor: pointer;
}

.visit-history-item > summary strong { color: var(--fo-text); overflow-wrap: anywhere; }
.visit-history-item > summary small { margin-left: auto; color: var(--fo-text-muted); }

.visit-kind {
    color: var(--fo-text-muted);
    font-size: var(--fo-font-caption);
    font-weight: 600;
    text-transform: uppercase;
}

.visit-outcome {
    padding: 1px 8px;
    border: 1px solid var(--fo-border);
    border-radius: var(--fo-radius-pill);
    color: var(--fo-text-secondary);
    font-size: var(--fo-font-caption);
}

.visit-outcome.non-completion { background: var(--fo-surface); }

.visit-history-detail {
    display: grid;
    gap: 12px;
    padding: 4px 14px 14px;
    min-width: 0;
}

.visit-history-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 8px 14px;
    margin: 0;
}

.visit-history-meta dt { color: var(--fo-text-muted); font-size: var(--fo-font-caption); }
.visit-history-meta dd { margin: 0; color: var(--fo-text); font-size: var(--fo-font-small); overflow-wrap: anywhere; }

.visit-history-reason,
.visit-history-reopen p {
    margin: 0;
    color: var(--fo-text-secondary);
    overflow-wrap: anywhere;
}

.visit-history-reopen {
    display: grid;
    gap: 2px;
    padding: 10px 12px;
    border: 1px solid var(--fo-border);
    border-radius: var(--fo-radius-sm);
    background: var(--fo-surface);
    font-size: var(--fo-font-small);
}

.visit-history-reopen span,
.visit-history-reopen small { color: var(--fo-text-muted); }

.visit-history-group > summary {
    color: var(--fo-text-emphasis);
    font-size: var(--fo-font-small);
    font-weight: 600;
    cursor: pointer;
}

.visit-history-group ul {
    display: grid;
    gap: 6px;
    margin: 8px 0 0;
    padding-left: 18px;
    color: var(--fo-text-secondary);
    font-size: var(--fo-font-small);
    overflow-wrap: anywhere;
}

.visit-history-group a { color: var(--fo-link); }

.visit-history-photos {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    padding-left: 0 !important;
    list-style: none;
}

.visit-history-photos li { display: grid; gap: 4px; min-width: 0; }

.visit-history-photos img {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border: 1px solid var(--fo-border);
    border-radius: var(--fo-radius-sm);
    background: var(--fo-surface-muted);
}

.visit-history-photos small { color: var(--fo-text-muted); }

.visit-history-links {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 10px;
}

.visit-history-materials {
    width: 100%;
    margin-top: 8px;
    border-collapse: collapse;
    font-size: var(--fo-font-small);
}

.visit-history-materials th,
.visit-history-materials td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--fo-border);
    color: var(--fo-text);
    text-align: left;
    vertical-align: top;
}

.visit-history-materials th { background: var(--fo-table-header); color: var(--fo-text-muted); font-weight: 600; }

.visit-history-provenance {
    display: block;
    color: var(--fo-text-muted);
    font-size: var(--fo-font-caption);
}

@media (max-width: 640px) {
    .visit-history-disclosure > summary { padding: 14px 16px; }
    .visit-history-body { padding: 0 16px 16px; }
    .reopen-review div { grid-template-columns: 1fr; gap: 2px; }
    .visit-history-item > summary small { margin-left: 0; width: 100%; }
    .visit-history-materials { display: block; overflow-x: auto; }
}
