/* Global Reset and Typography */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #f4f9f6; /* Very subtle green-tinted off-white background */
    color: #1f2937; /* Dark slate text for high readability */
    line-height: 1.5;
    padding: 20px;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
}

/* Header & Controls */
header {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 30px;
    gap: 15px;
}

h1 {
    color: #166534; /* Deep forest green */
    font-size: 2rem;
    font-weight: 700;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    width: 100%;
}

select, input {
    padding: 12px 16px;
    font-size: 15px;
    border-radius: 8px;
    border: 1px solid #d1d5db;
    background-color: white;
    outline: none;
    transition: border-color 0.2s;
}

select:focus, input:focus {
    border-color: #22c55e;
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
}

.primary-select {
    flex-grow: 1;
    min-width: 250px;
    max-width: 400px;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    font-size: 15px;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.primary-btn {
    background-color: #16a34a; /* Vibrant emerald green */
    color: white;
}

.primary-btn:hover {
    background-color: #15803d;
    transform: translateY(-1px);
}

.secondary-btn {
    background-color: #ffffff;
    color: #16a34a;
    border: 2px solid #16a34a;
    padding: 10px 24px; /* Adjust for border width */
}

.secondary-btn:hover {
    background-color: #f0fdf4;
}

.cancel-btn {
    background-color: #f3f4f6;
    color: #4b5563;
}

.cancel-btn:hover {
    background-color: #e5e7eb;
}

/* Stat Cards Grid (Top Row) */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    background: white;
    padding: 24px;
    border-radius: 16px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    text-align: center;
    border-top: 4px solid #22c55e; /* Green accent bar on top */
}

.stat-card h3 {
    font-size: 0.9rem;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: #111827;
    margin-bottom: 4px;
}

.stat-subtext {
    font-size: 0.85rem;
    color: #6b7280;
}

/* Text Colors for positive/negative values */
.text-success { color: #16a34a; }
.text-danger { color: #dc2626; }

/* Chart Area */
.chart-wrapper {
    background: white;
    padding: 24px;
    border-radius: 16px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    margin-bottom: 24px;
    width: 100%;
}

/* Details Grid (Bottom Half) */
.details-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 24px;
    margin-bottom: 24px;
}

.detail-card {
    background: white;
    padding: 24px;
    border-radius: 16px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.detail-card h3 {
    font-size: 1.1rem;
    color: #1f2937;
    margin-bottom: 16px;
    border-bottom: 2px solid #f3f4f6;
    padding-bottom: 10px;
}

/* 52-Week Range Bar */
.range-text {
    display: flex;
    justify-content: space-between;
    font-size: 0.95rem;
    margin-bottom: 8px;
}

progress {
    width: 100%;
    height: 12px;
    border-radius: 6px;
    appearance: none;
    -webkit-appearance: none;
}

progress::-webkit-progress-bar {
    background-color: #e5e7eb;
    border-radius: 6px;
}

progress::-webkit-progress-value {
    background-color: #22c55e;
    border-radius: 6px;
}

.range-subtext {
    text-align: center;
    font-size: 0.85rem;
    color: #6b7280;
    margin-top: 8px;
    font-style: italic;
}

/* Risk Table */
.risk-table {
    width: 100%;
    border-collapse: collapse;
}

.risk-table td {
    padding: 12px 0;
    border-bottom: 1px solid #f3f4f6;
    font-size: 0.95rem;
}

.risk-table tr:last-child td {
    border-bottom: none;
}

.risk-table td:nth-child(2) {
    text-align: right;
    font-weight: 600;
}

.cat-avg {
    text-align: right;
    color: #9ca3af;
    font-size: 0.85rem;
    padding-left: 10px;
}

/* History Table */
.table-wrapper {
    background: white;
    border-radius: 16px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    overflow: hidden; /* Keeps rounded corners on table */
    max-height: 400px;
    overflow-y: auto;
}

#historyTable {
    width: 100%;
    border-collapse: collapse;
}

#historyTable th, #historyTable td {
    padding: 14px 20px;
    text-align: left;
}

#historyTable th {
    background-color: #dcfce7; /* Very light green header */
    color: #166534;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 10;
}

