/* ═══════════════════════════════════════════════════════════════════════════
   JASCA Patient Registration Portal
   Aesthetic: Clinical Warmth - Medical precision meets Scandinavian coziness
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
    /* Color Palette - medrepo.de design system */
    --color-cream: #faf7f2;
    --color-cream-dark: #f0ebe1;
    --color-sage: #00a878;
    --color-sage-light: #b3e8d8;
    --color-sage-dark: #0f1d3a;
    --color-sage-muted: #e6f7f2;
    --color-charcoal: #0f1d3a;
    --color-charcoal-light: #1a2f58;
    --color-text: #1a1410;
    --color-text-muted: #7a7268;
    --color-white: #ffffff;
    --color-error: #c0392b;
    --color-error-bg: #fef2f2;
    --color-success: #00a878;
    --color-success-bg: #e6f7f2;

    /* Typography - Fonts from Bunny Fonts (privacy-friendly) */
    --font-display: 'Cormorant Garamond', Georgia, serif;
    --font-body: 'Figtree', system-ui, sans-serif;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;
    --space-3xl: 64px;

    /* Borders & Shadows */
    --radius-sm: 4px;
    --radius-md: 4px;
    --radius-lg: 4px;
    --radius-full: 4px;
    --shadow-soft: 0 2px 8px rgba(15,29,58,.06);
    --shadow-medium: 0 4px 20px rgba(15,29,58,.08);
    --shadow-lifted: 0 12px 40px rgba(15,29,58,.12);

    /* Transitions */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --duration-fast: 150ms;
    --duration-normal: 250ms;
    --duration-slow: 400ms;
}

/* ═══════════════════════════════════════════════════════════════════════════
   BASE & RESET
   ═══════════════════════════════════════════════════════════════════════════ */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-body);
    background: var(--color-cream);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
    padding: var(--space-lg);
    position: relative;
    overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n' x='0' y='0'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 200px 200px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   BACKGROUND PATTERN - Soft organic circles
   ═══════════════════════════════════════════════════════════════════════════ */

.bg-pattern {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 0;
}

.bg-circle {
    position: absolute;
    border-radius: 50%;
    background: var(--color-sage);
    opacity: 0;
}

.bg-circle-1 {
    width: 600px;
    height: 600px;
    top: -200px;
    right: -100px;
    animation: float 20s ease-in-out infinite;
}

.bg-circle-2 {
    width: 400px;
    height: 400px;
    bottom: -100px;
    left: -150px;
    animation: float 25s ease-in-out infinite reverse;
}

.bg-circle-3 {
    width: 300px;
    height: 300px;
    top: 50%;
    right: 10%;
    animation: float 18s ease-in-out infinite 5s;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(30px, -30px) scale(1.05); }
    66% { transform: translate(-20px, 20px) scale(0.95); }
}

/* ═══════════════════════════════════════════════════════════════════════════
   CONTAINER
   ═══════════════════════════════════════════════════════════════════════════ */

.container {
    position: relative;
    z-index: 1;
    max-width: 580px;
    margin: 0 auto;
    background: var(--color-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lifted);
    overflow: hidden;
    animation: slideUp 0.6s var(--ease-out) both;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   TRUST BADGE
   ═══════════════════════════════════════════════════════════════════════════ */

.trust-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--color-sage-muted);
    color: var(--color-sage-dark);
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    animation: slideUp 0.6s var(--ease-out) 0.1s both;
}

