/**
 * @file
 * NIS2Secure Organisation Registration - Modern Professional Design
 * Clean, trustworthy, minimalistic UX for compliance forms
 */

/* ====================================
   CSS VARIABLES
   ==================================== */
:root {
  /* Colors - Professional blue-gray palette */
  --color-primary: #2563eb;
  --color-success: #16a34a;
  --color-text-dark: #0f172a;
  --color-text-body: #1e293b;
  --color-text-muted: #64748b;
  --color-border: #cbd5e1;
  --color-border-light: #e2e8f0;
  --color-bg-page: #f8fafc;
  --color-bg-white: #ffffff;
  --color-bg-info: #eff6ff;
  --color-bg-neutral: #f1f5f9;
  --color-highlight: #2563eb;
  
  /* Spacing */
  --spacing-xs: 0.5rem;
  --spacing-sm: 0.75rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.25rem;
  --spacing-xl: 1.5rem;
  --spacing-2xl: 2rem;
  --spacing-3xl: 2.5rem;
  --spacing-4xl: 3rem;
  
  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  
  /* Borders & Shadows */
  --radius-sm: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --shadow-card: 0 6px 20px rgba(0, 0, 0, 0.05);
  --shadow-hover: 0 6px 12px rgba(37, 99, 235, 0.25);
  --shadow-focus: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

/* ====================================
   GLOBAL STYLES
   ==================================== */
* {
  box-sizing: border-box;
}

body {
  font-family: var(--font-family);
  color: var(--color-text-body);
  line-height: 1.6;
}

/* ====================================
   PAGE CONTAINER
   ==================================== */
.nis2-registration-container,
#nis2secure-organisation-form,
form#nis2secure-organisation-form {
  padding: var(--spacing-4xl) var(--spacing-md);
  background: var(--color-bg-page);
  min-height: 100vh;
}

.registration-card,
#nis2secure-organisation-form > div,
form#nis2secure-organisation-form > div {
  background: var(--color-bg-white);
  margin: 0 auto;
  padding: var(--spacing-3xl) var(--spacing-4xl);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

/* ====================================
   BREADCRUMB (Optional)
   ==================================== */
.breadcrumb {
  font-size: 0.875rem;
  margin-bottom: var(--spacing-xl);
  color: var(--color-text-muted);
}

/* ====================================
   PAGE TITLE
   ==================================== */
.page-title,
h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: var(--spacing-md);
  color: var(--color-text-dark);
  line-height: 1.2;
}

/* ====================================
   PACKAGE INFO BANNER
   ==================================== */
.package-confirmation,
.package-info {
  background: var(--color-bg-info);
  border-left: 4px solid var(--color-primary);
  padding: var(--spacing-lg) var(--spacing-xl);
  border-radius: var(--radius-md);
  margin-bottom: var(--spacing-2xl);
  animation: slideDown 0.4s ease-out;
}

.package-confirmation h3,
.package-info h3 {
  margin: 0 0 var(--spacing-sm);
  color: var(--color-text-dark);
  font-size: 1.125rem;
  font-weight: 600;
}

.package-confirmation p,
.package-info p {
  margin: var(--spacing-sm) 0;
  color: var(--color-text-body);
  font-size: 1rem;
  line-height: 1.6;
}

.package-info .highlight {
  color: var(--color-highlight);
  font-weight: 600;
}

.package-info .note {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-top: var(--spacing-sm);
}

.package-confirmation strong,
.package-info strong {
  font-weight: 600;
  color: var(--color-text-dark);
}

/* ====================================
   SECTION TITLES
   ==================================== */
.section-title,
details summary,
fieldset > legend,
h3.section-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-top: var(--spacing-2xl);
  margin-bottom: var(--spacing-md);
  color: var(--color-text-body);
  border-bottom: 1px solid var(--color-border-light);
  padding-bottom: var(--spacing-xs);
}

/* First section - no top margin */
.section-title:first-of-type,
details:first-of-type summary {
  margin-top: 0;
}

/* Section Description */
.section-description {
  font-size: 0.95rem;
  color: var(--color-text-muted);
  margin-bottom: var(--spacing-md);
  line-height: 1.6;
}

/* ====================================
   DETAILS/FIELDSET SECTIONS
   ==================================== */
details.organisation-section,
details.primary-contact-section,
details.role-contacts-section,
details.admin-section {
  border: none;
  background: transparent;
  margin-bottom: var(--spacing-2xl);
}

details summary {
  cursor: pointer;
  user-select: none;
  list-style: none;
  background: transparent;
  padding: 0;
  border: none;
  color: var(--color-text-body);
}

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

/* Open state */
details[open] {
  margin-bottom: var(--spacing-2xl);
}

/* Details content wrapper */
details > .details-wrapper {
  padding: 0;
  margin-top: var(--spacing-md);
}

/* Fieldsets */
fieldset.role-subsection {
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  margin-bottom: var(--spacing-lg);
  padding: var(--spacing-md);
  background: var(--color-bg-neutral);
}

