/* CSS Variables for Theme Management */
:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-card: #1e293b;
    --bg-input: #334155;
    --bg-button: #3b82f6;
    --bg-button-hover: #2563eb;
    --bg-button-secondary: #6366f1;

    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --text-accent: #60a5fa;

    --border-color: #475569;
    --border-focus: #3b82f6;
    --border-error: #ef4444;
    --border-success: #10b981;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;

    --transition: all 0.2s ease-in-out;
}

/* Light theme override (auto-detected) */
@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
        --bg-primary: #ffffff;
        --bg-secondary: #f8fafc;
        --bg-tertiary: #e2e8f0;
        --bg-card: #ffffff;
        --bg-input: #ffffff;
        --bg-button: #3b82f6;
        --bg-button-hover: #2563eb;
        --bg-button-secondary: #6366f1;

        --text-primary: #1e293b;
        --text-secondary: #475569;
        --text-muted: #64748b;
        --text-accent: #2563eb;

        --border-color: #cbd5e1;
        --border-focus: #3b82f6;
        --border-error: #ef4444;
        --border-success: #10b981;

        --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
        --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
        --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    }
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: var(--transition);
}

/* Header */
.header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 1.5rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.header h1 {
    font-size: 1.875rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--text-accent), #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Language Selector */
.language-selector {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.language-flag {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: var(--radius-md);
    background: var(--bg-tertiary);
    border: 2px solid transparent;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    text-decoration: none;
    position: relative;
    overflow: hidden;
}

.language-flag:hover {
    border-color: var(--border-focus);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.language-flag.active {
    border-color: var(--border-focus);
    background: rgba(59, 130, 246, 0.1);
}

.language-flag::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transition: left 0.5s;
}

.language-flag:hover::before {
    left: 100%;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Info Card */
.info-card {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(139, 92, 246, 0.1));
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    backdrop-filter: blur(10px);
}

.info-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.info-content h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-accent);
}

.info-content p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Sections */
.section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 2rem;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--bg-button), var(--bg-button-secondary));
    opacity: 0;
    transition: var(--transition);
}

.section:hover::before {
    opacity: 1;
}

