/* HL7 Portugal Color Scheme */
:root {
    --hl7-red: #ec2227;
    --hl7-blue: #2f5aae;
    --hl7-purple: #9463ae;
    --hl7-bg-light: #f4f5f7;
    --hl7-bg-dark: #121212;
    --hl7-text: #272626;
    --hl7-text-light: #666666;
    --hl7-border: #e2e8f0;

    /* Softer red tones for background (HL7 inspired) */
    --hl7-red-soft: #d45d62;
    --hl7-red-lighter: #e89093;
    --hl7-coral: #e67378;
}

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

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
        'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
        sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background: linear-gradient(135deg, #c85a5f 0%, #8b3a3e 50%, #5d2729 100%);
    display: flex;
    flex-direction: column;
}

#root {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.app-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 16px;
    overflow: hidden;
}

/* Header */
.header {
    background: white;
    border-radius: 8px;
    padding: 16px 24px;
    margin-bottom: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.logo {
    height: 50px;
    width: auto;
    max-width: 120px;
    object-fit: contain;
}

.header-text h1 {
    color: var(--hl7-text);
    font-size: 24px;
    margin-bottom: 2px;
}

.header-text p {
    color: var(--hl7-text-light);
    font-size: 13px;
}

.version {
    background: var(--hl7-red);
    color: white;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

/* Disclaimer */
.disclaimer {
    background: #fff3cd;
    border: 2px solid #ffc107;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 12px;
    display: flex;
    align-items: start;
    gap: 12px;
    flex-shrink: 0;
}

.disclaimer-icon {
    font-size: 24px;
    flex-shrink: 0;
}

.disclaimer-content h3 {
    color: #856404;
    font-size: 16px;
    margin-bottom: 6px;
}

.disclaimer-content p {
    color: #856404;
    font-size: 14px;
    line-height: 1.5;
}

/* Main content */
.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

.panel {
    background: white;
    border-radius: 8px;
    padding: 16px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.panel-header h2 {
    color: var(--hl7-text);
    font-size: 18px;
    font-weight: 600;
}

.textarea-container {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.message-input,
.message-output {
    width: 100%;
    height: 100%;
    padding: 12px;
    border: 2px solid var(--hl7-border);
    border-radius: 6px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 12px;
    line-height: 1.7;
    letter-spacing: 0;
    resize: none;
    transition: border-color 0.2s;
}

.message-input:focus {
    outline: none;
    border-color: var(--hl7-blue);
}

.message-output {
    background: var(--hl7-bg-light);
}

/* HL7 Message Styling */
.hl7-message {
    font-family: 'Courier New', Courier, monospace;
    font-size: 12px;
    line-height: 1.7;
    letter-spacing: 0;
    white-space: pre-wrap;
    word-break: keep-all;
    background: var(--hl7-bg-light);
    border: 2px solid var(--hl7-border);
    border-radius: 6px;
    padding: 12px;
    height: 100%;
    overflow-y: auto;
    flex: 1;
}

.hl7-segment {
    display: block;
    margin-bottom: 2px;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.hl7-segment:hover {
    background: rgba(47, 90, 174, 0.08);
}

.hl7-segment-msh {
    background: rgba(47, 90, 174, 0.12);
}

.hl7-segment-pid {
    background: rgba(236, 34, 39, 0.12);
}

.hl7-segment-pv1 {
    background: rgba(148, 99, 174, 0.12);
}

.hl7-segment-obr {
    background: rgba(47, 90, 174, 0.18);
}

.hl7-segment-obx {
    background: rgba(148, 99, 174, 0.18);
}

.hl7-segment-nk1 {
    background: rgba(236, 34, 39, 0.18);
}

.hl7-segment-evn,
.hl7-segment-orc,
.hl7-segment-sch,
.hl7-segment-rgs,
.hl7-segment-aig,
.hl7-segment-ail,
.hl7-segment-aip {
    background: rgba(47, 90, 174, 0.08);
}

.hl7-field {
    display: inline;
    padding: 0;
    margin: 0;
}

.hl7-field-editable {
    cursor: text;
    padding: 1px 2px;
    margin: 0;
    border-radius: 2px;
    transition: background-color 0.2s;
}

.hl7-field-editable:hover {
    background: rgba(47, 90, 174, 0.15);
    outline: 1px solid rgba(47, 90, 174, 0.3);
}

.hl7-field-editable:focus {
    outline: 2px solid var(--hl7-blue);
    background: white;
}

/* Highlight anonymized/changed fields */
.hl7-field-anonymized {
    background: rgba(236, 34, 39, 0.15);
    padding: 1px 3px;
    margin: 0 1px;
    border-radius: 2px;
    font-weight: 700 !important;
    font-family: 'Courier New', Courier, monospace;
    box-shadow: 0 0 0 1px rgba(236, 34, 39, 0.3);
    color: #000000;
    text-shadow: 0.3px 0 0 currentColor;
}

.field-separator {
    color: var(--hl7-blue);
    font-weight: 600;
    padding: 0 1px;
    margin: 0;
}

.component-separator {
    color: var(--hl7-red);
    font-weight: 600;
    padding: 0 1px;
    margin: 0;
}

/* Buttons */
.button-group {
    display: flex;
    gap: 10px;
    margin-top: 12px;
    flex-shrink: 0;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

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

.btn-primary {
    background: linear-gradient(135deg, var(--hl7-red) 0%, var(--hl7-blue) 100%);
    color: white;
    flex: 1;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(236, 34, 39, 0.3);
}

.btn-secondary {
    background: white;
    color: var(--hl7-blue);
    border: 2px solid var(--hl7-blue);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--hl7-bg-light);
}

.btn-clear {
    background: #dc3545;
    color: white;
}

.btn-clear:hover:not(:disabled) {
    background: #c82333;
}

.btn-copy {
    background: #28a745;
    color: white;
}

.btn-copy:hover:not(:disabled) {
    background: #218838;
}

.btn-validate {
    background: var(--hl7-purple);
    color: white;
    flex: 1;
}

.btn-validate:hover:not(:disabled) {
    background: #7a51a0;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(148, 99, 174, 0.3);
}

/* Validation Results Container */
.validation-results-container {
    margin-top: 12px;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    align-items: flex-start;
}

/* Validation Badge Container */
.validation-badge-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 100%;
}

/* Validation Badge (Compact Status) */
.validation-badge {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    animation: slideDown 0.3s ease-out;
    transition: all 0.2s;
}

.validation-badge.clickable {
    cursor: pointer;
}

.validation-badge.clickable:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.validation-badge-success {
    background: #c6f6d5;
    border: 2px solid #48bb78;
    color: #22543d;
}

.validation-badge-error {
    background: #fed7d7;
    border: 2px solid #f56565;
    color: #742a2a;
}

.validation-badge-content {
    display: flex;
    align-items: center;
    gap: 6px;
}

.validation-badge-number {
    font-weight: 700;
    font-size: 11px;
    opacity: 0.8;
}

.validation-badge-icon {
    font-size: 16px;
    font-weight: bold;
}

.validation-badge-text {
    font-size: 13px;
}

.validation-badge-arrow {
    font-size: 10px;
    margin-left: 2px;
    opacity: 0.7;
}

/* Validation Details (Expanded) */
.validation-details {
    margin-top: 8px;
    padding: 12px 16px;
    border-radius: 6px;
    background: #fed7d7;
    border: 2px solid #f56565;
    color: #742a2a;
    animation: slideDown 0.3s ease-out;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.validation-details-message {
    font-weight: 600;
    font-size: 14px;
}

.validation-errors {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
}

.validation-error-item {
    padding: 4px 0;
}

.validation-error-level {
    font-weight: 700;
    margin-right: 6px;
}

.validation-more {
    font-style: italic;
    opacity: 0.8;
    margin-top: 4px;
}

.validation-details-link {
    color: inherit;
    text-decoration: underline;
    font-size: 13px;
    opacity: 0.9;
    transition: opacity 0.2s;
}

.validation-details-link:hover {
    opacity: 1;
}

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

/* Loading spinner */
.spinner {
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top: 3px solid white;
    width: 20px;
    height: 20px;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Alert messages */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideIn 0.3s ease-out;
}

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

.alert-success {
    background: #c6f6d5;
    color: #22543d;
    border: 1px solid #48bb78;
}

.alert-error {
    background: #fed7d7;
    color: #742a2a;
    border: 1px solid #f56565;
}

.alert-info {
    background: #bee3f8;
    color: #2c5282;
    border: 1px solid #4299e1;
}

/* Footer */
.footer {
    text-align: center;
    color: white;
    padding: 12px;
    font-size: 12px;
    flex-shrink: 0;
}

.footer a {
    color: white;
    text-decoration: underline;
}

/* Legend */
.legend {
    background: white;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.legend h3 {
    color: var(--hl7-text);
    font-size: 14px;
    margin-bottom: 8px;
}

.legend-items {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
}

.legend-color {
    width: 20px;
    height: 14px;
    border-radius: 3px;
}

/* Character counter */
.char-counter {
    position: absolute;
    bottom: 8px;
    right: 12px;
    font-size: 12px;
    color: #718096;
    background: white;
    padding: 2px 8px;
    border-radius: 4px;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 100%;
    max-width: 800px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 2px solid var(--hl7-border);
}

.modal-header h2 {
    color: var(--hl7-text);
    font-size: 20px;
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 32px;
    color: var(--hl7-text-light);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--hl7-bg-light);
    color: var(--hl7-text);
}

.modal-body {
    padding: 16px 24px 24px;
    overflow-y: auto;
    flex: 1;
}

.example-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.example-item {
    padding: 16px;
    border: 2px solid var(--hl7-border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    background: white;
}

.example-item:hover {
    border-color: var(--hl7-blue);
    background: rgba(47, 90, 174, 0.03);
    transform: translateX(4px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.example-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.example-name {
    font-weight: 600;
    color: var(--hl7-text);
    font-size: 14px;
}

.example-version {
    background: var(--hl7-blue);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

.example-description {
    color: var(--hl7-text-light);
    font-size: 13px;
    line-height: 1.5;
}

/* Field Tooltip */
.field-tooltip {
    position: fixed;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    pointer-events: none;
    z-index: 10000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    animation: tooltipFadeIn 0.2s ease-out;
}

@keyframes tooltipFadeIn {
    from {
        opacity: 0;
        transform: translate(-50%, calc(-100% - 5px));
    }
    to {
        opacity: 1;
        transform: translate(-50%, -100%);
    }
}

.hl7-field {
    cursor: help;
    position: relative;
}
