/* Modern CSS Reset & Variable Definitions */
:root {
    --bg-gradient-start: #020617;
    --bg-gradient-end: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.45);
    --card-border: rgba(255, 255, 255, 0.06);
    --card-shadow: 0 20px 40px -15px rgba(0, 0, 0, 0.7);
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #10b981;
    
    --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

/* Custom Scrollbar for Chrome/Safari/Edge */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 9999px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

body {
    font-family: var(--font-sans);
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    line-height: 1.5;
}

/* Utility Helper Classes */
.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Header Styling */
.app-header {
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--card-border);
    position: sticky;
    top: 0;
    z-index: 50;
    padding: 1rem 0;
}

.header-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    color: var(--primary);
    background: rgba(99, 102, 241, 0.15);
    padding: 0.5rem;
    border-radius: 12px;
    border: 1px solid rgba(99, 102, 241, 0.3);
    animation: pulse 2s infinite alternate;
}

@keyframes pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.4); }
    100% { transform: scale(1.05); box-shadow: 0 0 12px 2px rgba(99, 102, 241, 0.2); }
}

.main-title {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    background: linear-gradient(to right, #fff, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    font-size: 0.825rem;
    color: var(--text-secondary);
}

/* Dashboard Grid Layout */
.dashboard-grid {
    flex: 1;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    padding: 2.5rem 2rem;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 2.5rem;
    align-content: start;
}

.loading-state {
    grid-column: span 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8rem 0;
    color: var(--text-secondary);
    gap: 1.5rem;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(255, 255, 255, 0.05);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s infinite linear;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* User Card Glassmorphism Card Style */
.user-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    box-shadow: var(--card-shadow);
    border-radius: 24px;
    padding: 1.75rem;
    display: flex;
    flex-direction: row;
    gap: 1.75rem;
    overflow: hidden;
    position: relative;
    transition: transform var(--transition-normal), border-color var(--transition-normal);
}

.user-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--accent-color);
}

.user-card:hover {
    transform: translateY(-4px);
    border-color: rgba(255, 255, 255, 0.12);
}

/* Card - Left Side (Controls & Entries) */
.card-left {
    flex: 1 1 42%;
    min-width: 290px;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

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

.user-identity {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-size: 1.35rem;
    font-weight: 600;
    color: var(--text-primary);
}

.user-badges {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.25rem;
    flex-wrap: wrap;
}

.badge {
    font-size: 0.725rem;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-weight: 500;
}

.badge-outline {
    border: 1px solid var(--text-muted);
    color: var(--text-secondary);
}

.badge-accent {
    background: var(--accent-color-glow);
    color: var(--accent-color);
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.user-stats {
    text-align: right;
    display: flex;
    flex-direction: column;
}

.stat-val {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-color);
    text-shadow: 0 0 10px var(--accent-color-glow);
}

.stat-label {
    font-size: 0.725rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    background: rgba(15, 23, 42, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.03);
    border-radius: 16px;
    padding: 0.75rem;
    text-align: center;
    gap: 0.5rem;
}

.grid-stat {
    display: flex;
    flex-direction: column;
}

.grid-stat-num {
    font-size: 1rem;
    font-weight: 600;
}

.grid-stat-num.loss {
    color: var(--success);
}
.grid-stat-num.gain {
    color: var(--danger);
}

.grid-stat-lbl {
    font-size: 0.675rem;
    color: var(--text-muted);
}

/* Weight Entry Form styling */
.weight-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: rgba(255, 255, 255, 0.02);
    padding: 1rem;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.form-inline-fields {
    display: flex;
    gap: 0.5rem;
}

.form-field {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.form-field label {
    font-size: 0.725rem;
    color: var(--text-secondary);
    font-weight: 500;
}

input[type="text"],
input[type="number"],
input[type="date"],
select {
    width: 100%;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    padding: 0.5rem 0.75rem;
    border-radius: 10px;
    font-family: var(--font-sans);
    font-size: 0.875rem;
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

input:focus, select:focus {
    border-color: var(--accent-color, var(--primary));
    box-shadow: 0 0 0 3px var(--accent-color-glow, rgba(99, 102, 241, 0.15));
}

.btn {
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 600;
    padding: 0.5rem 1.25rem;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: center;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.4);
}

.btn-accent {
    background: var(--accent-color);
    color: #fff;
}
.btn-accent:hover {
    filter: brightness(1.1);
    box-shadow: 0 0 15px var(--accent-color-glow);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.05);
}
.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
}

.btn-icon {
    padding: 0.35rem;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
}
.btn-icon:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

