/* CSS Variables */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --success-color: #22c55e;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    --background-color: #0f172a;
    --surface-color: #1e293b;
    --surface-hover: #334155;
    --border-color: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --font-mono: 'SF Mono', 'Fira Code', 'Monaco', 'Consolas', monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.3);
    --transition: 150ms ease;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--surface-color) 0%, var(--background-color) 100%);
    border-bottom: 1px solid var(--border-color);
    padding: 1.5rem 1rem;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    text-align: center;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.logo-icon {
    width: 32px;
    height: 32px;
    color: var(--primary-color);
}

.logo h1 {
    font-size: 1.75rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color) 0%, #a855f7 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Main Content */
.main-content {
    flex: 1;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Toolbar */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: space-between;
}

.toolbar-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    font-family: var(--font-sans);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn svg {
    width: 16px;
    height: 16px;
}

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

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background-color: var(--surface-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: var(--surface-hover);
    border-color: var(--text-muted);
}

.btn-small {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 500;
    font-family: var(--font-sans);
    background-color: var(--surface-color);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.btn-small:hover {
    background-color: var(--surface-hover);
    color: var(--text-primary);
}

/* View Toggle */
.view-toggle {
    display: flex;
    gap: 0.25rem;
    background-color: var(--surface-color);
    padding: 0.25rem;
    border-radius: var(--radius-md);
    width: fit-content;
}

.view-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    font-family: var(--font-sans);
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.view-btn svg {
    width: 16px;
    height: 16px;
}

.view-btn:hover {
    color: var(--text-primary);
}

.view-btn.active {
    background-color: var(--primary-color);
    color: white;
}

/* Notification */
.notification {
    padding: 0.875rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    animation: slideIn 0.3s ease;
}

.notification.hidden {
    display: none;
}

.notification.success {
    background-color: rgba(34, 197, 94, 0.15);
    color: var(--success-color);
    border: 1px solid rgba(34, 197, 94, 0.3);
}

.notification.error {
    background-color: rgba(239, 68, 68, 0.15);
    color: var(--error-color);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.notification.info {
    background-color: rgba(99, 102, 241, 0.15);
    color: var(--primary-color);
    border: 1px solid rgba(99, 102, 241, 0.3);
}

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

/* Editor Container */
.editor-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    flex: 1;
    min-height: 400px;
}

/* Panels */
.panel {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.875rem 1rem;
    background-color: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid var(--border-color);
}

.panel-header h2 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.char-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.tree-controls {
    display: flex;
    gap: 0.5rem;
}

/* Textarea */
.xml-textarea {
    flex: 1;
    width: 100%;
    padding: 1rem;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.6;
    background-color: transparent;
    color: var(--text-primary);
    border: none;
    resize: none;
    outline: none;
}

.xml-textarea::placeholder {
    color: var(--text-muted);
}

/* Output */
.output-wrapper,
.tree-wrapper {
    flex: 1;
    overflow: auto;
    padding: 1rem;
}

.xml-output {
    margin: 0;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.xml-output code {
    font-family: inherit;
}

/* Syntax Highlighting */
.xml-tag {
    color: #f472b6;
}

.xml-attr-name {
    color: #a78bfa;
}

.xml-attr-value {
    color: #fbbf24;
}

.xml-text {
    color: var(--text-primary);
}

.xml-comment {
    color: var(--text-muted);
    font-style: italic;
}

.xml-declaration {
    color: #60a5fa;
}

.xml-cdata {
    color: #34d399;
}

/* Tree View */
.xml-tree {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.8;
}

.tree-node {
    margin-left: 1.25rem;
    position: relative;
}

.tree-node::before {
    content: '';
    position: absolute;
    left: -0.75rem;
    top: 0;
    bottom: 0;
    width: 1px;
    background-color: var(--border-color);
}

.tree-node:last-child::before {
    bottom: 50%;
}

.tree-item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.125rem 0;
    position: relative;
}

.tree-item::before {
    content: '';
    position: absolute;
    left: -0.75rem;
    top: 50%;
    width: 0.5rem;
    height: 1px;
    background-color: var(--border-color);
}

.tree-toggle {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    background: none;
    border: none;
    padding: 0;
    font-size: 0.75rem;
    transition: transform var(--transition);
    flex-shrink: 0;
}

.tree-toggle:hover {
    color: var(--text-primary);
}

.tree-toggle.collapsed {
    transform: rotate(-90deg);
}

.tree-toggle.empty {
    visibility: hidden;
}

.tree-label {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.tree-tag {
    color: #f472b6;
    font-weight: 500;
}

.tree-attr {
    color: #a78bfa;
}

.tree-attr-value {
    color: #fbbf24;
}

.tree-text {
    color: var(--text-secondary);
    font-style: italic;
}

.tree-children {
    overflow: hidden;
    transition: max-height 0.2s ease;
}

.tree-children.collapsed {
    max-height: 0 !important;
}

.tree-root {
    margin-left: 0;
}

.tree-root::before {
    display: none;
}

.tree-root > .tree-item::before {
    display: none;
}

/* Hidden utility */
.hidden {
    display: none !important;
}

/* Footer */
.footer {
    background-color: var(--surface-color);
    border-top: 1px solid var(--border-color);
    padding: 1.25rem 1rem;
    text-align: center;
}

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

.footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: color var(--transition);
}

.footer a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--background-color);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

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

/* Responsive Design */
@media (max-width: 900px) {
    .editor-container {
        grid-template-columns: 1fr;
    }

    .input-panel,
    .output-panel {
        min-height: 300px;
    }
}

@media (max-width: 600px) {
    .header {
        padding: 1rem;
    }

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

    .tagline {
        font-size: 0.85rem;
    }

    .toolbar {
        flex-direction: column;
    }

    .toolbar-group {
        justify-content: center;
    }

    .btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }

    .btn svg {
        width: 14px;
        height: 14px;
    }

    .view-toggle {
        width: 100%;
        justify-content: center;
    }

    .view-btn {
        flex: 1;
        justify-content: center;
    }

    .panel-header {
        flex-direction: column;
        gap: 0.5rem;
        align-items: flex-start;
    }

    .tree-controls {
        width: 100%;
    }

    .tree-controls .btn-small {
        flex: 1;
    }

    .input-panel,
    .output-panel {
        min-height: 250px;
    }
}

/* Focus States */
.btn:focus-visible,
.view-btn:focus-visible,
.btn-small:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.xml-textarea:focus {
    box-shadow: inset 0 0 0 2px var(--primary-color);
}

/* Selection */
::selection {
    background-color: rgba(99, 102, 241, 0.3);
    color: var(--text-primary);
}
