/**
 * Amazon Ranker - Main Stylesheet
 * Dark theme design with responsive layout
 */

/* === CSS Variables === */
:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #0f3460;
    --text-primary: #eaeaea;
    --text-secondary: #a0a0a0;
    --accent-primary: #e94560;
    --accent-secondary: #0f4c75;
    --accent-success: #4ade80;
    --accent-warning: #fbbf24;
    --accent-error: #ef4444;
    --border-color: #2d3748;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    --radius: 8px;
    --transition: 0.2s ease;
}

/* === Reset & Base === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* === Layout === */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

.app-header {
    background: var(--bg-secondary);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border-color);
}

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

.app-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-primary);
}

.quota-display {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.quota-value {
    font-weight: 600;
}

.quota-value.green { color: var(--accent-success); }
.quota-value.orange { color: var(--accent-warning); }
.quota-value.red { color: var(--accent-error); }

main {
    padding: 2rem 0;
}

/* === Cards === */
.card {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

/* === Forms === */
.form-group {
    margin-bottom: 1rem;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.375rem;
    color: var(--text-secondary);
}

input[type="text"],
input[type="number"],
input[type="password"],
select,
textarea {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color var(--transition);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

textarea {
    resize: vertical;
    min-height: 80px;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

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

.btn-primary:hover:not(:disabled) {
    background: #d13354;
    transform: translateY(-1px);
}

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

.btn-secondary:hover:not(:disabled) {
    background: #0d3d5f;
}

.btn-icon {
    padding: 0.5rem;
    background: transparent;
    color: var(--text-secondary);
}

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

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* === Toggle Switch === */
.toggle-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.toggle {
    position: relative;
    width: 48px;
    height: 24px;
    background: var(--border-color);
    border-radius: 12px;
    cursor: pointer;
    transition: background var(--transition);
}

.toggle.active {
    background: var(--accent-primary);
}

.toggle::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform var(--transition);
}

.toggle.active::after {
    transform: translateX(24px);
}

.toggle-label {
    font-size: 0.9rem;
    color: var(--text-primary);
}

/* === Collapsible === */
.collapsible-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    padding: 0.5rem 0;
}

.collapsible-header::after {
    content: "\25BC";
    font-size: 0.75rem;
    color: var(--text-secondary);
    transition: transform var(--transition);
}

.collapsible-header.collapsed::after {
    transform: rotate(-90deg);
}

.collapsible-content {
    max-height: 500px;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.collapsible-content.collapsed {
    max-height: 0;
}

/* === Results === */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.results-count {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.product-grid {
    display: grid;
    gap: 1rem;
}

.product-card {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 1rem;
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1rem;
    transition: all var(--transition);
    border-left: 4px solid transparent;
}

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

.product-card.visited {
    border-left-color: var(--accent-success);
}

.product-rank {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.rank-number {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-primary);
    cursor: pointer;
}

.rank-number:hover {
    color: var(--text-primary);
}

.product-card.visited .rank-number {
    color: var(--text-secondary);
}

.visit-badge {
    font-size: 0.75rem;
    color: var(--accent-success);
}

.product-thumbnail {
    width: 80px;
    height: 80px;
    object-fit: contain;
    background: white;
    border-radius: 4px;
}

.product-content {
    min-width: 0;
}

.product-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin-bottom: 0.5rem;
}

.badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    text-transform: uppercase;
}

.badge-prime {
    background: #232f3e;
    color: #00a8e1;
    border: 1px solid #00a8e1;
}

.badge-bestseller {
    background: #ff9900;
    color: #111;
}

.badge-choice {
    background: #002f36;
    color: #ff9900;
    border: 1px solid #ff9900;
}

.badge-climate {
    background: #1a472a;
    color: #4ade80;
    border: 1px solid #4ade80;
}

.product-title {
    font-size: 0.95rem;
    font-weight: 500;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-title a {
    color: inherit;
    text-decoration: none;
}

.product-title a:hover {
    color: var(--accent-primary);
}

.product-metrics {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    font-size: 0.875rem;
}

.metric {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.metric-icon {
    font-size: 1rem;
}

.metric-value {
    font-weight: 600;
}

.metric-label {
    color: var(--text-secondary);
}

.score-value { color: var(--accent-warning); }
.rating-value { color: #fbbf24; }
.reviews-value { color: var(--text-primary); }
.price-value { color: var(--accent-success); }

/* === History Sidebar === */
.history-section {
    margin-top: 2rem;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background: var(--bg-primary);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition);
}

.history-item:hover {
    background: var(--bg-card);
}

.history-query {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.history-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.history-delete {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    cursor: pointer;
}

.history-delete:hover {
    color: var(--accent-error);
}

/* === Modal === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal-overlay.hidden {
    display: none;
}

.modal {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 2rem;
    max-width: 450px;
    width: 100%;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.modal-description {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

/* === Status Messages === */
.status-bar {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.status-bar.info {
    background: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
}

.status-bar.success {
    background: rgba(74, 222, 128, 0.2);
    color: var(--accent-success);
}

.status-bar.warning {
    background: rgba(251, 191, 36, 0.2);
    color: var(--accent-warning);
}

.status-bar.error {
    background: rgba(239, 68, 68, 0.2);
    color: var(--accent-error);
}

.status-bar.hidden {
    display: none;
}

/* === Loading Spinner === */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* === Responsive === */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        align-items: flex-start;
    }

    .product-card {
        grid-template-columns: 1fr;
    }

    .product-rank {
        flex-direction: row;
        justify-content: space-between;
    }

    .product-metrics {
        flex-direction: column;
        gap: 0.5rem;
    }

    .form-row {
        grid-template-columns: 1fr;
    }
}

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

.text-center {
    text-align: center;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
