/**
 * HL7 Web Parser - Main Styles
 * Modern, clean design with tree visualization
 * Supports system theme detection (light/dark mode)
 */

/* CSS Variables for theming */
:root {
    /* Light theme (default) */
    --bg-primary: #f5f7fa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f8f9fa;
    --bg-quaternary: #f7fafc;
    --bg-code: #f8f9fa;

    --text-primary: #333333;
    --text-secondary: #4a5568;
    --text-tertiary: #718096;
    --text-quaternary: #a0aec0;

    --border-primary: #e2e8f0;
    --border-secondary: #cbd5e0;

    --accent-primary: #667eea;
    --accent-primary-hover: #5568d3;
    --accent-secondary: #48bb78;
    --accent-secondary-hover: #38a169;

    --header-gradient-start: #667eea;
    --header-gradient-end: #764ba2;

    --segment-bg: #e6f2ff;
    --segment-bg-hover: #bee3f8;
    --segment-border: #3182ce;
    --segment-text: #2c5282;

    --field-path-color: #38a169;
    --field-value-color: #2d3748;
    --comp-path-color: #dd6b20;
    --sub-path-color: #9f7aea;

    --error-color: #e53e3e;
    --error-bg: #fff5f5;
    --success-bg: #d4edda;
    --success-border: #c3e6cb;
    --success-text: #155724;
    --warning-bg: #fff3cd;
    --warning-border: #ffc107;
    --warning-text: #856404;

    --footer-bg: #2d3748;
    --footer-link: #90cdf4;

    --scrollbar-track: #edf2f7;
    --scrollbar-thumb: #cbd5e0;
    --scrollbar-thumb-hover: #a0aec0;
}

/* Dark theme - via media query (system preference) */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg-primary: #1a202c;
        --bg-secondary: #2d3748;
        --bg-tertiary: #1a202c;
        --bg-quaternary: #2d3748;
        --bg-code: #1a202c;

        --text-primary: #e2e8f0;
        --text-secondary: #cbd5e0;
        --text-tertiary: #a0aec0;
        --text-quaternary: #718096;

        --border-primary: #4a5568;
        --border-secondary: #718096;

        --accent-primary: #7c3aed;
        --accent-primary-hover: #6d28d9;
        --accent-secondary: #10b981;
        --accent-secondary-hover: #059669;

        --header-gradient-start: #7c3aed;
        --header-gradient-end: #9333ea;

        --segment-bg: #2d3748;
        --segment-bg-hover: #4a5568;
        --segment-border: #60a5fa;
        --segment-text: #93c5fd;

        --field-path-color: #34d399;
        --field-value-color: #e2e8f0;
        --comp-path-color: #fb923c;
        --sub-path-color: #c084fc;

        --error-color: #f87171;
        --error-bg: #7f1d1d;
        --success-bg: #064e3b;
        --success-border: #10b981;
        --success-text: #6ee7b7;
        --warning-bg: #78350f;
        --warning-border: #fbbf24;
        --warning-text: #fde047;

        --footer-bg: #111827;
        --footer-link: #60a5fa;

        --scrollbar-track: #2d3748;
        --scrollbar-thumb: #4a5568;
        --scrollbar-thumb-hover: #718096;
    }
}

/* Dark theme - via data attribute (manual toggle) */
:root[data-theme="dark"] {
    --bg-primary: #1a202c;
    --bg-secondary: #2d3748;
    --bg-tertiary: #1a202c;
    --bg-quaternary: #2d3748;
    --bg-code: #1a202c;

    --text-primary: #e2e8f0;
    --text-secondary: #cbd5e0;
    --text-tertiary: #a0aec0;
    --text-quaternary: #718096;

    --border-primary: #4a5568;
    --border-secondary: #718096;

    --accent-primary: #7c3aed;
    --accent-primary-hover: #6d28d9;
    --accent-secondary: #10b981;
    --accent-secondary-hover: #059669;

    --header-gradient-start: #7c3aed;
    --header-gradient-end: #9333ea;

    --segment-bg: #2d3748;
    --segment-bg-hover: #4a5568;
    --segment-border: #60a5fa;
    --segment-text: #93c5fd;

    --field-path-color: #34d399;
    --field-value-color: #e2e8f0;
    --comp-path-color: #fb923c;
    --sub-path-color: #c084fc;

    --error-color: #f87171;
    --error-bg: #7f1d1d;
    --success-bg: #064e3b;
    --success-border: #10b981;
    --success-text: #6ee7b7;
    --warning-bg: #78350f;
    --warning-border: #fbbf24;
    --warning-text: #fde047;

    --footer-bg: #111827;
    --footer-link: #60a5fa;

    --scrollbar-track: #2d3748;
    --scrollbar-thumb: #4a5568;
    --scrollbar-thumb-hover: #718096;
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
}

