import SwiftUI

extension Color {
    // MARK: - Canvas / Background (adaptive light/dark)
    static let canvas = Color(UIColor { traits in
        traits.userInterfaceStyle == .dark
            ? UIColor(red: 0.10, green: 0.09, blue: 0.08, alpha: 1) // warm dark
            : UIColor(red: 0.96, green: 0.94, blue: 0.90, alpha: 1) // #F5EFE6
    })

    // MARK: - Accent
    static let accentWarm = Color(UIColor { traits in
        traits.userInterfaceStyle == .dark
            ? UIColor(red: 0.78, green: 0.62, blue: 0.25, alpha: 1) // brighter gold for dark
            : UIColor(red: 0.545, green: 0.412, blue: 0.078, alpha: 1) // #8B6914
    })
    static let emerald = Color(red: 0.020, green: 0.588, blue: 0.412) // #059669

    // MARK: - Surfaces (adaptive)
    static let surfaceCard = Color(UIColor { traits in
        traits.userInterfaceStyle == .dark
            ? UIColor(red: 0.15, green: 0.14, blue: 0.13, alpha: 1) // warm dark card
            : UIColor(red: 1.0, green: 0.988, blue: 0.973, alpha: 1) // warm white
    })
    static let surfaceSheet = Color(UIColor { traits in
        traits.userInterfaceStyle == .dark
            ? UIColor(red: 0.13, green: 0.12, blue: 0.11, alpha: 1)
            : UIColor(red: 0.98, green: 0.97, blue: 0.95, alpha: 1)
    })

    // MARK: - Text (adaptive)
    static let textPrimary = Color(UIColor { traits in
        traits.userInterfaceStyle == .dark
            ? UIColor(red: 0.93, green: 0.91, blue: 0.88, alpha: 1)
            : UIColor(red: 0.12, green: 0.12, blue: 0.12, alpha: 1)
    })
    static let textSecondary = Color(UIColor { traits in
        traits.userInterfaceStyle == .dark
            ? UIColor(red: 0.62, green: 0.60, blue: 0.57, alpha: 1)
            : UIColor(red: 0.45, green: 0.45, blue: 0.45, alpha: 1)
    })
    static let textTertiary = Color(UIColor { traits in
        traits.userInterfaceStyle == .dark
            ? UIColor(red: 0.45, green: 0.43, blue: 0.40, alpha: 1)
            : UIColor(red: 0.65, green: 0.65, blue: 0.65, alpha: 1)
    })

    // MARK: - Meal Colors
    static let mealBreakfast = Color(red: 1.0, green: 0.72, blue: 0.27)   // warm orange
    static let mealLunch = Color(red: 0.30, green: 0.69, blue: 0.31)      // green
    static let mealDinner = Color(red: 0.40, green: 0.35, blue: 0.80)     // purple
    static let mealSnack = Color(red: 0.93, green: 0.46, blue: 0.46)      // coral

    // MARK: - Macros
    static let macroProtein = Color(red: 0.35, green: 0.56, blue: 0.91)   // blue
    static let macroCarbs = Color(red: 0.96, green: 0.65, blue: 0.14)     // amber
    static let macroFat = Color(red: 0.85, green: 0.35, blue: 0.45)       // pink-red

    static func mealColor(for mealType: String) -> Color {
        switch mealType.lowercased() {
        case "breakfast": return .mealBreakfast
        case "lunch": return .mealLunch
        case "dinner": return .mealDinner
        case "snack": return .mealSnack
        default: return .accentWarm
        }
    }
}