.shield-icon {
    width: 14px;
    height: 14px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   HEADER
   ═══════════════════════════════════════════════════════════════════════════ */

.header {
    padding: var(--space-xl) var(--space-lg) var(--space-lg);
    text-align: center;
    border-bottom: 1px solid var(--color-cream-dark);
    animation: slideUp 0.6s var(--ease-out) 0.15s both;
}

/* Logo */
.logo {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-bottom: var(--space-md);
    text-decoration: none;
}

.logo-img-wrap {
    width: 36px;
    height: 36px;
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo-img {
    width: 220%;
    height: 220%;
    object-fit: contain;
    margin: -60%;
}

.logo-text-group {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.logo-text {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 500;
    color: var(--color-charcoal);
    letter-spacing: -0.01em;
    line-height: 1;
}

.logo-sub-text {
    font-family: var(--font-body);
    font-size: 0.5625rem;
    font-weight: 500;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--color-sage);
    line-height: 1;
}

.title {
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 400;
    color: var(--color-charcoal);
    margin-bottom: var(--space-sm);
    letter-spacing: -0.01em;
}

.subtitle {
    font-size: 0.9375rem;
    color: var(--color-text-muted);
    max-width: 320px;
    margin: 0 auto;
}

/* ═══════════════════════════════════════════════════════════════════════════
   BANNERS (Error & Success)
   ═══════════════════════════════════════════════════════════════════════════ */

.banner {
    display: flex;
    align-items: flex-start;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    animation: slideDown 0.4s var(--ease-out);
}

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

.banner.hidden {
    display: none;
}

.banner-error {
    background: var(--color-error-bg);
    border-left: 3px solid var(--color-error);
}

.banner-error .banner-icon {
    color: var(--color-error);
}

.banner-success {
    background: var(--color-success-bg);
    border-left: 3px solid var(--color-success);
}

.banner-success .banner-icon {
    color: var(--color-success);
}

.banner-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    margin-top: 2px;
}

.banner-content {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.banner-title {
    font-weight: 600;
    color: var(--color-charcoal);
}

.banner-text {
    font-size: 0.9375rem;
    line-height: 1.5;
}

.banner-error .banner-text {
    color: var(--color-error);
}

.banner-success .banner-text {
    color: var(--color-text-muted);
}

/* ═══════════════════════════════════════════════════════════════════════════
   FORM
   ═══════════════════════════════════════════════════════════════════════════ */

.form {
    padding: var(--space-lg);
}

.form.hidden {
    display: none;
}

/* Form Sections */
.form-section {
    border: none;
    padding: 0;
    margin-bottom: var(--space-xl);
    animation: slideUp 0.6s var(--ease-out) both;
}

.form-section:nth-child(1) { animation-delay: 0.2s; }
.form-section:nth-child(2) { animation-delay: 0.25s; }
.form-section:nth-child(3) { animation-delay: 0.3s; }

.section-legend {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--color-cream-dark);
}

.section-number {
    font-family: var(--font-display);
    font-size: 0.875rem;
    color: var(--color-sage);
    background: var(--color-sage-muted);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    min-width: 32px;
    text-align: center;
}

.section-title {
    font-family: var(--font-display);
    font-size: 1.125rem;
    color: var(--color-charcoal);
}

/* Field Grid */
.field-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
}

.field-grid-address {
    grid-template-columns: 2fr 1fr 1.5fr;
}

.form-field-full {
    margin-bottom: var(--space-md);
}

/* Form Fields */
.form-field {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
}

.label-text {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-charcoal-light);
}

.label-required {
    font-size: 0.6875rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-sage);
    background: var(--color-sage-muted);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
}

.label-optional {
    font-size: 0.6875rem;
    color: var(--color-text-muted);
}

/* Input Wrapper with Focus Ring */
.input-wrapper {
    position: relative;
}

.input-focus-ring {
    position: absolute;
    inset: -3px;
    border-radius: calc(var(--radius-md) + 3px);
    border: 2px solid var(--color-sage);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--duration-fast) var(--ease-out);
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="date"] {
    width: 100%;
    padding: var(--space-md);
    font-family: var(--font-body);
    font-size: 1rem;
    color: var(--color-charcoal);
    background: var(--color-cream);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    transition: all var(--duration-normal) var(--ease-out);
}

input::placeholder {
    color: var(--color-text-muted);
    opacity: 0.7;
}

input:hover {
    background: var(--color-cream-dark);
}

input:focus {
    outline: none;
    background: var(--color-white);
    border-color: var(--color-sage-light);
    box-shadow: var(--shadow-soft);
}

input:focus + .input-focus-ring {
    opacity: 0.15;
}

/* Exclude date inputs: they have no real placeholder, so :not(:placeholder-shown) is
   always true and the field would appear red on page load before the user touches it. */
input:invalid:not(:placeholder-shown):not(:focus):not([type="date"]) {
    border-color: var(--color-error);
    background: var(--color-error-bg);
}

/* JS-controlled invalid state (used by validateForm() for all input types) */
input.invalid {
    border-color: var(--color-error) !important;
    background: var(--color-error-bg) !important;
}

/* Date input styling */
input[type="date"] {
    cursor: pointer;
}

input[type="date"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
    opacity: 0.5;
    transition: opacity var(--duration-fast);
}

input[type="date"]:hover::-webkit-calendar-picker-indicator {
    opacity: 0.8;
}

/* ═══════════════════════════════════════════════════════════════════════════
   CONSENT SECTION
   ═══════════════════════════════════════════════════════════════════════════ */

