/* ═══════════════════════════════════════════════════════
   Lawsuit Portal — Custom Styles (extends Pico CSS)
   ═══════════════════════════════════════════════════════ */

/* ── Root Variables ─────────────────────────────────── */
:root {
    --portal-primary: #1e40af;
    --portal-primary-hover: #1e3a8a;
    --portal-accent: #2563eb;
    --portal-bg-section: #f8fafc;
    --portal-border: #e2e8f0;
    --portal-error: #dc2626;
    --portal-error-bg: #fef2f2;
    --portal-success: #16a34a;
    --portal-text-muted: #64748b;
    --portal-transition: 0.25s ease;
}

/* ── General Layout ─────────────────────────────────── */
body {
    background: linear-gradient(135deg, #f0f4ff 0%, #e8eef8 100%);
    min-height: 100vh;
}

header.container {
    text-align: center;
    padding-block: 2rem 1rem;
}

header h1 {
    color: var(--portal-primary);
    font-size: 1.8rem;
    margin-bottom: 0.25rem;
}

header p {
    color: var(--portal-text-muted);
    font-size: 0.95rem;
}

footer.container {
    text-align: center;
    padding-block: 2rem;
    color: var(--portal-text-muted);
}

/* ── Form Sections ──────────────────────────────────── */
#claim-form > fieldset {
    background: #fff;
    border: 1px solid var(--portal-border);
    border-radius: 12px;
    padding: 1.5rem 2rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    transition: box-shadow var(--portal-transition);
}

#claim-form > fieldset:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

#claim-form > fieldset > legend h2 {
    font-size: 1.25rem;
    color: var(--portal-primary);
    border-bottom: 2px solid var(--portal-accent);
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
}

/* Nested fieldsets (bank details, measurements, dates) */
#claim-form fieldset fieldset {
    background: var(--portal-bg-section);
    border: 1px solid var(--portal-border);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin-top: 1rem;
}

#claim-form fieldset fieldset legend {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--portal-primary);
}

/* ── Buyer II Toggle ────────────────────────────────── */
#buyer2-toggle-section {
    text-align: center;
    padding: 1rem;
    background: linear-gradient(135deg, #eff6ff 0%, #e0e7ff 100%);
    border: 1px dashed var(--portal-accent);
}

#buyer2-toggle-section label {
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

/* Buyer II Section — hidden state */
.buyer2-hidden {
    display: none !important;
}

/* Buyer II Section — visible state with animation */
.buyer2-visible {
    display: block !important;
    animation: slideDown 0.35s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── Measurements Grid (2 columns on desktop) ──────── */
.measurements-grid {
    grid-template-columns: repeat(2, 1fr) !important;
}

/* Last item full-width if odd count */
.measurements-grid label:last-child:nth-child(odd) {
    grid-column: 1 / -1;
    max-width: 50%;
}

/* ── Delivery Date Group ────────────────────────────── */
.delivery-actual-group {
    display: flex;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
}

.delivery-actual-group > label:first-child {
    flex: 1;
    min-width: 200px;
}

.not-delivered-label {
    white-space: nowrap;
    padding-bottom: 0.5rem;
}

/* ── Validation States ──────────────────────────────── */
input:user-invalid,
input.is-invalid {
    border-color: var(--portal-error) !important;
    background-color: var(--portal-error-bg);
    outline-color: var(--portal-error);
}

input:user-valid,
input.is-valid {
    border-color: var(--portal-success);
}

/* Error message */
.field-error {
    color: var(--portal-error);
    font-size: 0.8rem;
    margin-top: 0.2rem;
    display: block;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ── Readonly Fields ────────────────────────────────── */
input[readonly] {
    background: var(--portal-bg-section) !important;
    cursor: not-allowed;
    opacity: 0.8;
}

/* ── Submit Button ──────────────────────────────────── */
#submit-btn {
    width: 100%;
    max-width: 400px;
    display: block;
    margin: 2rem auto 1rem;
    padding: 0.9rem 2rem;
    font-size: 1.1rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--portal-primary) 0%, var(--portal-accent) 100%);
    border: none;
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    transition: all var(--portal-transition);
    box-shadow: 0 2px 8px rgba(30, 64, 175, 0.25);
}

#submit-btn:hover {
    background: linear-gradient(135deg, var(--portal-primary-hover) 0%, var(--portal-primary) 100%);
    box-shadow: 0 4px 16px rgba(30, 64, 175, 0.35);
    transform: translateY(-1px);
}

#submit-btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 4px rgba(30, 64, 175, 0.25);
}

/* ── Landing Page ───────────────────────────────────── */
#landing-section {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 50vh;
}

#auth-card {
    width: 100%;
    max-width: 480px;
    background: #fff;
    border: 1px solid var(--portal-border);
    border-radius: 16px;
    padding: 2.5rem 2rem;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
    text-align: center;
}

#auth-card header {
    padding: 0;
    margin-bottom: 1.5rem;
}

#auth-card header h2 {
    color: var(--portal-primary);
    font-size: 1.4rem;
    margin-bottom: 0.5rem;
}

#auth-card header p {
    color: var(--portal-text-muted);
    font-size: 0.9rem;
    margin: 0;
}

#auth-card label {
    text-align: right;
}

