/* =================================================
   THIS IS WHERE GLOBAL STYLES & RESET ARE LOCATED
   ================================================= */

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

:root {
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --secondary-color: #8b5cf6;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.4);
    --btn-number: #334155;
    --btn-operator: #6366f1;
    --btn-equals: #10b981;
    --btn-function: #475569;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    transition: all 0.3s ease;
}

body.light-theme {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #cbd5e1;
    --btn-number: #e2e8f0;
    --btn-operator: #6366f1;
    --btn-equals: #10b981;
    --btn-function: #cbd5e1;
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* ==============================================
   THIS IS THE HEADER AREA
   ============================================== */

.app-header {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 25px 30px;
    margin-bottom: 30px;
    box-shadow: var(--shadow);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 15px;
}

.logo i {
    font-size: 2rem;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo h1 {
    font-size: 1.8rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.theme-toggle {
    width: 45px;
    height: 45px;
    border: 2px solid var(--border-color);
    background: var(--bg-tertiary);
    border-radius: 8px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.theme-toggle:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    transform: rotate(15deg);
}

/* =================================================
   THIS IS WHERE THE CALCULATOR CONTAINER IS LOCATED
   ================================================= */

.calculator-container {
    display: grid;
    grid-template-columns: 1fr 350px;
    gap: 30px;
    align-items: start;
}

.calculator {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 30px;
    box-shadow: var(--shadow-lg);
    max-width: 450px;
    margin: 0 auto;
    width: 100%;
}

/* =================================================
   THIS IS WHERE THE DISPLAY IS LOCATED
   ================================================= */

.display-container {
    background: var(--bg-tertiary);
    border-radius: 12px;
    padding: 25px;
    margin-bottom: 20px;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    text-align: right;
    word-wrap: break-word;
    word-break: break-all;
}

.display-previous {
    color: var(--text-secondary);
    font-size: 1.2rem;
    min-height: 30px;
    margin-bottom: 10px;
}

.display-current {
    color: var(--text-primary);
    font-size: 2.5rem;
    font-weight: 600;
    min-height: 50px;
}

/* =================================================
   THIS IS WHERE THE BUTTONS ARE LOCATED
   ================================================= */

.history-toggle {
    margin-bottom: 15px;
}

.history-btn {
    width: 100%;
    padding: 12px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

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

.buttons-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 15px;
}

.btn {
    padding: 25px;
    border: none;
    border-radius: 12px;
    font-size: 1.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.btn:active {
    transform: translateY(0);
}

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

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

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

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

.btn-zero {
    grid-column: span 2;
}

/* =================================================
   THIS IS WHERE THE ADVANCED FUNCTIONS ARE LOCATED
   ================================================= */

.advanced-toggle {
    margin-bottom: 15px;
}

.advanced-btn {
    width: 100%;
    padding: 10px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

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

.advanced-btn.active i {
    transform: rotate(180deg);
}

.advanced-functions {
    display: none;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-top: 10px;
    padding: 15px;
    background: var(--bg-tertiary);
    border-radius: 12px;
}

.advanced-functions.show {
    display: grid;
}

.btn-advanced {
    padding: 15px 10px;
    background: var(--secondary-color);
    color: white;
    font-size: 1rem;
}

/* =================================================
   THIS IS WHERE THE HISTORY PANEL IS LOCATED
   ================================================= */

.history-panel {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 25px;
    box-shadow: var(--shadow-lg);
    max-height: 600px;
    display: flex;
    flex-direction: column;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--border-color);
}

.history-header h3 {
    color: var(--text-primary);
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.history-header i {
    color: var(--primary-color);
}

.clear-history-btn {
    padding: 8px 15px;
    background: var(--danger-color);
    border: none;
    border-radius: 6px;
    color: white;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.clear-history-btn:hover {
    background: #dc2626;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-list::-webkit-scrollbar {
    width: 8px;
}

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

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

.history-empty {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 20px;
}

.history-item {
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    cursor: pointer;
    transition: all 0.3s ease;
    animation: slideIn 0.3s ease;
}

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

.history-item:hover {
    border-color: var(--primary-color);
    transform: translateX(5px);
}

.history-expression {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 5px;
}

.history-result {
    color: var(--text-primary);
    font-size: 1.3rem;
    font-weight: 600;
}

/* =================================================
   THIS IS WHERE THE FOOTER IS LOCATED
   ================================================= */

.app-footer {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 20px 30px;
    margin-top: 30px;
    text-align: center;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.app-footer p {
    color: var(--text-secondary);
}

.app-footer i.fa-heart {
    color: var(--danger-color);
}

.back-link {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.back-link:hover {
    color: var(--secondary-color);
    transform: translateX(-5px);
}

/* =================================================
   THIS IS WHERE RESPONSIVE DESIGN IS LOCATED
   ================================================= */

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

    .history-panel {
        max-height: 400px;
    }
}

@media (max-width: 768px) {
    .calculator {
        padding: 20px;
    }

    .display-current {
        font-size: 2rem;
    }

    .btn {
        padding: 20px;
        font-size: 1.3rem;
    }

    .advanced-functions {
        grid-template-columns: repeat(3, 1fr);
    }

    .app-footer {
        flex-direction: column;
        text-align: center;
    }
}

@media (max-width: 480px) {
    .buttons-grid {
        gap: 8px;
    }

    .btn {
        padding: 18px 10px;
        font-size: 1.2rem;
    }

    .advanced-functions {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    .btn-advanced {
        padding: 12px 8px;
        font-size: 0.9rem;
    }
}