#historyTable td {
    border-bottom: 1px solid #f3f4f6;
}

#historyTable tr:hover {
    background-color: #f8fafc;
}

/* Loading State */
.loading {
    text-align: center;
    padding: 40px;
    color: #16a34a;
    font-weight: 500;
    font-size: 1.1rem;
}

/* Add Fund Modal */
.modal {
    display: none; /* Hidden by default */
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(17, 24, 39, 0.4);
    backdrop-filter: blur(4px);
    z-index: 100;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 16px;
    width: 90%;
    max-width: 450px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    overflow: visible;
}

.modal-content h2 {
    color: #166534;
    margin-bottom: 20px;
}

.input-group {
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: relative;
    z-index: 120;
}

.input-group label {
    font-size: 0.9rem;
    font-weight: 600;
    color: #4b5563;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
}

.search-results-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    width: 100%;
    max-height: 200px;
    overflow-y: auto;
    z-index: 110;
    display: none;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.search-item {
    padding: 10px 15px;
    cursor: pointer;
    font-size: 0.9rem;
    border-bottom: 1px solid #f3f4f6;
}

.search-item:hover {
    background-color: #f0fdf4;
}

.auto-filled-preview {
    background: #f8fafc;
    padding: 15px;
    border-radius: 8px;
    margin-top: 15px;
    font-size: 0.85rem;
    border-left: 4px solid #22c55e;
    position: relative;
    z-index: 1;
}

.delete-fund-btn {
    background-color: #fff1f2;
    color: #dc2626;
    border: 2px solid #fecaca;
    padding: 10px 20px;
}

.delete-fund-btn:hover {
    background-color: #fee2e2;
    border-color: #dc2626;
}

.sort-btn {
    background: none;
    border: 1px solid #86efac;
    border-radius: 4px;
    color: #166534;
    cursor: pointer;
    font-size: 0.75rem;
    padding: 2px 7px;
    margin-left: 6px;
    font-weight: 600;
    vertical-align: middle;
}

.sort-btn:hover {
    background-color: #dcfce7;
}

/* Monthly Dip Tracker */
.dip-tracker-card {
    background: white;
    padding: 24px;
    border-radius: 16px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
    margin-bottom: 24px;
}

.dip-tracker-card > h3 {
    font-size: 1.1rem;
    color: #1f2937;
    margin-bottom: 16px;
    border-bottom: 2px solid #f3f4f6;
    padding-bottom: 10px;
}

.dip-list {
    max-height: 280px;
    overflow-y: auto;
    margin-bottom: 24px;
}

.dip-row {
    display: grid;
    grid-template-columns: 80px 1fr 110px 130px;
    gap: 8px;
    padding: 9px 4px;
    border-bottom: 1px solid #f3f4f6;
    align-items: center;
    font-size: 0.875rem;
}

.dip-row:last-child { border-bottom: none; }

.dip-month {
    font-weight: 700;
    color: #166534;
    white-space: nowrap;
}

.dip-date { color: #374151; }

.dip-nav {
    text-align: right;
    font-weight: 600;
    font-size: 0.85rem;
}

.dip-discount {
    text-align: right;
    color: #16a34a;
    font-size: 0.8rem;
    font-weight: 600;
}

.pattern-section > h4 {
    font-size: 0.8rem;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
}

.pattern-subtitle {
    font-size: 0.75rem;
    color: #9ca3af;
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
}

.pattern-bar-container {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 80px;
}

.pattern-day {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
}

.pattern-bar-inner {
    flex: 1;
    width: 100%;
    display: flex;
    align-items: flex-end;
}

.pattern-bar-fill {
    width: 100%;
    background-color: #16a34a;
    border-radius: 2px 2px 0 0;
}

.pattern-day-label {
    font-size: 0.5rem;
    color: #9ca3af;
    margin-top: 3px;
    line-height: 1;
}

/* Responsive adjustments */
@media (min-width: 768px) {
    header {
        flex-direction: row;
        justify-content: space-between;
    }
    .controls {
        width: auto;
        justify-content: flex-end;
    }
}