.section:hover {
    border-color: var(--border-focus);
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.section-header {
    margin-bottom: 1.5rem;
}

.section-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-description {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Input Groups */
.input-group {
    margin-bottom: 1.5rem;
}

.input-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.input-row-inline {
    display: flex;
    align-items: start;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.input-group-inline {
    flex: 1;
    min-width: 200px;
}

.input-group-inline label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.875rem;
}

input, textarea, select {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: var(--transition);
    font-family: inherit;
    resize: vertical;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    background: var(--bg-card);
}

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

textarea {
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 0.8rem;
    line-height: 1.4;
}

/* Buttons */
.btn-primary {
    background: linear-gradient(135deg, var(--bg-button), var(--bg-button-secondary));
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-inline {
    background: linear-gradient(135deg, var(--bg-button), var(--bg-button-secondary));
    color: white;
    border: none;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
    flex-shrink: 0;
    height: fit-content;
    margin-top: 1.875rem; /* Offset for label height (0.875rem font + 0.5rem margin + 0.5rem extra) */
}

.btn-primary:hover, .btn-inline:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-primary:active, .btn-inline:active {
    transform: translateY(0);
}

.btn-primary::before, .btn-inline::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.btn-primary:hover::before, .btn-inline:hover::before {
    left: 100%;
}

/* Tab System */
.tab-container {
    margin-top: 1rem;
}

.tab-buttons {
    display: flex;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 0.25rem;
    margin-bottom: 1.5rem;
}

.tab-button {
    flex: 1;
    padding: 0.75rem 1rem;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.875rem;
    cursor: pointer;
    transition: var(--transition);
}

.tab-button.active {
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.tab-button:hover:not(.active) {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease-in-out;
}

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

/* Result Containers */
.result-container {
    margin-top: 1.5rem;
    min-height: 2rem;
}

.result {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    margin-bottom: 1rem;
    animation: slideIn 0.3s ease-out;
}

.result.success {
    border-color: var(--border-success);
    background: rgba(16, 185, 129, 0.1);
}

.result.error {
    border-color: var(--border-error);
    background: rgba(239, 68, 68, 0.1);
    color: #fca5a5;
}

.result.warning {
    border-color: #f59e0b;
    background: rgba(245, 158, 11, 0.1);
    color: #fbbf24;
}

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

.result h4 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.result-data {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    margin: 0.5rem 0;
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 0.8rem;
    line-height: 1.4;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.result-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.5rem 1rem;
    margin: 0.75rem 0;
    font-size: 0.875rem;
}

.result-label {
    font-weight: 600;
    color: var(--text-accent);
}

.result-value {
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    color: var(--text-secondary);
}

.copy-button {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    cursor: pointer;
    transition: var(--transition);
    margin-left: 0.5rem;
}

.copy-button:hover {
    background: var(--bg-button);
    color: white;
    border-color: var(--bg-button);
}

/* Footer */
footer {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 2rem;
    text-align: center;
    color: var(--text-muted);
    margin-top: 4rem;
}

footer p {
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

/* Modal window */
/* Modal window */
.modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 9999;
    transition: var(--transition);
    padding: 1rem;
}

.modal.open {
    display: flex;
}

.modal-box {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    padding: 1.5rem 2rem;
    width: min(90vw, 600px);
    max-height: 80vh;
    overflow: auto;
    position: relative;
    animation: fadeIn 0.25s ease-out;
}

.modal-box h3 {
    margin-bottom: 1rem;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-accent);
}

.modal-box .close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: transparent;
    border: none;
    font-size: 1.25rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
    padding: 0.25rem;
    border-radius: var(--radius-sm);
}

.modal-box .close:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.hist-row {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    margin-bottom: 0.75rem;
    transition: var(--transition);
}

.hist-row:hover {
    border-color: var(--border-focus);
    box-shadow: var(--shadow-sm);
}

.hist-date {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 0.025em;
    margin-bottom: 0.25rem;
}

.hist-fields {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.hist-field {
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 0.875rem;
    color: var(--text-secondary);
    word-break: break-all;
    line-height: 1.4;
}

.hist-field strong {
    color: var(--text-accent);
    font-weight: 600;
}

.hist-value {
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 0.875rem;
    color: var(--text-secondary);
    word-break: break-all;
    line-height: 1.4;
    background: var(--bg-input);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.hist-row button {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--bg-button), var(--bg-button-secondary));
    color: white;
    border: none;
    border-radius: var(--radius-md);
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    min-width: 80px;
}

.hist-row button:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.history-content {
    max-height: 60vh;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.history-content::-webkit-scrollbar {
    width: 6px;
}

.history-content::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 3px;
}

.history-content::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.history-content::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.history-btn {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 0.75rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    margin-top: 1.875rem;
    width: 3rem;
    flex-shrink: 0;
    font-size: 1rem;
}

.history-btn:hover {
    background: var(--bg-button);
    color: white;
    border-color: var(--bg-button);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* Mobile styles for modal */
@media (max-width: 768px) {
    .modal {
        padding: 0.5rem;
        align-items: flex-end;
    }

    .modal-box {
        padding: 1rem 1.25rem;
        width: 100%;
        max-height: 90vh;
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
        animation: slideUp 0.3s ease-out;
    }

    .hist-fields {
        gap: 0.75rem;
    }

    .hist-field,
    .hist-value {
        font-size: 0.8rem;
    }

    .hist-row button {
        align-self: stretch;
        text-align: center;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(100%);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}


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

    .header h1 {
        font-size: 1.5rem;
    }

    .container {
        padding: 1rem;
        gap: 1.5rem;
    }

    .section {
        padding: 1.5rem;
    }

    .input-row {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .input-row-inline {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .input-group-inline {
        min-width: unset;
    }

    .btn-inline {
        width: 100%;
        justify-content: center;
        margin-top: 0;
    }

    .tab-buttons {
        flex-direction: column;
    }

    .language-selector {
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0.75rem;
    }

    .section {
        padding: 1rem;
    }

    .info-card {
        padding: 1rem;
    }

    .header h1 {
        font-size: 1.25rem;
    }
}

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

/* High contrast mode */
@media (prefers-contrast: high) {
    :root {
        --border-color: #ffffff;
        --text-secondary: #ffffff;
    }
}

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

/* Loading animation for async operations */
.loading {
    position: relative;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 1rem;
    height: 1rem;
    margin: -0.5rem;
    border: 2px solid transparent;
    border-top: 2px solid var(--text-accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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