/* --- 1. THEME VARIABLES --- */
:root {
    --bg-color: #f4f4f4;
    --surface-color: #ffffff;
    --text-color: #333333;
    --text-muted-color: #666666;
    --primary-color: #0275d8;
    --border-color: #dddddd;
    --input-bg-color: #ffffff;
    --header-bg-color: #f7f7f7;
    --danger-color: #d9534f;
    --danger-text-color: #d9534f;
    --filtered-text-color-light: #e67e22; /* Orange text */
}

body.dark-mode {
    --bg-color: #212529;
    --surface-color: #343a40;
    --text-color: #f8f9fa;
    --text-muted-color: #adb5bd;
    --primary-color: #58a6ff;
    --border-color: #495057;
    --input-bg-color: #495057;
    --header-bg-color: #212529;
    --danger-color: #dc3545;
    --danger-text-color: #dc3545;
    --filtered-text-color-dark: #f0c419; /* Yellowish orange text */
}

/* --- 2. GENERAL STYLES (using variables) --- */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    margin: 0;
    padding: 2rem 0;
    transition: background-color 0.3s, color 0.3s;
}

.container {
    width: 90%;
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem;
    background: var(--surface-color);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.15);
    transition: background-color 0.3s, border-color 0.3s;
    box-sizing: border-box;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 15px;
    margin-bottom: 15px;
}

h1 { font-size: 1.75rem; margin: 0; }
h2 { font-size: 1.25rem; }
h1, h2 { color: var(--primary-color); }

input[type="text"],
input[type="number"] {
    background-color: var(--input-bg-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 8px;
    font-size: 1em;
    transition: background-color 0.3s, border-color 0.3s, color 0.3s;
}


/* --- 3. COMPONENT STYLES --- */
.totals, .silver-price, .search-container, .coin-list, .coin-format-explanation {
    margin-bottom: 25px;
}

.totals.filtered-active {
    border-color: var(--filtered-text-color-light);
}
body.dark-mode .totals.filtered-active {
    border-color: var(--filtered-text-color-dark);
}

.filtered-text {
    font-size: 0.9em;
    font-weight: bold;
    color: var(--filtered-text-color-light);
    margin-left: 5px;
    transition: color 0.3s;
}
body.dark-mode .filtered-text {
    color: var(--filtered-text-color-dark);
}

.silver-price .price-input-group {
    margin-bottom: 10px; 
    display: flex; 
    align-items: center;
    flex-wrap: wrap; /* Allow items to wrap to the next line */
}
.silver-price label { 
    margin-right: 10px; 
    flex-basis: auto; /* Allow label to shrink */
    white-space: nowrap; /* Prevent label text from breaking too early */
}
.silver-price .price-input-group input {
    flex-grow: 1; /* Allow input to take up available space */
    max-width: 200px; /* Prevent inputs from becoming too wide on large screens */
    min-width: 100px; /* Ensure a minimum width */
    box-sizing: border-box; /* Include padding/border in width calculation */
}

@media (max-width: 480px) {
    .silver-price .price-input-group {
        flex-direction: column; /* Stack label and input vertically */
        align-items: flex-start; /* Align stacked items to the left */
    }
    .silver-price label {
        margin-right: 0;
        margin-bottom: 5px; /* Add space below label */
        min-width: unset; /* Remove min-width on very small screens */
    }
    .silver-price .price-input-group input {
        width: 100%; /* Make input full width when stacked */
        max-width: unset;
    }
    .container {
        padding: 1rem; /* Reduce padding on container for small screens */
    }
    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.1rem; }
}


.clear-button {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%; padding: 10px; margin-top: 15px; font-size: 1em; font-weight: bold;
    color: var(--danger-text-color); background-color: transparent;
    border: 1px solid var(--danger-color); border-radius: 5px; cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
}
.clear-button:hover { background-color: var(--danger-color); color: #fff; }

.search-container {
    margin-bottom: 25px;
    position: relative;
}

#search-input {
    width: 100%; padding: 12px; font-size: 1.1em; box-sizing: border-box;
    padding-right: 40px;
}

.clear-search-button {
    position: absolute;
    right: 10px; top: 50%; transform: translateY(-50%);
    background: none; border: none;
    color: var(--text-muted-color);
    font-size: 1.5em; cursor: pointer; padding: 0 5px; transition: color 0.2s;
    line-height: 1; height: 1.5em; width: 1.5em;
    display: flex; align-items: center; justify-content: center;
}
.clear-search-button:hover { color: var(--primary-color); }

.country-group { border: 1px solid var(--border-color); border-radius: 5px; margin-bottom: 15px; }
.country-title {
    font-size: 1.5em; font-weight: bold; padding: 15px; cursor: pointer;
    background-color: var(--header-bg-color); color: var(--primary-color);
    list-style: none; transition: background-color 0.3s;
}
.country-group[open] .country-title { border-bottom: 1px solid var(--border-color); }
.country-title::-webkit-details-marker { display: none; }
.country-title::before { content: '▶'; margin-right: 10px; font-size: 0.8em; display: inline-block; transition: transform 0.2s; }
.country-group[open] > summary::before { transform: rotate(90deg); }

.coin-item {
    display: flex; justify-content: space-between; align-items: center; padding: 10px 15px;
    border-bottom: 1px solid var(--border-color);
}
.coin-item:last-child { border-bottom: none; }
.coin-item > *:first-child { flex-grow: 1; margin-right: 10px; }
.coin-item input.coin-quantity {
    width: 60px;
    padding: 5px;
    text-align: center;
    background-color: var(--input-bg-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}
.coin-subtotal { font-weight: bold; min-width: 80px; text-align: right; color: var(--text-muted-color); }

.coin-name-link {
    color: var(--text-color);
    text-decoration: none;
    font-weight: bold;
    transition: color 0.2s;
}
.coin-name-link:hover {
    text-decoration: underline;
    color: var(--primary-color);
}


/* --- 4. THEME TOGGLE SWITCH STYLES --- */
.theme-switch-wrapper { display: flex; align-items: center; }
.theme-switch { position: relative; display: inline-block; width: 50px; height: 26px; }
.theme-switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc; transition: .4s; border-radius: 26px;
    display: flex; align-items: center; justify-content: space-between; padding: 0 5px;
}
.slider:before {
    position: absolute; content: ""; height: 18px; width: 18px; left: 4px; bottom: 4px;
    background-color: white; transition: .4s; border-radius: 50%; z-index: 2;
}
.slider svg { height: 14px; width: 14px; z-index: 1; }
.slider .sun-icon { color: #f39c12; }
.slider .moon-icon { color: #f1c40f; }
input:checked + .slider { background-color: var(--primary-color); }
input:checked + .slider:before { transform: translateX(24px); }

/* --- 5. FOOTER STYLES --- */
.app-footer {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
    text-align: center;
    font-size: 0.85em;
    color: var(--text-muted-color);
}

.app-footer p { margin-bottom: 1rem; }

.github-link {
    display: inline-flex; align-items: center; gap: 8px;
    text-decoration: none; color: var(--text-muted-color);
    transition: color 0.2s;
}
.github-link:hover { color: var(--primary-color); }