:root {
    --bg-dark: #0f172a;
    --bg-card: #1e293b;
    --bg-sidebar: #020617;
    --primary: #3b82f6;
    --primary-glow: rgba(59, 130, 246, 0.5);
    --secondary: #10b981;
    --accent: #8b5cf6;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: #334155;
    --glass: rgba(30, 41, 59, 0.7);
    --font-main: 'Outfit', sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-main);
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    /* Using min-height to support mobile scrolling better */
    min-height: 100vh;
    /* overflow: hidden removed to allow container to manage it, or natural scroll */
    background-image:
        radial-gradient(circle at 10% 20%, rgba(59, 130, 246, 0.15) 0%, transparent 20%),
        radial-gradient(circle at 90% 80%, rgba(139, 92, 246, 0.15) 0%, transparent 20%);
}

.app-container {
    display: flex;
    height: 100dvh;
    /* Keeps it full screen on desktop */
    width: 100%;
    overflow: hidden;
    /* Prevents double scrolls */
}

/* Mobile adjustment handled in media query */

/* Sidebar */
.sidebar {
    width: 280px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    backdrop-filter: blur(10px);
}

.logo {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.logo i {
    color: var(--primary);
    filter: drop-shadow(0 0 8px var(--primary-glow));
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1rem;
    cursor: pointer;
    border-radius: 12px;
    transition: all 0.3s ease;
    text-align: left;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.nav-item.active {
    background: linear-gradient(90deg, rgba(59, 130, 246, 0.1) 0%, transparent 100%);
    color: var(--primary);
    border-left: 3px solid var(--primary);
}

.nav-item i {
    width: 24px;
    text-align: center;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

h1 {
    font-size: 2rem;
    font-weight: 600;
    background: linear-gradient(to right, #fff, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Calculator Grid */
.calculator-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 2rem;
    padding-bottom: 2rem;
}

/* Calculator Card */
.calc-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    position: relative;
    overflow: hidden;
}

.calc-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    border-color: var(--primary);
}

.calc-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    opacity: 0;
    transition: opacity 0.3s ease;
}

.calc-card:hover::before {
    opacity: 1;
}

.card-header {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.card-icon {
    width: 48px;
    height: 48px;
    background: rgba(59, 130, 246, 0.1);
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--primary);
    font-size: 1.25rem;
}

.card-title h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.card-title p {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.input-group label {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 500;
}

.input-wrapper {
    position: relative;
}

.input-wrapper input,
.input-wrapper select {
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    color: var(--text-main);
    font-size: 0.95rem;
    transition: all 0.2s ease;
}

.input-wrapper input:focus,
.input-wrapper select:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(0, 0, 0, 0.3);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.btn-calculate {
    width: 100%;
    padding: 0.875rem;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
}

.btn-calculate:hover {
    opacity: 0.9;
    transform: scale(1.02);
}

.result-area {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    margin-top: auto;
    border: 1px solid transparent;
}

.result-area.has-result {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.2);
}

.result-label {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.result-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--secondary);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fade-in {
    animation: fadeIn 0.4s ease forwards;
}

/* Responsive */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }

    .sidebar {
        width: 100%;
        height: auto;
        padding: 1rem;
        flex-direction: row;
        overflow-x: auto;
        align-items: center;
        flex-shrink: 0;
    }

    .nav-menu {
        flex-direction: row;
    }

    .nav-item {
        white-space: nowrap;
    }

    .main-content {
        padding: 1rem;
    }
}

/* Data Tables */
.data-table-container {
    margin-top: 1rem;
    max-height: 400px;
    /* Increased for better visibility */
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 100%;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    color: var(--text-main);
}

.data-table th,
.data-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    background: rgba(0, 0, 0, 0.3);
    position: sticky;
    top: 0;
    font-weight: 600;
    color: var(--primary);
}

.data-table tr:hover {
    background: rgba(255, 255, 255, 0.05);
}

.data-table tr:last-child td {
    border-bottom: none;
}

/* Scrollbar for table */
.data-table-container::-webkit-scrollbar {
    width: 6px;
}

.data-table-container::-webkit-scrollbar-track {
    background: transparent;
}

.data-table-container::-webkit-scrollbar-thumb {
    border-radius: 3px;
}

.history-sidebar {
    width: 280px;
    background-color: var(--bg-sidebar);
    border-left: 1px solid var(--border);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    backdrop-filter: blur(10px);
    transition: transform 0.3s ease;
    flex-shrink: 0;
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-main);
    font-weight: 600;
}

.clear-history-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    transition: color 0.3s ease;
}

.clear-history-btn:hover {
    color: #ef4444;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.history-item {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    padding: 0.75rem;
    border: 1px solid transparent;
    transition: all 0.2s ease;
}

.history-item:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--border);
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.history-result {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--secondary);
    text-align: right;
}

/* Scrollbar for history */
.history-list::-webkit-scrollbar {
    width: 6px;
}

.history-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

@media (max-width: 1024px) {
    .history-sidebar {
        position: fixed;
        right: 0;
        top: 0;
        bottom: 0;
        z-index: 2000;
        transform: translateX(100%);
    }

    .history-sidebar.open {
        transform: translateX(0);
    }

    .history-toggle {
        display: block;
    }
}

/* Desktop Calculator Styles */
.desktop-calc-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.desktop-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    padding: 15px;
    border-radius: 8px;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    transition: background 0.2s;
}

.desktop-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.desktop-btn.operator {
    background: rgba(59, 130, 246, 0.3);
    color: #60a5fa;
}

.desktop-btn.equal {
    background: #3b82f6;
    color: white;
    grid-column: span 1;
    grid-row: span 2;
}

.desktop-btn.clear {
    background: #ef4444;
    color: white;
}

.calc-display {
    background: #0f172a;
    color: #22d3ee;
    font-family: 'Courier New', monospace;
    font-size: 2rem;
    padding: 1rem;
    text-align: right;
    border-radius: 8px;
    margin-bottom: 1rem;
    border: 1px solid #334155;
}