/* Header */
.app-header {
    background: linear-gradient(135deg, var(--header-gradient-start) 0%, var(--header-gradient-end) 100%);
    color: white;
    padding: 30px 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
}

.header-content > div {
    text-align: center;
    flex: 1;
}

.app-header h1 {
    font-size: 2.2em;
    margin-bottom: 10px;
    font-weight: 600;
}

.subtitle {
    font-size: 1.1em;
    opacity: 0.95;
}

/* Theme Toggle Button */
.theme-toggle {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    padding: 0;
    flex-shrink: 0;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.theme-icon {
    font-size: 24px;
    display: block;
    transition: transform 0.3s ease;
}

.theme-toggle:active .theme-icon {
    transform: rotate(20deg);
}

/* Container */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* Sections */
section {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 25px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}

section h2 {
    color: var(--accent-primary);
    margin-bottom: 15px;
    font-size: 1.3em;
    font-weight: 600;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 5px;
}

.btn-primary {
    background: var(--accent-primary);
    color: white;
    font-size: 16px;
    padding: 12px 30px;
}

.btn-primary:hover {
    background: var(--accent-primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.btn-primary:disabled {
    background: var(--text-quaternary);
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: var(--accent-secondary);
    color: white;
}

.btn-secondary:hover {
    background: var(--accent-secondary-hover);
}

.btn-outline {
    background: var(--bg-secondary);
    color: var(--accent-primary);
    border: 2px solid var(--accent-primary);
}

.btn-outline:hover {
    background: var(--accent-primary);
    color: white;
}

.btn-small {
    padding: 6px 12px;
    font-size: 13px;
}

.button-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* Input Section */
textarea {
    width: 100%;
    min-height: 250px;
    padding: 15px;
    border: 2px solid var(--border-primary);
    border-radius: 6px;
    font-family: 'Courier New', Consolas, monospace;
    font-size: 13px;
    resize: vertical;
    transition: border-color 0.3s ease;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.input-info {
    margin: 10px 0;
    color: var(--text-tertiary);
    font-size: 14px;
}

/* Message Info */
.message-info-content {
    padding: 15px;
    background: var(--bg-quaternary);
    border-radius: 6px;
    border-left: 4px solid var(--accent-primary);
    font-size: 14px;
}

.message-info-content strong {
    color: var(--accent-primary);
}

/* Output Section */
.output-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 10px;
}

.toolbar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.search-bar {
    margin-bottom: 15px;
}

.search-input {
    width: 100%;
    padding: 10px 15px;
    border: 2px solid var(--border-primary);
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.3s ease;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.search-input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.search-input:disabled {
    background: var(--bg-quaternary);
    cursor: not-allowed;
}

/* Tree Output */
.tree-output {
    background: var(--bg-code);
    border: 2px solid var(--border-primary);
    border-radius: 6px;
    padding: 20px;
    min-height: 300px;
    max-height: 600px;
    overflow-y: auto;
    font-family: 'Courier New', Consolas, monospace;
    font-size: 13px;
    color: var(--text-primary);
}

/* Messages */
.info-message {
    color: var(--text-secondary);
    text-align: center;
    padding: 40px;
    font-size: 14px;
}

.error-message {
    color: var(--error-color);
    background: var(--error-bg);
    padding: 15px;
    border-radius: 6px;
    border-left: 4px solid var(--error-color);
}

.loading-message {
    color: var(--text-secondary);
    text-align: center;
    padding: 40px;
    font-size: 14px;
}

.empty-message {
    color: var(--text-quaternary);
    text-align: center;
    padding: 40px;
    font-style: italic;
}

/* Tree Structure */
.tree-segment {
    margin: 12px 0;
}

.tree-segment-header {
    background: var(--segment-bg);
    border-left: 4px solid var(--segment-border);
    padding: 10px 12px;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.tree-segment-header:hover {
    background: var(--segment-bg-hover);
}

.segment-id {
    color: var(--segment-text);
    font-weight: bold;
    margin-left: 5px;
    font-size: 14px;
}

.definition {
    color: var(--text-secondary);
    margin-left: 8px;
    font-weight: normal;
    font-style: italic;
}

.tree-segment-content {
    padding-left: 10px;
    margin-top: 5px;
}

/* Field Styling */
.tree-field {
    margin: 3px 0;
}

.tree-field-line {
    padding: 4px 0 4px 10px;
    transition: background 0.2s ease;
}

.tree-field-line:hover {
    background: var(--bg-quaternary);
}

.field-path {
    color: var(--field-path-color);
    font-weight: bold;
    margin-right: 5px;
}

.field-value {
    color: var(--field-value-color);
    margin-right: 8px;
}

.field-definition {
    color: var(--text-tertiary);
    font-style: italic;
}

/* Component Styling */
.tree-components {
    padding-left: 20px;
}

.tree-component {
    padding: 2px 0;
}

.comp-path {
    color: var(--comp-path-color);
    font-weight: bold;
    margin-right: 5px;
}

.comp-value {
    color: var(--field-value-color);
    margin-right: 8px;
}

.comp-definition {
    color: var(--text-quaternary);
    font-style: italic;
}

/* Subcomponent Styling */
.tree-subcomponents {
    padding-left: 15px;
}

.tree-subcomponent {
    padding: 2px 0;
}

.sub-path {
    color: var(--sub-path-color);
    font-weight: bold;
    margin-right: 5px;
}

.sub-value {
    color: var(--field-value-color);
    margin-right: 8px;
}

.sub-definition {
    color: var(--border-secondary);
    font-style: italic;
}

/* Toggle Icons */
.toggle {
    display: inline-block;
    width: 18px;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    font-weight: bold;
}

.toggle-spacer {
    display: inline-block;
    width: 18px;
}

/* Tree Indentation */
.tree-indent {
    color: var(--border-secondary);
    margin-right: 5px;
    user-select: none;
}

/* Footer */
.app-footer {
    background: var(--footer-bg);
    color: white;
    text-align: center;
    padding: 20px;
    margin-top: 40px;
}

.app-footer a {
    color: var(--footer-link);
    text-decoration: none;
}

.app-footer a:hover {
    text-decoration: underline;
}

/* Scrollbar Styling */
.tree-output::-webkit-scrollbar {
    width: 10px;
}

.tree-output::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
    border-radius: 5px;
}

.tree-output::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 5px;
}

.tree-output::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

/* Responsive Design */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 15px;
    }

    .theme-toggle {
        width: 45px;
        height: 45px;
    }

    .theme-icon {
        font-size: 20px;
    }

    .app-header h1 {
        font-size: 1.6em;
    }

    .subtitle {
        font-size: 0.95em;
    }

    .container {
        padding: 10px;
    }

    section {
        padding: 15px;
    }

    .output-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .toolbar {
        width: 100%;
    }

    .btn-small {
        flex: 1;
        min-width: 100px;
    }

    textarea {
        min-height: 200px;
        font-size: 12px;
    }

    .tree-output {
        font-size: 12px;
        max-height: 400px;
    }
}

/* Validation Section */
.validation-section {
    margin-top: 20px;
}

.validation-results {
    padding: 15px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    border: 1px solid var(--border-primary);
}

.validation-success {
    padding: 15px;
    background: var(--success-bg);
    border: 1px solid var(--success-border);
    border-radius: 4px;
    color: var(--success-text);
    font-weight: 600;
    margin-bottom: 15px;
}

.validation-invalid {
    padding: 15px;
    background: var(--warning-bg);
    border: 1px solid var(--warning-border);
    border-radius: 4px;
    color: var(--warning-text);
    font-weight: 600;
    margin-bottom: 15px;
}

.validation-errors {
    margin-bottom: 20px;
}

.validation-errors h3 {
    color: var(--error-color);
    margin-bottom: 10px;
    font-size: 1.1em;
}

.validation-warnings h3 {
    color: var(--warning-border);
    margin-bottom: 10px;
    font-size: 1.1em;
}

.validation-errors ul,
.validation-warnings ul {
    list-style: none;
    padding: 0;
}

.validation-error,
.validation-warning {
    padding: 10px;
    margin-bottom: 8px;
    border-radius: 4px;
    background: var(--bg-secondary);
}

.validation-error {
    border-left: 4px solid var(--error-color);
}

.validation-warning {
    border-left: 4px solid var(--warning-border);
}

.validation-location {
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    color: var(--text-tertiary);
    font-style: italic;
}

/* Print Styles */
@media print {
    .app-header,
    .sample-section,
    .input-section,
    .output-header .toolbar,
    .search-bar,
    .app-footer {
        display: none;
    }

    .tree-output {
        max-height: none;
        border: none;
    }
}
