:root {
    --primary-color: #6366f1;
    --accent-color: #10b981;
    /* Emerald green for positive/action */
    --danger-color: #ef4444;
    --text-color: #f3f4f6;
    --text-muted: #9ca3af;
    --bg-dark: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --border-color: rgba(255, 255, 255, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background: radial-gradient(ellipse at bottom, #1b2735 0%, #090a0f 100%);
    min-height: 100vh;
    overflow: auto;
    /* Allow scroll if needed */
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

/* --- Utilities --- */
.hidden {
    display: none !important;
}

/* --- Login Overlay --- */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.95);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(10px);
}

.login-box {
    max-width: 380px !important;
    text-align: center;
    padding: 3rem !important;
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.login-box h2 {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
    background: linear-gradient(to right, #fff, #a5b4fc);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.login-box p {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 2rem;
}

.login-box input[type="password"] {
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    color: #fff;
    font-size: 1rem;
    transition: all 0.3s ease;
    text-align: center;
    letter-spacing: 2px;
}

.login-box input[type="password"]:focus {
    background: rgba(0, 0, 0, 0.5);
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15);
    transform: translateY(-1px);
}

.remember-me-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin: 1.5rem 0;
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
    user-select: none;
}

/* Custom Checkbox */
.remember-me-container input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    margin: 0;
    cursor: pointer;
    position: relative;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.remember-me-container input[type="checkbox"]:checked {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.remember-me-container input[type="checkbox"]:checked::after {
    content: '✓';
    color: white;
    font-size: 12px;
    font-weight: bold;
}

.remember-me-container:hover input[type="checkbox"] {
    border-color: var(--primary-color);
}

.remember-me-container label {
    cursor: pointer;
    transition: color 0.2s;
}

.remember-me-container:hover label {
    color: #e2e8f0;
}

/* --- Space Background Animation --- */
#stars,
#stars2,
#stars3 {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    pointer-events: none;
}

#stars {
    background-image:
        radial-gradient(1px 1px at 20px 30px, #eee, rgba(0, 0, 0, 0)),
        radial-gradient(1px 1px at 40px 70px, #fff, rgba(0, 0, 0, 0)),
        radial-gradient(1px 1px at 50px 160px, #ddd, rgba(0, 0, 0, 0)),
        radial-gradient(1px 1px at 90px 40px, #fff, rgba(0, 0, 0, 0)),
        radial-gradient(1px 1px at 130px 80px, #fff, rgba(0, 0, 0, 0));
    background-repeat: repeat;
    background-size: 200px 200px;
    opacity: 0.3;
    animation: zoom 100s infinite;
}

#stars2 {
    background-image:
        radial-gradient(2px 2px at 50px 100px, #fff, rgba(0, 0, 0, 0)),
        radial-gradient(2px 2px at 150px 20px, #ddd, rgba(0, 0, 0, 0));
    background-repeat: repeat;
    background-size: 300px 300px;
    opacity: 0.2;
    animation: zoom 150s infinite;
}

@keyframes zoom {
    0% {
        transform: scale(1);
    }

    100% {
        transform: scale(1.5);
    }
}

/* --- Navbar --- */
.navbar {
    width: 100%;
    padding: 1rem 2rem;
    position: absolute;
    top: 0;
    z-index: 10;
    pointer-events: none;
    display: flex;
    justify-content: flex-end;
    /* Align to right */
    align-items: center;
    max-width: 1200px;
    left: 50%;
    transform: translateX(-50%);
}

.stock-display {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    background: rgba(30, 41, 59, 0.8);
    padding: 0.75rem 1.25rem;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

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

.stock-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.stock-divider {
    width: 1px;
    height: 24px;
    background: rgba(255, 255, 255, 0.1);
}

.stock-icon {
    width: 28px;
    height: 28px;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.stock-value {
    color: #fff;
    font-weight: 700;
    font-size: 1.1rem;
    font-variant-numeric: tabular-nums;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-left: 1.5rem;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
}

.add-stock-btn,
.logout-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.add-stock-btn {
    background: var(--primary-color);
    color: white;
    font-size: 1.2rem;
    line-height: 1;
}

.add-stock-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.logout-btn {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger-color);
}

.logout-btn:hover {
    background: var(--danger-color);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.navbar .logo {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 1px;
    background: linear-gradient(to right, #fff, #a5b4fc);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
    pointer-events: auto;
}

/* --- Main Container --- */
.main-container {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 6rem 1rem 2rem 1rem;
    width: 100%;
    gap: 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

/* --- Main Container --- */
.main-container {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 7rem 1rem 2rem 1rem;
    /* Increased top padding */
    width: 100%;
    gap: 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

/* --- Glass Card --- */
.glass-card {
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 2.5rem;
    width: 100%;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.calculator-section {
    flex: 1;
    max-width: 480px;
}

.history-section {
    flex: 1;
    max-width: 480px;
    height: fit-content;
    max-height: 800px;
    /* Limit height if list gets long */
}

.glass-card:hover {
    transform: translateY(-5px);
    border-color: rgba(255, 255, 255, 0.2);
}

.card-header {
    text-align: center;
    margin-bottom: 2rem;
}

.card-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.card-header p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

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

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

.split-inputs {
    display: flex;
    gap: 1rem;
}

.input-wrapper {
    flex: 1;
}

.label-text {
    display: block;
    font-size: 0.75rem;
    color: #cbd5e1;
    margin-bottom: 0.25rem;
}

input[type="number"],
input[type="text"] {
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.85rem 1rem;
    color: #fff;
    font-size: 1rem;
    transition: all 0.2s;
    outline: none;
}

input[type="number"]:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
    background: rgba(0, 0, 0, 0.3);
}

/* --- Radio Selection --- */
.selection-group {
    margin-bottom: 1.5rem;
}

.selection-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.radio-group {
    display: flex;
    gap: 1.5rem;
    background: rgba(0, 0, 0, 0.2);
    padding: 0.75rem;
    border-radius: 12px;
}

.radio-container {
    display: flex;
    align-items: center;
    position: relative;
    padding-left: 30px;
    cursor: pointer;
    font-size: 0.95rem;
    user-select: none;
    color: var(--text-color);
}

.radio-container input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
}

.checkmark {
    position: absolute;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    height: 20px;
    width: 20px;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border: 1px solid var(--border-color);
    transition: all 0.2s;
}

.radio-container:hover input~.checkmark {
    background-color: rgba(255, 255, 255, 0.2);
}

.radio-container input:checked~.checkmark {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

.checkmark:after {
    content: "";
    position: absolute;
    display: none;
}

.radio-container input:checked~.checkmark:after {
    display: block;
}

.radio-container .checkmark:after {
    top: 6px;
    left: 6px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: white;
}


/* --- Result Boxes --- */
.result-box {
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 12px;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.result-box span {
    font-size: 0.9rem;
    color: #c7d2fe;
}

.result-box .value {
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
}

.divider {
    border: none;
    height: 1px;
    background: linear-gradient(to right, transparent, rgba(255, 255, 255, 0.1), transparent);
    margin: 1.5rem 0;
}

/* --- Results Grid --- */
.results-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.result-item {
    background: rgba(0, 0, 0, 0.2);
    padding: 1rem;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    text-align: center;
    border: 1px solid transparent;
}

.result-item.highlight {
    grid-column: span 2;
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.3);
}

.result-item span {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.result-item strong {
    font-size: 1.1rem;
    color: #fff;
}

.text-danger {
    color: #fca5a5 !important;
}

.text-success {
    color: #6ee7b7 !important;
}

/* --- Buttons --- */
.btn-primary {
    width: 100%;
    margin-top: 1.5rem;
    padding: 1rem;
    border-radius: 12px;
    border: none;
    background: linear-gradient(135deg, var(--primary-color), #818cf8);
    color: white;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
    transition: all 0.2s;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.5);
}

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

.btn-danger-outline {
    width: 100%;
    margin-top: 1rem;
    padding: 0.75rem;
    border-radius: 12px;
    border: 1px solid rgba(239, 68, 68, 0.3);
    background: transparent;
    color: var(--danger-color);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-danger-outline:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--danger-color);
}

/* --- History Styles --- */
.history-summary {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.summary-row {
    display: flex;
    gap: 0.75rem;
}

.summary-row.full-width .summary-item {
    width: 100%;
}

.summary-item {
    flex: 1;
    background: rgba(0, 0, 0, 0.2);
    padding: 1rem;
    border-radius: 12px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.history-list {
    flex-grow: 1;
    overflow-y: auto;
    max-height: 400px;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding-right: 0.5rem;
}

/* Custom Scrollbar */
.history-list::-webkit-scrollbar {
    width: 6px;
}

.history-list::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

.history-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

.history-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 1rem;
    position: relative;
    transition: all 0.2s;
}

.history-item:hover {
    background: rgba(255, 255, 255, 0.07);
    transform: translateX(2px);
}

.delete-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    padding: 2px;
    border-radius: 4px;
}

.delete-btn:hover {
    color: var(--danger-color);
    background: rgba(239, 68, 68, 0.1);
}

.history-details {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    margin-top: 0.5rem;
    color: var(--text-muted);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    padding-right: 1.5rem;
    /* Space for delete button */
}

.history-profit {
    font-weight: 700;
    font-size: 1rem;
}

.history-date {
    font-size: 0.7rem;
    color: var(--text-muted);
    opacity: 0.7;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
    padding: 2rem 0;
}

/* --- Modals --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.95);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(10px);
}

.modal-box {
    max-width: 400px;
    width: 90%;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.close-modal {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
}

.close-modal:hover {
    color: #fff;
}