:root {
    /* Base Colors - Dark Theme */
    --bg-app: #0f172a; /* Slate 900 */
    --bg-card: rgba(30, 41, 59, 0.6); /* Slate 800 with opacity */
    --bg-input: #1e293b;
    --bg-hover: #334155;
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    
    --border-color: rgba(255, 255, 255, 0.1);
    --border-focus: #3b82f6;
    
    --accent-1: #3b82f6; /* Blue 500 */
    --accent-2: #8b5cf6; /* Violet 500 */
    
    --success: #10b981;
    --error: #ef4444;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
    
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    
    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: 'Roboto Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

[data-theme="light"] {
    --bg-app: #f8fafc;
    --bg-card: rgba(255, 255, 255, 0.8);
    --bg-input: #ffffff;
    --bg-hover: #f1f5f9;
    
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    
    --border-color: rgba(0, 0, 0, 0.1);
    --border-focus: #2563eb;
    
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-app);
    background-image: 
        radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(139, 92, 246, 0.15) 0px, transparent 50%);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    transition: background-color 0.3s, color 0.3s;
    overflow-x: hidden;
}

/* Typography Classes */
.font-mono { font-family: var(--font-mono); }
.text-success { color: var(--success); }
.text-error { color: var(--error); }

/* Layout */
.app-layout {
    width: 100%;
    max-width: 1100px;
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Navbar */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.brand {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.app-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4);
}
.app-icon i { width: 24px; height: 24px; }

.brand h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(to right, var(--text-primary), var(--text-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.nav-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Buttons */
button {
    cursor: pointer;
    font-family: inherit;
    border: none;
    background: transparent;
    color: inherit;
    transition: all 0.2s ease;
}

.icon-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    border: 1px solid transparent;
}
.icon-btn:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.9rem;
}
.btn i { width: 16px; height: 16px; }
.btn-sm { padding: 0.5rem 0.875rem; font-size: 0.85rem; }

.btn-primary {
    background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
    color: white;
    box-shadow: 0 2px 10px rgba(59, 130, 246, 0.3);
}
.btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4);
}
.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: var(--bg-hover);
    color: var(--text-secondary);
    box-shadow: none;
}

.btn-outline {
    border: 1px solid var(--border-color);
    background: var(--bg-card);
}
.btn-outline:hover:not(:disabled) {
    background: var(--bg-hover);
    borderColor: var(--text-secondary);
}
.btn-outline:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-text {
    color: var(--accent-1);
    font-weight: 500;
}
.btn-text:hover {
    color: var(--accent-2);
}

/* Main Container */
.main-container {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Grid */
.input-grid {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 1.5rem;
    align-items: center;
}

@media (max-width: 860px) {
    .input-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    .swap-action {
        transform: rotate(90deg);
        justify-self: center;
    }
}

/* Cards & Glassmorphism */
.glass-card {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.input-card {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    position: relative;
    overflow: hidden;
}

.input-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; height: 2px;
    background: linear-gradient(to right, transparent, var(--accent-1), transparent);
    opacity: 0;
    transition: opacity 0.3s;
}
.input-card:focus-within::before {
    opacity: 1;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.card-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-primary);
}
.badge-letter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: var(--bg-hover);
    color: var(--accent-1);
    font-size: 0.85rem;
    font-weight: 700;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.input-group label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}
.input-wrapper input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.875rem 1rem;
    padding-right: 2.5rem;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-family: var(--font-mono);
    transition: all 0.2s;
    outline: none;
}
.input-wrapper input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.input-clear {
    position: absolute;
    right: 0.5rem;
    color: var(--text-secondary);
    padding: 0.25rem;
    display: none; /* managed by js */
}
.input-clear:hover {
    color: var(--text-primary);
}
.input-clear i { width: 18px; height: 18px; }

.helper-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.parsed-result {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-radius: var(--radius-md);
    background: var(--bg-hover);
    font-size: 0.85rem;
    color: var(--text-primary);
}
.parsed-result i { width: 16px; height: 16px; color: var(--accent-1); flex-shrink: 0; }
.parsed-text { word-break: break-all; }