fieldset.role-subsection legend {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text-body);
  padding: 0 var(--spacing-xs);
  margin-bottom: var(--spacing-sm);
  background: transparent;
  border: none;
}

fieldset.role-subsection .fieldset-wrapper {
  padding: 0;
}

/* ====================================
   FORM ELEMENTS
   ==================================== */
.form-group,
.form-item {
  margin-bottom: var(--spacing-lg);
}

.form-group label,
.form-item label {
  display: block;
  margin-bottom: var(--spacing-xs);
  font-weight: 500;
  color: var(--color-text-body);
  font-size: 0.95rem;
}

.form-item label .form-required {
  color: var(--color-primary);
  margin-left: 0.25rem;
}

.description,
.form-text {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-top: 0.25rem;
  line-height: 1.5;
}

/* Form Rows */
.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-md);
  margin-bottom: var(--spacing-lg);
}

.form-row .form-group,
.form-row .form-item {
  flex: 1;
  min-width: 200px;
}

.form-row .col-md-4 {
  flex: 1 1 calc(33.333% - var(--spacing-md));
  min-width: 200px;
}

.form-row .col-md-6 {
  flex: 1 1 calc(50% - var(--spacing-md));
  min-width: 200px;
}

.form-row .col-md-8 {
  flex: 1 1 calc(66.667% - var(--spacing-md));
  min-width: 200px;
}

/* Text inputs, selects, textareas */
.form-control,
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--spacing-sm) var(--spacing-md);
  font-size: 1rem;
  font-family: var(--font-family);
  color: var(--color-text-dark);
  background: var(--color-bg-white);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  line-height: 1.5;
}

.form-control:focus,
input[type="text"]:focus,
input[type="email"]:focus,
input[type="tel"]:focus,
input[type="password"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: var(--shadow-focus);
}

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

/* Select dropdown styling */
select {
  cursor: pointer;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="8"><path fill="%232563eb" d="M0 0l6 8 6-8z"/></svg>');
  background-repeat: no-repeat;
  background-position: right var(--spacing-md) center;
  background-size: 12px;
  padding-right: 2.5rem;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
}

/* Textarea */
textarea {
  min-height: 100px;
  resize: vertical;
}

/* ====================================
   PACKAGE SUMMARY
   ==================================== */
.package-summary {
  background: var(--color-bg-neutral);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  padding: var(--spacing-lg);
  margin-top: var(--spacing-md);
  margin-bottom: var(--spacing-2xl);
}

.package-summary h4 {
  margin: 0 0 var(--spacing-xs);
  color: var(--color-text-dark);
  font-size: 1.125rem;
  font-weight: 600;
}

.package-summary p {
  margin: 0;
  color: var(--color-text-body);
  font-size: 1rem;
  line-height: 1.6;
}

/* ====================================
   FORM ACTIONS (Submit buttons)
   ==================================== */
.form-actions {
  padding: 0;
  margin-top: var(--spacing-2xl);
  text-align: center;
  background: transparent;
  border: none;
}

.form-actions .btn-primary,
.form-actions .btn,
.form-actions input[type="submit"],
.form-actions button[type="submit"] {
  background: linear-gradient(to right, var(--color-primary), var(--color-success));
  color: white;
  font-weight: 600;
  font-size: 1rem;
  padding: 0.9rem var(--spacing-xl);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  width: 100%;
  font-family: var(--font-family);
  display: inline-block;
}

.form-actions .btn-primary:hover,
.form-actions .btn:hover,
.form-actions input[type="submit"]:hover,
.form-actions button[type="submit"]:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.form-actions .btn-primary:active,
.form-actions .btn:active,
.form-actions input[type="submit"]:active,
.form-actions button[type="submit"]:active {
  transform: translateY(0);
}

/* Loading state */
.form-actions .btn-primary[disabled],
.form-actions input[type="submit"][disabled] {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* ====================================
   VALIDATION & ERROR STATES
   ==================================== */
.form-item.error input,
.form-item.error select,
.form-item.error textarea,
input.error,
select.error,
textarea.error {
  border-color: #dc2626;
  background: #fef2f2;
}

.form-item .error,
.error-message {
  color: #dc2626;
  font-size: 0.875rem;
  margin-top: var(--spacing-xs);
  display: block;
}

/* Success state */
.form-item.success input,
.form-item.success select,
input.success,
select.success {
  border-color: var(--color-success);
}

/* Drupal messages */
.messages {
  margin-bottom: var(--spacing-2xl);
  padding: var(--spacing-md) var(--spacing-lg);
  border-radius: var(--radius-md);
  border-left: 4px solid;
}

.messages.status {
  background: #f0fdf4;
  border-color: var(--color-success);
  color: #166534;
}

.messages.error {
  background: #fef2f2;
  border-color: #dc2626;
  color: #991b1b;
}

.messages.warning {
  background: #fffbeb;
  border-color: #f59e0b;
  color: #92400e;
}

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

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

/* Animate form sections when opening */
details[open] > .details-wrapper {
  animation: fadeIn 0.3s ease-out;
}

/* ====================================
   RESPONSIVE DESIGN
   ==================================== */
@media (max-width: 768px) {
  .nis2-registration-container,
  #nis2secure-organisation-form,
  form#nis2secure-organisation-form {
    padding: var(--spacing-xl) var(--spacing-md);
  }
  
  .registration-card,
  #nis2secure-organisation-form > div,
  form#nis2secure-organisation-form > div {
    padding: var(--spacing-xl);
  }
  
  .page-title,
  h1 {
    font-size: clamp(1.25rem, 4vw, 1.75rem);
  }
  
  .section-title,
  details summary,
  h3.section-title {
    font-size: 1.125rem;
  }
  
  /* Stack form rows on mobile */
  .form-row {
    flex-direction: column;
    gap: 0;
  }
  
  .form-row .form-group,
  .form-row .form-item,
  .form-row .col-md-4,
  .form-row .col-md-6,
  .form-row .col-md-8 {
    flex: 1 1 100%;
    min-width: 100%;
    width: 100%;
  }
}