.consent-section {
    margin-bottom: var(--space-lg);
    animation: slideUp 0.6s var(--ease-out) 0.35s both;
}

.consent-label {
    display: flex;
    align-items: flex-start;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--color-cream);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--duration-fast);
}

.consent-label:hover {
    background: var(--color-cream-dark);
}

.consent-label input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.consent-checkbox {
    position: relative;
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    background: var(--color-white);
    border: 2px solid var(--color-sage-light);
    border-radius: var(--radius-sm);
    transition: all var(--duration-fast) var(--ease-out);
}

.consent-label:hover .consent-checkbox {
    border-color: var(--color-sage);
}

.consent-label input:checked + .consent-checkbox {
    background: var(--color-sage);
    border-color: var(--color-sage);
}

.check-icon {
    position: absolute;
    inset: 2px;
    color: var(--color-white);
    opacity: 0;
    transform: scale(0.5);
    transition: all var(--duration-fast) var(--ease-spring);
}

.consent-label input:checked + .consent-checkbox .check-icon {
    opacity: 1;
    transform: scale(1);
}

.consent-text {
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--color-text-muted);
}

/* ═══════════════════════════════════════════════════════════════════════════
   SUBMIT BUTTON
   ═══════════════════════════════════════════════════════════════════════════ */

.submit-btn {
    position: relative;
    width: 100%;
    padding: var(--space-lg) var(--space-xl);
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-white);
    background: var(--color-sage-dark);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    overflow: hidden;
    transition: all var(--duration-normal) var(--ease-out);
    animation: slideUp 0.6s var(--ease-out) 0.4s both;
}

.submit-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.08);
    opacity: 0;
    transition: opacity var(--duration-normal) var(--ease-out);
}

.submit-btn:hover::before {
    opacity: 1;
}

.submit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(15,29,58,.25);
}

.submit-btn:active {
    transform: translateY(0);
}

.submit-btn:disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

.submit-btn:disabled:hover {
    transform: none;
    box-shadow: none;
}

.btn-content,
.btn-loading {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
}

.btn-loading {
    display: none;
}

.submit-btn.loading .btn-content {
    display: none;
}

.submit-btn.loading .btn-loading {
    display: flex;
}

.btn-arrow {
    width: 18px;
    height: 18px;
    transition: transform var(--duration-normal) var(--ease-out);
}

.submit-btn:hover .btn-arrow {
    transform: translateX(4px);
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: var(--color-white);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ═══════════════════════════════════════════════════════════════════════════
   FOOTER
   ═══════════════════════════════════════════════════════════════════════════ */

.footer {
    padding: var(--space-lg);
    background: var(--color-cream);
    text-align: center;
    border-top: 1px solid var(--color-cream-dark);
    animation: slideUp 0.6s var(--ease-out) 0.45s both;
}

.footer-secure {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
    color: var(--color-sage);
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.footer-secure svg {
    width: 14px;
    height: 14px;
}

.footer-text {
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE DESIGN
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
    body {
        padding: var(--space-md);
    }

    .container {
        border-radius: var(--radius-md);
    }

    .header {
        padding: var(--space-lg) var(--space-md);
    }

    .title {
        font-size: 1.5rem;
    }

    .form {
        padding: var(--space-md);
    }

    .field-grid,
    .field-grid-address {
        grid-template-columns: 1fr;
        gap: var(--space-md);
    }

    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="date"] {
        font-size: 16px; /* Prevents iOS zoom on focus */
    }

    .section-legend {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-sm);
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   LOADING STATE
   ═══════════════════════════════════════════════════════════════════════════ */

.validating-token .form {
    opacity: 0.4;
    pointer-events: none;
}

.validating-token .form::after {
    content: '';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.5);
}

/* ═══════════════════════════════════════════════════════════════════════════
   ACCESSIBILITY
   ═══════════════════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .bg-circle {
        animation: none;
    }

    .pulse-ring,
    .pulse-core {
        animation: none;
    }
}

/* Focus visible for keyboard navigation */
*:focus-visible {
    outline: 2px solid var(--color-sage);
    outline-offset: 2px;
}

input:focus-visible {
    outline: none;
}

.consent-label:has(input:focus-visible) .consent-checkbox {
    outline: 2px solid var(--color-sage);
    outline-offset: 2px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   HIDDEN UTILITY
   ═══════════════════════════════════════════════════════════════════════════ */

.hidden {
    display: none !important;
}