/* Swap Button */
.swap-action {
    display: flex;
    align-items: center;
    justify-content: center;
}
.swap-btn {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-full);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

/* Results */
.results-card {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
}
.results-header h2 {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    color: var(--text-primary);
}
.results-header h2 i { color: var(--accent-2); }
.calc-formula {
    font-family: var(--font-mono);
    color: var(--text-secondary);
    font-size: 1rem;
    margin-left: 0.5rem;
    opacity: 0.5;
}

.results-actions {
    display: flex;
    gap: 0.5rem;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    text-align: center;
    color: var(--text-secondary);
    gap: 1rem;
}
.empty-state i {
    width: 48px; height: 48px;
    opacity: 0.2;
}

/* Highlighted Diffs (Top of results) */
.highlight-diff {
    display: flex;
    gap: 1rem;
    background: var(--bg-hover);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    flex-wrap: wrap;
}

.primary-diff {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.primary-diff.relative-diff {
    border-left: 1px solid var(--border-color);
    padding-left: 1rem;
}
@media (max-width: 600px) {
    .highlight-diff { flex-direction: column; }
    .primary-diff.relative-diff { border-left: none; border-top: 1px solid var(--border-color); padding-left: 0; padding-top: 1rem; }
}

.diff-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-text);
    background: linear-gradient(to right, var(--accent-1), var(--accent-2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    word-break: break-word;
}
.diff-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Metrics Grid */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.metric-item {
    background: var(--bg-hover);
    padding: 1rem;
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    border: 1px solid transparent;
    transition: border-color 0.2s;
}
.metric-item:hover {
    border-color: var(--border-color);
}

.metric-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.metric-value {
    font-size: 1.25rem;
    color: var(--text-primary);
    word-break: break-all;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.2s;
}
.modal-overlay.show {
    display: flex;
    animation: fadeIn 0.2s forwards;
}

.modal {
    width: 100%;
    max-width: 450px;
    padding: 1.5rem;
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}
.modal-header h2 { font-size: 1.25rem; font-weight: 600; }
.modal-close { margin-right: -0.5rem; margin-top: -0.5rem; }

.shortcuts-list { list-style: none; display: flex; flex-direction: column; gap: 1rem; }
.shortcuts-list li { display: flex; justify-content: space-between; align-items: center; font-size: 0.95rem; color: var(--text-secondary); }
.shortcuts-list li span { flex: 1; }
.helper { font-size: 0.75rem; opacity: 0.6; display: block; }
kbd {
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.2rem 0.4rem;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--text-primary);
    box-shadow: 0 1px 1px rgba(0,0,0,0.1);
}

/* History Dropdown */
.history-dropdown {
    position: relative;
}
.badge {
    position: absolute;
    top: 2px; right: 2px;
    background: var(--error);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    width: 16px; height: 16px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
}
.dropdown-menu {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: 320px;
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 100;
    display: none;
    flex-direction: column;
    overflow: hidden;
}
.dropdown-menu.show { display: flex; }

.menu-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.menu-header h3 { font-size: 0.95rem; font-weight: 600; }
.history-list {
    list-style: none;
    max-height: 300px;
    overflow-y: auto;
}
.history-item {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.2s;
}
.history-item:hover { background: var(--bg-hover); }
.history-item:last-child { border-bottom: none; }
.hi-meta { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--text-secondary); margin-bottom: 0.25rem; }
.hi-diff { font-weight: 600; color: var(--text-primary); font-size: 0.9rem; }
.empty-msg { padding: 1.5rem 1rem; text-align: center; color: var(--text-secondary); font-size: 0.85rem; }

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-primary);
    color: var(--bg-app);
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-full);
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 0.9rem;
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Animations */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { 
    from { opacity: 0; transform: translateY(20px); } 
    to { opacity: 1; transform: translateY(0); } 
}
