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

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --error: #dc2626;
    --warning: #eab308;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-light: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
        'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 3rem;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-light);
    font-size: 1.1rem;
}

/* Main Content */
main {
    display: grid;
    gap: 2rem;
    grid-template-columns: 1fr;
}

@media (min-width: 768px) {
    main {
        grid-template-columns: 1fr 1fr;
    }
}

section {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: var(--shadow);
}

section h2 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    color: var(--text);
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--border);
}

.tab-button {
    background: none;
    border: none;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    color: var(--text-light);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}

.tab-button:hover {
    color: var(--primary);
}

.tab-button.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Input Fields */
textarea {
    width: 100%;
    padding: 1rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    resize: vertical;
    transition: border-color 0.2s;
}

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

/* File Upload */
.file-upload {
    position: relative;
}

#file-input {
    display: none;
}

.file-label {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 2rem;
    border: 2px dashed var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    justify-content: center;
}

.file-label:hover {
    border-color: var(--primary);
    background: var(--bg);
}

.file-icon {
    font-size: 2rem;
}

/* Options */
.options {
    display: grid;
    gap: 1rem;
    margin: 1.5rem 0;
}

.option-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.option-group label {
    font-weight: 500;
    color: var(--text);
}

.option-group select {
    padding: 0.75rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.2s;
}

.option-group select:focus {
    outline: none;
    border-color: var(--primary);
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* Buttons */
.convert-btn {
    width: 100%;
    padding: 1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.convert-btn:hover {
    background: var(--primary-dark);
}

.convert-btn:disabled {
    background: var(--text-light);
    cursor: not-allowed;
}

/* Output */
.validation-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-weight: 500;
}

.validation-status.valid {
    background: #dcfce7;
    color: var(--success);
}

.validation-status.invalid {
    background: #fee2e2;
    color: var(--error);
}

.status-icon::before {
    font-size: 1.2rem;
}

.validation-status.valid .status-icon::before {
    content: '✓';
}

.validation-status.invalid .status-icon::before {
    content: '✗';
}

.error-box {
    padding: 1rem;
    background: #fee2e2;
    border: 2px solid var(--error);
    border-radius: 8px;
    color: var(--error);
    margin-bottom: 1rem;
}

.output-container {
    background: #1e293b;
    border-radius: 8px;
    overflow: hidden;
}

.json-output {
    padding: 1.5rem;
    margin: 0;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.875rem;
    line-height: 1.6;
    color: #e2e8f0;
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.action-buttons {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
}

.action-btn {
    flex: 1;
    padding: 0.75rem;
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.action-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* Footer */
footer {
    text-align: center;
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
    color: var(--text-light);
}

footer a {
    color: var(--primary);
    text-decoration: none;
}

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

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loader {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    animation: spin 1s linear infinite;
}

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

.loading-overlay p {
    color: white;
    margin-top: 1rem;
    font-size: 1.2rem;
}

/* Grounding Visualization */
.grounding-section {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 2rem;
    margin-top: 2rem;
    box-shadow: var(--shadow-lg);
    border: 2px solid var(--primary);
}

.grounding-header {
    text-align: center;
    margin-bottom: 2rem;
}

.grounding-header h2 {
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.grounding-subtitle {
    color: var(--text-light);
    font-size: 0.95rem;
}

.grounding-container {
    display: grid;
    gap: 2rem;
    grid-template-columns: 1fr 1fr;
    margin-bottom: 2rem;
}

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

.grounding-panel {
    background: var(--bg);
    border-radius: 8px;
    padding: 1.5rem;
    border: 2px solid var(--border);
}

.grounding-panel h3 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    color: var(--text);
    border-bottom: 2px solid var(--border);
    padding-bottom: 0.5rem;
}

.grounded-text,
.grounded-json {
    line-height: 1.8;
    font-size: 0.95rem;
    max-height: 500px;
    overflow-y: auto;
}

.grounded-json pre {
    margin: 0;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9rem;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Grounded spans - color coding by field */
.grounded-span,
.grounded-field {
    padding: 2px 4px;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.grounded-span {
    border-bottom: 2px solid transparent;
}

.grounded-field {
    font-weight: 600;
}

/* Field colors */
.field-eventTime {
    background-color: rgba(59, 130, 246, 0.15);
    border-color: rgb(59, 130, 246);
}

.field-epcList {
    background-color: rgba(16, 185, 129, 0.15);
    border-color: rgb(16, 185, 129);
}

.field-quantityList {
    background-color: rgba(245, 158, 11, 0.15);
    border-color: rgb(245, 158, 11);
}

.field-action {
    background-color: rgba(139, 92, 246, 0.15);
    border-color: rgb(139, 92, 246);
}

.field-bizLocation {
    background-color: rgba(236, 72, 153, 0.15);
    border-color: rgb(236, 72, 153);
}

.field-bizStep {
    background-color: rgba(20, 184, 166, 0.15);
    border-color: rgb(20, 184, 166);
}

.field-disposition {
    background-color: rgba(251, 146, 60, 0.15);
    border-color: rgb(251, 146, 60);
}

.field-readPoint {
    background-color: rgba(244, 63, 94, 0.15);
    border-color: rgb(244, 63, 94);
}

/* Active/hover state */
.grounded-span:hover,
.grounded-field:hover,
.grounded-span.active,
.grounded-field.active {
    background-color: rgba(255, 215, 0, 0.3);
    border-bottom-color: rgb(255, 193, 7);
    box-shadow: 0 2px 8px rgba(255, 193, 7, 0.4);
    transform: translateY(-1px);
    z-index: 10;
}

/* Legend */
.grounding-legend {
    background: var(--bg);
    border-radius: 8px;
    padding: 1rem;
    border: 1px solid var(--border);
}

.grounding-legend h4 {
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
    color: var(--text);
}

.legend-items {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-light);
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    border: 2px solid;
    display: inline-block;
}

/* Apply same colors as field classes */
.legend-color.field-eventTime {
    background-color: rgba(59, 130, 246, 0.15);
    border-color: rgb(59, 130, 246);
}

.legend-color.field-epcList {
    background-color: rgba(16, 185, 129, 0.15);
    border-color: rgb(16, 185, 129);
}

.legend-color.field-quantityList {
    background-color: rgba(245, 158, 11, 0.15);
    border-color: rgb(245, 158, 11);
}

.legend-color.field-action {
    background-color: rgba(139, 92, 246, 0.15);
    border-color: rgb(139, 92, 246);
}

.legend-color.field-bizLocation {
    background-color: rgba(236, 72, 153, 0.15);
    border-color: rgb(236, 72, 153);
}

.legend-color.field-bizStep {
    background-color: rgba(20, 184, 166, 0.15);
    border-color: rgb(20, 184, 166);
}

.legend-color.field-disposition {
    background-color: rgba(251, 146, 60, 0.15);
    border-color: rgb(251, 146, 60);
}

.legend-color.field-readPoint {
    background-color: rgba(244, 63, 94, 0.15);
    border-color: rgb(244, 63, 94);
}

/* Mobile Responsive */
@media (max-width: 767px) {
    .container {
        padding: 1rem;
    }
    
    header h1 {
        font-size: 1.75rem;
    }
    
    section {
        padding: 1.5rem;
    }
    
    .action-buttons {
        flex-direction: column;
    }
    
    .grounding-section {
        padding: 1rem;
    }
    
    .legend-items {
        flex-direction: column;
        gap: 0.5rem;
    }
}