/* Tablet adjustments */
@media (min-width: 769px) and (max-width: 1024px) {
  .registration-card,
  #nis2secure-organisation-form > div,
  form#nis2secure-organisation-form > div {
    padding: var(--spacing-2xl) var(--spacing-3xl);
  }
}

/* ====================================
   CVR LOOKUP FUNCTIONALITY
   ==================================== */
.cvr-lookup-wrapper {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  flex-wrap: wrap;
}

.cvr-lookup-wrapper input {
  flex: 1;
  min-width: 200px;
}

.btn-cvr-lookup {
  background: linear-gradient(135deg, var(--color-primary), var(--color-success));
  color: white;
  border: none;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.3s ease;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2);
}

.btn-cvr-lookup:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

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

.btn-cvr-lookup:disabled {
  background: #9ca3af;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.cvr-loading {
  color: var(--color-primary);
  font-weight: 500;
  font-size: 0.9rem;
  animation: cvr-pulse 1.5s ease-in-out infinite;
}

@keyframes cvr-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.cvr-message {
  margin-top: var(--spacing-sm);
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  animation: cvr-slideDown 0.3s ease-out;
}

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

.cvr-populated {
  border-color: var(--color-success) !important;
  animation: cvr-highlight 2s ease-out;
}

@keyframes cvr-highlight {
  0% { background-color: #d4edda; }
  100% { background-color: transparent; }
}

/* ====================================
   TERMS & CONDITIONS SECTION
   ==================================== */
.terms-acceptance-section {
  background: var(--color-bg-info);
  border: 2px solid var(--color-primary);
  border-radius: var(--radius-md);
  padding: var(--spacing-xl);
  margin: var(--spacing-2xl) 0;
}

.terms-acceptance-section legend {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-primary);
  padding: 0 var(--spacing-sm);
}

/* Single terms checkbox */
.accept-terms-single {
  margin: 0;
}

.accept-terms-single input[type="checkbox"] {
  width: 1.5rem;
  height: 1.5rem;
  margin-right: var(--spacing-md);
  cursor: pointer;
  accent-color: var(--color-primary);
  vertical-align: middle;
}

.accept-terms-single label {
  display: flex;
  align-items: center;
  font-size: 1.05rem;
  line-height: 1.7;
  cursor: pointer;
  padding: var(--spacing-lg);
  background: white;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: all 0.2s ease;
}

.accept-terms-single label:hover {
  border-color: var(--color-primary);
  box-shadow: 0 2px 12px rgba(37, 99, 235, 0.15);
}

.accept-terms-single input[type="checkbox"]:checked + label {
  border-color: var(--color-success);
  background: #f0fdf4;
}

.accept-terms-single label a {
  color: var(--color-primary);
  text-decoration: underline;
  font-weight: 600;
}

.accept-terms-single label a:hover {
  color: #1d4ed8;
}

/* Error states */
.accept-terms-single.error label {
  border-color: #dc2626;
  background: #fef2f2;
}

@media (max-width: 768px) {
  .accept-terms-single label {
    font-size: 0.95rem;
    padding: var(--spacing-md);
  }
  
  .accept-terms-single input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
  }
}

/* ====================================
   UTILITIES
   ==================================== */
.text-muted {
  color: var(--color-text-muted);
}

.text-center {
  text-align: center;
}

.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: var(--spacing-xs) !important; }
.mb-2 { margin-bottom: var(--spacing-md) !important; }
.mb-3 { margin-bottom: var(--spacing-lg) !important; }
.mb-4 { margin-bottom: var(--spacing-2xl) !important; }

.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: var(--spacing-xs) !important; }
.mt-2 { margin-top: var(--spacing-md) !important; }
.mt-3 { margin-top: var(--spacing-lg) !important; }
.mt-4 { margin-top: var(--spacing-2xl) !important; }