#send-code-btn,
#verify-code-btn {
    width: 100%;
    margin-top: 1rem;
    padding: 0.85rem 2rem;
    font-size: 1.05rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--portal-primary) 0%, var(--portal-accent) 100%);
    border: none;
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    transition: all var(--portal-transition);
    box-shadow: 0 2px 8px rgba(30, 64, 175, 0.25);
}

#send-code-btn:hover,
#verify-code-btn:hover {
    background: linear-gradient(135deg, var(--portal-primary-hover) 0%, var(--portal-primary) 100%);
    box-shadow: 0 4px 16px rgba(30, 64, 175, 0.35);
    transform: translateY(-1px);
}

/* HTMX loading indicator */
.htmx-indicator {
    display: none;
    margin-top: 0.75rem;
    color: var(--portal-text-muted);
}

.htmx-request .htmx-indicator {
    display: block;
    animation: fadeIn 0.2s ease;
}

/* Disabled inputs (e.g., pre-filled email) */
input:disabled {
    background: var(--portal-bg-section) !important;
    cursor: not-allowed;
    opacity: 0.7;
    border-style: dashed;
}

/* ── File Upload Fields ─────────────────────────────── */
.upload-field {
    background: var(--portal-bg-section);
    border: 1px solid var(--portal-border);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
    transition: box-shadow var(--portal-transition);
}

.upload-field:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

/* Collapsible optional uploads */
details.upload-optional {
    padding: 0;
}

details.upload-optional > .upload-area {
    padding: 0 1.25rem 1rem;
}

.upload-summary {
    cursor: pointer;
    padding: 1rem 1.25rem;
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.3rem;
}

.upload-summary::-webkit-details-marker {
    display: none;
}

.upload-summary::marker {
    display: none;
    content: "";
}

.upload-summary::after {
    display: none;
}

.upload-summary::before {
    content: "◂";
    font-size: 0.75rem;
    color: var(--portal-text-muted);
    transition: transform var(--portal-transition);
    margin-left: 0.5rem;
}

details.upload-optional[open] > .upload-summary::before {
    transform: rotate(-90deg);
}

.upload-summary .upload-title {
    font-size: 0.9rem;
}

.upload-summary small {
    width: 100%;
    color: var(--portal-text-muted);
    font-size: 0.75rem;
    padding-right: 1.2rem;
}

.upload-label {
    margin-bottom: 0.75rem;
}

.upload-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--portal-primary);
}

.upload-required {
    color: var(--portal-error);
    font-weight: 700;
    margin-right: 0.2em;
    margin-left: 0.3em;
}

.upload-label small {
    display: block;
    color: var(--portal-text-muted);
    font-weight: 400;
    margin-top: 0.2rem;
}

/* Hidden native file input */
.upload-input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Drop zone / click target */
.upload-drop-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    border: 2px dashed var(--portal-border);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    transition: all var(--portal-transition);
    text-align: center;
    min-height: 80px;
}

.upload-drop-zone:hover,
.upload-drop-zone:focus-visible {
    border-color: var(--portal-accent);
    background: #f0f4ff;
    outline: none;
}

.upload-drop-zone:focus-visible {
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.3);
}

.upload-icon {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

.upload-text {
    font-weight: 600;
    color: var(--portal-accent);
    font-size: 0.9rem;
}

.upload-drop-zone small {
    color: var(--portal-text-muted);
    font-size: 0.75rem;
    margin-top: 0.2rem;
}

/* Upload status */
.upload-status {
    min-height: 1.5rem;
    margin-top: 0.5rem;
    font-size: 0.85rem;
}

.upload-success {
    color: var(--portal-success);
    font-weight: 500;
}

.upload-error {
    color: var(--portal-error);
    font-weight: 500;
}

.upload-uploading {
    color: var(--portal-text-muted);
    font-style: italic;
}

/* Upload spinner */
@keyframes spin {
    to { transform: rotate(360deg); }
}

.upload-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--portal-border);
    border-top-color: var(--portal-accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
    margin-left: 0.5rem;
}

/* Hide drop zone when file already uploaded */
.upload-field.has-file .upload-drop-zone {
    border-color: var(--portal-success);
    background: #f0fdf4;
}

/* ── Responsive ─────────────────────────────────────── */
@media (max-width: 768px) {
    #claim-form > fieldset {
        padding: 1rem;
    }

    .measurements-grid {
        grid-template-columns: 1fr !important;
    }

    .measurements-grid label:last-child:nth-child(odd) {
        max-width: 100%;
    }

    .delivery-actual-group {
        flex-direction: column;
        align-items: stretch;
    }

    header h1 {
        font-size: 1.4rem;
    }

    #submit-btn {
        max-width: 100%;
    }
}

@media (max-width: 480px) {
    .grid {
        grid-template-columns: 1fr !important;
    }
}

/* ── Required Field Indicator ───────────────────────── */
label:has(input[required])::before,
label:has(input[aria-required="true"])::before {
    content: "*";
    color: var(--portal-error);
    font-weight: 700;
    float: right;
    margin-left: 0.3em;
}

/* ── Small Helper Text ──────────────────────────────── */
label small {
    color: var(--portal-text-muted);
    font-weight: 400;
}