.btn-submit-weight {
    margin-top: 0.25rem;
}

/* History Collapsible Section */
.history-section {
    display: flex;
    flex-direction: column;
}

.history-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 0.825rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0.25rem 0;
    transition: color var(--transition-fast);
}

.history-toggle:hover {
    color: var(--text-primary);
}

.history-toggle svg {
    transition: transform var(--transition-normal);
}

.history-toggle.active svg {
    transform: rotate(180deg);
}

.history-table-container {
    max-height: 0;
    overflow-y: auto;
    transition: max-height var(--transition-normal) ease-out, margin-top var(--transition-fast);
}

.history-table-container.open {
    max-height: 180px; /* limits table height, scrolls if longer */
    margin-top: 0.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.775rem;
    text-align: left;
}

.history-table th {
    color: var(--text-muted);
    font-weight: 500;
    padding: 0.5rem 0.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.history-table td {
    padding: 0.45rem 0.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    color: var(--text-secondary);
}

.history-table tr:hover td {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.01);
}

/* Card - Right Side (Chart) */
.card-right {
    flex: 1 1 58%;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 250px;
    position: relative;
    background: rgba(15, 23, 42, 0.2);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.02);
    padding: 0.5rem;
}

.chart-container {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 230px;
}

/* Modal Styling */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(2, 6, 17, 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-normal);
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.8);
    border-radius: 28px;
    width: 90%;
    max-width: 650px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    transform: scale(0.95);
    transition: transform var(--transition-normal);
}

.modal-overlay.open .modal-content {
    transform: scale(1);
}

.modal-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 1.35rem;
    font-weight: 600;
}

.modal-close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.75rem;
    cursor: pointer;
    transition: color var(--transition-fast);
    line-height: 1;
}

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

.modal-body {
    padding: 2rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.75rem;
}

.form-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-section h3 {
    font-size: 0.95rem;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid rgba(99, 102, 241, 0.15);
    padding-bottom: 0.35rem;
}

.form-row.split-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.user-setting-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 50px;
    gap: 0.75rem;
    align-items: end;
    background: rgba(255, 255, 255, 0.01);
    padding: 0.75rem;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.03);
    margin-bottom: 0.75rem;
}

.user-setting-row:last-child {
    margin-bottom: 0;
}

.color-input-wrapper {
    position: relative;
    width: 100%;
    height: 38px;
}

.color-input-wrapper input[type="color"] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.color-preview-btn {
    width: 100%;
    height: 100%;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: border-color var(--transition-fast);
}

.modal-footer {
    padding: 1.25rem 2rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    z-index: 200;
}

.toast {
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-left: 4px solid var(--primary);
    backdrop-filter: blur(12px);
    border-radius: 12px;
    padding: 0.85rem 1.25rem;
    color: var(--text-primary);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    font-size: 0.875rem;
    min-width: 250px;
    max-width: 400px;
    animation: slideIn 0.3s ease-out forwards;
}

.toast.success {
    border-left-color: var(--success);
}

.toast.error {
    border-left-color: var(--danger);
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.toast.fade-out {
    animation: fadeOut 0.3s ease-out forwards;
}

@keyframes fadeOut {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(100%); opacity: 0; }
}

/* Footer Styling */
.app-footer {
    background: rgba(2, 6, 17, 0.4);
    border-top: 1px solid var(--card-border);
    padding: 1.5rem 0;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Responsive Breakpoints */
@media (max-width: 1200px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
        padding: 2rem;
        gap: 2rem;
    }
}

@media (max-width: 768px) {
    .header-container {
        padding: 0 1rem;
    }
    
    .dashboard-grid {
        padding: 1rem;
        gap: 1.5rem;
    }
    
    .user-card {
        flex-direction: column;
        gap: 1.5rem;
        padding: 1.25rem;
    }
    
    .card-left {
        max-width: 100%;
        flex: 1 1 auto;
    }
    
    .card-right {
        min-height: 220px;
        flex: 1 1 auto;
    }
    
    .user-setting-row {
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
    }
    .user-setting-row .form-field:nth-child(1) {
        grid-column: span 2;
    }
    
    .modal-content {
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }
}

/* Custom Input Styling (remove spin buttons and fix calendar indicator) */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
}

/* Style calendar picker button for dark mode visibility */
input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(0.9) sepia(0.2) saturate(1) hue-rotate(200deg);
    cursor: pointer;
    opacity: 0.6;
    transition: opacity var(--transition-fast);
}

input[type="date"]::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
}
